5 Replies Latest reply on Sep 22, 2009 8:18 AM by alexaverbuch

    Accessing cl_uint4 elements?

    alexaverbuch
      Trying to individually access cl_uint4 elements in Host program

      Hi,

      I've been reading the OpenCL spec and it only seems to show how to access individual vector elements when in the kernel code, but not within the host. Is this even possible?

      I've had multiple syntax attempts with no success. Please see the attached code for reference.

      Thank in advance for any help,

      Alex

      cl_uint4 test = {1,2,3,4}; test.0; test.x; test[0];

        • Accessing cl_uint4 elements?
          omkaranathan

          The correct way to access individual elements within the host in this case is,

          test.u32[0],  test.u32[1] etc. 

           

            • Accessing cl_uint4 elements?
              alexaverbuch

              Thanks, but that still results in this error message:

              request for member ‘u32’ in ‘test’, which is of non-class type ‘unsigned int __vector__’

              The line below actually works fine:

               cl_uint4 test = {1,2,3,4};

              But I can not figure out how to access individual elements within the host...

              Any other suggestions?

                • Accessing cl_uint4 elements?
                  omkaranathan

                  Which compiler are you using?

                  The openCL specification does not define a way to access individual elements within the host.

                  The above code will work in case of windows compiler, but not with GCC/Intel compiler etc. 

                  Take a look into platform.h for the details of how vectors are declared. 

                    • Accessing cl_uint4 elements?
                      alexaverbuch

                       

                      Originally posted by: omkaranathan Which compiler are you using?

                      The openCL specification does not define a way to access individual elements within the host.

                      The above code will work in case of windows compiler, but not with GCC/Intel compiler etc. 

                      Take a look into platform.h for the details of how vectors are declared. 

                      Thanks for the tip!

                      Yeah, as mentioned in my original post, I also noticed the spec made no mention of this. I'll check out platform.h

                      In the mean time, I'm having a related problem that you (or someone else) may be able to help me with.

                      Please see the attached code, I've commented the guilty line. This line gives me a "Segmentation Fault", but the fault goes away when I comment it out.

                      Please also note that the compiler doesn't allow me to assign {1,2,3,4} directly to the array element... but with "temp" it compiles... strange

                      Thanks,

                      Alex

                      int width = //ASSIGN VALUE int height = //ASSIGN VALUE cl_uint4 **imageArray = (cl_uint4**)malloc(width * sizeof(cl_uint4*)); for (int i = 0 ; i < width; i++) imageArray[i] = (cl_uint4*)malloc(height * sizeof(cl_uint4)); for (int y=0; y<raw->height; y++) for (int x=0; x<raw->width; x++) { cl_uint4 temp = {0,1,2,3}; imageArray[x][y] = temp; // <------- this line goes BOOM! }

                        • Accessing cl_uint4 elements?
                          alexaverbuch

                          Ok, I think I solved this by using "cl_uint myUint4[4]" in the Host, and then accessing it as a cl_uint4 in the Kernel

                          Compiling and Buffer allocation seems to work fine now

                          I still can't run the program due to a "clBuildProgram - Invalid Operation" error.. but I'll make another thread about that.

                          Thanks for the help