Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

CUDA placement new and virtual functions

I’m in a situation where I desperately need virtual functions in a kernel. I know that you can’t use objects created in host memory in kernels if they have virtual functions.

If i use placement new with a device pointer allocated by cudaMallocManaged, can I pass that to a kernel and use it’s virtual functions properly?

The reason I’m asking and not just trying it is because I have a load of other issues with implementing this, and was wondering if it was even possible, because if it isn’t I could try the more complicated, but definitely working method explained here.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

If i use placement new with a device pointer allocated by cudaMallocManaged, can I pass that to a kernel and use it’s virtual functions properly?

No, it won’t work. The host constructor that gets called in that case will initialize the object as if it were a host object, and the virtual functions in that object will not work correctly if invoked in device code.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading