Mockup Nvidia GPUs on Linux systems

rnts081 pts1 comments

GitHub - rnts08/Mock-nvidia-gpu-linux: A mock implementation of the nvml module and driver. · GitHub

/" data-turbo-transient="true" />

Skip to content

Search/

Sign in<br>Sign upAppearance settings

You signed in with another tab or window. Reload to refresh your session.<br>You signed out in another tab or window. Reload to refresh your session.<br>You switched accounts on another tab or window. Reload to refresh your session.

Dismiss alert

{{ message }}

rnts08

Mock-nvidia-gpu-linux

Public

Notifications<br>You must be signed in to change notification settings

Fork

Star

master

BranchesTags

Go to file

CodeOpen more actions menu

Latest commit

History<br>4 Commits<br>4 Commits

Folders and files<br>NameNameLast commit message<br>Last commit date<br>bin

bin

examples

examples

include

include

scenarios

scenarios

src

src

tests

tests

.gitignore

.gitignore

Makefile

Makefile

README.md

README.md

View all files

Repository files navigation

Mock NVIDIA telemetry stack

Mock nvidia gpus in Linux for monitoring software that reads NVIDIA telemetry<br>through NVML or nvidia-smi. It does not emulate CUDA, PCI hardware, kernel<br>ioctls, MIG provisioning, or GPU computation.

Build and test

make<br>make test

Requirements: Linux, gcc, make, Python 3.

Run

export MOCK_NVIDIA_STATE="$PWD/scenarios/loaded.json"<br>export LD_LIBRARY_PATH="$PWD/build${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}"<br>export PATH="$PWD/bin:$PATH"

nvidia-smi<br>nvidia-smi --query-gpu=uuid,name,utilization.gpu,memory.used,memory.total,temperature.gpu,power.draw,power.limit --format=csv,noheader,nounits<br>python3 examples/read_nvml.py

Run the loader diagnostic before testing a third-party program:

./bin/diagnose-loader

The build provides all common loader names: libnvidia-ml.so.1,<br>libnvidia-ml.so, libnvml.so.1, and libnvml.so. NVTOP currently documents<br>that it loads libnvml.so, rather than the canonical NVIDIA filename.

For an application linked to NVML:

LD_LIBRARY_PATH="$PWD/build" MOCK_NVIDIA_STATE="$PWD/scenarios/thermal.json" ./monitor

If the application loads an absolute path, mount build/libnvidia-ml.so.1 over<br>that library inside an isolated test container. Never replace the host driver<br>library.

LD_LIBRARY_PATH is commonly removed by sudo and ignored by confined Snap or<br>setuid applications. A systemd service also needs both LD_LIBRARY_PATH and<br>MOCK_NVIDIA_STATE in its unit environment. Run the tool directly as the same<br>user while establishing basic compatibility.

Modes

Point MOCK_NVIDIA_STATE at a scenario file to render a different operating<br>face through nvidia-smi or the NVML library. Each mode is independent and<br>can be swapped at runtime.

Idle

scenarios/idle.json — a GPU at rest. Low GPU and memory utilization, an idle<br>temperature, fans near their floor, and a minimal power draw. Clocks sit at<br>their baseline speed.

Loaded

scenarios/loaded.json — a GPU running a busy compute workload. High GPU<br>utilization, boosted graphics and memory clocks, and most of VRAM consumed.

Thermal

scenarios/thermal.json — a GPU at its thermal and power ceiling. Temperature<br>approaches maximum, fans run at 100%, power draw is capped at the limit, the<br>performance state sags, and ECC reports errors.

Multi-GPU

scenarios/4gpus.json — four GPUs under a mixed workload: two H100s in a<br>busy state and two L40S blades, one loaded and one idle. GPU order in the<br>array determines the NVML index.

State

The library reloads the JSON file when its modification time changes. Switch<br>scenarios without restarting the monitored process:

cp scenarios/thermal.json /tmp/mock-gpu.json<br>export MOCK_NVIDIA_STATE=/tmp/mock-gpu.json<br># edit or replace /tmp/mock-gpu.json while the collector runs

Supported state fields are demonstrated in scenarios/loaded.json. Memory is<br>specified in MiB and power in watts. NVML returns bytes and milliwatts as the<br>real API does.

For multiple GPUs, place one to eight device objects in gpus:

"gpus": [<br>"name": "NVIDIA H100 80GB HBM3",<br>"uuid": "GPU-FAKE-0001",<br>"pci_bus_id": "00000000:01:00.0",<br>"gpu_utilization_percent": 94,<br>"vram_total_mib": 81559,<br>"vram_used_mib": 74200,<br>"temperature_c": 78,<br>"power_draw_w": 610,<br>"power_limit_w": 700<br>},<br>"name": "NVIDIA L40S",<br>"uuid": "GPU-FAKE-0002",<br>"pci_bus_id": "00000000:02:00.0",<br>"gpu_utilization_percent": 20,<br>"vram_total_mib": 46068,<br>"vram_used_mib": 9000,<br>"temperature_c": 51,<br>"power_draw_w": 160,<br>"power_limit_w": 350

See scenarios/4gpus.json for a complete mixed-load example. GPU order in the<br>array determines the NVML index. UUID and PCI bus ID must be unique.

Implemented NVML subset

initialization and shutdown

device count and handles by index or UUID

name, UUID, serial and PCI information

utilization, memory, temperature and fan speed

power draw and power limit

graphics, SM and memory clocks

performance state and compute mode

ECC mode and aggregate error count

running compute process count

driver and NVML versions

Unsupported calls are absent. Add any required function to src/mock_nvml.c<br>using the same state...

nvidia json scenarios nvml mock power

Related Articles