title: Copying a multi-branch tree to GPU memory
body: <p>i have a tree of nodes and i am trying to copy it to GPU memory. the Node looks like this:</p>
  
  <pre><code>struct Node
  {
     char *Key;
     int ChildCount;
     Node *Children;
  }
  </code></pre>
  
  <p>And my copy function looks like this:</p>
  
  <pre><code>void CopyTreeToDevice(Node* node_s, Node* node_d)
  {
  
  
       //allocate node on device and copy host node
       cudaMalloc( (void**)&amp;node_d, sizeof(Node));
       cudaMemcpy(node_d, node_s, sizeof(Node), cudaMemcpyHostToDevice);
  
       //test
       printf("ChildCount of node_s looks to be : %d\n", node_s-&gt;ChildCount);
       printf("Key of node_s looks to be : %s\n", node_s-&gt;Key);
  
       Node *temp;
       temp =(Node *) malloc(sizeof(Node));
       cudaMemcpy(temp, node_d, sizeof(Node), cudaMemcpyDeviceToHost);
       printf("ChildCount of node_d on device is actually : %d\n", temp-&gt;ChildCount);
       printf("Key of node_d on device is actually : %s\n", temp-&gt;Key);
       free(temp);
  
  
  
       //       continue with child nodes
       if(node_s-&gt;ChildCount &gt; 0)
       {
           //problem here
           cudaMalloc( (void**)&amp;(node_d-&gt;Children), sizeof(Node)*(node_s-&gt;ChildCount));
  
           cudaMemcpy(node_d-&gt;Children, node_s-&gt;Children, 
                      sizeof(Node)*node_s-&gt;ChildCount, cudaMemcpyHostToDevice);
  
           for(int i=0;i&lt;node_s-&gt;ChildCount;i++)
           {
                   CopyTreeToDevice(&amp;(node_s-&gt;Children[i]), &amp;(node_d-&gt;Children[i]));
           }
       }
  
  }
  </code></pre>
  
  <p>But i have a problem with the line :</p>
  
  <pre><code>cudaMalloc( (void**)&amp;(node_d-&gt;Children), sizeof(Node)*(node_s-&gt;ChildCount));
  </code></pre>
  
  <p>Gives me access violation exception.Test section works smoothly.no problem at initializing fields.</p>
  
  <p>Here is the output of test section :</p>
  
  <pre><code>ChildCount of node_s looks to be : 35
  Key of node_s looks to be : root
  ChildCount of node_d on device is actually : 35
  Key of node_d on device is actually : root
  </code></pre>
  
  <p>What is the reason for this? </p>
  
  <p>Thanks.</p>