Skip to content

Add GPU memory telemetry to the nvidia_power trace collector - #7246

Open
shreyaskommuri wants to merge 1 commit into
GoogleCloudPlatform:masterfrom
shreyaskommuri:add-gpu-memory-telemetry
Open

shreyaskommuri wants to merge 1 commit into
GoogleCloudPlatform:masterfrom
shreyaskommuri:add-gpu-memory-telemetry

Conversation

@shreyaskommuri

Copy link
Copy Markdown

Summary

Fixes #7245. perfkitbenchmarker/traces/nvidia_power.py already runs a background
nvidia-smi collector for the whole RUN stage of any benchmark (hooked generically
via events.before_phase/after_phase on stages.RUN, so no per-benchmark wiring is
needed), and already samples power draw, p-state, utilization percentage, temperature,
and clock speeds at a configurable interval. It had no way to sample actual GPU memory
consumption: utilization.memory (percent of the memory bus busy) exists, but
memory.used/memory.total (actual MiB consumed) did not. The only other
GPU-memory-related function in the codebase, nvidia_driver.GetGpuMem(), only reads
static total capacity once at install time, never live usage during a run.

This adds memory.used and memory.total as two new QUERY_TABLE entries and a new
'memory' QUERY_GROUPS selection, following the exact same declarative shape as the
existing power/utilization/temperature/clocks entries. No changes needed to
_NvidiaPowerResults, _CollectorRunCommand, or Analyze, since all three are already
fully driven by these tables.

Purely additive: --nvidia_power_selections still defaults to 'power', unaffected by
this change; 'all' now also picks up the new 'memory' group automatically. Also
updates the flag's help text, which explicitly enumerates valid group names.

Test Plan

New unit test testParseNvidiaMemoryResult in tests/traces/nvidia_power_test.py,
mirroring the existing testParseNvidiaPowerResult exactly: parses a synthetic CSV
fixture (tests/data/nvidia_memory_output.txt) through the existing
_NvidiaPowerResults parser and asserts both metrics/units/values.

I don't have access to real GPU hardware, so the fixture is synthetic, built to match
the documented nvidia-smi --format=csv output shape (same format the existing
nvidia_power_output.txt fixture uses) rather than captured from a real run. Flagging
this explicitly rather than presenting it as real hardware output.

$ python -m unittest tests.traces.nvidia_power_test -v
testParseNvidiaMemoryResult ... ok
testParseNvidiaPowerResult ... ok
OK

Also verified the collector wiring directly (not just the parser), since QUERY_TABLE/
QUERY_GROUPS feed into _CollectorRunCommand too:

>>> from perfkitbenchmarker.traces import nvidia_power
>>> c = nvidia_power._NvidiaPowerCollector(selections='memory', output_directory='/tmp')
>>> c._CollectorRunCommand(None, '/tmp/out.csv')
'nvidia-smi --query-gpu=index,timestamp,memory.used,memory.total --format=csv -lms 1000 > /tmp/out.csv 2>&1 & echo $!'

Confirmed selections='all' also includes memory.used/memory.total automatically.

Ran the full tests/traces/ suite (all existing collectors) via the documented
python -m unittest invocation with zero regressions.

pyink --pyink-indentation 2 --pyink-use-majority-quotes --unstable --line-length=80
is clean on every line this PR adds. git diff -U0 master | lint-diffs flags 3 style
items on the new test method (PascalCase test name, no per-test docstring, protected-
member access) — confirmed via plain pylint that the pre-existing, untouched sibling
test (testParseNvidiaPowerResult) in the same file has the identical three findings,
so this matches the file's own established convention rather than introducing a new
one.

Additional Notes

I've signed the Google CLA. AI was used for context and guidance while investigating
and drafting this change.

nvidia_power.py already runs a background nvidia-smi collector for the
whole RUN stage of any benchmark, but its QUERY_TABLE/QUERY_GROUPS had
no entry for memory.used/memory.total, only utilization.memory
(percent busy, not actual MiB consumed). There was no way to sample
live GPU memory consumption during a benchmark run anywhere in the
codebase; nvidia_driver.GetGpuMem() only reads static total capacity
once at setup.

Adds memory.used and memory.total as two new declarative QUERY_TABLE
entries plus a 'memory' QUERY_GROUPS selection, following the exact
pattern already used for power/utilization/temperature/clocks. No
changes needed to the parsing, collection, or Analyze logic, since
those are already fully table-driven.

Purely additive: --nvidia_power_selections defaults to 'power' and is
unaffected; 'all' now also includes the new memory group.

New unit test (testParseNvidiaMemoryResult) parses a synthetic CSV
fixture (tests/data/nvidia_memory_output.txt, modeled on documented
nvidia-smi --format=csv output; not captured from real hardware, which
I don't have access to) through the existing _NvidiaPowerResults
parser, mirroring the existing testParseNvidiaPowerResult test
exactly.
@shreyaskommuri
shreyaskommuri marked this pull request as ready for review November 10, 2026 20:02

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant