cancel
Showing results for 
Search instead for 
Did you mean: 

Archives Discussions

eklund_n
Journeyman III

Quick question about vector types

Structural relation between arrays and vectors

Hi.

In AESEncryptDecrypt sample, some memory buffers are created and filled with an array of uchar. The buffer is later read from kernel, but as array of uchar4.

Can we always expect the structural layout of an array of 'type' to map into an array of 'typeX' (where X is 2-16)?

'type' ptr[nbr]; cl_mem buffer_object = clCreateBuffer(context, CL_MEM_COPY_HOST_PTR, sizeof('type')*nbr, ptr, NULL); clSetKernelArg(kernel, 0, sizeof(cl_mem), (void *)&buffer_object); __kernel void kernel_name(__global 'typeX' *buffer_object) {}

0 Likes
3 Replies
DTop
Staff

Also, whether it is always steight mapping like char[0] will map to char4.x, char[1] will map to char4.y, etc .

0 Likes

On our architecture, probably. In general, definitely not. For a start you have to be careful about alignment, that might change from one implementation to another. You also have to be careful about endianness. On a big-endian setup you might find that char[0] is char4.w. That is of course something you have to consider when you try to relate a char array to an int array, too. All architectures supported by the AMD OpenCL SDK are little endian.

Unfortunately that is a non-portable trick you just have to use sometimes. For example, try doing atomic operations on an element of a vector without it.

0 Likes

Thanks. That's what i thought.

0 Likes