Tensorflow 2.2在我的Microsoft Windows Surface book 3上找不到GPU——没有



设备查询确认计算机具有支持Cuda的设备我得到这个错误后似乎加载了cuda文件:

2020-07-19 17:18:41.922056: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cudart64_101.dll
2020-07-19 17:18:56.392936: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library nvcuda.dll
2020-07-19 17:18:56.969124: E tensorflow/stream_executor/cuda/cuda_driver.cc:313] failed call to cuInit: CUDA_ERROR_NO_DEVICE: no CUDA-capable device is detected
2020-07-19 17:18:56.976577: I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:176] hostname: SURFACE-
2020-07-19 17:18:56.980572: I tensorflow/core/platform/cpu_feature_guard.cc:143] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2
2020-07-19 17:18:57.018199: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x25fbcf00ee0 initialized for platform Host (this does not guarantee that XLA will be used). Devices:
2020-07-19 17:18:57.018616: I tensorflow/compiler/xla/service/service.cc:176]   StreamExecutor device (0): Host, Default Version

我签入了我的Python代码:tf.test.gpu_device_name(),但没有返回任何内容。此外,不在print(device_lib.list_local_devices())中列出GPU

要测试的代码是:

from tensorflow.python.client import device_lib
with tf.device('/gpu:0'):
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)
tf.print(c)
print('Default GPU Device: {}'.format(tf.test.gpu_device_name()))
if tf.test.is_built_with_cuda():
print("Built with cuda")
if tf.test.is_built_with_gpu_support():
print('Built with GPU support')
if tf.test.gpu_device_name():
print('Default GPU Device: {}'.format(tf.test.gpu_device_name()))
else:
print("No Installed GPU version of TF")
print(device_lib.list_local_devices())

我通过添加以下内容解决了这个问题:os.environ['CUDA_VISIBLE_DEVICES'] = "0"

最新更新