這個程序看起來很好,但我仍然得到一個錯誤,一些建議?編譯Cuda時出錯 - 預期的小學表達式
計劃:
#include "dot.h"
#include <cuda.h>
#include <cuda_runtime.h>
#include <stdio.h>
int main(int argc, char** argv)
{
int *a, *b, *c;
int *dev_a, *dev_b, *dev_c;
int size = N * sizeof(int);
cudaMalloc((void**)&dev_a, size);
cudaMalloc((void**)&dev_b, size);
cudaMalloc((void**)&dev_c, sizeof(int));
a = (int *)malloc (size);
b = (int *)malloc (size);
c = (int *)malloc (sizeof(int));
random_ints(a, N);
random_ints(b, N);
cudaMemcpy(dev_a, a, size, cudaMemcpyHostToDevice);
cudaMemcpy(dev_b, b, size, cudaMemcpyHostToDevice);
int res = N/THREADS_PER_BLOCK;
dot<<< res, THREADS_PER_BLOCK >>> (dev_a, dev_b, dev_c);
//helloWorld<<< dimGrid, dimBlock >>>(d_str);
cudaMemcpy (c, dev_c, sizeof(int), cudaMemcpyDeviceToHost);
free(a); free(b); free(c);
cudaFree(dev_a);
cudaFree(dev_b);
cudaFree(dev_c);
return 0;
}
錯誤:
DotProductCuda.cpp:27: error: expected primary-expression before
'<'
token
DotProductCuda.cpp:27: error: expected primary-expression before'>'
token
回答關於<<>>的問題,但是現在我得到了'DotProductCuda.cu(26):錯誤:無法配置主機函數調用'某些想法? – Custodio 2011-05-13 16:40:48
是的,你還沒有宣佈dot作爲nvcc的內核,所以它將它視爲一個隱式定義的主機函數。 – talonmies 2011-05-13 17:15:24
我找到了。我沒有將__global__方法聲明爲點。 Cuda函數就像'__global__ void dot ....' – Custodio 2011-05-13 17:18:48