cudaMemPrefetchAsync returns cudaErrorInvalidDevice

OK, it’s now September, I’m using 9.2, and just ran into this problem.
Why are nVidia sooo Windows belligerent?

Thanks for reporting this ticket .After checking with our engineers , we think this is expected behavior , please see CUDA Runtime API :: CUDA Toolkit Documentation
Passing in cudaCpuDeviceId for dstDevice will prefetch the data to host memory. If dstDevice is a GPU, then the device attribute cudaDevAttrConcurrentManagedAccess must be non-zero. Additionally, stream must be associated with a device that has a non-zero value for the device attribute cudaDevAttrConcurrentManagedAccess.

Doing cudaMemPrefetchAsync on managed memory requires support for “cudaDevAttrConcurrentManagedAccess”.

Currently, this is only supported on Linux. You are suggested to check for the above device attr before doing mem prefetch on managed mem. like

int* data;
size_t len = 10;
int featureSupported = 0;

CHECK_RT(cudaMallocManaged(reinterpret_cast<void **>(&data), len, cudaMemAttachGlobal));
CHECK_RT(cudaDeviceGetAttribute(&featureSupported, cudaDevAttrConcurrentManagedAccess, 0));

if (featureSupported) {
CHECK_RT(cudaMemPrefetchAsync(data, len, 0, 0));
}

Hope this explains your question.

Best,
Yuki

1 Like