Skip to content

Different kernels for Apple Metal vs Nvidia and everything else - #92

Merged
n13 merged 2 commits into
mainfrom
n13/gpu-kernel-paths
Sep 1, 2026
Merged

Different kernels for Apple Metal vs Nvidia and everything else#92
n13 merged 2 commits into
mainfrom
n13/gpu-kernel-paths

Conversation

@n13

@n13 n13 commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Overview

v4.0.1's Metal-tuned u64 kernel is ~1.8x faster on Apple and ~37% slower on NVIDIA (RTX 3080 Ti). This PR keeps 4.0.0 GPU coverage and uses the 4.0.1 kernel only on Apple Metal.

What changed (engine-gpu)

Poseidon2 kernels live in crates/engine-gpu/src/kernels/ and are selected by backend:

  • Metal + SHADER_INT64 → v4.0.1 u64 (mining_u64_apple.wgsl)
  • other + SHADER_INT64 → v4.0.0 u64 (mining_u64.wgsl)
  • no SHADER_INT64 → 32-bit fallback (mining.wgsl), same as 4.0.0

CI uploads quantus-miner-linux-x86_64 from the benchmark job so NVIDIA boxes can run the PR binary without a local Rust toolchain.

Validation

  • cargo fmt --all -- --check
  • cargo clippy -p engine-gpu --all-targets -- -D warnings
  • kernel selection unit tests
  • component suite against 32-bit, 4.0.0 u64, and 4.0.1 u64 (CPU-verified hashes)
  • CI green on this PR

Live GPU benches of this PR binary (10s, --gpu-devices 1 --cpu-workers 0):

Machine Kernel logged Rate vs official
Apple M5 Pro (Metal) native-u64 Apple Metal (4.0.1) 43.44 MH/s matches 4.0.1 (~43.3)
RTX 3080 Ti Vast.ai (Vulkan) native-u64 (4.0.0) 41.45 MH/s matches 4.0.0 (~39.8), not the slow 4.0.1 (~25)

Risks and mitigations

  • Wrong backend pick would ship the slow NVIDIA path on Apple or vice versa. Selection is wgpu::Backend::Metal vs everything else, covered by unit tests and startup logs.
  • 32-bit fallback is unchanged from 4.0.0.

Follow-ups

None for this PR. Ready to tag a release once merged.

NVIDIA was ~37% slower on the 4.0.1 Metal-tuned kernel. Split
Poseidon2 kernels and pick by backend:

- Metal + SHADER_INT64: v4.0.1 u64
- other SHADER_INT64: v4.0.0 u64
- no SHADER_INT64: 32-bit fallback (same as 4.0.0)

CI uploads the Linux release binary as an artifact so we can
bench NVIDIA without building on the GPU box.
@n13 n13 added the bot-review label Sep 1, 2026
Log native-u64 vs native-u64 Apple Metal without tying
the strings to release tags.
@n13 n13 changed the title Select Apple Metal 4.0.1 kernel; keep 4.0.0 u64 elsewhere Different kernels for Apple Metal vs Nvidia and everything else Sep 1, 2026

@n13 n13 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Reviewer model: GPT Sol

Verdict (advisory): Approve

No blocking findings.

The centralized selector correctly uses the Apple-tuned u64 kernel for Metal adapters with SHADER_INT64, the v4.0.0-era u64 kernel for other int64-capable backends, and the unchanged 32-bit kernel otherwise. The production engine, component runner, and trusted-hashrate example all reuse that selector. I also verified that the moved 32-bit shader is byte-identical to v4.0.0 and that both u64 kernels differ from their claimed source revisions only in header text.

Non-blocking: after 13abd969 removed version suffixes from the runtime labels, the PR description's two Kernel logged entries still quote the old versioned strings.

Validation on exact head 13abd9697dae25d47e8d5f91c195ae87c9298e1b:

  • git diff --check ceff470a...13abd969 — passed
  • taplo format --check --config taplo.toml — passed
  • cargo fmt --all -- --check — passed
  • cargo clippy --locked -p engine-gpu --all-targets -- -D warnings — passed
  • cargo test --locked -p engine-gpu — 23 passed
  • cargo run --locked -p engine-gpu on Apple Metal — all component and CPU-verified end-to-end suites passed for the 32-bit, default u64, and Apple Metal u64 kernels
  • Current GitHub format, build/test, Clippy/doc, benchmark, and dependency-cooldown checks — passed

@n13
n13 merged commit 09323d3 into main Sep 1, 2026
6 checks passed
@n13 n13 removed the bot-review label Sep 1, 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.

1 participant