0

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.

2
  • Your question is not clear. Doesn't the method you have depicted already create the left and right vertices on the device? Are you asking "once created, how to I move the left and right vertices back to the host?" I think your setup of dProd is a little odd, but that doesn't seem to be impacting anything. Commented Jan 31, 2016 at 16:20
  • I would like to dereference leftChild and rightChild back on the host. They are created on the device and I need them on the host. Commented Jan 31, 2016 at 16:40

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.