Note that there are some explanatory texts on larger screens.

plurals
  1. POFetching CUDA texture problems
    text
    copied!<p>I am having trouble fetching a texture of floats. The texture is defined as follows:</p> <pre><code>texture&lt;float, 2, cudaReadModeElementType&gt; cornerTexture; </code></pre> <p>The binding and parameter settings are:</p> <pre><code>cornerTexture.addressMode[0] = cudaAddressModeClamp; cornerTexture.addressMode[1] = cudaAddressModeClamp; cornerTexture.filterMode = cudaFilterModePoint; cornerTexture.normalized = false; cudaChannelFormatDesc cornerDescription = cudaCreateChannelDesc&lt;float&gt;(); cudaBindTexture2D(0, &amp;cornerTexture, cornerImage-&gt;imageData_device, &amp;cornerDescription, cornerImage-&gt;width, cornerImage-&gt;height, cornerImage-&gt;widthStep); </code></pre> <p><code>height</code> and <code>width</code> are the sizes of the two dimensions in terms of numbers of elements. <code>widthStep</code> is in terms of number of bytes. In-kernel access occurs as follows:</p> <pre><code>thisValue = tex2D(cornerTexture, thisPixel.x, thisPixel.y); printf("thisPixel.x: %i thisPixel.y: %i thisValue: %f\n", thisPixel.x, thisPixel.y, thisValue); </code></pre> <p><code>thisValue</code> should always be a non-negative float. <code>printf()</code> is giving me strange, useless values that are different from what the linear memory actually stores. I have tried offsetting the access with a <code>0.5f</code> on both coordinates, but it gives me the same wrong results.</p> <p>Any ideas?</p> <p><strong>Update</strong> There seems to be a hidden alignment requirement. From what I can deduce, the pitch passed to the <code>cudaBindTexture</code> function needs to be a multiple of 32 bytes. For example, the following gives incorrect results</p> <pre><code>cudaBindTexture2D(0, &amp;debugTexture, deviceFloats, &amp;debugDescription, 10, 32, 40) </code></pre> <p>when fetching the texture, but the following (the same array with its width and height switched) works well:</p> <pre><code>cudaBindTexture2D(0, &amp;debugTexture, deviceFloats, &amp;debugDescription, 32, 10, 128) </code></pre> <p>I'm not sure whether I'm missing something or there really is a constraint on the pitch.</p> <p><strong>Update 2:</strong> I have filed a bug report with Nvidia. Those who are interested can view it in their developer zone, but I will post the reply back here. </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