cancel
Showing results for 
Search instead for 
Did you mean: 

Archives Discussions

felix
Journeyman III

Memory Pointer problem of clGetProgramInfo

Here is the function declaration in OpenCL 1.2.  I have chosen only one GPU device with CL_DEVICE_TYPE_GPU for the whole program.

cl_int clGetProgramInfo (cl_program program,

                                    cl_program_info param_name,

                                    size_t param_value_size,

                                    void *param_value,

                                    size_t *param_value_size_ret)

  1. Query devices in the platform and get one device
  2. Query binary size and get programSize
  3. Declare a variable unsigned char **binary
  4. Malloc 4 pointers for binary. binary = (unsigned char **)malloc(sizeof(unsigned char**) * 4);
  5. Init each pointer with a loop. binary = (unsigned char *)malloc(sizeof(unsigned char) * (programSize + 8));
  6. Check all the pointer. binary[0-3] are legal pointers, there are not any NULL pointer.
  7. Get the binary.

         err = clGetProgramInfo(program, CL_PROGRAM_BINARIES,

                                            programSize, binary, &retSize);

        After this call, I get ELF in binary[0]. However, binary[1-3] are set to 0x0, which are NULL pointers.

I just wonder, what is the root cause. This program work well on other platforms. Clinfo output is in the attachment.

0 Likes
1 Solution

Hi felix,

1. clGetProgramInfo with CL_PROGRAM_BINARIES needs a pointer to an array which u declared correct. But the size of this array should be equal to number of GPU devices. As you mentioned that you are using only one GPU device so instead of allocating 4 pointers for binary, you should use only 1 pointer.

2. The third argument of clGetProgramInfo is used to specify the size in bytes of memory pointed by binary. And hence change

err = clGetProgramInfo(program, CL_PROGRAM_BINARIES,

                                            programSize, binary, &retSize); with

-->>

err = clGetProgramInfo(program, CL_PROGRAM_BINARIES,

                                            n*sizeof(unsigned char *), binary, &retSize);  //where n is number of GPU devices (in your case, it should be 1).

Modify your program accordingly, and post here if you still have some issue.

Thanks,

AMD_Support

View solution in original post

0 Likes
2 Replies

Hi felix,

1. clGetProgramInfo with CL_PROGRAM_BINARIES needs a pointer to an array which u declared correct. But the size of this array should be equal to number of GPU devices. As you mentioned that you are using only one GPU device so instead of allocating 4 pointers for binary, you should use only 1 pointer.

2. The third argument of clGetProgramInfo is used to specify the size in bytes of memory pointed by binary. And hence change

err = clGetProgramInfo(program, CL_PROGRAM_BINARIES,

                                            programSize, binary, &retSize); with

-->>

err = clGetProgramInfo(program, CL_PROGRAM_BINARIES,

                                            n*sizeof(unsigned char *), binary, &retSize);  //where n is number of GPU devices (in your case, it should be 1).

Modify your program accordingly, and post here if you still have some issue.

Thanks,

AMD_Support

0 Likes

It is the solution. Thank you very much.

The root cause is that I misunderstanding the third argument of clGetProgramInfo. When I change it to  n*sizeof(unsigned char *), the program works.

I use four pointers to illustrate the problem. You could ignore it.

0 Likes