Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to pynvml_utils.smi for PyNVML 12 #4863

Merged
merged 7 commits into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2023-2024, NVIDIA CORPORATION.
# Copyright (c) 2023-2025, NVIDIA CORPORATION.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
Expand Down Expand Up @@ -36,7 +36,7 @@
def init_pytorch_worker(rank: int, use_rmm_torch_allocator: bool = False) -> None:
import cupy
import rmm
from pynvml.smi import nvidia_smi
from pynvml_utils.smi import nvidia_smi

jakirkham marked this conversation as resolved.
Show resolved Hide resolved
smi = nvidia_smi.getInstance()
pool_size = 16e9 # FIXME calculate this
jakirkham marked this conversation as resolved.
Show resolved Hide resolved
jakirkham marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2023-2024, NVIDIA CORPORATION.
# Copyright (c) 2023-2025, NVIDIA CORPORATION.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
Expand Down Expand Up @@ -201,9 +201,6 @@ def train(self):
)
logger.info(f"total time: {total_time_iter}")

# from pynvml.smi import nvidia_smi
jakirkham marked this conversation as resolved.
Show resolved Hide resolved
# mem_info = nvidia_smi.getInstance().DeviceQuery('memory.free, memory.total')['gpu'][self.rank % 8]['fb_memory_usage']
# logger.info(f"rank {self.rank} memory: {mem_info}")

y_true = data.y
y_true = y_true.reshape((y_true.shape[0],))
Expand Down
49 changes: 9 additions & 40 deletions python/utils/gpu_metric_poller.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2018-2022, NVIDIA CORPORATION.
# Copyright (c) 2018-2025, NVIDIA CORPORATION.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
Expand Down Expand Up @@ -31,7 +31,7 @@
import os
import sys
import threading
from pynvml 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 Expand Up @@ -147,34 +147,3 @@ def startGpuMetricPolling():
def stopGpuMetricPolling(gpuPollObj):
gpuPollObj.stop()
gpuPollObj.join() # consider using timeout and reporting errors


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

while not self.__stop:
time.sleep(0.01)

memObj = smi.nvmlDeviceGetMemoryInfo(devObj)
utilObj = smi.nvmlDeviceGetUtilizationRates(devObj)

memUsed = memObj.used - initialMemUsed
gpuUtil = utilObj.gpu - initialGpuUtil
if memUsed > self.maxGpuMemUsed:
self.maxGpuMemUsed = memUsed
if gpuUtil > self.maxGpuUtil:
self.maxGpuUtil = gpuUtil

smi.nvmlShutdown()
"""


# if __name__ == "__main__":
# sto=stopGpuMetricPolling
# po = startGpuMetricPolling()
Loading