cudaGetDeviceCount 返回 0

标签 cuda ubuntu-12.04 nvidia

我正在运行以下代码。但是,我得到的输出为
代码 38 出错
测试 = 0
设备计数= 0
代码 38 出错
测试2 = 0
我在 Ubuntu 上有一个 NVIDIA GTX 690 显卡。这是否意味着驱动程序未激活?

#include <iostream>

using namespace std;
__device__ __constant__ float* data;

template<class T> void allocOnly(T* deviceDest, size_t numElem)
{
    cudaError_t errCode = cudaMalloc((void**)&deviceDest, numElem*sizeof(T));
    if(errCode != cudaSuccess) 
        cout << "Got error with code " << errCode << endl;
}

int main()
{
    float* test(0);
    allocOnly<float>(test,10);
    cout << "test = " << test << endl;
    int deviceCount = 0;
    cudaGetDeviceCount(&deviceCount);
    cout << "deviceCount= " << deviceCount << endl;

    float* test2(0);    
    cudaError_t errCode = cudaMalloc((void**)&test2, 10*sizeof(float));
    if(errCode != cudaSuccess) 
        cout << "Got error with code " << errCode << endl;
    cout << "test2 = " << test2 << endl;

    return 0;
}

最佳答案

是的,您的系统设置有问题。尝试运行 nvidia-smi -a从终端查看它的报告。

你应该这样做 proper cuda error checking调用cudaGetDeviceCount (以及所有 cuda API 调用和内核调用)。 error returned from that API call也会很有启发性。

执行对 cudaGetDeviceCount 的调用对我来说也是有意义的。在任何其他 cuda API 调用之前(例如对 cudaMalloc 中的 allocOnly 的调用)。

关于cudaGetDeviceCount 返回 0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17689335/

相关文章:

c++ - 使用 Intel 编译器和 -std=c++11 标志时 NVCC 不工作

ubuntu - 无法运行 TeamCity 自定义脚本

linux - opengl与Nvidia gpu

CUDA 缩减优化

python - Tensorflow CUDA - CUPTI 错误 : CUPTI could not be loaded or symbol could not be found

c++ - 设备函数指针作为模板参数

c# - 寻找一个很好的资源来学习在 C# 中使用 CUDA

cuda - nvidia-smi 无法初始化 NVML : GPU access blocked by the operating system

linux - Oracle 10g ProC 的 Mach-o 到 Ubuntu 可执行文件

ubuntu - 无法在 ubuntu 18.04 中为 rvm 安装 libssl-dev