按照这个 github 示例。我在尝试使用预构建的二进制文件时遇到了问题。
收到消息后,我成功创建了二进制文件PLATFORM [Apple] --> SUCCESS (1)
。
但是,当尝试使用二进制文件时,该函数clBuildProgram
会给出错误代码CL_BUILD_PROGRAM_FAILURE
。¿ 有什么建议吗?
我正在使用这段代码:
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;
}
此外,值得注意的是,这段代码在 Sierra OS 中运行良好,但在我更新到 Mojave 后,它就不行了。