From c9f0a9453d54052efb78231550bfdbd77e256fdf Mon Sep 17 00:00:00 2001 From: xuma Date: Tue, 16 Aug 2022 01:37:04 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0tf=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../_posts/Tensorflow中的GPU配置及内存分配.md | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/source/_posts/Tensorflow中的GPU配置及内存分配.md b/source/_posts/Tensorflow中的GPU配置及内存分配.md index 9ea89c31..dab4d550 100644 --- a/source/_posts/Tensorflow中的GPU配置及内存分配.md +++ b/source/_posts/Tensorflow中的GPU配置及内存分配.md @@ -31,7 +31,7 @@ nvidia-sim简称NVSMI,提供监控GPU使用情况和更改GPU状态的功能 CMD中输入: -```plant +```text nvidia-smi ``` @@ -114,11 +114,26 @@ with tf.compat.v1.Session(config=config) as sess: ### 4 指定GPU -在有多块GPU的服务器上运行tensorflow的时候,如果使用python编程,则可指定GPU,代码如下: +* 在有多块GPU的服务器上运行tensorflow的时候,如果使用python编程,则可指定GPU,代码如下: ```python import os os.environ["CUDA_VISIBLE_DEVICES"] = "2" + +os.environ["CUDA_VISIBLE_DEVICES"]="-1" CPU模式 + + +CUDA_VISIBLE_DEVICES=1 Only device 1 will be seen +CUDA_VISIBLE_DEVICES=0,1 Devices 0 and 1 will be visible +CUDA_VISIBLE_DEVICES="0,1" Same as above, quotation marks are optional +CUDA_VISIBLE_DEVICES=0,2,3 Devices 0, 2, 3 will be visible; device 1 is masked ``` +- 另一种方案-给指定的Session分配单独的GPU + + 用 tf.device('/gpu:1') 指定Session在第二块GPU上运行。 + tensorflow中不同的GPU使用`/gpu:0`和`/gpu:1`区分, + CPU不区分设备号,表示为`/cpu:0`。 + + > 未完待续...