cancel
Showing results for 
Search instead for 
Did you mean: 

Archives Discussions

alexaverbuch
Journeyman III

Accessing cl_uint4 elements?

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];

0 Likes
5 Replies
omkaranathan
Adept I

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

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

 

0 Likes

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?

0 Likes

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. 

0 Likes

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 = (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 = temp; // <------- this line goes BOOM! }

0 Likes

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

0 Likes