David Skarbrevik
David Skarbrevik

Reputation: 775

Tensorflow: switch between CPU and GPU [Windows 10]

How can I quickly switch between running tensorflow code with my CPU and my GPU?

My setup:

OS = Windows 10

Python = 3.5

Tensorflow-gpu = 1.0.0

CUDA = 8.0.61

cuDNN = 5.1

I saw a post suggesting something about setting CUDA_VISIBLE_DEVICES=0 but I don't have this variable in my environment (not sure if it's because I'm running windows or what) but if I do set it using something like os.environ it doesn't effect how tensorflow runs code.

Upvotes: 3

Views: 3272

Answers (1)

David Parks
David Parks

Reputation: 32111

If you set the environment variable CUDA_VISIBLE_DEVICES=-1 you will use the CPU only. If you don't set that environment variable you will allocate memory to all GPUs but by default only use GPU 0. You can also set it to the specific GPU you want to use. CUDA_VISIBLE_DEVICES=0 will only use GPU 0.

This environment variable is created by the user, it won't exist until you create it. You need to set the variable before tensorflow is imported (usually that is before you start your script).

Upvotes: 4

Related Questions