Search code examples
c++cudaplacement-newgpu-managed-memory

Placement new after cuda malloc managed memory


I have terrible errors with CUDA managed allocation. I'd like to confirm that the following code is correct:

T* x;
cudaMallocManaged(&x, sizeof(*x));
new(x) T(..)

Is placement new syntax supported by CUDA version 11. Thanks.


Solution

  • yes, that should be usable, ignoring minor issues like the use of ellipsis and missing semicolon. You can find examples of proper and typical use of placement new in CUDA right here on the SO cuda tag with a bit of searching.

    Yes, placement new is supported/usable. The code you have depicted here is mostly host code (ignoring a call to a host code library). So the support for this operation (placement new) in the context you have shown is actually coming from the host compiler you are using, not anything provided by the CUDA toolkit.