title: CUDA: Why Thrust is so slow on uploading data to GPU?
body: <p>I'm new to GPU world and just installed CUDA for writing some program. I played with thrust library but find out that it is so slow when uploading data to GPU. Just about 35MB/s in host-to-device part on my not-bad desktop. How come it is?</p>
  
  <p>Environment: Visual Studio 2012, CUDA 5.0, GTX760, Intel-i7, Windows 7 x64</p>
  
  <p>GPU Bandwidth test:
  <img src="https://i.stack.imgur.com/ezM7E.png" alt="enter image description here"></p>
  
  <p>It is supposed to have at least 11GB/s of transfer speed for host to device or vice versa! But it didn't!</p>
  
  <p>Here's the test program:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;ctime&gt;
  #include &lt;thrust/device_vector.h&gt;
  #include &lt;thrust/host_vector.h&gt;
  
  #define N 32&lt;&lt;22
  
  int main(void)
  {
      using namespace std;
  
      cout&lt;&lt;"GPU bandwidth test via thrust, data size: "&lt;&lt; (sizeof(double)*N) / 1000000000.0 &lt;&lt;" Gbytes"&lt;&lt;endl;
      cout&lt;&lt;"============program start=========="&lt;&lt;endl;
  
      int now = time(0);
      cout&lt;&lt;"Initializing h_vec...";
      thrust::host_vector&lt;double&gt; h_vec(N,0.0f);
      cout&lt;&lt;"time spent: "&lt;&lt;time(0)-now&lt;&lt;"secs"&lt;&lt;endl;
  
      now = time(0);
      cout&lt;&lt;"Uploading data to GPU...";
      thrust::device_vector&lt;double&gt; d_vec = h_vec;
      cout&lt;&lt;"time spent: "&lt;&lt;time(0)-now&lt;&lt;"secs"&lt;&lt;endl;
  
      now = time(0);
      cout&lt;&lt;"Downloading data to h_vec...";
      thrust::copy(d_vec.begin(), d_vec.end(), h_vec.begin());
      cout&lt;&lt;"time spent: "&lt;&lt;time(0)-now&lt;&lt;"secs"&lt;&lt;endl&lt;&lt;endl;
  
      system("PAUSE");
      return 0;
  }
  </code></pre>
  
  <p>Program out put:
  <img src="https://i.stack.imgur.com/g5jA7.png" alt="enter image description here"></p>
  
  <ul>
  <li><p>Download speed: less than 1 sec, pretty make sense compare to nominal
  11GB/s.</p></li>
  <li><p>Upload speed: 1.07374GB /32 secs is about to be 33.5 MB/s, which doesn't make sense at all.</p></li>
  </ul>
  
  <p>Does anyone know the reason? Or is it just the way thrust is? </p>
  
  <p>Thanks!!</p>