perf(qdp): remove mid-stream D2H norm validation from batch GPU-pointer encoding paths
Maintainers usually reply within 2 days
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 55/100
- Issue type
- Refactor
- Clarity
- Clearly specified
- Activity status
- Quiet
- Domain
- machine-learning, performance
Research direction
Start with encode_batch_from_gpu_ptr_f32 and encode_batch_from_gpu_ptr, then inspect amplitude.rs around line 660 and the launch_l2_norm_batch_f32 pipeline. Run benchmark_pytorch_ref.py with the stated arguments and verify the batch path performs one final synchronization while preserving post-copy norm validation and improving encode-only throughput.
Written by the indexing model from the issue text.
Description
Update (2026-06-26): Two corrections after re-checking
main(full detail in the comment below).
- The single-sample "prior work" cited below is not on
main. Thelaunch_amplitude_encode_f32_device_normkernel exists only on an unmerged perf branch (commit4ebe417b3); PR #1310 is the trait-dispatch refactor, not the device-norm kernel. The single-sample path onmainstill does the blocking D2H round-trip too.- The batch path needs neither a policy decision nor a new kernel. The batch encode kernel already reads
inv_normsfrom device memory (amplitude.rs:660), so the fix is to defer validation: launch norm kernel → encode kernel on the same stream → single sync at the end → D2H-copy norms and validate after. This removes the mid-stream stall while keeping norm validation a hard guarantee — nostrictflag, no new CUDA kernel, and no remove-vs-optional-vs-keep policy call needed.
Summary
The batch amplitude encoding paths (encode_batch_from_gpu_ptr_f32, encode_batch_from_gpu_ptr) perform a blocking CPU round-trip for norm validation between the norm kernel and the encode kernel. This serializes two GPU kernel launches unnecessarily and is the primary reason Mahout's encode-only throughput falls behind PyTorch's reference implementation.
Current pipeline (batch path)
launch_l2_norm_batch_f32 (GPU, queued)
↓
cudaStreamSynchronize ← STALL #1
dtoh_sync_copy(norms) ← PCIe transfer: N floats CPU-bound
CPU: check norms[i] for zero/NaN
↓
launch_amplitude_encode_batch_f32 (GPU, queued)
↓
cudaStreamSynchronize ← STALL #2
Two syncs + one D2H copy per batch, even when all norms are valid (which is almost always).
Benchmark evidence
Running benchmark_pytorch_ref.py --qubits 16 --batches 200 --batch-size 64 (encode-only mode — both frameworks start with data already on GPU):
| Framework | Throughput |
|---|---|
| PyTorch GPU | 228,825 vec/s |
| Mahout | 66,615 vec/s |
| Ratio | 0.3x (Mahout 3.4x slower) |
PyTorch's amplitude_encode uses torch.linalg.vector_norm + data / norms.clamp(min=1e-10) — everything stays on GPU, no CPU validation.
In end-to-end mode (data gen + H2D + encode), Mahout is 7.8x faster than PyTorch because the full pipeline cost dominates. The gap only appears when isolating kernel work.
Related prior work
⚠️ Correction (see Update at top): this was measured on an unmerged perf branch, not
main.
The idea: a launch_amplitude_encode_f32_device_norm kernel reads inv_norm from device memory, letting the norm kernel and encode kernel chain on the same stream with a single sync at the end. On the unmerged branch (commit 4ebe417b3) this yielded 1.22x on the single-sample path (39.7 → 32.6 µs/sample at 16 qubits). It is not present on main.
The batch path has the same structure and benefits from the same idea — and, per the Update at top, it already passes inv_norms as a device pointer, so it gets there by deferring validation with no new kernel.
Related issues / PRs
- PR #1310 —
encode_from_gpu_ptr_f32single-sample trait dispatch - PR #1283 — configurable CUDA kernel build targets
- PR #1275 — F32 support for angle/basis encoders
- Dominant language
- Rust
- Stars
- 2.3k
- Forks
- 1k
- Avg merge
- 2d 20h
- Merged PRs (30d)
- 7
Getting set up
Starts the project's dev container in your browser, under your own GitHub account.
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from apache/mahout
-
[Bug] Amazon Braket get_final_state_vector() changes the circuit, so execute_circuit() fails afterwardsPossibly taken @Howardisme claimed this 48 days ago. Openbug enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 80/100
apache/mahout#1538 · 1 comment ·
Maintainers usually reply within 2 days
-
[Bug] Reusing a parameter name on two gates fails on Qiskit only (name conflict adding parameter)Possibly taken @Imad2702 claimed this 50 days ago. Openbug enhancement good-first-issue qumat
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
apache/mahout#1509 · 2 comments ·
Maintainers usually reply within 2 days
-
[Bug] Cirq backend ignores the initialized simulator and creates its own cirq.Simulator()Possibly taken @Howardisme claimed this 49 days ago. Openbug enhancement good-first-issue qumat
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
apache/mahout#1508 · 1 comment · 1 assignee ·
Maintainers usually reply within 2 days
-
[Bug] Unknown backend_name leaks ModuleNotFoundError instead of a clear ValueErrorPossibly taken @Asterisk-Hunter claimed this 38 days ago. Openbug enhancement good-first-issue qumat
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
apache/mahout#1506 · 5 comments ·
Maintainers usually reply within 2 days
-
bug docs enhancement question
Difficulty 5/5 Over a week Newbie friendliness 35/100
Maintainers usually reply within 2 days
Similar issues
-
chat compiler P1
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
HerringtonDarkholme/hd-lang#2793 ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
security-advisory
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
MinBZK/regelrecht#2173 ·
-
ci
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
jonathanong/no-mistakes#5804 ·
-
triage: failed
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
oxc-project/tsrs#1277 · 1 comment ·
Maintainers usually reply within 1 day