I am in the process of implementing multithreading through a NVIDIA GeForce GT 650M GPU for a simulation I have created. In order to make sure everything works properly, I have
It isn't possible to do what you are trying to do.
To allocate a vector using managed memory you would have to write your own implementation of an allocator which inherits from std::allocator_traits and calls cudaMallocManaged
under the hood. You can then instantiate a std::vector
using your allocator class.
Also note that your CUDA kernel code is broken in that you can't use std::vector
in device code.
Note that although the question has managed memory in view, this is applicable to other types of CUDA allocation such as pinned allocation.
As another alternative, suggested here, you could consider using a thrust host vector in lieu of std::vector
and use a custom allocator with it. A worked example is here in the case of pinned allocator (cudaMallocHost
/cudaHostAlloc
).