Linux Cuda - failed call to cuInit: CUDA_ERROR_NO_DEVICE
wu@wu-X555LF:~$ nvidia-smi
Sat Jul 27 14:07:04 2019
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 384.130 Driver Version: 384.130 |
|-------------------------------+----------------------+----------------------+
| GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr. ECC |
| Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. |
|===============================+======================+======================|
| 0 GeForce 930M Off | 00000000:04:00.0 Off | N/A |
| N/A 45C P0 N/A / N/A | 191MiB / 2002MiB | 0% Default |
+-------------------------------+----------------------+----------------------+
+-----------------------------------------------------------------------------+
| Processes: GPU Memory |
| GPU PID Type Process name Usage |
|=============================================================================|
| 0 1002 G /usr/lib/xorg/Xorg 142MiB |
| 0 1985 G compiz 45MiB |
| 0 2705 G /usr/lib/firefox/firefox 1MiB |
+-----------------------------------------------------------------------------+
查看电脑的GPU配置状况,只有1块GPU,序号为 0
import tensorflow as tf
import os
a = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[2, 3], name='a')
b = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[3, 2], name='b')
c = tf.matmul(a, b)
os.environ['CUDA_VISIBLE_DEVICES'] = "1"
sess = tf.Session()
print (sess.run(c))
sess.close()
wu@wu-X555LF:~$ python os.environ\[\'CUDA_VISIBLE_DEVICES\'\]\ \=\ \"1\".py
2019-07-27 14:05:52.372040: I tensorflow/core/platform/cpu_feature_guard.cc:140] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
2019-07-27 14:05:52.376105: E tensorflow/stream_executor/cuda/cuda_driver.cc:406] failed call to cuInit: CUDA_ERROR_NO_DEVICE
2019-07-27 14:05:52.376169: I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:158] retrieving CUDA diagnostic information for host: wu-X555LF
2019-07-27 14:05:52.376182: I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:165] hostname: wu-X555LF
2019-07-27 14:05:52.376221: I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:189] libcuda reported version is: 384.130.0
2019-07-27 14:05:52.376323: I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:193] kernel reported version is: 384.130.0
2019-07-27 14:05:52.376334: I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:300] kernel version seems to match DSO: 384.130.0
[[22. 28.]
[49. 64.]]
会显示出failed call to cuInit: CUDA_ERROR_NO_DEVICE,没用用到GPU设备
需要修改os.environ[‘CUDA_VISIBLE_DEVICES’] = “1”
为os.environ\['CUDA\_VISIBLE\_DEVICES'\] = "0"
序号要对应上nvidia-smi命令查找的GPU配置序号
import tensorflow as tf
import os
a = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[2, 3], name='a')
b = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[3, 2], name='b')
c = tf.matmul(a, b)
os.environ['CUDA_VISIBLE_DEVICES'] = "0"
sess = tf.Session()
print (sess.run(c))
sess.close()
wu@wu-X555LF:~$ python os.environ\[\'CUDA_VISIBLE_DEVICES\'\]\ \=\ \"1\".py
2019-07-27 14:07:07.830300: I tensorflow/core/platform/cpu_feature_guard.cc:140] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
2019-07-27 14:07:07.931219: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:898] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2019-07-27 14:07:07.931666: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1212] Found device 0 with properties:
name: GeForce 930M major: 5 minor: 0 memoryClockRate(GHz): 0.941
pciBusID: 0000:04:00.0
totalMemory: 1.96GiB freeMemory: 1.74GiB
2019-07-27 14:07:07.931696: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1312] Adding visible gpu devices: 0
2019-07-27 14:07:08.557549: I tensorflow/core/common_runtime/gpu/gpu_device.cc:993] Creating TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 1504 MB memory) -> physical GPU (device: 0, name: GeForce 930M, pci bus id: 0000:04:00.0, compute capability: 5.0)
[[22. 28.]
[49. 64.]]
wu@wu-X555LF:~$
还没有评论,来说两句吧...