编译Cuda程序时出错 [英] Error compiling Cuda Program
问题描述
嘿,这个程序似乎很好,但我还是得到一个错误,一些建议?
Hey, this program seems be fine but I still getting an erro, some suggestion?
程序:
#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:错误:'<'
符号前的预期主表达式
DotProductCuda.cpp :27:错误:'>'
DotProductCuda.cpp:27: error: expected primary-expression before
'<'
token
DotProductCuda.cpp:27: error: expected primary-expression before'>'
token
之前的预期主表达式
推荐答案
<< >>>
调用内核的语法不是标准C或C ++。这些调用必须在由NVCC编译器编译的文件中。这些文件通常以.cu扩展名命名。对CUDA的其他API调用(例如 cudaMalloc
)可以是常规的.c或.cpp文件。
The <<< >>>
syntax for calling a kernel is not standard C or C++. Those calls must be in a file compiled by the NVCC compiler. Those files are normally named with a .cu extension. Other API calls to CUDA such as cudaMalloc
can be in regular .c or .cpp files.
这篇关于编译Cuda程序时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!