我的程序是这样的:
#include <cuda_runtime_api.h>
int main() {
int id = -1;
cudaGetDevice(&id);
if (id != cudaSuccess) std::cout << "Failed!";
return 0;
}
我的输出是
Failed!
我尝试了一些类似这个问题的方法: cudaget设备失败状态cuda驱动程序版本对于cuda运行来说不足 然而它不起作用。 我的 nvcc 版本是:
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2024 NVIDIA Corporation
Built on Tue_Oct_29_23:50:19_PDT_2024
Cuda compilation tools, release 12.6, V12.6.85
Build cuda_12.6.r12.6/compiler.35059454_0
我的cuda驱动版本是:
⋊> /u/l/c/bin nvidia-smi (base) 23:20:24
Mon Dec 2 23:20:47 2024
+-----------------------------------------------------------------------------------------+
| NVIDIA-SMI 560.35.03 Driver Version: 560.35.03 CUDA Version: 12.6 |
|-----------------------------------------+------------------------+----------------------+
| GPU Name Persistence-M | Bus-Id Disp.A | Volatile Uncorr. ECC |
| Fan Temp Perf Pwr:Usage/Cap | Memory-Usage | GPU-Util Compute M. |
| | | MIG M. |
|=========================================+========================+======================|
| 0 NVIDIA GeForce RTX 3060 Ti Off | 00000000:01:00.0 On | N/A |
| 0% 41C P8 16W / 225W | 83MiB / 8192MiB | 41% Default |
| | | N/A |
+-----------------------------------------+------------------------+----------------------+
+-----------------------------------------------------------------------------------------+
| Processes: |
| GPU GI CI PID Type Process name GPU Memory |
| ID ID Usage |
|=========================================================================================|
| 0 N/A N/A 2908 G /usr/lib/xorg/Xorg 69MiB |
+-----------------------------------------------------------------------------------------+
你的代码应该是这样的
#include <cuda_runtime_api.h>
int main() {
int id = -1;
int rc = cudaGetDevice(&id);
if (rc != cudaSuccess) std::cout << "Failed!";
return 0;
}