问题描述
我正在使用ATI RV770显卡,OpenCl 1.0和ati-stream-sdk-v2.3-lnx64在linux上。在运行我的主机代码时,包括以下两节构建内核程序,我得到错误代码(-11),即 cl_build_program_failure
。这是否意味着内核程序编译,如果不是那么它如何编译和调试?
const char * KernelPath =abc_kernel。 cl //内核程序在单独的文件中,但在同一目录下的主机代码。
/ * 从内核源代码创建程序对象 * ** * /
char * sProgramSource = readKernelSource(KernelPath);
size_t sourceSize = strlen(sProgramSource);
program = clCreateProgramWithSource(context,1,(const char **)& sProgramSource,& sourceSize,& err);
checkStatus(创建程序时出错,err);
/ * 链接)计划 * ** * *** /
char * options =(char *)malloc(10 * sizeof(char));
strcpy(options,-g);
err = clBuildProgram(program,num_devices,devices_id,options,NULL,NULL);
checkStatus(Build Program Failed,err); //这行抛出错误....
函数读取内核程序如下:
/ *读程序源文件* /
char * readKernelSource (const char * kernelSourcePath){
FILE * fp = NULL;
size_t sourceLength;
char * sourceString;
fp = fopen(kernelSourcePath,r);
if(fp == 0)
{
printf(open to open file);
返回NULL;
}
//获取源代码的长度
fseek(fp,0,SEEK_END);
sourceLength = ftell(fp);
倒带(fp);
//为源代码字符串分配缓冲区,并在
sourceString =(char *)malloc(sourceLength + 1)中读取它;
if(fread(sourceString,1,sourceLength,fp)!= sourceLength)
{
printf(\\\
\t错误:无法读取文件);
return 0;
}
sourceString [sourceLength + 1] ='\0';
fclose(fp);
return sourceString;
} // readKernelSource的结尾
任何人都可以告诉如何解决它?
这是否意味着在运行时还是其他的OpenCl编译错误?
//打印build_log信息使用clGetProgramBuildInfo()如下,但为什么不打印任何东西?
char * build_log;
size_t log_size;
//首先调用以了解正确的大小
err = clGetProgramBuildInfo(程序, devices_id,CL_PROGRAM_BUILD_LOG,0,NULL,& log_size);
build_log =(char *)malloc((log_size + 1));
//第二次调用获取日志
err = clGetProgramBuildInfo(program,devices_id,CL_PROGRAM_BUILD_LOG,log_size,build_log,NULL);
build_log [log_size] ='\0';
printf(---构建日志--- \\\
);
fprintf(stderr,%s\\\
,build_log);
free(build_log);
这个错误通常是由你的内核代码。您可以使用标志 CL_PROGRAM_BUILD_LOG 调用OpenCL函数 clGetProgramBuildInfo 来访问编译器生成的日志。此日志包含您在命令行编译时可能使用的输出(错误,警告等)。
例如,您可以添加类似于以下你调用clBuildProgram后:
if(err == CL_BUILD_PROGRAM_FAILURE){
//确定大小log
size_t log_size;
clGetProgramBuildInfo(program,devices_id [0],CL_PROGRAM_BUILD_LOG,0,NULL,& log_size);
//为日志分配内存
char * log =(char *)malloc(log_size);
//获取日志
clGetProgramBuildInfo(program,devices_id [0],CL_PROGRAM_BUILD_LOG,log_size,log,NULL);
//打印日志
printf(%s\\\
,log);
}
您还可以在AMD的SDKCommon.cpp中看到函数buildOpenCLProgram() APP SDK为一个实例。
I am using ATI RV770 graphics card, OpenCl 1.0 and ati-stream-sdk-v2.3-lnx64 on linux.
While running my host code which includes following two sections to build kernel program, i am getting error code (-11) i.e. cl_build_program_failure
. Does it means that kernel program compiled, if not then how is it compiled and debugged?
const char* KernelPath = "abc_kernel.cl"; //kernel program is in separate file but in same directory of host code..
/* Create Program object from the kernel source *******/
char* sProgramSource = readKernelSource(KernelPath);
size_t sourceSize = strlen(sProgramSource) ;
program = clCreateProgramWithSource(context, 1,(const char **) &sProgramSource,&sourceSize, &err);
checkStatus("error while creating program",err);
/* Build (compile & Link ) Program *******/
char* options = (char* )malloc(10*sizeof(char));
strcpy(options, "-g");
err = clBuildProgram(program, num_devices, devices_id, options, NULL, NULL);
checkStatus("Build Program Failed", err); //This line throwing the error....
function to read kernel program is as follows::
/* read program source file*/
char* readKernelSource(const char* kernelSourcePath){
FILE *fp = NULL;
size_t sourceLength;
char *sourceString ;
fp = fopen( kernelSourcePath , "r");
if(fp == 0)
{
printf("failed to open file");
return NULL;
}
// get the length of the source code
fseek(fp, 0, SEEK_END);
sourceLength = ftell(fp);
rewind(fp);
// allocate a buffer for the source code string and read it in
sourceString = (char *)malloc( sourceLength + 1);
if( fread( sourceString, 1, sourceLength, fp) !=sourceLength )
{
printf("\n\t Error : Fail to read file ");
return 0;
}
sourceString[sourceLength+1]='\0';
fclose(fp);
return sourceString;
}// end of readKernelSource
Can anyone tell how to fix it?
Does it means that it is OpenCl compilation error at runtime or something else?
//Printing build_log info using clGetProgramBuildInfo() as below, But why is is not printing anything?
char* build_log; size_t log_size;
// First call to know the proper size
err = clGetProgramBuildInfo(program, devices_id, CL_PROGRAM_BUILD_LOG, 0, NULL, &log_size);
build_log = (char* )malloc((log_size+1));
// Second call to get the log
err = clGetProgramBuildInfo(program, devices_id, CL_PROGRAM_BUILD_LOG, log_size, build_log, NULL);
build_log[log_size] = '\0';
printf("--- Build log ---\n ");
fprintf(stderr, "%s\n", build_log);
free(build_log);
This error is typically caused by a syntax error in your kernel code. You can call the OpenCL function clGetProgramBuildInfo with the flag CL_PROGRAM_BUILD_LOG to access the log generated by the compiler. This log contains the output you are probably used to when compiling on the command-line (errors, warnings, etc.).
For example, you could add something similar to the following after you call clBuildProgram:
if (err == CL_BUILD_PROGRAM_FAILURE) {
// Determine the size of the log
size_t log_size;
clGetProgramBuildInfo(program, devices_id[0], CL_PROGRAM_BUILD_LOG, 0, NULL, &log_size);
// Allocate memory for the log
char *log = (char *) malloc(log_size);
// Get the log
clGetProgramBuildInfo(program, devices_id[0], CL_PROGRAM_BUILD_LOG, log_size, log, NULL);
// Print the log
printf("%s\n", log);
}
You can also see the function buildOpenCLProgram() in SDKCommon.cpp in the AMD APP SDK for a real example.
这篇关于错误代码(-11)::什么是所有可能的错误原因“cl_build_program_failure”在OpenCL中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!