tensorflow-GPU usage guide

Personal public account

Insert picture description here

View the GPU usage of the machine

Regular update shows the condition of the gpu on the machine, refreshed once in #10s

nvidia-smi -l 10      

Dynamically apply for video memory

config = tf.ConfigProto()  
config.gpu_options.allow_growth = True  
session = tf.Session(config=config)  

Limit GPU usage

config = tf.ConfigProto()  
config.gpu_options.per_process_gpu_memory_fraction = 0.4  #占用40%显存  
session = tf.Session(config=config)  

Specify which GPU to use

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
CUDA_VISIBLE_DEVICES=""          No GPU will be visible

Set up in Python


os.environ['CUDA_VISIBLE_DEVICES'] = '0' #使用 GPU 0  
os.environ['CUDA_VISIBLE_DEVICES'] = '0,1' # 使用 GPU 0,1  

Guess you like

Origin blog.csdn.net/zhonglongshen/article/details/115071200