Skip to content

Instantly share code, notes, and snippets.

@serihiro
Created October 31, 2018 03:14
Show Gist options
  • Select an option

  • Save serihiro/4a9dace1235ce692a18d597c588dab06 to your computer and use it in GitHub Desktop.

Select an option

Save serihiro/4a9dace1235ce692a18d597c588dab06 to your computer and use it in GitHub Desktop.
import pynvml
pynvml.nvmlInit()
handle0 = pynvml.nvmlDeviceGetHandleByIndex(0)
handle1 = pynvml.nvmlDeviceGetHandleByIndex(1)
util_rate0 = pynvml.nvmlDeviceGetUtilizationRates(handle0)
util_rate1 = pynvml.nvmlDeviceGetUtilizationRates(handle1)
print(f'device0 nvml.util.gpu: {util_rate0.gpu}')
print(f'device0 nvml.util.gpu: {util_rate0.memory}')
print(f'device1 nvml.util.gpu: {util_rate1.gpu}')
print(f'device1 nvml.util.gpu: {util_rate1.memory}')
print('')
mem0 = pynvml.nvmlDeviceGetMemoryInfo(handle0)
mem1 = pynvml.nvmlDeviceGetMemoryInfo(handle1)
print(f'device0 nvml.mem.total: {mem0.total}')
print(f'device0 nvml.mem.used: {mem0.used}')
print(f'device0 nvml.mem.free: {mem0.free}')
print(f'device1 nvml.mem.total: {mem1.total}')
print(f'device1 nvml.mem.used: {mem1.used}')
print(f'device1 nvml.mem.free: {mem1.free}')
pynvml.nvmlShutdown()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment