The latest Nvidia OpenCL driver/SDK (313.30) for Linux does not work for programs
that use “fork()”: Once the parent-process ever performed any OpenCL operation,
its son-process fails to create a context.
This problem only appeared with GTX Titan - everything worked well with older devices (i.e. GeForce GTX 480).
The trivial program below fails with the “Device Not Available” error (-2):
I don’t know whether this is the right forum, but I don’t know where else to turn
in order to have this problem fixed.
Thanks.
#include <cl.h>
#include <stdio.h>
int
main(na, argv)
char *argv;
{
cl_int res;
cl_platform_id platform;
cl_context_properties cps[3];
cl_context context;
if(clGetPlatformIDs(1, &platform, NULL) != CL_SUCCESS)
{
fprintf(stderr, "Parent could not get platform\n");
exit(1);
}
if(fork())
exit(0);
sleep(2);
if(clGetPlatformIDs(1, &platform, NULL) != CL_SUCCESS)
{
fprintf(stderr, "Son could not get platform\n");
exit(1);
}
cps[0] = CL_CONTEXT_PLATFORM;
cps[1] = (cl_context_properties)platform;
cps[2] = 0;
context = clCreateContextFromType(cps, CL_DEVICE_TYPE_ALL, NULL, NULL, &res);
if(context)
printf("OK\n");
else
printf("clCreateContextFromType failed, error=%d\n", res);
}