我已经在我的ubuntu 16.04中安装了tensorflow,使用的是ubuntu内置的apt cuda安装。
现在我的问题是,我如何测试tensorflow是否真的使用gpu?我有一个gtx 960m gpu。当我导入tensorflow时,这是输出
I tensorflow/stream_executor/dso_loader.cc:105] successfully opened CUDA library libcublas.so locally
I tensorflow/stream_executor/dso_loader.cc:105] successfully opened CUDA library libcudnn.so locally
I tensorflow/stream_executor/dso_loader.cc:105] successfully opened CUDA library libcufft.so locally
I tensorflow/stream_executor/dso_loader.cc:105] successfully opened CUDA library libcuda.so.1 locally
I tensorflow/stream_executor/dso_loader.cc:105] successfully opened CUDA library libcurand.so locally
这个输出是否足够检查tensorflow是否使用gpu ?
更新为tensorflow >= 2.1
检查TensorFlow是否使用GPU的推荐方法如下:
tf.config.list_physical_devices('GPU')
从TensorFlow 2.1开始,tf.test.gpu_device_name()已经被弃用,取而代之的是前面提到的。
然后,在终端中,您可以使用nvidia-smi检查有多少GPU内存已分配;同时,使用watch -n K nvidia-smi会告诉你,例如每K秒你使用了多少内存(你可能想使用K = 1实时)
如果你有多个GPU,你想使用多个网络,每个网络都在一个独立的GPU上,你可以使用:
with tf.device('/GPU:0'):
neural_network_1 = initialize_network_1()
with tf.device('/GPU:1'):
neural_network_2 = initialize_network_2()
这将证实张量流使用GPU同时训练也?
Code
sess = tf.Session(config=tf.ConfigProto(log_device_placement=True))
输出
I tensorflow/core/common_runtime/gpu/gpu_device.cc:885] Found device 0 with properties:
name: GeForce GT 730
major: 3 minor: 5 memoryClockRate (GHz) 0.9015
pciBusID 0000:01:00.0
Total memory: 1.98GiB
Free memory: 1.72GiB
I tensorflow/core/common_runtime/gpu/gpu_device.cc:906] DMA: 0
I tensorflow/core/common_runtime/gpu/gpu_device.cc:916] 0: Y
I tensorflow/core/common_runtime/gpu/gpu_device.cc:975] Creating TensorFlow device (/gpu:0) -> (device: 0, name: GeForce GT 730, pci bus id: 0000:01:00.0)
Device mapping:
/job:localhost/replica:0/task:0/gpu:0 -> device: 0, name: GeForce GT 730, pci bus id: 0000:01:00.0
I tensorflow/core/common_runtime/direct_session.cc:255] Device mapping:
/job:localhost/replica:0/task:0/gpu:0 -> device: 0, name: GeForce GT 730, pci bus id: 0000:01:00.0