title: cudaMemPrefetchAsync() returns cudaErrorInvalidDevice - why?
body: <p>Whenever I call <code>cudaMemPrefetchAsync()</code> it returns the error code <code>cudaErrorInvalidDevice</code>. I am sure that I pass right device id (I have only one CUDA-capable GPU in my laptop under <code>id == 0</code>). <Br></p>
  
  <p>I believe that code sample posted below is error-free, but at line <code>52</code> (call to <code>cudaMemPrefetchAsync()</code>) I keep getting this error.</p>
  
  <hr>
  
  <h2>I tried:</h2>
  
  <ol>
  <li>Clean driver installation. (Latest version)</li>
  <li>I check Google for an answer, but I could not find any. (I managed only to find <a href="https://devtalk.nvidia.com/default/topic/981147/cuda-programming-and-performance/cudamemprefetchasync-returns-cudaerrorinvaliddevice/" rel="nofollow noreferrer">this</a>)</li>
  </ol>
  
  <p>(I haven't idea for anything else)</p>
  
  <hr>
  
  <h2>System Spec:</h2>
  
  <p><strong>OS:</strong> Microsoft windows 8.1 x64 home. <Br>
  <strong>IDE:</strong> Visual studio 2015 <Br>
  <strong>CUDA toolkit:</strong> 8.0.61 <Br>
  <strong>NVIDIA GPU:</strong> GeForce GTX 960M <Br>
  <strong>NVIDIA GPU driver:</strong> ver 381.65 (latest) <Br>
  <strong>Compute Capability:</strong> 5.0 (Maxwell) <Br>
  <strong>Unified Memory support:</strong> is supported. <Br>
  <strong>Intel integrated gpu:</strong> Intel HD graphics 4600</p>
  
  <hr>
  
  <h2>Code Sample:</h2>
  
  <pre><code>/////////////////////////////////////////////////////////////////////////////////////////////////////////
  // TEST AREA:
  // -- INCLUDE: 
  /////////////////////////////////////////////////////////////////////////////////////////////////////////
  
  // Cuda Libs: ( Device Side ):
  #include &lt;cuda_runtime.h&gt;
  #include &lt;device_launch_parameters.h&gt;
  
  // Std C++ Libs:
  #include &lt;iostream&gt;
  #include &lt;iomanip&gt;
  ///////////
  
  
  
  
  
  /////////////////////////////////////////////////////////////////////////////////////////////////////////
  // TEST AREA:
  // -- NAMESPACE:
  /////////////////////////////////////////////////////////////////////////////////////////////////////////
  using namespace std;
  ///////////
  
  
  
  
  
  /////////////////////////////////////////////////////////////////////////////////////////////////////////
  // TEST AREA:
  // -- START POINT:
  /////////////////////////////////////////////////////////////////////////////////////////////////////////
  int main() {
  
      // Set cuda Device:
      if (cudaSetDevice(0) != cudaSuccess)
          cout &lt;&lt; "ERROR: cudaSetDevice(***)" &lt;&lt; endl;
  
      // Array:
      unsigned int size = 1000;
      double * d_ptr = nullptr;
  
      // Allocate unified memory:
      if (cudaMallocManaged(&amp;d_ptr, size * sizeof(double), cudaMemAttachGlobal) != cudaSuccess)
          cout &lt;&lt; "ERROR: cudaMallocManaged(***)" &lt;&lt; endl;
  
      if (cudaDeviceSynchronize() != cudaSuccess)
          cout &lt;&lt; "ERROR: cudaDeviceSynchronize(***)" &lt;&lt; endl;
  
      // Prefetch:
      if(cudaMemPrefetchAsync(d_ptr, size * sizeof(double), 0) != cudaSuccess)
          cout &lt;&lt; "ERROR: cudaMemPrefetchAsync(***)" &lt;&lt; endl;
  
      // Exit:
      getchar();
  }
  ///////////
  </code></pre>