简体   繁体   English

CUDA分段错误的简单教程示例

[英]CUDA segmentation fault for trivial tutorial example

I am trying to run the example add.cu (see below) from this official nvidia tutorial using nvcc add.cu -o add_cuda; ./add_cuda 我正在尝试使用nvcc add.cu -o add_cuda; ./add_cuda从此官方nvidia教程中运行示例add.cu (请参见下文) nvcc add.cu -o add_cuda; ./add_cuda nvcc add.cu -o add_cuda; ./add_cuda and get Segmentation fault (core dumped) . nvcc add.cu -o add_cuda; ./add_cuda并获得Segmentation fault (core dumped)

I installed the nvidia cuda toolkit on Ubuntu 18 using sudo apt install nvidia-cuda-toolkit . 我使用sudo apt install nvidia-cuda-toolkit在Ubuntu 18上安装了nvidia cuda工具sudo apt install nvidia-cuda-toolkit I have a NVIDIA GF100GL Quadro 5000 and am using NVIDIA driver metapackage from nvidia-driver-390 (proprietary, tested) 我有一个NVIDIA GF100GL Quadro 5000,并且正在使用NVIDIA driver metapackage from nvidia-driver-390 (proprietary, tested)软件包NVIDIA driver metapackage from nvidia-driver-390 (proprietary, tested)

I have little C++ experience, but the pure C++ code from the beginning of the tutorial compiled and ran correctly. 我几乎没有C ++经验,但是从本教程开始的纯C ++代码可以正确编译并运行。

Following a comment, I added a check for the return of cudaMallocManaged and got operation not supported . 发表评论后,我添加了一个检查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;
}

Your card belongs to fermi family with compute capability version 2.0. 您的卡属于具有计算功能2.0版的fermi系列。 It does not support the Unified Memory as stated here: 它不支持统一内存,如下所示

K.1.1. K.1.1。 System Requirements 系统要求

Unified Memory has two basic requirements: 统一内存有两个基本要求:

a GPU with SM architecture 3.0 or higher (Kepler class or newer) 具有SM架构3.0或更高版本(Kepler类或更高版本)的GPU

a 64-bit host application and non-embedded operating system (Linux, Windows, macOS) 64位主机应用程序和非嵌入式操作系统(Linux,Windows,macOS)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM