Note that there are some explanatory texts on larger screens.

plurals
  1. POOpenCL image2d and image3d memory layout
    text
    copied!<p>When transferring a 2d image stored in host memory to OpenCL, how is it reading the values - row major or column major? Let's assume row major.</p> <pre><code>index = row*NUM_COLS + col </code></pre> <p>How about 3d image stored in host memory? I believe that's treated as a stack of 2D images (which was assumed to be row major). Then pixel (row,col,slice) for limits (NUM_ROWS,NUM_COLS,NUM_SLICES) in terms of OpenCL is at:</p> <pre><code>index = slice*NUM_ROWS*NUM_COLS + row*NUM_COLS + col </code></pre> <p>However, according to <a href="http://en.wikipedia.org/wiki/Row-major_order#Generalization_to_higher_dimensions" rel="nofollow">wikipedia</a> formulas the 3d Row Major indexing <strong>should</strong> be:</p> <pre><code>index = slice + NUM_SLICES*(col + NUM_COLS*row) = row*NUM_COLS*NUM_SLICES + col*NUM_SLICES + slices </code></pre> <p>According to same article Column Major Ordering access should be:</p> <pre><code>index = row + NUM_ROWS*(col + NUM_COLS*slice) = slice*NUM_ROWS*NUM_COLS + col*NUM_ROWS + row </code></pre> <p>None of which seems to match what OpenCL is doing in 3d case.</p> <p>So I guess I really have 2 questions</p> <ol> <li>How do I lay out my memory for transfering 2d and 3d images to OpenCL?</li> <li>Why does it seem like OpenCL has chosen a non standard memory layout in 3d case?</li> </ol> <p><strong>Edit</strong></p> <p>I view wikipedia article as a generic layout scheme. "row" or "column" are secondary label words. Whether you are dealing with tuples (row, col, slice) limited to (NUM_ROWS, NUM_COLS, NUM_SLICES) or (x,y,z) (WIDTH, HEIGHT, DEPTH) doesn't matter as long as it's consistent. It just tells you which dimension is continuous in memory. In "row major" it's the last dimension - z values that are next to each other, in column major it's the first dimension - x.</p> <p>So once again I think "row major" layout for x,y,z 3d image indexing should have been:</p> <pre><code>index = z + DEPTH * (y + HEIGHT * x) = x * HEIGHT * DEPTH + y * HEIGHT + z </code></pre> <p>It isn't. But, I suppose you can chose whatever scheme you want.</p>
 

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