cudaMallocManaged - how to get it back?

Hello. The memory allocated by cudaMallocManaged will be rewritten automatically do the device when the time comes, right? So the kernel runs with the pointer, accesses it, the memory is copied to the device, kernel is happy and does its job. Now the kernel finishes and I would like to see what did it do inside this memory. So I’m expecting that reading this pointer on the host will show me it. But it does not. Is it wrong assumption, or wrong code?

Normally, when you access the managed memory from the host side, the data is copied back. Has your kernel really finished? Many kernel invocations are asynchronous.

I use cudaDeviceSynchronize() and the kernel is absolutely trivial. Anyway, after some non-related changes elsewhere and rebuilds this problem had unstuck and without any visible reason started to work as you say. I suspect incorrect management of compiler resources, or similar phenomenon. Thanks for confirming that I expected what I should expect.

1 Like