title: How to bind array of doubles to texture2D?
body: <p>I try to use texture memory/binding instead of global memory, but I cannot pass by binding texture. First thing I learned is CUDA does not support double for texture, so casting is needed, ok.</p>
  
  <p>I declared global texture variable:</p>
  
  <pre><code>texture&lt;int2, 2&gt; texData;
  </code></pre>
  
  <p>then right after allocating device memory (<code>cudaMalloc</code>) with size (in bytes) <code>width*height * sizeof(double)</code> I try to bind it:</p>
  
  <pre><code>cudaChannelFormatDesc desc = cudaCreateChannelDesc&lt;int2&gt;();
  cudaStatus = cudaBindTexture2D(nullptr, &amp;texData, dev_data, &amp;desc,  width, height, 0);
  if (cudaStatus != cudaSuccess) {
      fprintf(stderr, "Binding texture failed: %s\n", cudaGetErrorString(cudaStatus));
      goto Error;
  }
  </code></pre>
  
  <p>And this binding fails with error "invalid argument". Width and height are 2048 which is much below texture 2d limits: 65536 x 65536 x 1048544.</p>
  
  <p>So what did I do wrong here?</p>
  
  <p><em>Sidenote: the signature of <code>cudaBindTexture2D</code>:</em></p>
  
  <pre><code>extern __host__ cudaError_t CUDARTAPI cudaBindTexture2D(size_t *offset, 
      const struct textureReference *texref, const void *devPtr, 
      const struct cudaChannelFormatDesc *desc, size_t width, size_t height, size_t pitch);
  </code></pre>