MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / main

Function main

tensorflow/c/c_test.c:49–93  ·  view source on GitHub ↗

Exercises tensorflow's C API.

Source from the content-addressed store, hash-verified

47
48// Exercises tensorflow's C API.
49int main(int argc, char** argv) {
50 TF_InitMain(argv[0], &argc, &argv);
51
52 struct TF_StringStream* s = TF_GetLocalTempDirectories();
53 const char* path;
54
55 if (!TF_StringStreamNext(s, &path)) {
56 fprintf(stderr, "TF_GetLocalTempDirectories returned no results\n");
57 return 1;
58 }
59
60 char file_name[100];
61 struct timeval t;
62 if (gettimeofday(&t, NULL)) {
63 perror("gettimeofday failed");
64 return 1;
65 }
66 snprintf(file_name, sizeof(file_name), "test-%d-%ld.txt", getpid(), t.tv_sec);
67
68 size_t length = 2 + strlen(path) + strlen(file_name);
69 char* full_path = malloc(length);
70 snprintf(full_path, length, "%s/%s", path, file_name);
71
72 TF_WritableFileHandle* h;
73 TF_Status* status = TF_NewStatus();
74 TF_NewWritableFile(full_path, &h, status);
75 if (TF_GetCode(status) != TF_OK) {
76 fprintf(stderr, "TF_NewWritableFile failed: %s\n", TF_Message(status));
77 return 1;
78 }
79 fprintf(stderr, "wrote %s\n", full_path);
80 free(full_path);
81 TF_CloseWritableFile(h, status);
82 if (TF_GetCode(status) != TF_OK) {
83 fprintf(stderr, "TF_CloseWritableFile failed: %s\n", TF_Message(status));
84 }
85 TF_StringStreamDone(s);
86
87 TF_KernelBuilder* b =
88 TF_NewKernelBuilder("SomeOp", "SomeDevice", &create, &compute, NULL);
89 TF_RegisterKernelBuilder("someKernel", b, status);
90
91 TF_DeleteStatus(status);
92 return 0;
93}

Callers

nothing calls this directly

Calls 12

TF_InitMainFunction · 0.85
TF_StringStreamNextFunction · 0.85
TF_NewStatusFunction · 0.85
TF_NewWritableFileFunction · 0.85
TF_GetCodeFunction · 0.85
TF_MessageFunction · 0.85
TF_CloseWritableFileFunction · 0.85
TF_StringStreamDoneFunction · 0.85
TF_NewKernelBuilderFunction · 0.85
TF_RegisterKernelBuilderFunction · 0.85
TF_DeleteStatusFunction · 0.85

Tested by

no test coverage detected