CUDA - Creating objects in kernel and using them at host
<p>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</p>

<pre><code>class Production {
    Vertex * boundVertex;
}


class Vertex {
    Vertex * leftChild;
    Vertex * rightChild;
}
</code></pre>

<p>Then on the host I do:</p>

<pre><code>Production* dProd;
cudaMalloc(&amp;dProd, sizeof(Production *));
createProduction&lt;&lt;&lt;1,1&gt;&gt;&gt;(dProd);
</code></pre>

<p>where</p>

<pre><code>__global__ void createProduction(Production * prod) {
    prod = new Production();
    prod-&gt;leftChild = new Vertex();
    prod-&gt;rightChild = new Vertex();
}
</code></pre>

<p>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.</p>