cancel
Showing results for 
Search instead for 
Did you mean: 

Archives Discussions

bleveque
Journeyman III

Problem with clGetProgramInfo(CL_PROGRAM_BINARIES)

Jump to solution

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 = new char[70000]; // I know... it's bad... but if i use new char[np], 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 !

0 Likes
1 Solution

Accepted Solutions
Wenju
Elite

Re: Problem with clGetProgramInfo(CL_PROGRAM_BINARIES)

Jump to solution

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 = new char[np]; // I know... it's bad... but if i use new char[np], 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.

View solution in original post

0 Likes
2 Replies
Wenju
Elite

Re: Problem with clGetProgramInfo(CL_PROGRAM_BINARIES)

Jump to solution

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 = new char[np]; // I know... it's bad... but if i use new char[np], 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.

View solution in original post

0 Likes
bleveque
Journeyman III

Re: Problem with clGetProgramInfo(CL_PROGRAM_BINARIES)

Jump to solution

Thanks, it works !

(I have the same problem with "new char[np]" because np in undefined, but the rest of the algo works

0 Likes