0

When I try to execute the following code, I get errors :

#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]);

    }
}


The errors I get are :

/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".

Any help is deeply appreciated. Thanks!

2
  • 1
    Make sure you are using a supported GCC/G++ compiler for your CUDA version: see NVIDIA CUDA Installation Guide for Linux Mar 29 '19 at 14:20
  • Thanks for the reply! I've checked it, the version specified and the version I am using match exactly. Is there any other reason why this error might occur?
    – my_cse lab
    Mar 29 '19 at 17:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.