title: CUDA 1D texture fetch always return 0
body: <p>I am trying to test the CUDA 1D texture with a piece of simple code. It is quite straightforward: first allocates a global memory, then bind it to a texture reference; access the texture from within a kernel by tex1D(); print out the value returned by the texture fetch.</p>
  
  <p>The code is as follows:</p>
  
  <pre><code>#include "cuda.h"
  #include "cuda_runtime.h"
  #include &lt;iostream&gt;
  #include &lt;vector&gt;
  #include &lt;cstdio&gt;
  
  using namespace std;
  
  texture&lt;float, cudaTextureType1D, cudaReadModeElementType&gt; texX;
  
  __global__ void kernel(float *X)
  {
      int i = threadIdx.x ;
      if ( i &gt;= 128 ) return;
      printf("%.3f\t%.3f\n", tex1D( texX, i*1.0 ), X[i] );
  }
  
  int main()
  {
      float *devX;
      vector&lt;float&gt; X(128, 3.1415926 );
      cudaMalloc( &amp;devX, 128 * sizeof(float) );
      cudaMemcpy( devX, &amp;X[0], 128*sizeof(float), cudaMemcpyDefault );
      cudaDeviceSynchronize();
  
      cudaBindTexture( (size_t)0, texX, devX, 128 * sizeof(float) );
      cudaDeviceSynchronize();
  
      kernel&lt;&lt;&lt;1,128&gt;&gt;&gt;( devX );
      cudaDeviceSynchronize();
      cout&lt;&lt;endl;
      cout&lt;&lt; cudaGetErrorString( cudaGetLastError() ) &lt;&lt;endl;
  }
  </code></pre>
  
  <p>But all I got was like this:</p>
  
  <pre><code>0.000    3.142
  0.000    3.142
  ...
  0.000    3.142
  
  no error
  </code></pre>
  
  <p>Could anyone explain why?</p>