Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/CUDApp/blob/main/tests/zero_cuda_tool_stub.c # CUDApp CUDA++: AIEN’s GPU machine-code toolchain, runtime and driver client for NVIDIA GPUs without the CUDA toolkit. Hardware coverage and driver replacement limits are explicit. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `CUDApp / tests / zero_cuda_tool_stub.c` 69 lines · 1955 bytes Raw Blame History 1 /* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */ 2 /* Stand-in for ldd and nm. The zero-CUDA argv test copies this binary onto PATH 3 * under both names. It records argv and prints a CUDA line only when the named 4 * file itself contains a marker. It does not run a shell. */ 5 #include "omega_path_check.h" 6 7 #include 8 #include 9 #include 10 #include 11 #include 12 13 static const char *base_name(const char *path) { 14 const char *slash = strrchr(path, '/'); 15 return slash ? slash + 1 : path; 16 } 17 18 static void record_argv(int argc, char **argv) { 19 const char *env = getenv("ZERO_CUDA_ARGV_LOG"); 20 char log_path[4096]; 21 int fd; 22 FILE *log; 23 int i; 24 25 if (omega_path_copy(log_path, sizeof log_path, env) != 0) return; 26 fd = open(log_path, O_WRONLY | O_CREAT | O_APPEND | O_CLOEXEC | O_NOFOLLOW, 0600); 27 if (fd < 0) return; 28 log = fdopen(fd, "a"); 29 if (!log) { 30 close(fd); 31 return; 32 } 33 fprintf(log, "argc %d\n", argc); 34 for (i = 0; i < argc; i++) { 35 size_t n = strlen(argv[i]); 36 fprintf(log, "arg %d %zu\n", i, n); 37 fwrite(argv[i], 1, n, log); 38 fputc('\n', log); 39 } 40 fclose(log); 41 } 42 43 int main(int argc, char **argv) { 44 const char *tool = base_name(argv[0]); 45 const char *path = NULL; 46 FILE *f; 47 char buf[4096]; 48 size_t n; 49 50 record_argv(argc, argv); 51 if (strcmp(tool, "nm") == 0) { 52 if (argc >= 3) path = argv[2]; 53 } else if (argc >= 2) { 54 path = argv[1]; 55 } 56 if (!path) return 0; 57 f = fopen(path, "rb"); 58 if (!f) return 0; 59 n = fread(buf, 1, sizeof(buf) - 1, f); 60 fclose(f); 61 buf[n] = '\0'; 62 if (strcmp(tool, "ldd") == 0 && strstr(buf, "LIBCUDA_NEEDED")) { 63 printf("\tlibcuda.so.1 => /tmp/libcuda.so.1 (0x0000)\n"); 64 } 65 if (strcmp(tool, "nm") == 0 && strstr(buf, "CU_SYMBOL")) { 66 printf(" U cuInit\n"); 67 } 68 return 0; 69 }