4 Replies Latest reply on Aug 18, 2009 6:43 AM by titanius

    Brook+: copying a 1D array to part of a 2D array. Why is this not working?

    titanius

      I am trying to update part of a 2D array with a 1D array (basically a row/column of 2D matrix)

       

      [Not working Kernel, 1D in 2D]:

      kernel void MoveData3_copy(out int aout[][], int ta<>, int index<>, int msh){
          int n;
          aout[msh][index] = ta;
         
      }

      aout   size:mdim x nsample and i send msh=0 right now for testing.

      ta  size:nsample

      index = 0...(nsample-1)

      Tried aout[msh][index] = ta[index] and so on but nothing works. Only the first index is updated and everything else is garbage.

       

      So i tried on with 1D to 1D array and it works!

      kernel void MoveData3_copy(out int aout[], int ta<>, int index<>, int msh){
          int n;
          aout[index] = index; // or aout[index]=ta (both works)
         
      }

       

      So what is the problem with the 2D mapping?

       

      Any help is most appreciated.

        • Brook+: copying a 1D array to part of a 2D array. Why is this not working?
          gaurav.garg

          Do you see any error/errorLog on any stream? Are you using domain of execution for kernel call?

            • Brook+: copying a 1D array to part of a 2D array. Why is this not working?
              titanius

              Thanks for the reply.

              I did a small test case and i am still stumped. I don't see any error as such. Nor am i using domain of execution.

               

              Below are the kernels. The first to copy to columns, second to copy to row and the third an array copy

               

              Kernels

              kernel void MoveData2D_copy_index_leading(out int aout[][], int ta<>, int index<>, int msh){

              aout[index][msh]= ta;

              }

              kernel void MoveData2D_copy_msh_leading(out int aout[][], int ta<>, int index<>, int msh){

              aout[msh][index]= ta;

              }

              kernel void MoveData1D_copy(out int aout[], int ta<>, int index<>, int msh){

              aout[index]= ta;

              }

              Host code:

              unsigned int dim[] = {2,100}; //so array is basically s_matrix_2D[100][2]

              unsigned int dim100 = 100;

              Stream s_matrix_2D(2,dim);

              Stream s_array_1D(1,&dim100);

              Stream s_index(1,&dim100);

               

              int index[100],i,j;

              int array_1D[100], matrix_2D[200];

              for( i=0;i<100;i++) index=i;


              streamRead(s_index,index);


              MoveData2D_copy_index_leading(s_matrix_2D, s_index,s_index,0);

              MoveData1D_copy(s_array_1D, s_index,s_index,0);


              streamWrite(s_matrix_2D, matrix_2D);

              streamWrite(s_array_1D, array_1D);


              for(i=0;i<100;i++)

              printf("%d,", array_1D);

              printf("\n");

              for(i=0;i<200;i++)

              printf("%d,", matrix_2D);


              if(s_matrix_2D.error())

              printf("error");

              if(s_array_1D.error())

              printf("error");


              Copying to the column works fine as seen from output.

              1D 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,

              2D 0,0,1,0,2,0,3,0,4,0,5,0,6,0,7,0,8,0,9,0,10,0,11,0,12,0,13,0,14,0,15,0,16,0,17,0,18,0,19,0,20,0,21,0,22,0,23,0,24,0,25,0,26,0,27,0,28,0,29,0,30,0,31,0,32,0,33,0,34,0,35,0,36,0,37,0,38,0,39,0,40,0,41,0,42,0,43,0,44,0,45,0,46,0,47,0,48,0,49,0,50,0,51,0,52,0,53,0,54,0,55,0,56,0,57,0,58,0,59,0,60,0,61,0,62,0,63,0,64,0,65,0,66,0,67,0,68,0,69,0,70,0,71,0,72,0,73,0,74,0,75,0,76,0,77,0,78,0,79,0,80,0,81,0,82,0,83,0,84,0,85,0,86,0,87,0,88,0,89,0,90,0,91,0,92,0,93,0,94,0,95,0,96,0,97,0,98,0,99,0,



              So now i change the dimension of matrix_2D to [2][100] and try to write to [0][0..100] with 0..100. That doesn't work.


              Changed host code:

              unsigned int dim[] = {100,2}; //so array is basically s_matrix_2D[2][100]


              MoveData2D_copy_msh_leading(s_matrix_2D, s_index,s_index,0);

              MoveData1D_copy(s_array_1D, s_index,s_index,0);



              1D 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,

              2D 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,50,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,