You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mahout.apache.org by "botszhuang (via GitHub)" <gi...@apache.org> on 2026/06/06 03:00:51 UTC
[PR] perf(qdp): inline norm calculation in phase kernel loop for 5% speedup [mahout]
botszhuang opened a new pull request, #1380:
URL: https://github.com/apache/mahout/pull/1380
### Related Issues
Relates to #1227
### Changes
- [ ] Bug fix
- [ ] New feature
- [x] Refactoring
- [ ] Documentation
- [ ] Test
- [ ] CI/CD pipeline
- [ ] Other
### Why
This PR aims to strengthen the CUDA kernel implementation of `phase.cu` by optimizing the norm calculation.
Through PTX analysis and empirical benchmarks, I found that combining the norm multiplication into the existing loop yields a better performance improvement than using `pow()` or solely focusing on branch divergence.
### How
#### Optimization Details & Insights: norm Calculation Optimization (The Real Winner 🚀)
- **Hypothesis**: Using `pow(M_SQRT1_2, num_qubits)` via SFU would speed up the normalization factor.
- **Benchmark Reality**: `pow()` actually introduced overhead and slowed down the execution.
- **The Better Solution**: Embedding the norm scaling `(norm *= M_SQRT1_2;)` directly into the loop alongside the phase accumulation achieved the best results. This allows the compiler to pipelining the instructions effectively.
#### Benchmark Results
- **Environment**: RunPod GPU instance (CUDA 12.8, NVVM 7.0.1)
- **Configuration**: Grid size: 2048, Block size: 512
| Implementation | Execution Time (ms) | Speedup |
| :--- | :--- | :--- |
| **Original** | 0.4434 ms | Baseline |
| **Inline Norm in Loop (This PR)** | **0.3995 ms** | **~5% Performance Gain** |
## Checklist
- [ ] Added or updated unit tests for all changes
- [x] Added or updated documentation for all changes
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@mahout.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] perf(qdp): inline norm calculation in phase kernel loop for 5% speedup [mahout]
Posted by "botszhuang (via GitHub)" <gi...@apache.org>.
botszhuang commented on PR #1380:
URL: https://github.com/apache/mahout/pull/1380#issuecomment-4659961150
give me time to figure it out and fix it.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@mahout.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] perf(qdp): inline norm calculation in phase kernel loop for 5% speedup [mahout]
Posted by "ryankert01 (via GitHub)" <gi...@apache.org>.
ryankert01 commented on PR #1380:
URL: https://github.com/apache/mahout/pull/1380#issuecomment-4641536917
Need to fix precommit and copilot's comments.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@mahout.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] perf(qdp): inline norm calculation in phase kernel loop for 5% speedup [mahout]
Posted by "ryankert01 (via GitHub)" <gi...@apache.org>.
ryankert01 merged PR #1380:
URL: https://github.com/apache/mahout/pull/1380
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@mahout.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] perf(qdp): inline norm calculation in phase kernel loop for 5% speedup [mahout]
Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #1380:
URL: https://github.com/apache/mahout/pull/1380#discussion_r3366508945
##########
qdp/qdp-kernels/src/phase.cu:
##########
@@ -53,13 +53,15 @@ __global__ void phase_encode_kernel(
// φ(idx) = Σ_k phases[k] * b_k, b_k = (idx >> k) & 1
double phi = 0.0;
+ double norm = 1.0 ;
Review Comment:
There is an extra space before the semicolon in the new `norm` initialization, which is inconsistent with the surrounding formatting and may trip whitespace/format checks.
##########
qdp/qdp-kernels/src/phase.cu:
##########
@@ -53,13 +53,15 @@ __global__ void phase_encode_kernel(
// φ(idx) = Σ_k phases[k] * b_k, b_k = (idx >> k) & 1
double phi = 0.0;
+ double norm = 1.0 ;
for (unsigned int bit = 0; bit < num_qubits; ++bit) {
if ((idx >> bit) & 1U) {
phi += phases[bit];
}
+
+ norm *= M_SQRT1_2;
Review Comment:
This blank line contains trailing whitespace. Trailing whitespace tends to create noisy diffs and can fail style checks; please remove it (either delete the blank line or keep it fully empty).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@mahout.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org