robertradar
robertradar

Reputation: 65

CPU and GPU Tensorflow Installation

I'm very new with TensorFlow.

I want to run my code on my CUDA gpu. So I've installed TensorFlow -gpu, after I've installed normal TensorFlow.

How can I tell Python that it takes gpu based TensorFlow?

Upvotes: 1

Views: 1319

Answers (1)

FinleyGibson
FinleyGibson

Reputation: 921

If you have tensorflow-gpu installed there really isn't any reason to also have tensorflow. Without the presence of a gpu it will just run on cpu anyway.

To be specific in which GPU you use:

import os
os.environ["CUDA_VISIBLE_DEVICES"] = "0"

in place of "0" you can either list GPUs (if you have multiple), or "" if you want it to run on cpu.

alternatively, specify in the session:

sess = tf.Session(config=tf.ConfigProto(device_count={'GPU': 0}))

Furthermore you can check which version your computer prioritizes by opening python console and typing:

>>> import tensorflow
>>> tensorflow
<module 'tensorflow' from 
'/home/.../python3.6/site- packages/tensorflow/__init__.py'>
                                       ^
                                       |
                                      here

Upvotes: 2

Related Questions