Using virtual functions in CUDA kernels

故事扮演 提交于 2019-12-06 07:03:12

问题


So I want to allocate an object with virtual functions on the device, then call a kernel and execute some of those virtual functions. I have tried two ways to do this but neither work:

1) Allocate and copy the object from the host using cudaMalloc and cudaMemcpy. This copies over the virtual function table that contains host memory pointers which obviously crash the kernel when executing on the device.

2) Allocate the object from a second kernel, save the device memory pointer to the object and pass that pointer to the original kernel. However, since the kernels are different, the functions are not in the same places in device memory upon kernel execution and the virtual function table is incorrect and crashes the kernel when used.

Can I only use virtual functions with objects created in the kernel the functions are called from?

Can I somehow reference the original kernel when I allocate my objects to get the virtual function table right?

Do I even understand what the actual problem is here?


回答1:


Do I even understand what the actual problem is here?

Part of it.

As you experimented C++ in cuda is not fully supported. Only Starting from 4.0 you can use the virtual function.

  1. Make sure you have the 4.0 driver / api.

  2. Post your Error log.



来源:https://stackoverflow.com/questions/5722942/using-virtual-functions-in-cuda-kernels

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!