Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 751
David Skarbrevik Avatar asked Jun 13 '26 14:06

David Skarbrevik


1 Answers

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).

like image 194
David Parks Avatar answered Jun 15 '26 12:06

David Parks



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!