title: How to use template functions and CUDA
body: <p>So I have the following code:</p>
  
  <p>File: Cuda.cu</p>
  
  <pre><code>template &lt;typename T&gt;
  __global__ void xpy( int n, T *x, T *y, T *r )
  {
      int i = blockIdx.x * blockDim.x + threadIdx.x;
      if (i &lt; n) r[i] = x[i] + y[i];
  }
  
  mtx_mtx_add( float *a1, float *a2, float *r, const int &amp;numElements )
  {
  // snip
  xpy&lt;&lt;&lt;numBlocks, blockSize&gt;&gt;&gt;(numElements, a1, a2, r); 
  }
  mtx_mtx_add( int *a1, int *a2, int *r, const int &amp;numElements ) {:::}
  mtx_mtx_add( long long *a1, long long *a2, long long *r, const int &amp;numElements ) {:::}
  </code></pre>
  
  <p>File: Calling Code</p>
  
  <pre><code>extern "C" bool mtx_mtx_add( float *a1, float *a2, float *r, int &amp;numElements );
  extern "C" bool mtx_mtx_add( float *a1, float *a2, float *r, int &amp;numElements );
  extern "C" bool mtx_mtx_add( float *a1, float *a2, float *r, int &amp;numElements );
  
  int main()
  {
  ... ...
  mtx_mtx_add(...);
  }
  </code></pre>
  
  <p>Now what I want is for the mtx_mtx_add function to be templated. Is this possible and if so how?</p>