So that’s strange. When
CL.setExceptionsEnabled(true);
is NOT called, then it should never try to obtain any build logs. But if I unterstood you correctly, it still crashes when you comment OUT this line, right? Could you post the hs_err-File that is created in this case?
At least the error code CL_BUILD_PROGRAM_FAILURE was what I expected (although I don’t know why it happens). Unfortunately, one can not find out why it fails as long as it is not possible to obtain the build logs.
To summarize this: When
- Exceptions are enabled by calling CL.setExceptionsEnabled(true);
- AND it fails to compile the program
THEN it tries to obtain the build log. And there, something goes wrong. I can only guess why it fails to obtain the build logs. (For example: IF the OpenCL implementation reported a wrong size for the build log output, this could explain the segmentation fault).
So, as a first analysis step, I have created a small test that prints some information about the process of obtaining the build log for the program. Can you reproduce the crash there? (Possibly by modifiying the source code?) If yes, what does it print before the crash, and what is the contents of the hs_err-File?
(And, BTW: What OpenCL implementation are you using? Intel/AMD/NVIDIA…?)
import static org.jocl.CL.*;
import org.jocl.*;
import java.util.Arrays;
public class JOCLCompileTest
{
private static String programSource =
"__kernel void "+
"sampleKernel(__global const float *a,"+
" __global const float *b,"+
" __global float *c)"+
"{"+
" int gid = get_global_id(0);"+
" c[gid] = a[gid] * b[gid];"+
"}";
public static void main(String args[])
{
// The platform, device type and device number
// that will be used
final int platformIndex = 0;
final long deviceType = CL_DEVICE_TYPE_ALL;
final int deviceIndex = 0;
// Enable exceptions and subsequently omit error checks in this sample
//CL.setExceptionsEnabled(true);
// Obtain the number of platforms
int numPlatformsArray[] = new int[1];
clGetPlatformIDs(0, null, numPlatformsArray);
int numPlatforms = numPlatformsArray[0];
// Obtain a platform ID
cl_platform_id platforms[] = new cl_platform_id[numPlatforms];
clGetPlatformIDs(platforms.length, platforms, null);
cl_platform_id platform = platforms[platformIndex];
// Initialize the context properties
cl_context_properties contextProperties = new cl_context_properties();
contextProperties.addProperty(CL_CONTEXT_PLATFORM, platform);
// Obtain the number of devices for the platform
int numDevicesArray[] = new int[1];
clGetDeviceIDs(platform, deviceType, 0, null, numDevicesArray);
int numDevices = numDevicesArray[0];
// Obtain a device ID
cl_device_id devices[] = new cl_device_id[numDevices];
clGetDeviceIDs(platform, deviceType, numDevices, devices, null);
cl_device_id device = devices[deviceIndex];
// Create a context for the selected device
cl_context context = clCreateContext(
contextProperties, 1, new cl_device_id[]{device},
null, null, null);
// Create the program from the source code
cl_program program = clCreateProgramWithSource(context,
1, new String[]{ programSource }, null, null);
// Build the program
clBuildProgram(program, 0, null, null, null, null);
printProgramInfo(program);
// Create the kernel
cl_kernel kernel = clCreateKernel(program, "sampleKernel", null);
// Release kernel, program, and memory objects
clReleaseKernel(kernel);
clReleaseProgram(program);
clReleaseContext(context);
System.out.println("Done");
}
private static void printProgramInfo(cl_program program)
{
System.out.println("Program info:");
int numDevices[] = new int[1];
CL.clGetProgramInfo(program, CL.CL_PROGRAM_NUM_DEVICES, Sizeof.cl_uint, Pointer.to(numDevices), null);
System.out.println("numDevices "+numDevices[0]);
cl_device_id devices[] = new cl_device_id[numDevices[0]];
CL.clGetProgramInfo(program, CL.CL_PROGRAM_DEVICES, numDevices[0] * Sizeof.cl_device_id, Pointer.to(devices), null);
System.out.println("devices "+Arrays.toString(devices));
for (int i=0; i<devices.length; i++)
{
System.out.println("Build log info for device "+i);
long logSize[] = new long[1];
CL.clGetProgramBuildInfo(program, devices**, CL.CL_PROGRAM_BUILD_LOG, 0, null, logSize);
System.out.println("logSize "+logSize[0]);
byte logData[] = new byte[(int)logSize[0]];
CL.clGetProgramBuildInfo(program, devices**, CL.CL_PROGRAM_BUILD_LOG, logSize[0], Pointer.to(logData), null);
System.out.println("Obtained log data:");
System.out.println(">"+new String(logData, 0, logData.length-1)+"<");
}
}
}