Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The problem is here:</p> <pre><code>cudaMalloc((void**)&amp;nL,sizeof(NLayer)); cudaMalloc((void**)&amp;nL-&gt;neurons,6*sizeof(Neuron)); </code></pre> <p>In first line, <code>nL</code> is pointing to structure in global memory on device. Therefore, in second line the first argument to <code>cudaMalloc</code> is address residing on GPU, which is undefined behaviour (on my test system, it causes segfault; in your case, though, there is something more subtle).</p> <p>The correct way to do what you want is first to create structure in host memory, fill it with data, and then copy it to device, like this:</p> <pre><code>NLayer* nL; NLayer h_nL; int i; int tmp=9; // Allocate data on device cudaMalloc((void**)&amp;nL, sizeof(NLayer)); cudaMalloc((void**)&amp;h_nL.neurons, 6*sizeof(Neuron)); // Copy nlayer with pointers to device cudaMemcpy(nL, &amp;h_nL, sizeof(NLayer), cudaMemcpyHostToDevice); </code></pre> <p>Also, don't forget to always check for any errors from CUDA routines.</p> <p><strong>UPDATE</strong></p> <p>In second version of your code:</p> <p><code>cudaMemcpy(&amp;d_layer-&gt;neurons[i].weights,&amp;d_weights,...)</code> --- again, you are dereferencing device pointer (<code>d_layer</code>) on host. Instead, you should use</p> <pre><code>cudaMemcpy(&amp;h_layer.neurons[i].weights,&amp;d_weights,sizeof(float*),cudaMemcpyHostToDevice </code></pre> <p>Here you take <code>h_layer</code> (host structure), read its element (<code>h_layer.neurons</code>), which is pointer to device memory. Then you do some pointer arithmetics on it (<code>&amp;h_layer.neurons[i].weights</code>). No access to device memory is needed to compute this address.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload