Hi folks,
I try to retrieve the binaries of an OpenCL program, so that I do not have to recompile it every time.
While this works with LWJGL2, my code for LWJGL3 does not work:
long device, program; //Function inputs
int numDevices = Info.clGetProgramInfoInt(program, CL10.CL_PROGRAM_NUM_DEVICES);
PointerBuffer devices = PointerBuffer.allocateDirect(numDevices);
int ret = CL10.clGetProgramInfo(program, CL10.CL_PROGRAM_DEVICES, devices, null);
Utils.checkError(ret, "clGetProgramInfo: CL_PROGRAM_DEVICES");
int index = -1;
for (int i=0; i<numDevices; ++i) {
if (devices.get(i) == device) {
index = i;
}
}
if (index == -1) {
throw new Exception("Program was not built against the specified device "+device);
}
PointerBuffer sizes = PointerBuffer.allocateDirect(numDevices);
ret = CL10.clGetProgramInfo(program, CL10.CL_PROGRAM_BINARY_SIZES, sizes, null);
Utils.checkError(ret, "clGetProgramInfo: CL_PROGRAM_BINARY_SIZES");
int size = (int) sizes.get(index);
PointerBuffer binaryPointers = PointerBuffer.allocateDirect(numDevices * 8);
for (int i=0; i<binaryPointers.capacity(); ++i) {
binaryPointers.put(0L);
}
binaryPointers.rewind();
ByteBuffer binaries = ByteBuffer.allocateDirect(size);
binaryPointers.put(index, binaries);
//Fixme: why the hell does this line throw a segfault ?!?
ret = CL10.clGetProgramInfo(program, CL10.CL_PROGRAM_BINARIES, binaryPointers, null);
Utils.checkError(ret, "clGetProgramInfo: CL_PROGRAM_BINARIES");
return binaries;
Has someone an idea why this code results in a crash of the JVM?
Thanks