2D array on GPU


Compute with two dimensionnal array

Before begin you need to know how to create, allocate and use a two dimensionnal array in C#.

Hybridizer allow you to use multidimensionnal arrays instead of only one dimensionnal array, to use it we need to:

  • use the -hybridarray option in the command line

  • you can use the y component of threadIdx blockIdx blockDim gridDim to make a second loop to compute the 2D array.

  • you can choose the size of the block and the grid with SetDistrib function

    dynamic wrapper = HybRunner.Cuda().SetDistrib(number_of_block_x,
                                                  number_of_thread_x,
                                                  number_of_block_y,
                                                  number_of_thread_y,
                                                  number_of_block_z, //the value is 1 in this example
                                                  size_of_shared_memory //except if you use shared memory set 0
                                                  ).Wrap(new Program());
    

Edit the file 01-Array2D.cs and use a 2D array instead of an 1D array.

If you get stuck, you can refer to the solution.


In [ ]:
!hybridizer-cuda 01-array2D/01_Array2D.cs -o 01-array2D/01_Array2D.exe -run