Comments (4)
Using nvmlDeviceGetAccountingStats
might be solution, but I have not personally tested or experimented with this. I cannot immediately test this myself, because root/admin access is need to set the appropriate accounting mode for the target device (e.g. using nvmlDeviceSetAccountingMode
).
If you are interested in getting a pid breakdown of gpu-memory consomption for a given device, yout can use nvmlDeviceGetComputeRunningProcesses
:
import pynvml
pynvml.nvmlInit()
for dev_id in range(pynvml.nvmlDeviceGetCount()):
handle = pynvml.nvmlDeviceGetHandleByIndex(dev_id)
for proc in pynvml.nvmlDeviceGetComputeRunningProcesses(handle):
print(
"pid %d using %d bytes of memory on device %d."
% (proc.pid, proc.usedGpuMemory, dev_id)
)
I will try to take a harder look into this later and will update here if I find anything.
from pynvml.
This is the code I'm using now. It only works for type "C" processes, not type "G" in the list when calling nvidia-smi directly in the terminal (e.g. my neural network in python was a type "C" process, Xorg type "G") but I think it should suffice:
import os
from pynvml.smi import nvidia_smi
from bs4 import BeautifulSoup as bs
def get_gpu_usage(pid=None):
if pid is None:
# get current process id
pid = os.getpid()
pid = str(pid)
# find associated gpu usage
soup = bs(nvidia_smi.getInstance().XmlDeviceQuery(), "lxml")
for p in soup.find("processes").find_all("process_info"):
if p.find("pid").get_text() == pid:
return p.find("used_memory").get_text()
# process not found
return "0 MiB"
from pynvml.
I'd love that feature as well! Calling .XmlDeviceQuery()
gives an XML where the different processes are listed so it should be possible if something like beautiful soup could be an additional dependency.
from pynvml.
Related Issues (20)
- Uninitialized Error HOT 2
- NVLINK Ask HOT 10
- NVML Permissions HOT 2
- [pytest] test_nvmlSystemGetDriverVersion() and test_nvmlSystemGetNVMLVersion() fails HOT 3
- [pytest] nvlink related tests fail on a machine without nvlink HOT 1
- Support for WSL (Windows Subsystem for Linux) HOT 6
- How to get the maximally used GPU memory during a period? HOT 3
- adding support for CUDA_VISIBLE_DEVICES which is currently ignored HOT 5
- possibly integrating pynvx for Darwin as a substitute HOT 3
- MIG Support HOT 10
- Windows 10 location of Nvidia-smi and nvml HOT 2
- How to get the process pid in docker? HOT 1
- When failing on NVMLError exception, bug in handling HOT 5
- virtual GPU has brand number =10 which is not on the list HOT 4
- Readme.md import example HOT 2
- Wrong exn for wsl
- undefined symbol: nvmlDeviceGetComputeRunningProcesses_v2 HOT 1
- Higher-level application HOT 5
- AttributeError: module 'pynvml' has no attribute '_nvmlGetFunctionPointer' HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pynvml.