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/evidence/tools-om-2/2026-11-06/coverage/cudapp_doctor.c.gcov # 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 / evidence / tools-om-2 / 2026-11-06 / coverage / cudapp_doctor.c.gcov` 474 lines · 23660 bytes Raw Blame History 1 -: 0:Source:cudapp_doctor.c 2 -: 0:Graph:doc_cov-cudapp_doctor.gcno 3 -: 0:Data:doc_cov-cudapp_doctor.gcda 4 -: 0:Runs:40 5 -: 1:/* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */ 6 -: 2:/* cudapp-doctor: is this machine ready for CUDA++, and if not, what exactly to do. 7 -: 3: * 8 -: 4: * Developer bar D2 and D6 (docs/PAIN_POINTS.md). CUDA's install needs a driver, a toolkit, a 9 -: 5: * framework build and an extension build whose versions all agree, and a mismatch shows up later 10 -: 6: * as an undefined symbol or "no kernel image". CUDA++ has one thing to match: the NVIDIA kernel 11 -: 7: * module its driver client speaks to. This program checks that and everything else a first run 12 -: 8: * needs, and prints one line per check. Every failing line says what is wrong, why it matters and 13 -: 9: * the command to run next. 14 -: 10: * 15 -: 11: * It reads files only (/proc, /sys, /dev): no device is opened and no GPU window is needed. 16 -: 12: * CUDAPP_DOCTOR_ROOT= makes it read /proc, /sys and /dev instead (tests). 17 -: 13: * Exit 0: READY. Exit 1: at least one FAIL line. 18 -: 14: * 19 -: 15: * Which lines to print, the module version parse, the memory figures and the FAIL count are the seeded 20 -: 16: * Omega unit om/tools/doctor.om (omega_doctor). This file keeps the probes: fopen/fgets of the version 21 -: 17: * file, access(2) of the device files and nvcc paths, the PCI scan and chip table, the meminfo sscanf 22 -: 18: * and uname. -DCUDAPP_MIGRATION_PENDING_C_TOOLS_DOCTOR builds the former C body, kept as the oracle. 23 -: 19: * Exit 2: the Omega unit refused (a build text holding % or a newline, a malformed chip refusal). */ 24 -: 20:#include "omega_gpu_chip.h" 25 -: 21: 26 -: 22:#include 27 -: 23:#include 28 -: 24:#include 29 -: 25:#include 30 -: 26:#include 31 -: 27: 32 -: 28:#ifndef CUDAPP_NVIDIA_OPEN_ABI 33 -: 29:#error "build with make doctor: CUDAPP_NVIDIA_OPEN_ABI comes from the third_party/nvidia-open- folder" 34 -: 30:#endif 35 -: 31: 36 -: 32:#ifdef CUDAPP_MIGRATION_PENDING_C_TOOLS_DOCTOR 37 -: 33:static const char *g_root = ""; 38 -: 34:static int g_fail, g_warn; 39 -: 35: 40 function path called 278 returned 100% blocks executed 100% 41 278: 36:static void path(char *out, size_t n, const char *p) { snprintf(out, n, "%s%s", g_root, p); } 42 -: 37: 43 -: 38:static void line(const char *tag, const char *what, const char *fmt, ...) __attribute__((format(printf, 3, 4))); 44 -: 39:#include 45 function line called 308 returned 100% blocks executed 100% 46 308: 40:static void line(const char *tag, const char *what, const char *fmt, ...) { 47 308: 41: printf(" %-5s %s: ", tag, what); 48 call 0 returned 308 49 308: 42: va_list ap; va_start(ap, fmt); vprintf(fmt, ap); va_end(ap); 50 call 0 returned 308 51 308: 43: printf("\n"); 52 call 0 returned 308 53 308: 44: if (!strcmp(tag, "FAIL")) g_fail++; 54 branch 0 taken 50 (fallthrough) 55 branch 1 taken 258 56 308: 45: if (!strcmp(tag, "warn")) g_warn++; 57 branch 0 taken 5 (fallthrough) 58 branch 1 taken 303 59 308: 46:} 60 function more called 90 returned 100% blocks executed 100% 61 90: 47:static void more(const char *text) { /* indented follow-on lines, one per \n */ 62 90: 48: const char *s = text; 63 214: 49: while (*s) { 64 branch 0 taken 214 65 branch 1 taken 0 (fallthrough) 66 214: 50: const char *e = strchr(s, '\n'); 67 214: 51: size_t len = e ? (size_t)(e - s) : strlen(s); 68 branch 0 taken 124 (fallthrough) 69 branch 1 taken 90 70 214: 52: printf(" %.*s\n", (int)len, s); 71 call 0 returned 214 72 214: 53: if (!e) break; 73 branch 0 taken 90 (fallthrough) 74 branch 1 taken 124 75 124: 54: s = e + 1; 76 -: 55: } 77 90: 56:} 78 -: 57: 79 -: 58:/* ---- the kernel module: present, open or closed, and the one version CUDA++ must match ---- */ 80 function check_module called 40 returned 100% blocks executed 98% 81 40: 59:static void check_module(void) { 82 40: 60: char p[4200], buf[1024] = { 0 }; 83 40: 61: path(p, sizeof p, "/proc/driver/nvidia/version"); 84 call 0 returned 40 85 40: 62: FILE *f = fopen(p, "r"); 86 call 0 returned 40 87 40: 63: if (!f || !fgets(buf, sizeof buf, f)) { 88 branch 0 taken 38 (fallthrough) 89 branch 1 taken 2 90 call 2 returned 38 91 branch 3 taken 1 (fallthrough) 92 branch 4 taken 37 93 3: 64: if (f) fclose(f); 94 branch 0 taken 1 (fallthrough) 95 branch 1 taken 2 96 call 2 returned 1 97 3: 65: line("FAIL", "NVIDIA kernel module", "not loaded (%s/proc/driver/nvidia/version does not exist)", g_root); 98 call 0 returned 3 99 3: 66: more("CUDA++ uses no NVIDIA user-space software, but it talks to NVIDIA's kernel module.\n" 100 call 0 returned 3 101 -: 67: "Do this: sudo modprobe nvidia && sudo modprobe nvidia-uvm\n" 102 -: 68: "If modprobe finds no module, install NVIDIA's open kernel module " CUDAPP_NVIDIA_OPEN_ABI 103 -: 69: " (the open-gpu-kernel-modules release of that number), then run make doctor again."); 104 15: 70: return; 105 -: 71: } 106 37: 72: fclose(f); 107 call 0 returned 37 108 37: 73: int open_module = strstr(buf, "Open Kernel Module") != NULL; 109 -: 74: /* the version is the first word that looks like N.N or N.N.N after "Module" */ 110 37: 75: char ver[64] = { 0 }; 111 37: 76: const char *m = strstr(buf, "Module"); 112 1800: 77: for (const char *s = m ? m : buf; *s; s++) { 113 branch 0 taken 4 (fallthrough) 114 branch 1 taken 33 115 branch 2 taken 1797 116 branch 3 taken 3 (fallthrough) 117 1797: 78: if (*s >= '0' && *s <= '9') { 118 branch 0 taken 1663 (fallthrough) 119 branch 1 taken 134 120 branch 2 taken 64 (fallthrough) 121 branch 3 taken 1599 122 64: 79: size_t k = 0; 123 567: 80: while ((s[k] >= '0' && s[k] <= '9') || s[k] == '.') k++; 124 branch 0 taken 376 (fallthrough) 125 branch 1 taken 191 126 branch 2 taken 374 127 branch 3 taken 2 (fallthrough) 128 branch 4 taken 129 129 branch 5 taken 64 (fallthrough) 130 64: 81: if (k > 2 && memchr(s, '.', k) && k < sizeof ver) { memcpy(ver, s, k); break; } 131 branch 0 taken 36 (fallthrough) 132 branch 1 taken 28 133 branch 2 taken 35 (fallthrough) 134 branch 3 taken 1 135 branch 4 taken 34 (fallthrough) 136 branch 5 taken 1 137 30*: 82: s += k ? k - 1 : 0; 138 branch 0 taken 30 (fallthrough) 139 branch 1 taken 0 140 -: 83: } 141 -: 84: } 142 37: 85: if (!ver[0]) { 143 branch 0 taken 3 (fallthrough) 144 branch 1 taken 34 145 3: 86: line("FAIL", "NVIDIA kernel module", "loaded, but its version could not be read from: %.120s", buf); 146 call 0 returned 3 147 3: 87: more("Do this: report it with the output of `cat /proc/driver/nvidia/version` attached."); 148 call 0 returned 3 149 3: 88: return; 150 -: 89: } 151 34: 90: if (strcmp(ver, CUDAPP_NVIDIA_OPEN_ABI) != 0) { 152 branch 0 taken 4 (fallthrough) 153 branch 1 taken 30 154 4: 91: line("FAIL", "NVIDIA kernel module", "version %s is loaded; CUDA++ speaks the " CUDAPP_NVIDIA_OPEN_ABI " interface", ver); 155 call 0 returned 4 156 4: 92: more("Why: CUDA++ builds its driver calls from the " CUDAPP_NVIDIA_OPEN_ABI " open-module headers\n" 157 call 0 returned 4 158 -: 93: "(third_party/nvidia-open-" CUDAPP_NVIDIA_OPEN_ABI "). The layout of those calls can change between module versions,\n" 159 -: 94: "and a wrong layout fails in strange ways, so the doctor refuses instead of guessing.\n" 160 -: 95: "This is the only version CUDA++ asks you to match: no toolkit, no framework build, no extension build.\n" 161 -: 96: "Do this: install the " CUDAPP_NVIDIA_OPEN_ABI " open kernel module, or port the client to your version\n" 162 -: 97: "(CONTRIBUTING.md, \"Port a driver version\": copy the new headers, rebuild, run make test and make hello-gpu)."); 163 4: 98: return; 164 -: 99: } 165 30: 100: if (!open_module) { 166 branch 0 taken 5 (fallthrough) 167 branch 1 taken 25 168 5: 101: line("warn", "NVIDIA kernel module", "the closed module %s is loaded; CUDA++ was qualified on the open module of that version", ver); 169 call 0 returned 5 170 5: 102: more("It uses the same calls and should work. If anything fails, switch to the open module and say so in your report."); 171 call 0 returned 5 172 5: 103: return; 173 -: 104: } 174 25: 105: line("ok", "NVIDIA kernel module", "open module %s (CUDA++ speaks " CUDAPP_NVIDIA_OPEN_ABI ")", ver); 175 call 0 returned 25 176 -: 106:} 177 -: 107: 178 -: 108:/* ---- device files ---- */ 179 function check_nodes called 40 returned 100% blocks executed 100% 180 40: 109:static void check_nodes(void) { 181 -: 110: static const char *const nodes[] = { "/dev/nvidiactl", "/dev/nvidia0", "/dev/nvidia-uvm" }; 182 40: 111: int bad = 0; 183 160: 112: for (size_t i = 0; i < sizeof nodes / sizeof nodes[0]; i++) { 184 branch 0 taken 120 185 branch 1 taken 40 (fallthrough) 186 -: 113: char p[4200]; 187 120: 114: path(p, sizeof p, nodes[i]); 188 call 0 returned 120 189 120: 115: if (access(p, F_OK) != 0) { 190 call 0 returned 120 191 branch 1 taken 14 (fallthrough) 192 branch 2 taken 106 193 14: 116: line("FAIL", "device files", "%s is missing", nodes[i]); 194 call 0 returned 14 195 14: 117: if (!strcmp(nodes[i], "/dev/nvidia-uvm")) 196 branch 0 taken 5 (fallthrough) 197 branch 1 taken 9 198 5: 118: more("Do this: sudo modprobe nvidia-uvm (creates /dev/nvidia-uvm; CUDA++ maps GPU memory through it)"); 199 call 0 returned 5 200 -: 119: else 201 9: 120: more("Do this: sudo modprobe nvidia (or run nvidia-modprobe once, which creates the device files)"); 202 call 0 returned 9 203 14: 121: bad++; 204 106: 122: } else if (access(p, R_OK | W_OK) != 0) { 205 call 0 returned 106 206 branch 1 taken 2 (fallthrough) 207 branch 2 taken 104 208 2: 123: line("FAIL", "device files", "%s exists but this user cannot open it for reading and writing", nodes[i]); 209 call 0 returned 2 210 2: 124: more("Do this: ask the machine's owner to add you to the group that owns it (ls -l on the file shows it),\n" 211 call 0 returned 2 212 -: 125: "or set the module option NVreg_DeviceFileMode=0666."); 213 2: 126: bad++; 214 -: 127: } 215 -: 128: } 216 40: 129: if (!bad) line("ok", "device files", "/dev/nvidiactl /dev/nvidia0 /dev/nvidia-uvm can be opened by this user"); 217 branch 0 taken 33 (fallthrough) 218 branch 1 taken 7 219 call 2 returned 33 220 40: 130:} 221 -: 131: 222 -: 132:/* ---- the GPU itself: qualified, or refused with what is missing (D6) ---- */ 223 function check_gpu called 40 returned 100% blocks executed 100% 224 40: 133:static void check_gpu(int *unified) { 225 -: 134: OmegaGpuPciDev devs[16]; 226 40: 135: int n = omega_gpu_chip_scan(g_root, devs, 16); 227 call 0 returned 40 228 42: 136: if (n < 0) { line("FAIL", "GPU", "cannot read %s/sys/bus/pci/devices", g_root); more("Do this: run make doctor on the machine itself, not in a container without /sys."); return; } 229 branch 0 taken 3 (fallthrough) 230 branch 1 taken 37 231 call 2 returned 3 232 call 3 returned 3 233 37: 137: if (n == 0) { 234 branch 0 taken 2 (fallthrough) 235 branch 1 taken 35 236 2: 138: line("FAIL", "GPU", "no NVIDIA GPU found in /sys/bus/pci/devices"); 237 call 0 returned 2 238 2: 139: more("Do this: check the GPU is seated and powered (lspci | grep -i nvidia)."); 239 call 0 returned 2 240 2: 140: return; 241 -: 141: } 242 35: 142: if (n > 16) n = 16; 243 branch 0 taken 1 (fallthrough) 244 branch 1 taken 34 245 89: 143: for (int i = 0; i < n; i++) { 246 branch 0 taken 54 247 branch 1 taken 35 (fallthrough) 248 54: 144: const OmegaGpuChipRow *r = omega_gpu_chip_find(devs[i].vendor, devs[i].device); 249 call 0 returned 54 250 -: 145: char what[96]; 251 54: 146: snprintf(what, sizeof what, "GPU %.63s", devs[i].bdf); 252 54: 147: if (r) { 253 branch 0 taken 35 (fallthrough) 254 branch 1 taken 19 255 35: 148: line("ok", what, "%s (%s), supported target (historical summary: %s)", r->name, r->sm, r->receipt); 256 call 0 returned 35 257 35: 149: more("raw M16 evidence unavailable; not current-commit qualification"); 258 call 0 returned 35 259 35: 150: if (r->device == 0x2e12u) *unified = 1; /* GB10: one memory for CPU and GPU */ 260 branch 0 taken 35 (fallthrough) 261 branch 1 taken 0 262 -: 151: } else { 263 -: 152: char text[2048]; 264 19: 153: omega_gpu_chip_refusal(&devs[i], text, sizeof text); 265 call 0 returned 19 266 19: 154: const char *nl = strchr(text, '\n'); 267 19: 155: const char *first = text + 4 + strlen(devs[i].bdf) + 2; /* after "GPU : " (a PCI address has colons in it) */ 268 19: 156: line("FAIL", what, "%.*s", (int)(nl - first), first); 269 call 0 returned 19 270 19: 157: more(nl + 1); 271 call 0 returned 19 272 -: 158: } 273 -: 159: } 274 -: 160:} 275 -: 161: 276 -: 162:/* ---- memory: on a unified-memory chip the GPU's memory is the machine's memory ---- */ 277 function check_memory called 40 returned 100% blocks executed 100% 278 40: 163:static void check_memory(int unified) { 279 -: 164: char p[4200], l[256]; 280 40: 165: path(p, sizeof p, "/proc/meminfo"); 281 call 0 returned 40 282 40: 166: FILE *f = fopen(p, "r"); 283 call 0 returned 40 284 40: 167: if (!f) { line("info", "memory", "cannot read /proc/meminfo"); return; } 285 branch 0 taken 3 (fallthrough) 286 branch 1 taken 37 287 call 2 returned 3 288 37: 168: unsigned long long total = 0, avail = 0; 289 198: 169: while (fgets(l, sizeof l, f)) { 290 call 0 returned 198 291 branch 1 taken 161 292 branch 2 taken 37 (fallthrough) 293 161: 170: sscanf(l, "MemTotal: %llu kB", &total); 294 161: 171: sscanf(l, "MemAvailable: %llu kB", &avail); 295 -: 172: } 296 37: 173: fclose(f); 297 call 0 returned 37 298 37: 174: double gt = (double)total / `1048576`.0, ga = (double)avail / `1048576`.0; 299 37: 175: if (unified) line("ok", "memory", "%.1f GiB shared by the CPU and the GPU, %.1f GiB available now", gt, ga); 300 branch 0 taken 32 (fallthrough) 301 branch 1 taken 5 302 call 2 returned 32 303 5: 176: else line("info", "memory", "%.1f GiB system memory, %.1f GiB available now", gt, ga); 304 call 0 returned 5 305 -: 177:} 306 -: 178: 307 -: 179:/* ---- the CUDA toolkit: not needed. Say so, so nobody installs it for us. ---- */ 308 function note_toolkit called 40 returned 100% blocks executed 100% 309 40: 180:static void note_toolkit(void) { 310 40: 181: const char *paths[] = { "/usr/local/cuda/bin/nvcc", "/usr/bin/nvcc" }; 311 115: 182: for (size_t i = 0; i < 2; i++) { 312 branch 0 taken 78 313 branch 1 taken 37 (fallthrough) 314 -: 183: char p[4200]; 315 78: 184: path(p, sizeof p, paths[i]); 316 call 0 returned 78 317 78: 185: if (access(p, X_OK) == 0) { line("info", "CUDA toolkit", "not needed and not used by CUDA++ (one is installed at %s; that is fine)", paths[i]); return; } 318 call 0 returned 78 319 branch 1 taken 3 (fallthrough) 320 branch 2 taken 75 321 call 3 returned 3 322 -: 186: } 323 37: 187: line("info", "CUDA toolkit", "not needed and not used by CUDA++ (none installed)"); 324 call 0 returned 37 325 -: 188:} 326 -: 189: 327 function main called 40 returned 100% blocks executed 100% 328 40: 190:int main(int argc, char **argv) { 329 -: 191: (void)argc; (void)argv; 330 40: 192: const char *r = getenv("CUDAPP_DOCTOR_ROOT"); 331 call 0 returned 40 332 40: 193: if (r) g_root = r; 333 branch 0 taken 39 (fallthrough) 334 branch 1 taken 1 335 -: 194: struct utsname u; 336 40: 195: printf("cudapp doctor: is this machine ready for CUDA++?\n"); 337 call 0 returned 40 338 40: 196: printf("Diagnostic only: direct library use has no driver-version or PCI-ID admission guard.\n"); 339 call 0 returned 40 340 40: 197: if (uname(&u) == 0) line("info", "system", "%s %s %s", u.sysname, u.release, u.machine); 341 call 0 returned 40 342 branch 1 taken 40 (fallthrough) 343 branch 2 taken 0 344 call 3 returned 40 345 40: 198: check_module(); 346 call 0 returned 40 347 40: 199: check_nodes(); 348 call 0 returned 40 349 40: 200: int unified = 0; 350 40: 201: check_gpu(&unified); 351 call 0 returned 40 352 40: 202: check_memory(unified); 353 call 0 returned 40 354 40: 203: note_toolkit(); 355 call 0 returned 40 356 40: 204: line("info", "compiler", "this doctor was built by " __VERSION__ "; CUDA++ needs only make and a C compiler"); 357 call 0 returned 40 358 40: 205: if (g_fail) { 359 branch 0 taken 23 (fallthrough) 360 branch 1 taken 17 361 23: 206: printf("NOT READY: %d problem%s above. Fix the first FAIL line and run make doctor again.\n", g_fail, g_fail == 1 ? "" : "s"); 362 branch 0 taken 17 (fallthrough) 363 branch 1 taken 6 364 call 2 returned 23 365 23: 207: return 1; 366 -: 208: } 367 17: 209: printf("READY. Next: make hello-gpu\n"); 368 call 0 returned 17 369 17: 210: return 0; 370 -: 211:} 371 -: 212:#else 372 -: 213:#include "cudapp_native.h" 373 -: 214: 374 -: 215:#include 375 -: 216: 376 -: 217:/* Facts layout: om/tools/doctor.om. Texts go to the blob as offset and length pairs. */ 377 -: 218:static uint64_t g_facts[256]; 378 -: 219:static unsigned char g_blob[262144], g_out[786432]; 379 -: 220:static size_t g_used; 380 -: 221:static const char *g_root = ""; 381 -: 222: 382 -: 223:static void path(char *out, size_t n, const char *p) { snprintf(out, n, "%s%s", g_root, p); } 383 -: 224:static void text(int at, const char *s, size_t n) { 384 -: 225: if (n > sizeof g_blob - g_used) { fprintf(stderr, "cudapp doctor: probe texts exceed %zu bytes\n", sizeof g_blob); exit(2); } 385 -: 226: memcpy(g_blob + g_used, s, n); 386 -: 227: g_facts[at] = g_used; g_facts[at + 1] = n; 387 -: 228: g_used += n; 388 -: 229:} 389 -: 230:static void text0(int at, const char *s) { text(at, s, strlen(s)); } 390 -: 231: 391 -: 232:static void probe_module(void) { 392 -: 233: char p[4200], buf[1024] = { 0 }; 393 -: 234: path(p, sizeof p, "/proc/driver/nvidia/version"); 394 -: 235: FILE *f = fopen(p, "r"); 395 -: 236: if (!f || !fgets(buf, sizeof buf, f)) { if (f) fclose(f); return; } 396 -: 237: fclose(f); 397 -: 238: g_facts[13] = 1; 398 -: 239: text0(14, buf); 399 -: 240:} 400 -: 241:static void probe_nodes(void) { 401 -: 242: static const char *const nodes[] = { "/dev/nvidiactl", "/dev/nvidia0", "/dev/nvidia-uvm" }; 402 -: 243: for (size_t i = 0; i < 3; i++) { 403 -: 244: char p[4200]; 404 -: 245: path(p, sizeof p, nodes[i]); 405 -: 246: if (access(p, F_OK) != 0) g_facts[16 + i] = 1; 406 -: 247: else if (access(p, R_OK | W_OK) != 0) g_facts[16 + i] = 2; 407 -: 248: } 408 -: 249:} 409 -: 250:static void probe_gpu(void) { 410 -: 251: OmegaGpuPciDev devs[16]; 411 -: 252: int n = omega_gpu_chip_scan(g_root, devs, 16); 412 -: 253: if (n < 0) { g_facts[20] = 1; return; } 413 -: 254: g_facts[19] = (uint64_t)n; /* as scanned: the unit reports the first 16 */ 414 -: 255: for (int i = 0; i < n && i < 16; i++) { 415 -: 256: int g = 32 + 12 * i; 416 -: 257: const OmegaGpuChipRow *r = omega_gpu_chip_find(devs[i].vendor, devs[i].device); 417 -: 258: text(g, devs[i].bdf, strnlen(devs[i].bdf, 63)); 418 -: 259: if (r) { 419 -: 260: g_facts[g + 2] = 1; 420 -: 261: g_facts[g + 3] = r->device == 0x2e12u; /* GB10: one memory for CPU and GPU */ 421 -: 262: text0(g + 4, r->name); text0(g + 6, r->sm); text0(g + 8, r->receipt); 422 -: 263: } else { 423 -: 264: char t[2048]; 424 -: 265: omega_gpu_chip_refusal(&devs[i], t, sizeof t); 425 -: 266: text0(g + 4, t); 426 -: 267: } 427 -: 268: } 428 -: 269:} 429 -: 270:static void probe_memory(void) { 430 -: 271: char p[4200], l[256]; 431 -: 272: path(p, sizeof p, "/proc/meminfo"); 432 -: 273: FILE *f = fopen(p, "r"); 433 -: 274: if (!f) return; 434 -: 275: unsigned long long total = 0, avail = 0; 435 -: 276: while (fgets(l, sizeof l, f)) { 436 -: 277: sscanf(l, "MemTotal: %llu kB", &total); 437 -: 278: sscanf(l, "MemAvailable: %llu kB", &avail); 438 -: 279: } 439 -: 280: fclose(f); 440 -: 281: g_facts[21] = 1; g_facts[22] = total; g_facts[23] = avail; 441 -: 282:} 442 -: 283:static void probe_toolkit(void) { 443 -: 284: const char *paths[] = { "/usr/local/cuda/bin/nvcc", "/usr/bin/nvcc" }; 444 -: 285: for (size_t i = 0; i < 2; i++) { 445 -: 286: char p[4200]; 446 -: 287: path(p, sizeof p, paths[i]); 447 -: 288: if (access(p, X_OK) == 0) { g_facts[24] = i + 1; return; } 448 -: 289: } 449 -: 290:} 450 -: 291: 451 -: 292:int main(int argc, char **argv) { 452 -: 293: (void)argc; (void)argv; 453 -: 294: const char *r = getenv("CUDAPP_DOCTOR_ROOT"); 454 -: 295: if (r) g_root = r; 455 -: 296: text0(0, g_root); 456 -: 297: text0(2, CUDAPP_NVIDIA_OPEN_ABI); 457 -: 298: text0(4, __VERSION__); 458 -: 299: struct utsname u; 459 -: 300: if (uname(&u) == 0) { g_facts[6] = 1; text0(7, u.sysname); text0(9, u.release); text0(11, u.machine); } 460 -: 301: probe_module(); 461 -: 302: probe_nodes(); 462 -: 303: probe_gpu(); 463 -: 304: probe_memory(); 464 -: 305: probe_toolkit(); 465 -: 306: uint64_t res = 0; 466 -: 307: uint32_t st = omega_doctor(&res, g_facts, 256, g_blob, sizeof g_blob, g_out, sizeof g_out); 467 -: 308: if (st != OMEGA_OK || res >> 63) { 468 -: 309: fprintf(stderr, "cudapp doctor: omega_doctor refused (status %u, code %llu)\n", st, (unsigned long long)(res & 0xffu)); 469 -: 310: return 2; 470 -: 311: } 471 -: 312: fwrite(g_out, 1, (size_t)(res & 0xffffffffu), stdout); 472 -: 313: return (res >> 32) ? 1 : 0; 473 -: 314:} 474 -: 315:#endif