在CUDA内核中使用虚拟函数 [英] Using virtual functions in CUDA kernels

查看:200
本文介绍了在CUDA内核中使用虚拟函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我想在设备上分配一个带有虚函数的对象,然后调用一个内核并执行一些虚函数。我尝试了两种方法,但两者都不工作:



1)使用cudaMalloc和cudaMemcpy从主机分配和复制对象。这会复制包含主机内存指针的虚拟函数表,这些指针在设备上执行时会明显崩溃内核。



2)从第二个内核分配对象,保存设备内存指针指向对象,并将该指针传递给原始内核。然而,由于内核不同,在内核执行时函数不在设备存储器中的相同位置,并且虚拟函数表不正确,并且在使用时崩溃内核。



我可以只使用虚拟函数与在内核中创建的对象,函数是从哪里调用的?



当我分配我的对象来获得虚拟

解决方案




这是我真正的问题。



正如您所做的C ++中的C ++不完全支持。只有从4.0开始,您可以使用虚拟函数。




  1. 张贴错误纪录。



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?

解决方案

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.

这篇关于在CUDA内核中使用虚拟函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆