算术Cuda程序编译错误

时间:2014-04-28 10:34:25

标签: c++ cuda nvidia pointer-arithmetic

我正在开发一个新手的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 2010\Projects\lab\lab\kernel.cu 54  1   lab
Error   9   error MSB3721: The command ""C:\Program Files\NVIDIA 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] = %d\n", 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;
}

1 个答案:

答案 0 :(得分:2)

我可以在这一行中看到一个明显的问题:

cudaMemcpy( c, d_z, d_c, SIZE*sizeof(int), cudaMemcpyDeviceToHost );

您传递了5个参数,而cudaMemcpy只需要4个。我猜你是否正在尝试从d_z复制到c,所以它会是:

cudaMemcpy( c, d_z, SIZE*sizeof(int), cudaMemcpyDeviceToHost );

即。删除d_c