Skip to content

Commit

Permalink
Use pynvml directly (instead of through smi)
Browse files Browse the repository at this point in the history
  • Loading branch information
jakirkham committed Jan 13, 2025
1 parent 7b710ee commit 7289255
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions python/utils/gpu_metric_poller.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import os
import sys
import threading
from pynvml_utils import smi
import pynvml


class GPUMetricPoller(threading.Thread):
Expand Down Expand Up @@ -91,18 +91,18 @@ def __runChildLoop(self, readFileNo, writeFileNo):
childReadPipe = os.fdopen(readFileNo)
childWritePipe = os.fdopen(writeFileNo, "w")

smi.nvmlInit()
pynvml.nvmlInit()
# hack - get actual device ID somehow
devObj = smi.nvmlDeviceGetHandleByIndex(0)
memObj = smi.nvmlDeviceGetMemoryInfo(devObj)
utilObj = smi.nvmlDeviceGetUtilizationRates(devObj)
devObj = pynvml.nvmlDeviceGetHandleByIndex(0)
memObj = pynvml.nvmlDeviceGetMemoryInfo(devObj)
utilObj = pynvml.nvmlDeviceGetUtilizationRates(devObj)
initialMemUsed = memObj.used
initialGpuUtil = utilObj.gpu

controlStr = self.__waitForInput(childReadPipe)
while True:
memObj = smi.nvmlDeviceGetMemoryInfo(devObj)
utilObj = smi.nvmlDeviceGetUtilizationRates(devObj)
memObj = pynvml.nvmlDeviceGetMemoryInfo(devObj)
utilObj = pynvml.nvmlDeviceGetUtilizationRates(devObj)

memUsed = memObj.used - initialMemUsed
gpuUtil = utilObj.gpu - initialGpuUtil
Expand All @@ -113,7 +113,7 @@ def __runChildLoop(self, readFileNo, writeFileNo):
break
controlStr = self.__waitForInput(childReadPipe)

smi.nvmlShutdown()
pynvml.nvmlShutdown()
childReadPipe.close()
childWritePipe.close()

Expand Down

0 comments on commit 7289255

Please sign in to comment.