feat: add GPU filter (--gpus) to nvlink_monitor - #6
Merged
Conversation
Add `-g, --gpus <id1,id2,...>` to nvlink_monitor so the user can restrict
monitoring to a subset of GPUs. On an 8-GPU system where a bandwidth test
only touches 2 GPUs, this cuts the irrelevant output and lets the user
focus on the links that matter.
Behavior:
- Empty filter (default) => monitor all GPUs (unchanged).
- Non-empty filter => getNvLinkData skips GPUs whose index is not listed,
so CSV/JSON/text output and bandwidth calc only cover the selected GPUs.
Snapshot indices stay aligned across samples (filter is stable for the
monitor's lifetime), so calculateBandwidth's index-based matching is
unaffected.
- The filter is validated against discovered GPUs in the constructor after
discovery: an out-of-range id throws std::runtime_error (surfaced as
"Error: GPU id N out of range (0-M)" by main's catch) so a typo does not
silently monitor nothing. A "Monitoring K of N GPU(s) (filter applied)"
notice is printed to stderr when a filter is active.
Parsing (monitor/arg_parser.{h,cpp}): comma-separated integer list, e.g.
"0,1,3". Whitespace around tokens is tolerated. Negative ids, non-numeric
tokens, missing value, and empty lists are all rejected with ok=false.
Tests: 72 pass (was 66; +6 for --gpus: single short, multiple long,
whitespace tolerated, invalid token rejected, negative rejected, missing
value rejected; Defaults asserts gpuFilter empty). make check-format clean.
make monitor builds with -Wall -Wextra, no warnings. Verified on an 8x H20
system: -g 0,1 limits CSV output to GPUs 0 and 1; -g 9 errors with
"out of range (0-7)".
Signed-off-by: staryxchen <staryxchen@tencent.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Third of the feature-enhancement batch. Adds
-g, --gpus <id1,id2,...>tonvlink_monitorso the user can restrict monitoring to a subset of GPUs. On an 8-GPU system where a bandwidth test only touches 2 GPUs, this cuts irrelevant output and focuses on the links that matter.Changes
monitor/arg_parser.{h,cpp}std::vector<int> gpuFilterfield onMonitorCliArgs(empty = all GPUs).-g/--gpusas a comma-separated integer list, e.g.0,1,3. Whitespace around tokens is tolerated. Negative ids, non-numeric tokens, missing value, and empty lists are all rejected withok=false.monitor/nvlink_monitor.{h,cpp}const std::vector<int>& gpuFilter(stored asstd::set<int>for O(log n) lookup).isGpuSelected(id)— returns true if the filter is empty (all GPUs) or the id is in the set.getNvLinkDataskips GPUs not selected by the filter, so CSV/JSON/text output and bandwidth calc only cover the selected GPUs. Snapshot indices stay aligned across samples (filter is stable for the monitor's lifetime), socalculateBandwidth's index-based matching is unaffected.std::runtime_error(surfaced asError: GPU id N out of range (0-M)bymain's catch) so a typo doesn't silently monitor nothing.Monitoring K of N GPU(s) (filter applied)notice is printed to stderr when a filter is active.printHelpandmainupdated for the new flag.test/test_arg_parser.cpp+6 tests (72 total, was 66): single short (
-g 3), multiple long (--gpus 0,1,3), whitespace tolerated (0, 1, 3), invalid token rejected, negative rejected, missing value rejected;DefaultsassertsgpuFilterempty.README.mdDocumented
-g, --gpuswith the out-of-range-rejection note.Verification
make check-format— cleanmake test— 72/72 passmake monitor— builds with-Wall -Wextra, no warnings-g 0,1 -f csv→ CSV output contains only GPU 0 and 1-g 9→ errors withError: GPU id 9 out of range (0-7)Monitoring 2 of 8 GPU(s) (filter applied)Files changed