Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>One way to solve this problem is imaging the cube as a set of Z slides. The coordinates X, Y refers to the width and height of the image, and the Z coordinate to each slide in the Z dimension. Each thread will iterate in the Z coordinate to accumulate the values.</p> <p>With this in mind, configure a kernel to launch a block of 16x16 threads and a grid of enough blocks to process the width and height of the image (I'm assuming a gray scale image with 1 byte per pixel):</p> <pre><code>#define THREADS 16 // kernel configuration dim3 dimBlock = dim3 ( THREADS, THREADS, 1 ); dim3 dimGrid = dim3 ( WIDTH / THREADS, HEIGHT / THREADS ); // call the kernel kernel&lt;&lt;&lt;dimGrid, dimBlock&gt;&gt;&gt;(i_data, o_Data, WIDTH, HEIGHT, DEPTH); </code></pre> <p>If you are clear how to index a 2D array, loop through the Z dimension would be also clear</p> <pre><code>__global__ void kernel(unsigned char* i_data, unsigned char* o_data, int WIDTH, int HEIGHT, int DEPTH) { // in your kernel map from threadIdx/BlockIdx to pixel position int x = threadIdx.x + blockIdx.x * blockDim.x; int y = threadIdx.y + blockIdx.y * blockDim.y; // calculate the global index of a pixel into the image array // this global index is to the first slide of the cube int idx = x + y * WIDTH; // partial results int r = 0; // iterate in the Z dimension for (int z = 0; z &lt; DEPTH; ++z) { // WIDTH * HEIGHT is the offset of one slide int idx_z = z * WIDTH*HEIGHT + idx; r += i_data[ idx_z ]; } // o_data is a 2D array, so you can use the global index idx o_data[ idx ] = r; } </code></pre> <p>This is a naive implementation. In order to maximize memory throughput, the data should be properly aligned. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload