CUDA 编译错误 - 预期一个标识符

CUDA 编译错误 - 预期一个标识符

当我尝试执行以下代码时,出现错误:

#include "cuda_runtime.h"
#include "device_launch_parameters.h"
#include <stdio.h>
#include <stdlib.h>

__global__ void vecAdd(int *A, int *B, int *C)
{
    int id = threadIdx.x;
    C[id] = A[id] + B[id];
}

int main()
{
    printf("Enter the dimenstions of A");
    int n;
    scanf("%d", &n);
    int A[n], B[n], C[n];
    printf("Enter the elements of A: \n");
    for(int i = 0; i < n; i++)
    {
        scanf("%d", &A[i]);
    }

    printf("Enter the elements of B: \n");
    for(int i = 0; i < n; i++)
    {
        scanf("%d", &B[i]);
    }

    int *dA, *dB, *dC;
    cudaMalloc((void **)&dA, n*sizeof(int));
    cudaMalloc((void **)&dB, n*sizeof(int));
    cudaMalloc((void **)&dC, n*sizeof(int));

    cudaMemcpy(dA, A, n*sizeof(int), cudaMemcpyHostToDevice);
    cudaMemcpy(dB, B, n*sizeof(int), cudaMemcpyHostToDevice);

    vecAdd<<<1,n>>>(dA, dB, dC);

    cudaMemcpy(C, dC, n*sizeof(int), cudaMemcpyDeviceToHost);

    for(int i = 0; i < n; i ++)
    {
        printf("%d \t", C[i]);

    }
}


我收到的错误是:

/usr/include/x86_64-linux-gnu/c++/5/bits/c++config.h(218): error: expected an identifier

/usr/include/x86_64-linux-gnu/c++/5/bits/c++config.h(218): error: expected a type specifier

/usr/include/x86_64-linux-gnu/c++/5/bits/c++config.h(218): error: explicit type is missing ("int" assumed)

/usr/include/x86_64-linux-gnu/c++/5/bits/c++config.h(222): error: expected an identifier

/usr/include/x86_64-linux-gnu/c++/5/bits/c++config.h(222): error: expected a type specifier

/usr/include/x86_64-linux-gnu/c++/5/bits/c++config.h(222): error: explicit type is missing ("int" assumed)

/usr/include/x86_64-linux-gnu/bits/byteswap.h(47): error: identifier "__builtin_bswap32" is undefined

/usr/include/x86_64-linux-gnu/bits/byteswap.h(111): error: identifier "__builtin_bswap64" is undefined

/usr/include/c++/5/bits/cpp_type_traits.h(270): error: identifier "__int128" is undefined

/usr/include/c++/5/bits/cpp_type_traits.h(270): error: expected a ">"

/usr/include/c++/5/cstdlib(178): error: identifier "__int128" is undefined

/usr/include/c++/5/cstdlib(179): error: identifier "__int128" is undefined

12 errors detected in the compilation of "/tmp/tmpxft_0000200c_00000000-4_temp2.cpp1.ii".

非常感谢您的帮助。谢谢!

相关内容