Skip to content

Add native CUDA mining engine (--cuda-gpu) - #94

Merged
n13 merged 6 commits into
mainfrom
n13/cuda-engine
Sep 9, 2026
Merged

n13 merged 6 commits into
mainfrom
n13/cuda-engine

Conversation

@n13

@n13 n13 commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

Overview

Adds a native CUDA mining engine (--cuda-gpu / MINER_CUDA_GPU) for NVIDIA boxes that have CUDA but no usable Vulkan stack (Clore.ai, most rental containers). The kernel was tuned in two measured rounds on rented GPUs, gated on the fixed nonce/hash vectors at every step.

Measured on the same host, GPU-only, release miner: Vast RTX 3080 Ti WGSL 106 MH/s vs CUDA 274 MH/s (~2.6x). Clore RTX 3080 Ti (no Vulkan without manual driver injection) WGSL 51 MH/s vs CUDA 217-220 MH/s (~4.2x).

What changed

  • crates/engine-cuda (new): NVRTC-compiled Goldilocks/Poseidon2 mining kernel via cudarc with dynamic driver loading; multi-device workers, midstate reuse, CPU-verified seals. Kernel round 1 (constant-memory round tables, rolled rounds, __launch_bounds__(256, 4), native __umul64hi) gave 2.04x on RTX 3060 Ti and RTX 3080. Round 2 rewrote reduce128 as one 64-bit add/sub chain with a signed carry correction and passes kernel params by value (drops four H2D copies per batch), +3.7-4.2% end-to-end and ~8% kernel-only.
  • crates/pow-core: mining_midstate_u32s, u512_to_le_u32s, hash_from_nonce helpers shared by the CUDA path and its tests.
  • crates/miner-cli, crates/miner-service, crates/engine-gpu: --cuda-gpu flag wiring and engine selection.
  • README.md: CUDA usage.
  • docs/clore-gpu-benches.md, docs/vast-gpu-benches.md, docs/benchmarks/: per-host measurements, kept/rejected variants, raw JSON with clocks, power and binary hashes.
  • .agents/skills/cuda-benchmark: repo-local skill and same-host comparison script used for these runs.

Validation

  • engine-cuda tests on rented NVIDIA GPUs (RTX 3060 Ti, RTX 3080, RTX 3080 Ti): golden vectors, target boundaries hash-1 / hash / hash+1, CPU/GPU parity across nonce carries, 128-bit reduction vs u128 % p on 4177 inputs. All pass for the shipped kernel.
  • cargo fmt --check, taplo fmt --check, cargo clippy --workspace --all-targets -- -D warnings, cargo test clean on stable.
  • No behaviour change for the default wgpu path; the CUDA engine is opt-in.

Risks and mitigations

  • CUDA tests skip on hosts without an NVIDIA GPU, so CI does not exercise the kernel. Mitigation: every kernel change was run on real GPUs and the kernel hash of each measured run is recorded in docs/.
  • The by-value kernel-params step was GPU-tested and kernel-screened but not re-run through the end-to-end comparison script.
  • cudarc is loaded dynamically, so binaries still run on machines without libcuda.

Follow-ups

  • Version bump to 4.1.0 via the release-proposal workflow.
  • End-to-end re-measurement of the kernel-params step next time a GPU is rented.

n13 added 6 commits September 4, 2026 17:58
Rework the native CUDA kernel while keeping the golden-vector KV tests passing:
- round constants and MDS diagonal in __constant__ memory
- rolled round loops (#pragma unroll 1) to cut register spilling and raise occupancy
- wide 96-bit accumulators with one Goldilocks reduction per layer
- native __umul64hi multiply, inline-PTX add, folded round constants
- volatile results poll instead of atomicAdd, __launch_bounds__(256, 4)

~68 -> ~140 MH/s on a rented RTX 3060 Ti (2.04x). Records the Clore bench
progression and the Clore SSH/ControlMaster notes in docs/.
Same binaries, same 2.04x on an RTX 3080 (114 -> 233 MH/s), showing the
optimization is architectural rather than chip-specific.
Optimize CUDA mining kernel ~2x
- reduce128: fold 2^64 = 2^32 - 1 and 2^96 = -1 in one 64-bit add/sub chain
  with a signed carry correction, replacing the 13-op 32-bit PTX sequence
- mining_main takes one by-value MiningParams struct instead of four device
  buffers, dropping four host-to-device copies per batch
- New engine-cuda tests: exact target boundaries on the golden vectors,
  CPU/GPU parity across nonce carries, 128-bit reduction vs u128 modulo
- Add .agents/skills/cuda-benchmark with the same-host comparison script
- Record the 2026-09-05 Clore RTX 3080 Ti run in docs/benchmarks and
  docs/clore-gpu-benches.md

Validation: all five engine-cuda tests passed on a rented RTX 3080 Ti
(driver 535.171.04, NVRTC 12.2.140) for this exact kernel. End-to-end
+3.7-4.2% for the reduction alone; kernel-only 217 -> 233-236 MH/s with
both changes. cargo fmt, taplo, clippy -D warnings clean.
@n13 n13 added the bot-review label Sep 9, 2026
@n13
n13 merged commit 868bdf4 into main Sep 9, 2026
4 of 6 checks passed

@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 5.6 Sol

Verdict (advisory): Request changes

Blocking finding:

  • crates/engine-cuda/src/lib.rs:70-93, Cargo.toml:46-50 — CUDA setup relies on catch_unwind to turn cudarc's missing-library panics into errors, while release builds use panic = "abort" and silent_catch disables the panic hook. On this exact head, cargo build --release --locked -p miner-cli followed by ./target/release/quantus-miner benchmark --cuda-gpu --gpu-devices 1 --cpu-workers 0 --duration 1 on a host without NVRTC exited 134 and emitted zero bytes. docs/vast-gpu-benches.md:39-40 records the same behavior. Thus a common driver-only CUDA host fails silently instead of reaching main.rs:331-333's actionable error path. Preflight NVRTC and the CUDA driver through a non-panicking loader path (or otherwise avoid panic-based loading), then add a release-profile regression proving missing NVRTC/driver dependencies produce actionable stderr and a normal nonzero exit rather than aborting.

Validation:

  • git diff --check, cargo fmt --all -- --check, and taplo format --check --config taplo.toml passed.
  • cargo test --locked --workspace passed; all five CUDA tests self-skipped on this non-CUDA host, while the committed benchmark notes record execution of those tests on an RTX 3080 Ti.
  • cargo clippy --locked --workspace --all-targets --all-features -- -D warnings and the release build passed.
  • GitHub format, analysis/docs, build/test, and CPU benchmark jobs passed. The dependency-cooldown gate remains failed because [email protected] was 28 days old versus the required 30, with no bypass label.

@n13 n13 removed the bot-review label Sep 9, 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