Linux Cuda - failed call to cuInit: CUDA_ERROR_NO_DEVICE

痛定思痛。 2021-11-24 01:50 469阅读 0赞
  1. wu@wu-X555LF:~$ nvidia-smi
  2. Sat Jul 27 14:07:04 2019
  3. +-----------------------------------------------------------------------------+
  4. | NVIDIA-SMI 384.130 Driver Version: 384.130 |
  5. |-------------------------------+----------------------+----------------------+
  6. | GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr. ECC |
  7. | Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. |
  8. |===============================+======================+======================|
  9. | 0 GeForce 930M Off | 00000000:04:00.0 Off | N/A |
  10. | N/A 45C P0 N/A / N/A | 191MiB / 2002MiB | 0% Default |
  11. +-------------------------------+----------------------+----------------------+
  12. +-----------------------------------------------------------------------------+
  13. | Processes: GPU Memory |
  14. | GPU PID Type Process name Usage |
  15. |=============================================================================|
  16. | 0 1002 G /usr/lib/xorg/Xorg 142MiB |
  17. | 0 1985 G compiz 45MiB |
  18. | 0 2705 G /usr/lib/firefox/firefox 1MiB |
  19. +-----------------------------------------------------------------------------+

查看电脑的GPU配置状况,只有1块GPU,序号为 0

  1. import tensorflow as tf
  2. import os
  3. a = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[2, 3], name='a')
  4. b = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[3, 2], name='b')
  5. c = tf.matmul(a, b)
  6. os.environ['CUDA_VISIBLE_DEVICES'] = "1"
  7. sess = tf.Session()
  8. print (sess.run(c))
  9. sess.close()
  10. wu@wu-X555LF:~$ python os.environ\[\'CUDA_VISIBLE_DEVICES\'\]\ \=\ \"1\".py
  11. 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
  12. 2019-07-27 14:05:52.376105: E tensorflow/stream_executor/cuda/cuda_driver.cc:406] failed call to cuInit: CUDA_ERROR_NO_DEVICE
  13. 2019-07-27 14:05:52.376169: I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:158] retrieving CUDA diagnostic information for host: wu-X555LF
  14. 2019-07-27 14:05:52.376182: I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:165] hostname: wu-X555LF
  15. 2019-07-27 14:05:52.376221: I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:189] libcuda reported version is: 384.130.0
  16. 2019-07-27 14:05:52.376323: I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:193] kernel reported version is: 384.130.0
  17. 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
  18. [[22. 28.]
  19. [49. 64.]]

会显示出failed call to cuInit: CUDA_ERROR_NO_DEVICE,没用用到GPU设备

需要修改os.environ[‘CUDA_VISIBLE_DEVICES’] = “1”

  1. os.environ\['CUDA\_VISIBLE\_DEVICES'\] = "0"

序号要对应上nvidia-smi命令查找的GPU配置序号

  1. import tensorflow as tf
  2. import os
  3. a = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[2, 3], name='a')
  4. b = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[3, 2], name='b')
  5. c = tf.matmul(a, b)
  6. os.environ['CUDA_VISIBLE_DEVICES'] = "0"
  7. sess = tf.Session()
  8. print (sess.run(c))
  9. sess.close()
  10. wu@wu-X555LF:~$ python os.environ\[\'CUDA_VISIBLE_DEVICES\'\]\ \=\ \"1\".py
  11. 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
  12. 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
  13. 2019-07-27 14:07:07.931666: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1212] Found device 0 with properties:
  14. name: GeForce 930M major: 5 minor: 0 memoryClockRate(GHz): 0.941
  15. pciBusID: 0000:04:00.0
  16. totalMemory: 1.96GiB freeMemory: 1.74GiB
  17. 2019-07-27 14:07:07.931696: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1312] Adding visible gpu devices: 0
  18. 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)
  19. [[22. 28.]
  20. [49. 64.]]
  21. wu@wu-X555LF:~$

发表评论

表情:
评论列表 (有 0 条评论,469人围观)

还没有评论,来说两句吧...

相关阅读