Exercises tensorflow's C API.
| 47 | |
| 48 | // Exercises tensorflow's C API. |
| 49 | int 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 | } |
nothing calls this directly
no test coverage detected