step1: 安装pynvml
pip install pynvml
step2:
import pynvml
pynvml.nvmlInit()
deviceCount = pynvml.nvmlDeviceGetCount()
for i in range(deviceCount):
handle = pynvml.nvmlDeviceGetHandleByIndex(i)
print ("Device", i, ":", pynvml.nvmlDeviceGetName(handle))