Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to tell if tensorflow is using gpu acceleration from inside python shell?

I have installed tensorflow in my ubuntu 16.04 using the second answer here with ubuntu's builtin apt cuda installation.

Now my question is how can I test if tensorflow is really using gpu? I have a gtx 960m gpu. When I import tensorflow this is the output

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 

Is this output enough to check if tensorflow is using gpu ?

like image 426
Tamim Addari Avatar asked Jun 24 '16 09:06

Tamim Addari


People also ask

How do I know if my Python code is using my GPU?

is_gpu_available tells if the gpu is available. tf. test. gpu_device_name returns the name of the gpu device.

Does TensorFlow use GPU by default?

By default, TensorFlow maps nearly all of the GPU memory of all GPUs (subject to CUDA_VISIBLE_DEVICES ) visible to the process. This is done to more efficiently use the relatively precious GPU memory resources on the devices by reducing memory fragmentation. To limit TensorFlow to a specific set of GPUs, use the tf.


1 Answers

No, I don't think "open CUDA library" is enough to tell, because different nodes of the graph may be on different devices.

When using tensorflow2:

print("Num GPUs Available: ", len(tf.config.list_physical_devices('GPU'))) 

For tensorflow1, to find out which device is used, you can enable log device placement like this:

sess = tf.Session(config=tf.ConfigProto(log_device_placement=True)) 

Check your console for this type of output.

like image 122
Yao Zhang Avatar answered Oct 18 '22 15:10

Yao Zhang