简体   繁体   English

Tensorflow:在CPU和GPU之间切换[Windows 10]

[英]Tensorflow: switch between CPU and GPU [Windows 10]

How can I quickly switch between running tensorflow code with my CPU and my GPU? 如何在使用CPU和GPU运行Tensorflow代码之间快速切换?

My setup: 我的设置:

OS = Windows 10 操作系统= Windows 10

Python = 3.5 Python = 3.5

Tensorflow-gpu = 1.0.0 Tensorflow-gpu = 1.0.0

CUDA = 8.0.61 CUDA = 8.0.61

cuDNN = 5.1 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. 我看到一则帖子建议设置CUDA_VISIBLE_DEVICES=0但我的环境中没有此变量(不确定是因为我正在运行Windows还是什么),但是如果我使用os.environ之类的方法进行设置,则不会不会影响tensorflow如何运行代码。

If you set the environment variable CUDA_VISIBLE_DEVICES=-1 you will use the CPU only. 如果设置环境变量CUDA_VISIBLE_DEVICES=-1 ,则将仅使用CPU。 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. 如果您未设置该环境变量,则将为所有GPU分配内存,但默认情况下仅使用GPU0。您也可以将其设置为要使用的特定GPU。 CUDA_VISIBLE_DEVICES=0 will only use GPU 0. CUDA_VISIBLE_DEVICES=0将仅使用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). 您需要在导入tensorflow之前设置变量(通常是在启动脚本之前)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM