title: Using std::vector in CUDA device code
body: <p>The question is that: is there a way to use the class "vector" in Cuda kernels? When I try I get the following error:</p>
  
  <pre><code>error : calling a host function("std::vector&lt;int, std::allocator&lt;int&gt; &gt; ::push_back") from a __device__/__global__ function not allowed
  </code></pre>
  
  <p>So there a way to use a vector in global section?
  I recently tried the following:</p>
  
  <ol>
  <li>create a new Cuda project</li>
  <li>go to properties of the project</li>
  <li>open Cuda C/C++</li>
  <li>go to Device</li>
  <li>change the value in "Code Generation" to be set to this value:
  compute_20,sm_20</li>
  </ol>
  
  <p>........ after that I was able to use the printf standard library function in my Cuda kernel.</p>
  
  <p>is there a way to use the standard library class <code>vector</code> in the way printf is supported in kernel code? This is an example of using printf in kernel code:</p>
  
  <pre><code>// this code only to count the 3s in an array using Cuda
  //private_count is an array to hold every thread's result separately 
  
  __global__ void countKernel(int *a, int length, int* private_count) 
  {
      printf("%d\n",threadIdx.x);  //it's print the thread id and it's working
  
      // vector&lt;int&gt; y;
      //y.push_back(0); is there a possibility to do this?
  
      unsigned int offset  = threadIdx.x * length;
      int i = offset;
      for( ; i &lt; offset + length; i++)
      {
          if(a[i] == 3)
          {
              private_count[threadIdx.x]++;
              printf("%d ",a[i]);
          }
      }   
  }
  </code></pre>