PatrykB
PatrykB

Reputation: 1699

cudaMemPrefetchAsync() returns cudaErrorInvalidDevice - why?

Whenever I call cudaMemPrefetchAsync() it returns the error code cudaErrorInvalidDevice. I am sure that I pass right device id (I have only one CUDA-capable GPU in my laptop under id == 0).

I believe that code sample posted below is error-free, but at line 52 (call to cudaMemPrefetchAsync()) I keep getting this error.


I tried:

  1. Clean driver installation. (Latest version)
  2. I check Google for an answer, but I could not find any. (I managed only to find this)

(I haven't idea for anything else)


System Spec:

OS: Microsoft windows 8.1 x64 home.
IDE: Visual studio 2015
CUDA toolkit: 8.0.61
NVIDIA GPU: GeForce GTX 960M
NVIDIA GPU driver: ver 381.65 (latest)
Compute Capability: 5.0 (Maxwell)
Unified Memory support: is supported.
Intel integrated gpu: Intel HD graphics 4600


Code Sample:

/////////////////////////////////////////////////////////////////////////////////////////////////////////
// TEST AREA:
// -- INCLUDE: 
/////////////////////////////////////////////////////////////////////////////////////////////////////////

// Cuda Libs: ( Device Side ):
#include <cuda_runtime.h>
#include <device_launch_parameters.h>

// Std C++ Libs:
#include <iostream>
#include <iomanip>
///////////





/////////////////////////////////////////////////////////////////////////////////////////////////////////
// TEST AREA:
// -- NAMESPACE:
/////////////////////////////////////////////////////////////////////////////////////////////////////////
using namespace std;
///////////





/////////////////////////////////////////////////////////////////////////////////////////////////////////
// TEST AREA:
// -- START POINT:
/////////////////////////////////////////////////////////////////////////////////////////////////////////
int main() {

    // Set cuda Device:
    if (cudaSetDevice(0) != cudaSuccess)
        cout << "ERROR: cudaSetDevice(***)" << endl;

    // Array:
    unsigned int size = 1000;
    double * d_ptr = nullptr;

    // Allocate unified memory:
    if (cudaMallocManaged(&d_ptr, size * sizeof(double), cudaMemAttachGlobal) != cudaSuccess)
        cout << "ERROR: cudaMallocManaged(***)" << endl;

    if (cudaDeviceSynchronize() != cudaSuccess)
        cout << "ERROR: cudaDeviceSynchronize(***)" << endl;

    // Prefetch:
    if(cudaMemPrefetchAsync(d_ptr, size * sizeof(double), 0) != cudaSuccess)
        cout << "ERROR: cudaMemPrefetchAsync(***)" << endl;

    // Exit:
    getchar();
}
///////////

Upvotes: 5

Views: 2814

Answers (1)

PatrykB
PatrykB

Reputation: 1699

Thank to talonmies I have realized that my GPU does not support prefetch feature. In order to be able to use cudaMemPrefetchAsync(***) gpu must have non-zero value in (cudaDeviceProp)deviceProp.concurrentManagedAccess.

See more here.

Upvotes: 7

Related Questions