내부 구조체의 배열의 할당 난이 구조체를했습니다 :CUDA : 구조체
이typedef struct neuron
{
float* weights;
int n_weights;
}Neuron;
typedef struct neurallayer
{
Neuron *neurons;
int n_neurons;
int act_function;
}NLayer;
"NLayer는"구조체는 "신경 세포"의 임의의 수를 포함 할 수 있습니다 내가 해봤
가 할당 이 방법으로 호스트로부터 5 '뉴런'와 'NLayer'구조체 :
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);
는 ... 그때는 수정을 시도한 그 커널 변수를 "nL-> 뉴런 [0] .n_weights" :
__global__ void test(NLayer* n)
{
n->neurons[0].n_weights=121;
}
하지만 컴파일 시간 NVCC 반환에서 63,210 그 커널의 유일한 라인과 관련 "경고"
Warning: Cannot tell what pointer points to, assuming global memory space
커널이 작업을 완료 할 때 구조체에 연결할 시작합니다.
아마도 배정 과정에서 뭔가 잘못하고있는 것 같습니다. 누군가 나를 도와 줄 수 있을까요 ?? 대단히 고마워, 내 영어로 미안해! :)
UPDATE: 올란드에
덕분에 내가 구조체 "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;
}
을 그리고 난 그 함수를 호출 (커널 "test"는 이전에 선언 된 것입니다.) :
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);
}
이 코드를 컴파일하면 컴파일러가 표시됩니다 나에게 경고하고, 프로그램을 실행할 때 화면에 출력한다 :
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
커널 호출에 주석을 달면 마지막 오류는 비교되지 않는다.
내가 틀렸어? 나는 어떻게 해야할지 모르겠다 당신의 도움에 감사드립니다!
경고에 대해 잘 알고 있지만 프로그램의 비정상적인 동작을 일으키는 원인인지는 의심 스럽습니다. 결국, 전 세계 emory 공간에 상주하는 구조에 대한 컴파일러의 가정은 정확합니다 ... – aland
1.2 능력이있는 NVIDIA GeForce 320M 256MB를 사용하고있어서 "Fermi"카드라고 생각하지 않습니다. –