Troubles with clBuildProgram...

First hello to everybody and sorry for my english i’m an spanish speaker =), its my first time here and i want to congrats to everyone that colaborate ont his subject. Let’s go to the problem, i built my own “oclLoadProgSource” using the standart method for reading files in C, this is:


   FILE *fp;
   fp = fopen("kernel2.cl", "r");
   if (!fp) {
     fprintf(stderr, "Failed to load kernel.
");
     exit(1);
   }
   fseek(fp,0,SEEK_END);
   kernelLength = ftell(fp);
   rewind(fp);
   char *clMatrixMul = (char *) malloc (kernelLength);
   fread(clMatrixMul,1,kernelLength,fp);
   //printf("%s 
Cantidad de caracteres: %i. 
",clMatrixMul,kernelLength/sizeof(char));
   fclose(fp);

but when i do this:


   clProgram = clCreateProgramWithSource(clGPUContext, 
                1,(const char **)&clMatrixMul, 
                &kernelLength,&errcode);
   clCheckErr(errcode, "clCreateProgramWithSource");

   errcode = clBuildProgram(clProgram,0, 
              NULL,"",NULL,NULL);
   clCheckErr(errcode, "clBuildProgram");

appear to be a problem with clBuildProgram. I’m not sure if i’m doing well the read of the file, and clCreateProgramWithSource it’s well constructed.

Thanks.

I think your program looks fine. You can try and print the file to your screen to see if reading it was successful.

But I guess that you have a bug in your kernel code, i.e. in the file “kernel2.cl”. In this case, clBuildProgram will fail. Have a look at your kernel code again and see if you can find the error. If not, just post it here.

Use clGetProgramBuildInfo(program, device, CL_PROGRAM_BUILD_LOG, …) to get more Info about the Build. I do this even for successfull build to get all warning.

Thanks for your answers, i’m looking the clGetProgramBuildInfo and it appear to be an error on the kernel2.cl, fantastic!. I will continue looking this code this night and tomorrow will tells you if that was my only error. Thanks again!

By googling I found this page, and while playing with OpenCL I even discovered the original poster’s bug :slight_smile:
Where’s the ‘\0’ at the end of your loaded sources?!? :wink: