代码之家  ›  专栏  ›  技术社区  ›  Bananach

用于普通教程示例的CUDA分段错误

  •  0
  • Bananach  · 技术社区  · 6 年前

    我正在尝试运行这个示例 add.cu (见下文) this official nvidia tutorial 使用 nvcc add.cu -o add_cuda; ./add_cuda 然后得到 Segmentation fault (core dumped) .

    我在Ubuntu 18上安装了Nvidia Cuda工具包,使用 sudo apt install nvidia-cuda-toolkit . 我有一个Nvidia GF100GL Quadro 5000,正在使用 NVIDIA driver metapackage from nvidia-driver-390 (proprietary, tested)

    我有很少的C++经验,但是纯C++代码从教程开始编译并正确运行。

    在评论之后,我添加了一张支票 cudaMallocManaged 然后得到 operation not supported .

    #include <iostream>
    #include <math.h>
    // Kernel function to add the elements of two arrays
    __global__
    void add(int n, float *x, float *y)
    {
      for (int i = 0; i < n; i++)
        y[i] = x[i] + y[i];
    }
    
    int main(void)
    {
      int N = 1<<20;
      float *x, *y;
    
      // Allocate Unified Memory – accessible from CPU or GPU
      cudaMallocManaged(&x, N*sizeof(float));
      cudaMallocManaged(&y, N*sizeof(float));
    
      // initialize x and y arrays on the host
      for (int i = 0; i < N; i++) {
        x[i] = 1.0f;
        y[i] = 2.0f;
      }
    
      // Run kernel on 1M elements on the GPU
      add<<<1, 1>>>(N, x, y);
    
      // Wait for GPU to finish before accessing on host
      cudaDeviceSynchronize();
    
      // Check for errors (all values should be 3.0f)
      float maxError = 0.0f;
      for (int i = 0; i < N; i++)
        maxError = fmax(maxError, fabs(y[i]-3.0f));
      std::cout << "Max error: " << maxError << std::endl;
    
      // Free memory
      cudaFree(x);
      cudaFree(y);
    
      return 0;
    }
    
    1 回复  |  直到 6 年前
        1
  •  2
  •   tunglt    6 年前

    您的卡属于费米家族,计算能力为2.0版。它不支持如前所述的统一内存 here:

    K.1.1系统要求

    统一内存有两个基本要求:

    具有SM架构3.0或更高版本(开普勒类或更高版本)的GPU

    64位主机应用程序和非嵌入式操作系统(Linux、Windows、MacOS)