summaryrefslogtreecommitdiffstats
path: root/tools/test/cuda_drv_test.c
diff options
context:
space:
mode:
authorArthur Hanson Rasmusson <arthur@vgpu.io>2026-09-23 07:05:45 -0400
committerArthur Hanson Rasmusson <arthur@vgpu.io>2026-09-23 07:05:45 -0400
commit2aafde5cc3679020d8b31277c03d70fd6908384c (patch)
treea3d89236459b5586e5a4d0c3b2b1b574fbfb274b /tools/test/cuda_drv_test.c
parent7fdbe8713c8cf746cd1a15e93e0de39d333905c7 (diff)
downloadopen-iov-2aafde5cc3679020d8b31277c03d70fd6908384c.tar.gz
open-iov-2aafde5cc3679020d8b31277c03d70fd6908384c.zip
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.
Diffstat (limited to 'tools/test/cuda_drv_test.c')
-rw-r--r--tools/test/cuda_drv_test.c14
1 files changed, 14 insertions, 0 deletions
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;