0 Replies Latest reply on Jun 23, 2009 12:55 AM by xmuben

    handling 2D array gets error result

    xmuben

      Here, I define 2 kernels.

      the two have the same inputstream, a  3*4  array.

      Input:

      0     1     2

      3     4     5

      6     7     8

      9     10    11

       

      Kernel 1:

      kernel void kernelGPU1(int input[][],out int output[][])

      {
      int2 index = instance().xy;
       int a = index.x;
       int b = index.y;
       output(b,a) =input(b,a);                                                                        

      }

      the output of kernel 1 is the same as the input.

      Kernel 2:

       uint4 offset(0,0,0,0);
       uint4 index(3,1,1,1);
       kernelGPU2.domainOffset(offset);
       kernelGPU2.domainSize(index);

      kernel void kernelGPU2(

      int input[][],

      out int outputdata[][],// the size is 3*4

      out int sumofcolumn<>// the size is 3

      )
      {
       int2 index = instance().xy;
       int a =index.x;
       int b =index.y;
       int i =0;
       int t1=0,t2=0;
       for (i=0;i<4;i++)
       {
         outputdata(b,a) =input(b,a) ;
         t1=input(b,a) ;
         t2+=t1;
         b++;

       }
        sumofcolumn=t2;
      }

      the values of the parameter outputdata is

      9     1     2

      3     4     5

      6     7     8

      9     10    11

      the values of the parameter sumofcolumn is

      18     22    26

      sumofcolumn gets the right result, but outputdata get error values 9 in position(0,0), the right value should be 0.

       I don't know why this happened.

      Could anyone tell me what  is wrong with my code?

      thanks very much.