Skip to content

ROCMAI-214: extract GPU/device-policy parsing and VRAM usage warnings into gpu_policy.rs - #750

Draft
jussielo-amd wants to merge 2 commits into
rocmai-213-engine-ipcfrom
rocmai-214-gpu-policy
Draft

jussielo-amd wants to merge 2 commits into
rocmai-213-engine-ipcfrom
rocmai-214-gpu-policy

Conversation

@jussielo-amd

Copy link
Copy Markdown
Collaborator

Summary

Phase 6f-7 of the main.rs modularization (epic ROCMAI-27). Mechanical relocation, no behavior change: moves GPU/device-policy parsing and VRAM usage warning logic out of apps/rocm/src/main.rs into a new apps/rocm/src/gpu_policy.rs.

  • parse_device_policy/parse_gpu_selection/parse_gpu_indices_arg, select_gpu_indices_under_launch_lock, validate_pinned_gpu_index, effective_gpu_count, auto_select_gpu_indices/select_auto_gpu_index, gpu_vram_usage and its platform-gated gpu_vram_usage_sysfs variants (moved intact, cfg-gates unchanged — no platform-support change), read_drm_vram_usage/read_sysfs_u64/drm_device_is_amd, parse_gpu_vram_usage, gpu_low_memory_warning/vram_capacity_is_meaningful/serve_gpu_low_memory_warning, busy_gpu_indices, detect_gpu_count, plus struct GpuVramUsage and AUTO_FREE_VRAM_FRACTION, interleaved but part of the same cluster.
  • This cluster was documented as "staying in main.rs" by two earlier PRs in this same stack (ROCMAI-213: extract engine plugin binary resolution and IPC envelope into engine_ipc.rs #749's engine_ipc.rs, and serve_cmd.rs's pre-existing doc comment) — both corrected in this PR along with their imports, since those items are part of this ticket.
  • Real external callers beyond main.rs fixed: engine_ipc.rs, serve_cmd.rs.
  • An unrelated breakage from the move: advised_commands.rs's file-path allowlist for a CPU-fallback error string had to be updated to point at the new file.
  • dispatch()'s Command::EngineServeHttp arm calls parse_gpu_indices_arg directly — body confirmed byte-identical (independently re-verified by SHA-256), only the import changed.
  • 33 tests partitioned into the new module's own test block, including two shared test fixtures (vram(), host_gpu()) duplicated into main.rs's test module where a test that stays behind also needs them — documented inline. Total workspace test count unchanged.
  • docs/architecture.md updated with this module's entry.

Test plan

  • cargo build --workspace
  • cargo build --workspace --all-targets --features e2e-test-hooks
  • cargo clippy --workspace --all-targets -- -D warnings
  • cargo fmt --all -- --check
  • cargo xtask check-crate-edges
  • cargo test --workspace --no-fail-fast — 4322 passed, 0 failed, 17 ignored (independently re-run, matches baseline exactly; two unrelated pre-existing timing flakes observed and confirmed to pass in isolation — therock::tests::wait_with_output_bounded_waits_unbounded_when_no_timeout_is_given and cli_progress::tests::animated_spinner_keeps_ticking_without_progress_calls, neither in a file this PR touches)
  • cargo xtask manifest --check
  • python scripts/smoke_local.py --profile debug --skip-build
  • dispatch() call sites confirmed byte-identical (SHA-256 of the function body)
  • Windows-target clippy — x86_64-pc-windows-gnu is not installed in this environment; skipped and flagged rather than silently omitted. Platform-gated code (gpu_vram_usage_sysfs's two cfg variants) moved with its cfg-gates textually unchanged, not reauthored.

Depends on #749 (ROCMAI-213) — fourth PR in the ROCMAI-86 (Phase 6f) stack.
Part of Jira ROCMAI-214 / epic ROCMAI-27.

🤖 Generated with Claude Code

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Unconditional filesystem and path imports become unused on Windows non-test targets, causing warnings-as-errors checks to fail.

1 open issue
What changed in this PR

Continues the main.rs modularization by moving GPU policy parsing, selection, and VRAM warnings into a dedicated module, with no intended behavior change.

Changes:

  • Relocates GPU helpers and 33 tests into gpu_policy.rs.
  • Updates caller imports and the command-message allowlist.
  • Documents the new module and corrects comments about helper ownership.

Verification used the supplied diffs; the repository snapshot was unavailable, so builds and tests were not run.

File Description
docs/​architecture.md Documents GPU module responsibilities and callers.
apps/​rocm/​src/​serve_cmd.rs Updates GPU imports and ownership comments.
apps/​rocm/​src/​main.rs Removes relocated helpers and tests; imports the new module.
apps/​rocm/​src/​gpu_policy.rs Houses GPU parsing, selection, telemetry, warnings, and tests.
apps/​rocm/​src/​engine_ipc.rs Imports device-policy parsing from its new location.
apps/​rocm/​src/​advised_commands.rs Updates the error-message allowlist path.

Review effort: Balanced

Comment on lines +64 to +65
use std::fs;
use std::path::Path;
…into engine_ipc.rs

Signed-off-by: Jussi Elo <jussi.elo@amd.com>
… into gpu_policy.rs

Signed-off-by: Jussi Elo <jussi.elo@amd.com>
@jussielo-amd
jussielo-amd force-pushed the rocmai-214-gpu-policy branch from 6ba9e65 to f469b97 Compare October 28, 2026 08:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants