Compile cuda-c to ptx

Started by codex, August 24, 2024, 15:36:47

Previous topic - Next topic

codex

I need a little help here with compiling cuda-c to ptx. I've been using this demo as a guide, but it doesn't show how to do that exactly. I can't find any other demos/tutorials specific to lwjgl for cuda, so I'm a little lost here.

MemoryStack stack = ...

PointerBuffer program = stack.mallocPointer(1);
PointerBuffer headers = stack.mallocPointer(1);
PointerBuffer includeNames = stack.mallocPointer(1);
PointerBuffer options = stack.mallocPointer(1);
PointerBuffer codeSize = stack.mallocPointer(1);

String src = "insert-cuda-c-source-here";

NVRTC.nvrtcCreateProgram(program, src, "MyCuda.cu", headers, includeNames));
long prog = program.get(0);
NVRTC.nvrtcCompileProgram(program.get(0), options));
NVRTC.nvrtcGetCUBINSize(prog, codeSize));
ByteBuffer code = stack.malloc(codeSize.getIntBuffer(0, 1).get(0));
NVRTC.nvrtcGetCUBIN(prog, code);

My specific problem is that nvrtcGetCUBINSize writes to a PointerBuffer, and I am unclear of how to actually access the underlying value.