title: Usage of printf() in Cuda 4.0 Compilation Error
body: <p>I have a GTX 570 (Fermi architecture) which is of compute Capability 2.0. I have Cuda version 4.0 on my computer 
  and I am using Ubuntu 10.10</p>
  
  <p>With Cuda 4.0 it is possible to use <code>printf()</code> inside kernels. Here is an example code from page 125 of the Cuda 4.0 <a href="http://developer.download.nvidia.com/compute/cuda/4_0/toolkit/docs/CUDA_C_Programming_Guide.pdf" rel="nofollow">programming guide</a> </p>
  
  <pre><code>#if defined(__CUDA_ARCH__) &amp;&amp; (__CUDA_ARCH__ &lt; 200)
  #define printf(f, ...) ((void)(f, __VA_ARGS__),0)
  #endif
  
  
  __global__ void helloCUDA(float f)
  {
  printf(“Hello thread %d, f=%f\n”, threadIdx.x, f);
  }
  
  
  
  void main()
  {
  helloCUDA&lt;&lt;&lt;1, 5&gt;&gt;&gt;(1.2345f);
  cudaDeviceReset();
  }
  </code></pre>
  
  <p>I am getting the following compilation error.</p>
  
  <pre><code>gaurish108 MyPractice: nvcc printf_inkernel.cu -o printf_inkernel
  printf_inkernel.cu(10): error: unrecognized token
  
  printf_inkernel.cu(10): error: expected an expression
  
  printf_inkernel.cu(10): error: unrecognized token
  
  printf_inkernel.cu(10): error: unrecognized token
  
  printf_inkernel.cu(10): error: unrecognized token
  
  printf_inkernel.cu(10): error: unrecognized token
  
  printf_inkernel.cu(10): error: unrecognized token
  
  printf_inkernel.cu(10): error: unrecognized token
  
  printf_inkernel.cu(15): warning: return type of function "main" must be "int"
  
  8 errors detected in the compilation of "/tmp/tmpxft_000014cd_00000000-4_printf_inkernel.cpp1.ii".
  </code></pre>
  
  <p>Why is it not recognizing printf? I tried adding the flag <code>-arch=sm_20</code> , but I get the same error. </p>