Cuda 错误 std::integral

Cuda 错误 std::integral

我是 cuda 编程的新手,在 nvcc final 出现许多错误后,我可以安装 cuda 工具包,但我收到了一条错误消息nvcc 的输出

我的代码是

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

#define N 10

__global__ void vector_add(int* a, int* b, int* c) {
    int i = threadIdx.x;
    if (i < N) {
        c[i] = a[i] + b[i];
    }
}

int main() {
    int a[N], b[N], c[N];
    int *dev_a, *dev_b, *dev_c;

    cudaMalloc((void**)&dev_a, N * sizeof(int));
    cudaMalloc((void**)&dev_b, N * sizeof(int));
    cudaMalloc((void**)&dev_c, N * sizeof(int));

    for (int i = 0; i < N; i++) {
        a[i] = -i;
        b[i] = i * i;
    }

    cudaMemcpy(dev_a, a, N * sizeof(int), cudaMemcpyHostToDevice);
    cudaMemcpy(dev_b, b, N * sizeof(int), cudaMemcpyHostToDevice);

    vector_add<<<1, N>>>(dev_a, dev_b, dev_c);

    cudaMemcpy(c, dev_c, N * sizeof(int), cudaMemcpyDeviceToHost);

    for (int i = 0; i < N; i++) {
        printf("\n results of matrix addition %d. element equals to  %d",i+1, c[i]);
    }

    cudaFree(dev_a);
    cudaFree(dev_b);
    cudaFree(dev_c);

    return 0;
}

相关内容