[Refactor] KernelElem trait to deduplicate f32/f64 stubs
Maintainers usually reply within 2 days
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 50/100
- Issue type
- Refactor
- Clarity
- Clearly specified
- Activity status
- Quiet
- Tech stack
- rust
- Domain
- backend, performance
Research direction
Start by reading qdp-kernels/src/lib.rs and the proposed qdp-kernels/src/elem.rs design, then compare the paired FFI stubs and the f64-only symbols. Inspect qdp-core/src/gpu/encodings/angle.rs around encode_batch_async_pipeline and review issue #1310 for trait-surface overlap. Run cargo test -p qdp-kernels and the qdp-core GPU tests; done means reduced duplication, preserved FFI names and CUDA behavior, and no more than 2% amplitude f32 throughput regression.
Written by the indexing model from the issue text.
Description
What
Collapse the copy-paste *_f32 FFI stubs in qdp-kernels/src/lib.rs behind a KernelElem trait plus a define_stub! macro, and merge the two near-identical encode_batch_async_pipeline functions in angle.rs into one generic function.
Why
qdp-kernels/src/lib.rs is 726 lines, much of it mechanical duplication: the encode/norm FFI symbols exist as f64/f32 pairs (launch_amplitude_encode + _f32, and likewise for angle, basis, l2_norm) differing only in element type. qdp-core/src/gpu/encodings/angle.rs repeats the pattern: encode_batch_async_pipeline (lines 742–803) and encode_batch_async_pipeline_f32 (lines 806–867) are two ~61-line near-clones. This duplication is pure maintenance tax — every change has to be made twice and the copies drift. A KernelElem trait + macro expresses the f32/f64 pair once.
How
- Add
qdp-kernels/src/elem.rsdefining aKernelElemtrait withimpl KernelElem for f32andimpl KernelElem for f64, capturing the per-type bits (element type, suffix, FFI symbol mapping). - Replace the paired stub block with a
define_stub!macro invoked once per FFI symbol, generating both the f64 and f32 entry points from a single definition.- Note: not every symbol is paired —
launch_iqp_encode/launch_iqp_encode_batchandlaunch_phase_encode/launch_phase_encode_batchare f64-only. The macro must support declaring an f64-only symbol (no forced_f32twin), so it can't assume every symbol has both.
- Note: not every symbol is paired —
- Collapse
encode_batch_async_pipelineandencode_batch_async_pipeline_f32inangle.rsinto one genericfn encode_batch_async_pipeline<T: KernelElem>(...). - Coordinate with #1310 (single-sample f32 on
QuantumEncoder) so the trait surface does not overlap or conflict. - Keep the basis launcher's index parameter as
usize(notT): theKernelElemtype parameter governs state/feature dtype only, never the basis index, so index exactness is preserved regardless of f32/f64. (See the Track A basis-precision amendment.) - Keep CUDA kernel algorithms untouched — this is a Rust-side dedup only.
Out of scope: Changing CUDA kernel algorithms, performance tuning beyond keeping parity.
Acceptance criteria:
-
cargo test -p qdp-kernelsand theqdp-coreGPU tests pass - Net lines-of-code reduction in
lib.rsandangle.rs - Throughput regression ≤2% on the amplitude f32 baseline
- No change to CUDA kernel behavior or to public FFI symbol names (paired and f64-only symbols alike)
- 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