【问题标题】:Tensorflow Gpu Support, check if tf is using my GPU?Tensorflow Gpu Support,检查 tf 是否正在使用我的 GPU?
【发布时间】:2020-12-11 12:36:32
【问题描述】:

我尝试获得 tensorflows gpu 支持并安装了所有必需的软件,例如 cuda... 所以现在我想检查我的代码是否真的使用了我的 gpu,但我不太确定这意味着什么(由于“找到具有属性的设备 0”而不确定):

print(tf.config.experimental.list_physical_devices())

输出是:

2.3.0
2020-12-11 13:28:30.220505: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library nvcuda.dll
2020-12-11 13:28:30.249113: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1716] Found device 0 with properties: 
pciBusID: 0000:01:00.0 name: GeForce RTX 2070 with Max-Q Design computeCapability: 7.5
coreClock: 1.185GHz coreCount: 36 deviceMemorySize: 8.00GiB deviceMemoryBandwidth: 357.69GiB/s
2020-12-11 13:28:30.249473: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library cudart64_101.dll
2020-12-11 13:28:30.253079: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library cublas64_10.dll
2020-12-11 13:28:30.256500: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library cufft64_10.dll
2020-12-11 13:28:30.257517: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library curand64_10.dll
2020-12-11 13:28:30.261527: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library cusolver64_10.dll
2020-12-11 13:28:30.263554: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library cusparse64_10.dll
2020-12-11 13:28:30.271417: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library cudnn64_7.dll
2020-12-11 13:28:30.271623: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1858] Adding visible gpu devices: 0
[PhysicalDevice(name='/physical_device:CPU:0', device_type='CPU'), PhysicalDevice(name='/physical_device:XLA_CPU:0', device_type='XLA_CPU'), PhysicalDevice(name='/physical_device:GPU:0', device_type='GPU'), PhysicalDevice(name='/physical_device:XLA_GPU:0', device_type='XLA_GPU')]```

【问题讨论】:

  • 设备 0 是您的第一个 GPU。一种超级简单的检查方法是在运行代码时打开任务管理器或同等功能,看看是否正在使用 VRAM。

标签: python tensorflow gpu


【解决方案1】:

你安装什么pip install tensorflow或pip install tensorflow-gpu?

如果是后者,从tf.config.experimental.list_physical_devices()的输出看,你的GPU正在使用,因为tensorflow可以找到你的GeForce RTX 2070 GPU并成功打开tensorflow使用GPU所需的所有库,所以不用担心它

给你一个我安装前者的电脑的例子,输出是这样的:

2020-12-11 20:40:16.336824: W tensorflow/stream_executor/platform/default/dso_loader.cc:59] Could not load dynamic library 'cudart64_101.dll'; dlerror: cudart64_101.dll 
not found
2020-12-11 20:40:16.337402: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.
2020-12-11 20:40:19.716047: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library nvcuda.dll
2020-12-11 20:40:20.813638: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1716] Found device 0 with properties: 
pciBusID: 0000:01:00.0 name: GeForce RTX 2060 computeCapability: 7.5
coreClock: 1.2GHz coreCount: 30 deviceMemorySize: 6.00GiB deviceMemoryBandwidth: 245.91GiB/s
2020-12-11 20:40:20.814470: W tensorflow/stream_executor/platform/default/dso_loader.cc:59] Could not load dynamic library 'cudart64_101.dll'; dlerror: cudart64_101.dll 
not found
2020-12-11 20:40:20.814951: W tensorflow/stream_executor/platform/default/dso_loader.cc:59] Could not load dynamic library 'cublas64_10.dll'; dlerror: cublas64_10.dll not found
2020-12-11 20:40:20.815328: W tensorflow/stream_executor/platform/default/dso_loader.cc:59] Could not load dynamic library 'cufft64_10.dll'; dlerror: cufft64_10.dll not 
found
2020-12-11 20:40:20.816220: W tensorflow/stream_executor/platform/default/dso_loader.cc:59] Could not load dynamic library 'curand64_10.dll'; dlerror: curand64_10.dll not found
2020-12-11 20:40:20.816770: W tensorflow/stream_executor/platform/default/dso_loader.cc:59] Could not load dynamic library 'cusolver64_10.dll'; dlerror: cusolver64_10.dll not found
2020-12-11 20:40:20.818276: W tensorflow/stream_executor/platform/default/dso_loader.cc:59] Could not load dynamic library 'cusparse64_10.dll'; dlerror: cusparse64_10.dll not found
2020-12-11 20:40:20.818777: W tensorflow/stream_executor/platform/default/dso_loader.cc:59] Could not load dynamic library 'cudnn64_7.dll'; dlerror: cudnn64_7.dll not found
2020-12-11 20:40:20.818963: W tensorflow/core/common_runtime/gpu/gpu_device.cc:1753] Cannot dlopen some GPU libraries. Please make sure the missing libraries mentioned above are installed properly if you would like to use GPU. Follow the guide at https://www.tensorflow.org/install/gpu for how to download and setup the required libraries for your platform.
Skipping registering GPU devices...
[PhysicalDevice(name='/physical_device:CPU:0', device_type='CPU'), PhysicalDevice(name='/physical_device:XLA_CPU:0', device_type='XLA_CPU'), PhysicalDevice(name='/physical_device:XLA_GPU:0', device_type='XLA_GPU')]

使用日志检查:

import tensorflow as tf
tf.debugging.set_log_device_placement(True)

# Create some tensors
a = tf.constant([[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]])
b = tf.constant([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]])
c = tf.matmul(a, b)

print(c)

如果它打印出这样的东西,那么它就会在 GPU 中运行(如果以 CPU:0 结尾,那么 CPU 正在使用):

Executing op MatMul in device /job:localhost/replica:0/task:0/device:GPU:0
tf.Tensor(
[[22. 28.]
 [49. 64.]], shape=(2, 2), dtype=float32)

【讨论】:

  • 谢谢,问题是我需要使用特定的 tf 版本。所以我没有使用 tf-gpu 而只是 tf.当我运行 model.fit() 时,它还会显示:“已成功打开动态库 cublas64_10.dll”。但我仍然不确定它是否真的使用了我的 gpu
  • 有效!非常感谢你 ! :D
  • 没问题! :)
猜你喜欢
  • 2020-07-06
  • 1970-01-01
  • 2019-04-12
  • 2018-11-23
  • 1970-01-01
  • 2017-10-28
  • 2019-01-12
  • 2018-06-17
相关资源
最近更新 更多