c++ - opencl kernel file not entirely loading -
once opencl kernel file exceeds length, not correctly loaded anymore. programme build log (clbuildprogram) returns lots of errors, seems there cuts in middle of line (example int test;
-> error unknown identifier 't').
here function load programme source:
char * load_program_source(const char *filename) { file *fh; char* source; long lsize; fh = fopen(filename, "r"); if (fh == 0) homecoming 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); homecoming source; }
and here code programme build:
//load programme 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 error please create sure opencl has been initialized\r\n";
i happy if cound help me out!
try next code. if doesn't help, attach kernel source
file reading:
static char* read_source_file(const char *filename) { long int size = 0, res = 0; char *src = null; file *file = fopen(filename, "rb"); if (!file) homecoming null; if (fseek(file, 0, seek_end)) { fclose(file); homecoming null; } size = ftell(file); if (size == 0) { fclose(file); homecoming null; } rewind(file); src = (char *)calloc(size + 1, sizeof(char)); if (!src) { src = null; fclose(file); homecoming src; } res = fread(src, 1, sizeof(char) * size, file); if (res != sizeof(char) * size) { fclose(file); free(src); homecoming src; } src[size] = '\0'; /* null terminated */ fclose(file); homecoming src; }
programm building:
cl_int ret; programme = clcreateprogramwithsource( context, 1, (const char**)&src_file, null, &ret); if(ret != cl_success){ fprintf(stderr, "error code %d happened.\n", ret); } // warnings treated errors, useful debug char build_params[] = {"-werror"}; ret = clbuildprogram(program, 0, null, build_params, null, null); if (ret != cl_success) { size_t len = 0; char *buffer; clgetprogrambuildinfo(program, device_id, cl_program_build_log, 0, null, &len); buffer = calloc(len, sizeof(char)); clgetprogrambuildinfo(program, device_id, cl_program_build_log, len, buffer, null); fprintf(stderr, "%s\n", buffer); free(buffer); }
c++ winforms opencl
No comments:
Post a Comment