我想使用CUDA创建一个神经网络:
我的内核代码如下:
__global__ void feedForward(float *input, float *output, float **weight) {
//Here the threadId uniquely identifies weight in a neuron
int weightIndex = threadIdx.x;
//Here the blockId uniquely identifies a neuron
int neuronIndex = blockIdx.x;
if(neuronIndex<NO_OF_NEURONS && weightIndex<NO_OF_WEIGHTS)
output[neuronIndex] += weight[neuronIndex][weightIndex]
* input[weightIndex];
}
在将输出复制回主机时,我遇到了一个错误。
错误未指定发生故障的行 xx。
在第 xx 行:
CUDA_CHECK_RETURN(cudaMemcpy(h_output, d_Output, output_size, cudaMemcpyDeviceToHost));
我在这里做错了什么吗?
是因为我同时使用块索引和线程索引来引用权重矩阵吗?还是问题出在其他地方?
我是按以下方式分配权重矩阵的:
cudaMallocPitch((void**)&d_Weight, &pitch_W,input_size,NO_OF_NEURONS);
我的内核调用是:
feedForward<<<NO_OF_NEURONS,NO_OF_WEIGHTS>>>(d_Input,d_Output,d_Weight);
之后我调用:
cudaThreadSynchronize();
我对使用CUDA进行编程还不熟悉。 任何帮助都将不胜感激。
谢谢