【发布时间】:2014-06-26 22:01:12
【问题描述】:
一旦我的 opencl 内核文件超过一定长度,它就不能正确加载了。程序构建日志 (clBuildProgram) 返回大量错误,其中似乎在一行中间有切口(例如 int test; -> error unknown identifier 't')。
这是我加载程序源的函数:
char * load_program_source(const char *filename)
{
FILE *fh;
char* source;
long lSize;
fh = fopen(filename, "r");
if (fh == 0)
return 0;
//Get Filesize
fseek(fh,0,SEEK_END);
lSize = ftell(fh);
rewind(fh);
source = (char *) malloc(lSize);
memset(source,'\0',lSize);
fread(source, sizeof(char), lSize, fh);
return source;
}
这是构建程序的代码:
//load program from file, compile kernels
cl_program program[1];
cl_kernel kernel[13];
const char * filename = "addKernel.c";
char *program_source = load_program_source(filename);
program[0] = clCreateProgramWithSource(context, 1, (const char**)&program_source,
NULL, &err);
if (err == CL_OUT_OF_HOST_MEMORY){
textBox1->Text += "Error: out of Host Memory!\r\n";
}
else if (err == CL_INVALID_CONTEXT){
textBox1->Text += "Error: invalid Context!\r\n";
}
else if (err == CL_INVALID_VALUE){
textBox1->Text += "Error: invalid Value!\r\n";
}
err = clBuildProgram(program[0], 0, NULL, NULL, NULL, NULL);
textBox1->Text += "Program build error: " + err + "\r\n";
cl_build_status status;
size_t logSize;
clGetProgramBuildInfo(program[0], deviceID[0], CL_PROGRAM_BUILD_STATUS, sizeof(cl_build_status), &status, NULL);
clGetProgramBuildInfo(program[0], deviceID[0], CL_PROGRAM_BUILD_LOG, 0, NULL, &logSize);
char* programLog;
programLog = (char*)calloc(logSize + 1, sizeof(char));
clGetProgramBuildInfo(program[0], deviceID[0], CL_PROGRAM_BUILD_LOG, logSize + 1, programLog, NULL);
std::string tmp = std::string(programLog);
this->textBox1->Text += "Program build info: error=" + err + ", status=" + status + ", programLog:\r\n" + gcnew System::String(tmp.c_str()) + "\r\n" + "In case of an error please make sure that openCL has been initialized\r\n";
如果你能帮帮我,我会很高兴的!
【问题讨论】:
-
你试过“source = (char *) malloc(lSize + 1);”而不是“source = (char *) malloc(lSize);” ?
-
@RomanArzumanyan 刚刚尝试过。我在内核末尾添加了
//testtesttesttest行以增加文件大小。仍然出现bug错误:OCL2DFA.tmp.cl(629): warning: this declaration has no storage class or type specifier ttesttesttesttesttesttesttest ^ C:\Users\ASCHOE~1\AppData\Local\Temp\OCL2DFA.tmp.cl(629): error: global variable must be declared in addrSpace constant ttesttesttesttesttesttesttest ^ At end of source: error: expected a ";" 2 errors detected in the compilation of "C:\Users\ASCHOE~1\AppData\Local\Temp\OCL2DFA.tmp.cl".