[Graphics card] python view GPU (graphics card) resources

nvidia-ml-py install

Version: 375.53.1
pip install nvidia-ml-py

use

import pynvml
# 初始化模块
pynvml.nvmlInit()
# 获取0号位GPU
gpu = punvml.nvmlDeviceGeHandleByIndex(0)
gpu_info = pynvml.nvmlDeviceGetMemoryInfo(gpu)

The obtained gpu_info has three fields of information, and the acquisition method is as follows

gpu_info.total # 总量
gpu_info.used # 使用量
gpu_info.free # 空余量

question

SyntaxError: Missing parentheses in call to 'print'. Did you mean print(c_count.value)?

The reason for the error is that this version supports python2. There is a print method where python2 does not support python3. The modification is as follows:
insert image description here
after modification, it can support python3.

Guess you like

Origin blog.csdn.net/m0_37661841/article/details/109256680