CUDA - Creating objects in kernel and using them at host [duplicate]

限于喜欢 提交于 2019-12-20 06:09:10

问题


I need to use polymorphism in my kernels. The only way of doing this is to create those objects on the device (to make a virtual mehod table available at the device). Here's the object being created

class Production {
    Vertex * boundVertex;
}


class Vertex {
    Vertex * leftChild;
    Vertex * rightChild;
}

Then on the host I do:

Production* dProd;
cudaMalloc(&dProd, sizeof(Production *));
createProduction<<<1,1>>>(dProd);

where

__global__ void createProduction(Production * prod) {
    prod = new Production();
    prod->leftChild = new Vertex();
    prod->rightChild = new Vertex();
}

The question is how do I get both left and right vertices of the production created on the device back on the host? I know using pointers in classes makes them very hard to handle but... no other way of creating such tree structure.


回答1:


You can't do that.

The host runtime and driver memory management APIs can't be used to access allocations made on the runtime heap using new or malloc. There is no way for the host to copy those Vertexinstances from the device.



来源:https://stackoverflow.com/questions/35116030/cuda-creating-objects-in-kernel-and-using-them-at-host

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