Reputation: 66
Following this github example. I have encountered a problem trying to use the pre built binary.
I successfully create my binary since I get the message PLATFORM [Apple] --> SUCCESS (1)
.
But, when trying to use the binary, the function clBuildProgram
, gives the error code CL_BUILD_PROGRAM_FAILURE
. ¿Any advice?
I'm using this code:
int length = int_par[1];
cl_int err;
// Query platforms and devices
cl_platform_id platform;
err = clGetPlatformIDs(1, &platform, NULL);
cl_device_id device;
err = clGetDeviceIDs(platform, CL_DEVICE_TYPE_CPU, 1, &device, NULL);
const cl_context_properties prop[] = {
CL_CONTEXT_PLATFORM, (cl_context_properties)platform,
0
};
// Create context
cl_context context = clCreateContext(prop, 1, &device, NULL, NULL, &err);
// Create program
unsigned char* program_file = NULL;
size_t program_size = 0;
read_file1(&program_file, &program_size, "Kernel.clbin");
cl_program program =
clCreateProgramWithBinary(context, 1, &device, &program_size,
(const unsigned char **)&program_file,
NULL, &err);
if(err!=CL_SUCCESS) Rprintf("clCreateProgramWithBinary!!!!\n%s\n", err_code(err));
err = clBuildProgram(program, 1, &device, NULL, NULL, NULL);
free(program_file);
if (err != CL_SUCCESS)
{
size_t len;
//char buffer[2048*3000];
Rprintf("Error: Failed to build program executable!\n%s\n", err_code(err));
clGetProgramBuildInfo(program, device, CL_PROGRAM_BUILD_LOG, 0, NULL, &len);
//char *buffer = (char *) malloc(len);
//char *buffer = (char*)calloc(len, sizeof(char));
char *buffer =calloc(len,sizeof(char));
//memset(buffer, 0, len);
clGetProgramBuildInfo(program, device, CL_PROGRAM_BUILD_LOG, len, buffer, NULL);
SEP;
Rprintf("Build Log:\n%s\n", buffer);
SEP;
clGetProgramBuildInfo(program, device, CL_PROGRAM_BUILD_STATUS, sizeof(char), buffer, &len);
Rprintf("Build Status:\n%s\n", buffer);
SEP;
clGetProgramBuildInfo(program, device, CL_PROGRAM_BUILD_OPTIONS, sizeof(char), buffer, &len);
Rprintf("Build Options:\n%s\n", buffer);
SEP;
//return EXIT_FAILURE;
}
Besides, it is worth noting that this code worked fine in Sierra OS, but after I updated to Mojave, it did not anymore.
Upvotes: 1
Views: 740
Reputation: 66
I had to ask for help in another platform and finally got the answer. Let me share it if someone needs it sometime:
"The main fix was in cl-compile program that changed what is saved to the binary file. It used to save the program created by the clBuildProgram method, and now it saves the program created by the clCompileProgram method.
Bottom line, if you want to save a compiled kernel, save it after a call to clCompileProgram method. On #Mojave you cannot build a program from binary if that binary was previously built by clBuildProgram."
Upvotes: 2