I have these structures:
typedef struct neuron { float* weights; int n_weights; }Neuron; typedef struct neurallayer { Neuron *neurons; int n_neurons; int act_function; }NLayer;
The NLayer structure may contain an arbitrary number of Neuron
I tried to isolate the "NLayer" structure with 5 "Neurons" from the host in this way:
NLayer* nL; int i; int tmp=9; cudaMalloc((void**)&nL,sizeof(NLayer)); cudaMalloc((void**)&nL->neurons,6*sizeof(Neuron)); for(i=0;i<5;i++) cudaMemcpy(&nL->neurons[i].n_weights,&tmp,sizeof(int),cudaMemcpyHostToDevice);
... Then I tried to change the variable nL-> neurons [0] .n_weights "with this kernel:
__global__ void test(NLayer* n) { n->neurons[0].n_weights=121; }
but at compile time, nvcc returns this "warning" related to a single kernel line:
Warning: Cannot tell what pointer points to, assuming global memory space
and when the kernel completes its work, the structure will begin to be inaccessible.
It is very likely that I am doing something wrong during the allocation .... can someone help me? Thank you very much and sorry for my english! :)
UPDATE:
Thanks to aland, I changed my code by creating this function, which should highlight an instance of the "NLayer" structure:
NLayer* setNLayer(int numNeurons,int weightsPerNeuron,int act_fun) { int i; NLayer h_layer; NLayer* d_layer; float* d_weights;
and I call this function from the main in this way (the kernel test is checked earlier):
int main() { NLayer* nL; int h_tmp1; float h_tmp2; nL=setNLayer(10,12,13); test<<<1,1>>>(nL); if(cudaMemcpy(&h_tmp1,&nL->neurons[0].n_weights,sizeof(float),cudaMemcpyDeviceToHost)!=cudaSuccess); puts("ERROR!!"); printf("RESULT:%d",h_tmp1); }
When I compile this code, the compiler shows me a warning, and when I run the program, it displays:
Error: unable to copy weights' pointer to the device Error: unable to copy weights' pointer to the device Error: unable to copy weights' pointer to the device Error: unable to copy weights' pointer to the device Error: unable to copy weights' pointer to the device Error: unable to copy weights' pointer to the device Error: unable to copy weights' pointer to the device Error: unable to copy weights' pointer to the device Error: unable to copy weights' pointer to the device Error: unable to copy weights' pointer to the device ERROR!! RESULT:1
The last error is not compared if I comment on the kernel call.
Where am I mistaken? I do not know how to do this. Thanks for your help!