算术Cuda程序编译错误
Arithmetic Cuda program compilation error
我正在开发一个CUDA程序,这是我的新手。我遇到了下面的错误,尝试修复,但失败了。有人能看一眼,告诉我可能遗漏了什么吗?任何帮助都将不胜感激。
Error 5 error : too few arguments in function call
Error 6 error : argument of type "int *" is incompatible with parameter of type "size_t"
Error 7 error : argument of type "unsigned int" is incompatible with parameter of type "cudaMemcpyKind"
Error 8 error : too many arguments in function call 2010Projectslablabkernel.cu 54 1 lab
Error 9 error MSB3721: The command ""C:Program FilesNVIDIA GPU
这是我的代码:
#include <stdio.h>
#define SIZE 500
#include <cuda.h>
__global__ void InitialAdd(int *a, int *b, int *c, int *z, int n, float aspa, float bspb, float apa, float bpb)
{
int i = blockIdx.x + blockIdx.x * threadIdx.x;
aspa = (-*a);
bspb = (-*b);
aspa = (10,*a);
bspb = (10,*b);
*z = (a,2) + (b,2) + aspa + bspb + apa + bpb;
if(i < n)
c[i] = a[i] * b[i];
}
int main(void)
{
int *a, *b, *c, *z;
int *d_a, *d_b, *d_c, *d_z;
a = (int *)malloc(SIZE*sizeof(int));
b = (int *)malloc(SIZE*sizeof(int));
c = (int *)malloc(SIZE*sizeof(int));
z = (int *)malloc(SIZE*sizeof(int));
cudaMalloc( &d_a, SIZE*sizeof(int));
cudaMalloc( &d_b, SIZE*sizeof(int));
cudaMalloc( &d_c, SIZE*sizeof(int));
cudaMalloc( &d_z, SIZE*sizeof(int));
for( int i = 0; i < SIZE; i++ )
{
a[i] =i;
b[i] =i;
c[i] =0;
z[i] =i;
}
cudaMemcpy( d_a, a, SIZE*sizeof(int), cudaMemcpyHostToDevice );
cudaMemcpy( d_b, b, SIZE*sizeof(int), cudaMemcpyHostToDevice );
cudaMemcpy( d_c, c, SIZE*sizeof(int), cudaMemcpyHostToDevice );
cudaMemcpy( d_z, z, SIZE*sizeof(int), cudaMemcpyHostToDevice );
InitialAdd<<< 4 , SIZE >>>( d_a, d_b, d_c, d_z, SIZE);
cudaMemcpy( c, d_z, d_c, SIZE*sizeof(int), cudaMemcpyDeviceToHost );
for( int i = 0; i < 1000; i++)
printf("c[%d] = %dn", i, c[i], *z);
free(a);
free(b);
free(c);
free(z);
cudaFree(d_a);
cudaFree(d_b);
cudaFree(d_c);
cudaFree(d_z);
return 0;
}
我可以在这行看到一个明显的问题:
cudaMemcpy( c, d_z, d_c, SIZE*sizeof(int), cudaMemcpyDeviceToHost );
您传递了5个参数,而cudaMemcpy
只需要4个。我想你正试图从d_z
复制到c
,所以它应该是:
cudaMemcpy( c, d_z, SIZE*sizeof(int), cudaMemcpyDeviceToHost );
即移除CCD_ 4。
相关文章:
- 用MacOS Mojave编译C++:致命错误:mpi.h:没有这样的文件或目录
- std::is_base_of表示ctor编译错误
- 我的项目不会像"undefined reference to `grpc::g_core_codegen_interface'"那样使用未定义的引用错误进行编译
- 在没有定义返回类型的函数中返回布尔值,并将结果保存在无错误的char编译中-为什么
- Qt5:使用QCommandLineParser类时出现奇怪的编译错误
- Qt Cmake 错误编译"GuiSupportQt not found"
- Opengl 精度转换错误编译错误 E0415
- 库将ARM架构错误编译为架构X64
- RT 音频 Mac 错误 g++ 编译错误
- 错误编译Boost.log
- 错误编译QT创建者 / QT窗口小部件示例
- 错误编译MIPS32
- Visual Studio 2013 中的错误(编译和运行代码)
- 链接错误编译qt项目在visual 2010
- 无法用模板错误编译nsgmls
- 奇怪的错误.编译失败
- 如果有人调用c++中的方法,则强制错误(编译时)
- 来自autoconf测试的错误编译命令
- 时间限制超出错误C++编译
- SFML 2.3 和 CodeBlocks 错误编译