Hi,
I’m trying to make my code run quickly on CUDA 8.0 after the change in behaviour for managed memory (see the main answer to c++ - Why is NVIDIA Pascal GPUs slow on running CUDA Kernels when using cudaMallocManaged - Stack Overflow for background).
I have code that utilises the nice Managed class for writing portable code between c++ and CUDA:
class Managed {
public:
void *operator new(size_t len) {
void *ptr;
cudaMallocManaged(&ptr, len);
cudaDeviceSynchronize();
return ptr;
}
void operator delete(void *ptr) {
cudaDeviceSynchronize();
cudaFree(ptr);
}
};
(see https://devblogs.nvidia.com/parallelforall/unified-memory-in-cuda-6/).
In order that my managed code is quick, I need to the GPU to preload the managed memory. I added a method to my class that derives from Managed:
__host__ void SyncronizeGPUMemory()
{
void* ptr = (void*) this;
size_t byteSize = sizeof(MyManagedClass);
cudaMemPrefetchAsync(ptr, byteSize, 0);
}
and call this method before I launch the kernel that utilises the managed memory object.
However, I get an error when debugging the kernel:
CUDART error: cudaMemPrefetchAsync returned cudaErrorInvalidDevice
Has anyone seen this or has an idea of what I’m doing wrong? I was wondering if it is okay to put 0 in the third parameter of cudaMemPrefetchAsync for the stream (I’m not using streams).
Many thanks