5 Replies Latest reply on Jan 19, 2011 3:40 PM by himanshu.gautam

    cl_mem buffer handler in OpenCL

    enliten

       

      I am trying to do simple pointer arithmetic on OpenCL like:

      cl_mem obj1;

      ...

      obj1=obj1+10; // Does not work as it gives following error:

      error: invalid use of incomplete type ‘struct _cl_mem’

       

      Ho can I achieve this behavior in OpenCL as I could not find much in OpenCL Specifications as well? 

       



        • cl_mem buffer handler in OpenCL
          rick.weber

          It's not so simple in OpenCL. In OpenCL 1.1, you can create subbuffers using clCreateSubBuffer(). Before 1.1, you had to pass offsets to your kernel and compute the addresses there. Don't even try stripping the pointer out of the cl_mem object and passing it around either... It doesn't work on AMD GPUs, believe me I've tried.

            • cl_mem buffer handler in OpenCL
              nou

              you can look into cl.h and see that all cl_object are defined as pointers.

              typedef struct _cl_context *        cl_context;
              typedef struct _cl_command_queue *  cl_command_queue;
              typedef struct _cl_mem *            cl_mem;

              but what is in _cl_* struct? well it is implementation defined but OpenCL ICD specify that it has this content

              struct _cl_<object>
              {
              struct _cl_icd_dispatch *dispatch;
              // ... remainder of internal data
              };

              an _cl_icd_dispatch is only table of functions pointers. so forget about look into CL objects.

                • cl_mem buffer handler in OpenCL
                  enliten

                  Thankyou for your valuable feedback.

                  My needs can be fulfilled by clCreateSubBuffer function introduced in OpenCL 1.1 But I have following problem with using that function:

                   

                   



                  It gives me Segmentation fault on last line. I could not investigate, what mistake I have in this case as I have ensured that origin and size are well in limits of the original buffer which is not a subbuffer by itself.

                  Could someone give me a running usage example of clCreateSubBuffer ?

                   

                  cl_buffer_region *info= new cl_buffer_region(); info->size= (size_t)8;//in bytes for float info->origin=(size_t)0; // in bytes for float newBuffer = clCreateSubBuffer (newDevicePointer,CL_MEM_READ_WRITE, CL_BUFFER_CREATE_TYPE_REGION, info, NULL);

              • cl_mem buffer handler in OpenCL
                Raistmer
                Originally posted by: enliten

                I am trying to do simple pointer arithmetic on OpenCL like:




                cl_mem obj1;




                ...




                obj1=obj1+10; // Does not work as it gives following error:




                error: invalid use of incomplete type 'struct _cl_mem'




                 



                Inside OpenCL kernel buffer should be accessed by "usual" pointer (float* for example). You can use pointer arithmetic inside kernel, but cl_mem is not the pointer, consider it as some opaque memory buffer handler/ID. Pointer arithmetic inappropriate here.


                Ho can I achieve this behavior in OpenCL as I could not find much in OpenCL Specifications as well? 




                 






                  • cl_mem buffer handler in OpenCL
                    himanshu.gautam

                    I am able to create a subBuffer using the following snippet.

                    I suggest you to check if any parameter inth the clCreateBuffer is uninitialized and the input buffer is big enough. Also Do not leave the last parameter in any cl Command which shows the error status for that command. Debugging will be much easier if you do proper checking for every cl command.

                    cl_buffer_region* region = new cl_buffer_region(); region -> origin = 0; region -> size = SIZE; cl_mem inputSubBuffer_U ; inputSubBuffer_U = clCreateSubBuffer(inputBuffer_U,CL_MEM_READ_WRITE, CL_BUFFER_CREATE_TYPE_REGION,region,&status);