7 Replies Latest reply on Aug 26, 2010 9:58 AM by mihzaha

    copying cl_mem directly to GPU

    mihzaha

      if I have a structure like this:

      struct x

      {

          cl_mem a;

          cl_mem b;

      };

       

      struct x cpu_struct_x;

      cl_mem gpu_struct_x;

       

      gpu_struct_x = clCreateBuffer(..., sizeof(struct x), ...);

       

      cpu_struct_x.a =  clCreateBuffer(..., sizeof(cl_uint) * N, ...);

      cpu_struct_x.b =  clCreateBuffer(..., sizeof(cl_float) * M, ...);

       

      and on the GPU:

      struct x

      {

          uint *a;

          float *b;

      };

       

      can I do:

      clEnqueueWriteBuffer(..., gpu_struct_x, ...,  sizeof(struct x), &cpu_struct_x, ...); ?

      I need this, because I have many lists, and I just want to pass a pointer to a structure which contains pointers to all the lists to the kernels.

      I thought this, because I understand cl_mem objects as simple pointers, and I'm not sure that's true...

       

      Thank you

       

      [edit] And what about pointer arithmetics? If I want to copy from element 2 can I do 

      clEnqueueReadBuffer(..., cl_mem_vector + sizeof(dim_element) * 2 , ...); ?

      -I found out I can't do that, so how could I read only a part of a vector, starting with index N ?

        • copying cl_mem directly to GPU
          genaganna

          clEnqueueReadBuffer has 4th parameter as offset. You can use that.

            • copying cl_mem directly to GPU
              mihzaha

              he didn't notice that, thank you

              And about the cl_mems? if the kernel reads a a cl_mem object from a struct like the one above, does it interpret it correctly as a memory location, or does passing the cl_mem as a parameter for the kernel change it in a way, so the significance of the bits is different between cl_mem on host and pointer on device?

            • copying cl_mem directly to GPU
              genaganna

               

              Originally posted by: mihzahaI found out I can't do that, so how could I read only a part of a vector, starting with index N ?


              clEnqueueReadBuffer has 4th parameter as offset. You can use that.

              • copying cl_mem directly to GPU
                genaganna

                 

                Originally posted by: mihzaha if I have a structure like this:

                 

                struct x

                 

                {

                 

                    cl_mem a;

                 

                    cl_mem b;

                 

                };

                 

                 

                 

                struct x cpu_struct_x;

                 

                cl_mem gpu_struct_x;

                 

                 

                 

                gpu_struct_x = clCreateBuffer(..., sizeof(struct x), ...);

                 

                 

                 

                cpu_struct_x.a =  clCreateBuffer(..., sizeof(cl_uint) * N, ...); cpu_struct_x.b =  clCreateBuffer(..., sizeof(cl_float) * M, ...);   and on the GPU: struct x {     uint *a;     float *b; };   can I do:

                clEnqueueWriteBuffer(..., gpu_struct_x, ...,  sizeof(struct x), &cpu_struct_x, ...); ?



                I need this, because I have many lists, and I just want to pass a pointer to a structure which contains pointers to all the lists to the kernels. I thought this, because I understand cl_mem objects as simple pointers, and I'm not sure that's true...



                Above code is completely illegal.

                  • copying cl_mem directly to GPU
                    mihzaha

                    that's bad, I was hoping it could work

                    so the only way to send cl_mems' is though kernel parameters?

                      • copying cl_mem directly to GPU
                        genaganna

                         

                        Originally posted by: mihzaha that's bad, I was hoping it could work

                        I am sure no implementor will support your request forever.

                         

                        so the only way to send cl_mems' is though kernel parameters?

                         

                        Remember you are sending data containing cl_mem not cl_mem.

                          • copying cl_mem directly to GPU
                            mihzaha

                            I hope I'm not to insistent  Please forgive me. I'm very new and I didn't quite understand the language.

                            I ment that it's bad for me, because I already did the structures with that organisation, not that the implementation is bad And it's not a request, it just was an idea I hope could have worked.

                            I'll try to explain what I'm trying to do:

                            -I have many arrays (9 arrays) and a few other parameters (they all reside in the device memory).

                            -In one kernel I need 2 arrays in the general case, but once in a while I have to do something complicated and use all the other arrays.

                            -I thought it would be a waste to send every time 9 pointers to the arrays + 9 values characterizing the arrays, so I wanted to only send the arrays I want (2) + a pointer to a structure residing in global memory containing pointers to all the other arrays and parameters, in case I need to go the long way.

                            Since I saw that I can pass as kernel parameter something like (sizeof(cl_mem), cl_mem) and read it like (__global *pointer_to_array), I imagined that cl_mem is something like void*, so I thought to make a structure of cl_mems, but you say it's totally illegal.

                            If I'm not to insistent I would like to know what is that object and how can I sent the pointers as I mentioned.

                            Mihai