J'ai ces struct:CUDA: l'attribution d'un tableau de struct dans une struct
typedef struct neuron
{
float* weights;
int n_weights;
}Neuron;
typedef struct neurallayer
{
Neuron *neurons;
int n_neurons;
int act_function;
}NLayer;
« nLayer » struct peut contenir un nombre arbitraire de « Neuron »
J'ai essayé de allouent une struct « nLayer » avec 5 « neurones » de l'hôte de cette façon:
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);
... alors j'ai essayé de modifier les « NL-> neurones [0] .n_weights » variable que le noyau :
__global__ void test(NLayer* n)
{
n->neurons[0].n_weights=121;
}
mais le temps de compilation revient FPUNV que « avertissement » lié à la seule ligne du noyau:
Warning: Cannot tell what pointer points to, assuming global memory space
et lorsque le noyau terminé son travail inatteignable commencer la struct.
C'est très probablement que je fais quelque chose de mal lors de l'allocation .... quelqu'un peut m'aider ?? Merci beaucoup, et désolé pour mon anglais! :)
MISE À JOUR:
Merci à Aland J'ai modifié mon code la création de cette fonction qui doit allouer une instance de la struct "nLayer":
NLayer* setNLayer(int numNeurons,int weightsPerNeuron,int act_fun)
{
int i;
NLayer h_layer;
NLayer* d_layer;
float* d_weights;
//SET THE LAYER VARIABLE OF THE HOST NLAYER
h_layer.act_function=act_fun;
h_layer.n_neurons=numNeurons;
//ALLOCATING THE DEVICE NLAYER
if(cudaMalloc((void**)&d_layer,sizeof(NLayer))!=cudaSuccess)
puts("ERROR: Unable to allocate the Layer");
//ALLOCATING THE NEURONS ON THE DEVICE
if(cudaMalloc((void**)&h_layer.neurons,numNeurons*sizeof(Neuron))!=cudaSuccess)
puts("ERROR: Unable to allocate the Neurons of the Layer");
//COPING THE HOST NLAYER ON THE DEVICE
if(cudaMemcpy(d_layer,&h_layer,sizeof(NLayer),cudaMemcpyHostToDevice)!=cudaSuccess)
puts("ERROR: Unable to copy the data layer onto the device");
for(i=0;i<numNeurons;i++)
{
//ALLOCATING THE WEIGHTS' ARRAY ON THE DEVICE
cudaMalloc((void**)&d_weights,weightsPerNeuron*sizeof(float));
//COPING ITS POINTER AS PART OF THE i-TH NEURONS STRUCT
if(cudaMemcpy(&d_layer->neurons[i].weights,&d_weights,sizeof(float*),cudaMemcpyHostToDevice)!=cudaSuccess)
puts("Error: unable to copy weights' pointer to the device");
}
//RETURN THE DEVICE POINTER
return d_layer;
}
et j'appeler cette fonction de la principale de cette façon (le noyau « test » est déjà déclarée):
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);
}
Quand je compile ce code le spectacle du compilateur moi l'avertissement, et quand je l'exécution du programme, il imprime à l'écran:
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
La dernière erreur ne compare pas si je commente l'appel du noyau.
Où est-ce que je me trompe? Je ne sais pas comment faire Merci pour votre aide!
Alors que vous avez raison à propos de l'avertissement, je doute que ce soit ce qui provoque un comportement anormal du programme. Après tout, l'hypothèse du compilateur sur la structure résidant dans l'espace emory global est correcte ... – aland
J'utilise un NVIDIA GeForce 320M 256 Mo avec la capacité 1.2, donc je ne pense pas que ce soit une carte "Fermi" –