2 Replies Latest reply on Apr 24, 2012 5:52 AM by bleveque

    Problem with clGetProgramInfo(CL_PROGRAM_BINARIES)

    bleveque

      Hello !

       

      I want to save the binary (after my clBuildProgram) on a file, so this is my code :


         err = clBuildProgram(plan->program, 1, &devices[0], "-cl-mad-enable", NULL, NULL); //build the program

       




      err = clGetProgramInfo(plan->program, CL_PROGRAM_NUM_DEVICES, sizeof(size_t), &nb_devices, &nbread);// Return 1 devices

       




      size_t *np = new size_t[nb_devices];//Create size array

       




      err = clGetProgramInfo(plan->program, CL_PROGRAM_BINARY_SIZES, nb_devices, &np, &nbread);//Load in np the size of my binary

       

       




      char** bn = new char* [nb_devices]; //Create the binary array



      for(int i =0; i <nb_devices;i++)  bn[i] = new char[70000]; // I know... it's bad... but if i use new char[np[i]], i have a segfault... :/




       

       




      err = clGetProgramInfo(plan->program, CL_PROGRAM_BINARIES, nb_devices, bn, &nbread); //Load the binary itself




       




      printf("%s\n", bn[0]); //Print the first binary. But here, I have some curious characters

       

       



      fp = fopen("binar.bin", "wb");


      fwrite(bn[0], sizeof(char*), 70000, fp); // Save the binary, but my file stay empty



       

      I don't know how to retrieve the binary, my clBuildProgram work (and my binary too), but i think i'm doing something wrong on my program.

      If someone can help me, thank you !

        • Re: Problem with clGetProgramInfo(CL_PROGRAM_BINARIES)
          Wenju

          Hi bleveque,

           

          you can try this.

           

              err = clBuildProgram(program, 1, &devices[0], "-cl-mad-enable", NULL, NULL); //build the program
          
          
              err = clGetProgramInfo(program, CL_PROGRAM_NUM_DEVICES, sizeof(size_t), &nb_devices, &nbread);// Return 1 devices
          
          
              size_t *np = new size_t[nb_devices];//Create size array
          
          
              err = clGetProgramInfo(program, CL_PROGRAM_BINARY_SIZES, sizeof(size_t)*nb_devices, np, &nbread);//Load in np the size of my binary
          
          
              char** bn = new char* [nb_devices]; //Create the binary array
          
          
              for(int i =0; i < nb_devices;i++)  bn[i] = new char[np[i]]; // I know... it's bad... but if i use new char[np[i]], i have a segfault... :/
          
          
              err = clGetProgramInfo(program, CL_PROGRAM_BINARIES, sizeof(unsigned char *)*nb_devices, bn, &nbread); //Load the binary itself
          
          
              printf("%s\n", bn[0]); //Print the first binary. But here, I have some curious characters
          
          
              FILE *fp = fopen("binar.bin", "wb");
          
          
              fwrite(bn[0], sizeof(char), np[0], fp); // Save the binary, but my file stay empty
              
              fclose(fp);
          
          

           

           

          and you can use clCreateProgramWithBinary to build program with binary.