Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tensor flow toggle between CPU/GPU

Tags:

tensorflow

Having installed tensorflow GPU (running on a measly NVIDIA GeForce 950), I would like to compare performance with the CPU.

I am running the tensorFlow MNIST tutorial code, and have noticed a dramatic increase in speed--estimated anyways (I ran the CPU version 2 days ago on a laptop i7 with a batch size of 100, and this on a desktop GPU, batch size of 10)--between the CPU and the GPU when I switched...but I only noticed the speed increase when I lowered the batch size on the GPU to 10 from 100...

Now I lack an objective measure for what I am gaining.

Is there a way to toggle between the CPU and GPU tensor flows?

like image 411
Chris Avatar asked Apr 12 '16 22:04

Chris


People also ask

Can TensorFlow use both CPU and GPU?

TensorFlow supports running computations on a variety of types of devices, including CPU and GPU. They are represented with string identifiers for example: "/device:CPU:0" : The CPU of your machine.

Can I have both TensorFlow and TensorFlow-GPU?

When both tensorflow and tensorflow-gpu are installed , is it by default CPU or GPU accelaration? In case both are installed, tensorflow will place operations on GPU by default unless instructed not to.

Does TensorFlow 2 automatically use GPU?

If a TensorFlow operation has both CPU and GPU implementations, TensorFlow will automatically place the operation to run on a GPU device first. If you have more than one GPU, the GPU with the lowest ID will be selected by default. However, TensorFlow does not place operations into multiple GPUs automatically.


2 Answers

To make GPU invisible

export CUDA_VISIBLE_DEVICES="" 

To return to normal

unset CUDA_VISIBLE_DEVICES 
like image 192
Yaroslav Bulatov Avatar answered Sep 20 '22 23:09

Yaroslav Bulatov


try setting tf.device to cpu:0

with tf.Session() as sess:      with tf.device("/cpu:0"): 
like image 36
user18101 Avatar answered Sep 19 '22 23:09

user18101