Skip to content

engine-gpu: fix multi-GPU detection on hybrid (discrete + integrated) systems#1

Closed
adamtpang wants to merge 1 commit into
mainfrom
claude/nicholas-engineering-problem-rfI4r
Closed

engine-gpu: fix multi-GPU detection on hybrid (discrete + integrated) systems#1
adamtpang wants to merge 1 commit into
mainfrom
claude/nicholas-engineering-problem-rfI4r

Conversation

@adamtpang
Copy link
Copy Markdown
Owner

@adamtpang adamtpang commented May 15, 2026

Closing — this duplicates the core fix already in flight at Quantus-Network/quantus-miner#62 (filter Cpu adapters, dedupe across backends, sort discrete-first).

The genuinely additive bits over Quantus-Network#62 are kept on the branch claude/nicholas-engineering-problem-rfI4r for later cherry-picking onto the upstream branch:

  1. --gpu-devices N now actually caps adapter initialization (fix(gpu): filter CPU-emulated adapters and dedupe per physical GPU Quantus-Network/quantus-miner#62 marked this as a future follow-up). Requires changing GpuEngine::try_new signature to take max_devices: Option<usize>.
  2. Auto-detect heuristic: when any discrete GPU exists, skip integrated entirely instead of just sorting it after.
  3. Refactored select_adapter_indices into a pure function so the policy is unit-testable with synthetic wgpu::AdapterInfo (real wgpu::Adapter can't be constructed without a GPU).
  4. 6 unit tests covering: hybrid-laptop dedup, multi-discrete, integrated-only fallback, software-adapter filter, explicit cap, single-device discrete preference.
  5. Verified cargo check --workspace --all-targets and cargo clippy -- -D warnings pass.

https://claude.ai/code/session_01M8TsvfAHfST4D8zTDevK4x

On Windows, wgpu's enumerate_adapters(Backends::PRIMARY) returns every
physical GPU twice (DX12 and Vulkan), and hybrid laptops also expose the
integrated GPU. The engine previously created a context for every entry
and round-robined worker threads across them, so a miner with a discrete
NVIDIA + integrated Intel could end up doing all its work on the slow
integrated GPU.

Also, --gpu-devices N was only capping worker threads, not the number of
adapters opened, so the engine still kept handles to GPUs it didn't use.

New behavior:
  * Drop DeviceType::Cpu software adapters (llvmpipe, WARP).
  * Deduplicate physical GPUs across backends, keeping the most native
    backend per (vendor, device, name).
  * Sort by device-type rank (discrete > virtual > integrated > other).
  * Auto-detect prefers discrete GPUs exclusively when any exist, and
    falls back to the single best non-discrete adapter otherwise.
  * --gpu-devices N now actually caps adapter initialization.

Selection logic is split into select_adapter_indices so it can be
unit-tested with synthetic AdapterInfo; 6 tests cover the hybrid-laptop,
multi-discrete, integrated-only, software-adapter, and explicit-cap
cases.

https://claude.ai/code/session_01M8TsvfAHfST4D8zTDevK4x
@adamtpang adamtpang closed this May 15, 2026
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