3 Replies Latest reply on Dec 21, 2010 4:47 PM by Barsik107

    2 dimentions memory

    Barsik107

      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?





        • 2 dimentions memory
          Marix

          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.

          • 2 dimentions memory
            dravisher

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