|
4 | 4 | #include "dlpack/dlpack.h" |
5 | 5 |
|
6 | 6 | int main() { |
7 | | - printf("Hello from libTorch C library version %s\n", "1.0"); |
8 | | - torchBasicTest(); |
| 7 | + printf("Hello from libTorch C library version %s\n", "1.0"); |
| 8 | + torchBasicTest(); |
9 | 9 |
|
10 | | - void* ctx; |
11 | | - char *err = NULL; |
| 10 | + void *ctx; |
| 11 | + char *err = NULL; |
12 | 12 |
|
13 | | - const char script[] = "\n\ |
| 13 | + const char script[] = "\n\ |
14 | 14 | def foo(a): \n\ |
15 | 15 | return a * 2 \n\ |
16 | 16 | "; |
17 | 17 |
|
18 | | - ctx = torchCompileScript(script, kDLCPU, &err); |
19 | | - if (err) { |
20 | | - printf("ERR: %s\n", err); |
21 | | - free(err); |
22 | | - err = NULL; |
23 | | - return 1; |
24 | | - } |
25 | | - printf("Compiled: %p\n", ctx); |
| 18 | + ctx = torchCompileScript(script, kDLCPU, &err); |
| 19 | + if (err) { |
| 20 | + printf("ERR: %s\n", err); |
| 21 | + free(err); |
| 22 | + err = NULL; |
| 23 | + return 1; |
| 24 | + } |
| 25 | + printf("Compiled: %p\n", ctx); |
26 | 26 |
|
27 | | - DLDataType dtype = (DLDataType){ .code = kDLFloat, .bits = 32, .lanes = 1}; |
28 | | - int64_t shape[1] = {1}; |
29 | | - int64_t strides[1] = {1}; |
30 | | - char data[4] = "0000"; |
31 | | - DLManagedTensor* input = torchNewTensor(dtype, 1, shape, strides, data); |
32 | | - DLManagedTensor* output; |
33 | | - torchRunScript(ctx, "foo", 1, &input, 1, &output, &err); |
34 | | - if (err) { |
35 | | - printf("ERR: %s\n", err); |
36 | | - free(err); |
37 | | - return 1; |
38 | | - } |
| 27 | + DLDataType dtype = (DLDataType){.code = kDLFloat, .bits = 32, .lanes = 1}; |
| 28 | + int64_t shape[1] = {1}; |
| 29 | + int64_t strides[1] = {1}; |
| 30 | + char data[4] = "0000"; |
| 31 | + DLManagedTensor *input = torchNewTensor(dtype, 1, shape, strides, data); |
| 32 | + DLManagedTensor *output; |
| 33 | + torchRunScript(ctx, "foo", 1, &input, 1, &output, &err); |
| 34 | + if (err) { |
| 35 | + printf("ERR: %s\n", err); |
| 36 | + free(err); |
| 37 | + return 1; |
| 38 | + } |
39 | 39 |
|
40 | | - torchDeallocContext(ctx); |
41 | | - printf("Deallocated\n"); |
| 40 | + torchDeallocContext(ctx); |
| 41 | + printf("Deallocated\n"); |
42 | 42 |
|
43 | | - return 0; |
| 43 | + return 0; |
44 | 44 | } |
0 commit comments