更新tf文档

main
xuma 2 years ago
parent aa9bdbd56d
commit c9f0a9453d
  1. 19
      source/_posts/Tensorflow中的GPU配置及内存分配.md

@ -31,7 +31,7 @@ nvidia-sim简称NVSMI,提供监控GPU使用情况和更改GPU状态的功能
CMD中输入: CMD中输入:
```plant ```text
nvidia-smi nvidia-smi
``` ```
@ -114,11 +114,26 @@ with tf.compat.v1.Session(config=config) as sess:
### 4 指定GPU ### 4 指定GPU
在有多块GPU的服务器上运行tensorflow的时候,如果使用python编程,则可指定GPU,代码如下: * 在有多块GPU的服务器上运行tensorflow的时候,如果使用python编程,则可指定GPU,代码如下:
```python ```python
import os import os
os.environ["CUDA_VISIBLE_DEVICES"] = "2" 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`。
> 未完待续... > 未完待续...

Loading…
Cancel
Save