cancel
Showing results for 
Search instead for 
Did you mean: 

Archives Discussions

Barsik107
Journeyman III

2 dimentions memory

I need to use some kind of two dimension memory and I don't know exactly how to create and work with it. I tried to use smth like this

lEnqueueNDRangeKernel(commandQueue,kernelTay,1,NULL,

globalThreads,localThreads,0,NULL,&events[0]);

where globalThreads = {200,200} and localThreads = {1} for example.

Incide kernel i tried to calculate index like this:

uint tid = get_global_id(0);

uint lid = get_global_id(1);

uint index;

const uint range=200;

index = tid*range+lid;

But seems that it's wrong, because if I tried to save indexes like this:

input_Tay[index]=index; 

then only one of 200 elements of input_Tay has nonzero value. And this values like 200,400,600 and so on. I donk know what to think about this. Maybe somebody have example of how to use 2 dimension memory?





0 Likes
3 Replies
Marix
Adept II

You actually only create 200 threads (well, it might be more, but you only ask for 200).

If you use a two-dimensional value for globalThreads you have to set the NDimensions argument, the third to clEnqueueNDRangeKernel, to 2.

Note that you then also have to use a two-value localThreads value, e.g. {64,1}, as otherwise OpenCL will read invalid memory trying to get the second value from localThreads.

Another remark, if you don't care about grouping I wouldn't set it to {1,1}, but to NULL and leave it to OpenCL to properly group the threads.

0 Likes

that helped me a lot

0 Likes
dravisher
Journeyman III

Edit: Apologies, I got thrown off since you called the second global ID "lid", which I though was the local ID.

0 Likes