[英]Tensorflow 2 is not running on gpu
I'm working with tensorflow-gpu
version 2.0.0
and I have installed gpu driver and CUDA and cuDNN ( CUDA version 10.1.243_426
and cuDNN v7.6.5.32
and I'm using windows!)我正在使用
tensorflow-gpu
版本2.0.0
并且我已经安装了 gpu 驱动程序和 CUDA 和 cuDNN ( CUDA version 10.1.243_426
和cuDNN v7.6.5.32
,我使用的是 Windows!)
When I compile my model or run:当我编译我的模型或运行时:
from tensorflow.python.client import device_lib
print(device_lib.list_local_devices())
It will print out:它会打印出:
2020-01-12 19:56:50.961755: I tensorflow/core/platform/cpu_feature_guard.cc:142] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2
2020-01-12 19:56:50.974003: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library nvcuda.dll
2020-01-12 19:56:51.628299: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1618] Found device 0 with properties:
name: GeForce MX150 major: 6 minor: 1 memoryClockRate(GHz): 1.5315
pciBusID: 0000:01:00.0
2020-01-12 19:56:51.636256: I tensorflow/stream_executor/platform/default/dlopen_checker_stub.cc:25] GPU libraries are statically linked, skip dlopen check.
2020-01-12 19:56:51.642106: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1746] Adding visible gpu devices: 0
2020-01-12 19:56:52.386608: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1159] Device interconnect StreamExecutor with strength 1 edge matrix:
2020-01-12 19:56:52.393162: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1165] 0
2020-01-12 19:56:52.396516: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1178] 0: N
2020-01-12 19:56:52.400632: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1304] Created TensorFlow device (/device:GPU:0 with 1356 MB memory) -> physical GPU (device: 0, na
me: GeForce MX150, pci bus id: 0000:01:00.0, compute capability: 6.1)
[name: "/device:CPU:0"
device_type: "CPU"
memory_limit: 268435456
locality {
}
incarnation: 1008745203605650029
, name: "/device:GPU:0"
device_type: "GPU"
memory_limit: 1422723891
locality {
bus_id: 1
links {
}
}
incarnation: 18036547379173389852
physical_device_desc: "device: 0, name: GeForce MX150, pci bus id: 0000:01:00.0, compute capability: 6.1"
]
Which is saying tensorflow is going to use gpu device for sure!这就是说 tensorflow 肯定会使用 GPU 设备! But when I run my model, I can see that gpu isn't doing anything!
但是当我运行我的模型时,我可以看到 gpu 没有做任何事情!
However you can see that a part of gpu memory is being used and even I can see a gpu activity which is my program!!但是你可以看到一部分 gpu 内存正在被使用,甚至我也可以看到一个 gpu 活动,这是我的程序!!
What's going on?!这是怎么回事?! Am I doing something wrong?!
难道我做错了什么?! I have searched a lot and have checked a lot of questions in SO but nobody asked such a question!
我已经搜索了很多并检查了很多问题,但是没有人问这样的问题!
Taken from the official documentation of TensorFlow.取自 TensorFlow 的官方文档。
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)
If you run the code above (which should run on your GPU if your GPU is visible to TensorFlow), then your training will run on TensorFlow.如果你运行上面的代码(如果你的 GPU 对 TensorFlow 可见,它应该在你的 GPU 上运行),那么你的训练将在 TensorFlow 上运行。
You must see an output like this one:您必须看到这样的输出:
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)
在设备 /job:localhost/replica:0/task:0/device:GPU:0 tf.Tensor( [[22. 28.] [49. 64.]], shape=(2, 2), dtype=float32)
Also, you can see that you have a surge in the dedicated GPU memory usage in the Task Manager --> it appears that your GPU is being used, but for certainty run the code above.此外,您可以看到任务管理器中的专用 GPU 内存使用量激增 --> 似乎您的 GPU 正在被使用,但可以肯定地运行上面的代码。
Have also noted that Windows Task Manager is not useful for monitoring GPU(dual) activity.还注意到 Windows 任务管理器对于监控 GPU(双)活动没有用。 Try installing TechPowerUp GPU-Z.
尝试安装 TechPowerUp GPU-Z。 (I am running dual NVidia cards).
(我正在运行双 NVidia 卡)。 This monitors CPU and GPU activity, power and temperatures.
这会监控 CPU 和 GPU 活动、功率和温度。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.