title: How to get surf2Dwrite to correctly compile in C++ CUDA
body: <p>Ignore this question - the code is fine - the problem was with use of C++ header files which are not included in the example shared.</p>
  <p>I am using Visual studio 2019 with CUDA 11.0 and I have hit a brick wall trying to use a cudaSurfaceObject_t to store the results of a calculation.</p>
  <p>I recieve the following compiler errors</p>
  <p>Error   C3861   'surf2Dwrite': identifier not found<br />
  Error   C2059   syntax error: '&lt;'</p>
  <p>I have stuffed the <code>include#</code> section of the .cu file with headers in a vain attempt to get surf2Dwrite to be identified...</p>
  <p>My example version of the code is a simple attempt to fill the surface with a <code>float</code> of value <code>NAN</code>:-</p>
  <pre><code>    #include &lt;stdio.h&gt;
      #include &lt;stdlib.h&gt;
      #include &lt;math.h&gt;
      #include &lt;cuda.h&gt;
      #include &lt;ctype.h&gt;
      #include &lt;string.h&gt; 
      #include &quot;cuda_runtime.h&quot;
      #include &quot;device_launch_parameters.h&quot;
      #include &quot;export.h&quot;
      #include&quot;surface_functions.h&quot; 
  
      __global__
      void TestGrids(cudaSurfaceObject_t surf, int size)
      {
          int y = threadIdx.y + blockIdx.y * blockDim.y;
          int x = threadIdx.x + blockIdx.x * blockDim.x;
      
          if (x &lt; size &amp;&amp; y &lt; size)
          {
              surf2Dwrite(NAN, surf, x * 4, y);//Error C3861 'surf2Dwrite': identifier not found
          }   
      }        
      
      void TestSurfWrite( int size)
      {   
          cudaDeviceProp prop;
          cudaError_t c_err = cudaGetDeviceProperties(&amp;prop, 0);
          
          //Set grid and block sizes
      
          dim3 dimblock(16, 16, 1);   
          int gridDimX = prop.multiProcessorCount;
          int gridDimY = 16;
          while (gridDimX &gt; 2 * gridDimY)
          {
              gridDimX = gridDimX / 2;
              gridDimY = gridDimY * 2;
          }   
          dim3 dimGrid(gridDimX, gridDimY, 1);    
      
          cudaChannelFormatDesc nanchannelDescSurf = cudaCreateChannelDesc(32, 0, 0, 0, cudaChannelFormatKindFloat);
          cudaArray_t nanArray;
          cudaMallocArray(&amp;nanArray, &amp;nanchannelDescSurf, size, size, 0);
          struct cudaResourceDesc nanDescSurf;
          memset(&amp;nanDescSurf, 0, sizeof(cudaResourceDesc));
          nanDescSurf.resType = cudaResourceTypeArray;
          nanDescSurf.res.array.array = nanArray;
          cudaSurfaceObject_t nanSurf;
          cudaCreateSurfaceObject(&amp;nanSurf, &amp;nanDescSurf);
          
          TestGrids&lt;&lt;&lt;dimGrid, dimblock&gt;&gt;&gt;(nanSurf, size); // Error C2059 syntax error: '&lt;'
          
          c_err = cudaGetLastError();
      
          // perform work on nansurf here..
      
          cudaDestroySurfaceObject(nanSurf);
          cudaFreeArray(nanArray);
      }
  </code></pre>
  <p>The above code fails to build with the errors as shown.  The relevant line from the output is as follows:-</p>
  <pre><code>&gt;Compiling CUDA source file hough.cu...
  1&gt;  
  1&gt;C:\dev\Test&gt;&quot;C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.0\bin\nvcc.exe&quot; -gencode=arch=compute_52,code=\&quot;sm_52,compute_52\&quot; --use-local-env -ccbin &quot;C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.27.29110\bin\HostX86\x64&quot; -x cu   -I&quot;C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.0\include&quot; -I&quot;C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.0\include&quot;  -G   --keep-dir x64\Debug -maxrregcount=0  --machine 64 --compile -cudart static  -g   -DWIN32 -DWIN64 -D_DEBUG -D_CONSOLE -D_WINDLL -D_MBCS -Xcompiler &quot;/EHsc /W3 /nologo /Od /Fdx64\Debug\vc142.pdb /FS /Zi /RTC1 /MDd &quot; -o x64\Debug\hough.cu.obj &quot;C:\dev\Test\test.cu&quot;  
  1&gt;test.cu
  </code></pre>
  <p>I'm a beginner with both C++ and CUDA in C++ so I expect there will be an obvious issue here.</p>
  <p>talonmies has identified that this is a project set up problem in the comments below - this is an are I have no expertise in and do not really know where to start looking for a solution, so I have added the VisualStudio-2019 tag in the hopes that it will attract someone who does know about these things...</p>