From 54ca82d81bacb56197a607d0039ca6a015f5ac44 Mon Sep 17 00:00:00 2001 From: Arthur Hanson Rasmusson Date: Wed, 23 Sep 2026 07:05:45 -0400 Subject: userspace/cuda: libcuda analysis tree (debug-focused), guest ioctl tracer Analysis tooling for debugging CUDA execution in Open-IOV guests: - userspace/cuda/570.144/: fetch a library from a running guest (nc), objdump helpers, crash ip -> file vaddr + symbol mapping, and Ghidra headless import/analysis/decompile scripts (project kept so single functions decompile in seconds). The purpose is debugging correctness and performance of CUDA in Open-IOV VMs (not a reimplementation); extracted binaries and decompiled output are gitignored. - tools/guest-diag/ioctl_trace.c: ptrace tracker for the NVIDIA driver ioctls of a child (libcuda issues raw syscalls, so LD_PRELOAD sees nothing). Decodes RM_ALLOC (class) and RM_CONTROL (cmd) arguments; this is how the cuCtxCreate crash sequence was captured. - tools/test/cuda_drv_test.c: unbuffered + per-call markers so a crash identifies the CUDA call it happened in. --- tools/test/cuda_drv_test.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'tools/test') diff --git a/tools/test/cuda_drv_test.c b/tools/test/cuda_drv_test.c index 6868a2e..20ad88a 100644 --- a/tools/test/cuda_drv_test.c +++ b/tools/test/cuda_drv_test.c @@ -30,8 +30,13 @@ typedef uint64_t CUdeviceptr; printf("%-24s OK\n", #expr); \ } while (0) +/* Print before entering libcuda so a crash identifies the call. */ +#define MARK(name) do { printf("-> %s\n", name); } while (0) + int main(void) { + setvbuf(stdout, NULL, _IONBF, 0); + void *h = dlopen("libcuda.so.1", RTLD_NOW); if (!h) { printf("dlopen libcuda.so.1 failed: %s\n", dlerror()); return 1; } @@ -59,28 +64,37 @@ int main(void) unsigned int back[64]; size_t i; + MARK("cuInit"); CHECK(cuInit(0)); + MARK("cuDeviceGetCount"); CHECK(cuDeviceGetCount(&count)); printf("device count = %d\n", count); if (count < 1) return 1; + MARK("cuDeviceGet"); CHECK(cuDeviceGet(&dev, 0)); printf("device 0 = %d\n", dev); + MARK("cuCtxCreate"); CHECK(cuCtxCreate(&ctx, 0, dev)); printf("context = %p\n", ctx); + MARK("cuMemAlloc"); CHECK(cuMemAlloc(&dptr, sizeof(buf))); printf("device ptr = 0x%llx (%zu bytes)\n", (unsigned long long)dptr, sizeof(buf)); for (i = 0; i < 64; i++) buf[i] = (unsigned int)(i * 3 + 1); + MARK("cuMemcpyHtoD"); CHECK(cuMemcpyHtoD(dptr, buf, sizeof(buf))); memset(back, 0, sizeof(back)); + MARK("cuMemcpyDtoH"); CHECK(cuMemcpyDtoH(back, dptr, sizeof(buf))); printf("roundtrip %s (back[7]=%u expected 22)\n", memcmp(buf, back, sizeof(buf)) ? "MISMATCH" : "match", back[7]); + MARK("cuMemFree"); CHECK(cuMemFree(dptr)); + MARK("cuCtxDestroy"); CHECK(cuCtxDestroy(ctx)); printf("ALL OK\n"); return 0; -- cgit v1.2.3