You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mahout.apache.org by "0lai0 (via GitHub)" <gi...@apache.org> on 2026/03/06 17:09:38 UTC

[PR] [QDP] Optimize run_throughput_pipeline to avoid per-iteration Vec allocations [mahout]

0lai0 opened a new pull request, #1136:
URL: https://github.com/apache/mahout/pull/1136

   ### Related Issues
   
   <!-- Closes #123 -->
   Close [#1125](https://github.com/apache/mahout/issues/1125) 
   
   ### Changes
   
   - [x] Bug fix
   - [ ] New feature
   - [ ] Refactoring
   - [ ] Documentation
   - [ ] Test
   - [ ] CI/CD pipeline
   - [ ] Other
   
   ### Why
   
   <!-- Why is this change needed? -->
   In `run_throughput_pipeline`, each iteration of the warmup and timed loops called `generate_batch(...)`, which allocates a new `Vec<f64>` (`batch_size * vector_len` elements). For high-frequency throughput benchmarks, this creates significant memory allocation pressure and adds allocator overhead to the timing results, making them reflect CPU allocation time rather than pure GPU `encode_batch` throughput.
   
   ### How
   
   - Pre-allocate a single batch buffer before entering the loops
   - Reuse the buffer in each iteration via a new `fill_batch_inplace(...)` function that writes data in-place
   - Refactor `generate_batch` to delegate to `fill_batch_inplace`, eliminating code duplication
   
   
   ## Checklist
   
   - [x] 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] [QDP] Optimize run_throughput_pipeline to avoid per-iteration Vec allocations [mahout]

Posted by "rich7420 (via GitHub)" <gi...@apache.org>.
rich7420 merged PR #1136:
URL: https://github.com/apache/mahout/pull/1136


-- 
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] [QDP] Optimize run_throughput_pipeline to avoid per-iteration Vec allocations [mahout]

Posted by "0lai0 (via GitHub)" <gi...@apache.org>.
0lai0 commented on code in PR #1136:
URL: https://github.com/apache/mahout/pull/1136#discussion_r2900087701


##########
qdp/qdp-core/src/pipeline_runner.rs:
##########
@@ -569,3 +583,42 @@ pub fn run_throughput_pipeline(config: &PipelineConfig) -> Result<PipelineRunRes
 pub fn run_latency_pipeline(config: &PipelineConfig) -> Result<PipelineRunResult> {
     run_throughput_pipeline(config)
 }
+
+#[cfg(test)]
+mod tests {
+    use super::*;
+
+    fn assert_generate_and_inplace_match(encoding_method: &str) {
+        let config = PipelineConfig {
+            num_qubits: 5,
+            batch_size: 8,
+            encoding_method: encoding_method.to_string(),
+            seed: Some(123),
+            ..Default::default()
+        };
+
+        let vector_len = vector_len(config.num_qubits, &config.encoding_method);
+        let batch_idx = 7;

Review Comment:
   Thanks @ryankert01 for review. I'll update in next commit.



-- 
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] [QDP] Optimize run_throughput_pipeline to avoid per-iteration Vec allocations [mahout]

Posted by "rich7420 (via GitHub)" <gi...@apache.org>.
rich7420 commented on PR #1136:
URL: https://github.com/apache/mahout/pull/1136#issuecomment-4029289455

   @0lai0 thanks for the patch, @ryankert01 and @viiccwen thanks for the review


-- 
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] [QDP] Optimize run_throughput_pipeline to avoid per-iteration Vec allocations [mahout]

Posted by "ryankert01 (via GitHub)" <gi...@apache.org>.
ryankert01 commented on code in PR #1136:
URL: https://github.com/apache/mahout/pull/1136#discussion_r2898843260


##########
qdp/qdp-core/src/pipeline_runner.rs:
##########
@@ -569,3 +583,42 @@ pub fn run_throughput_pipeline(config: &PipelineConfig) -> Result<PipelineRunRes
 pub fn run_latency_pipeline(config: &PipelineConfig) -> Result<PipelineRunResult> {
     run_throughput_pipeline(config)
 }
+
+#[cfg(test)]
+mod tests {
+    use super::*;
+
+    fn assert_generate_and_inplace_match(encoding_method: &str) {
+        let config = PipelineConfig {
+            num_qubits: 5,
+            batch_size: 8,
+            encoding_method: encoding_method.to_string(),
+            seed: Some(123),
+            ..Default::default()
+        };
+
+        let vector_len = vector_len(config.num_qubits, &config.encoding_method);
+        let batch_idx = 7;

Review Comment:
   we add edge cases like: 0, batch_size-1



##########
qdp/qdp-core/src/pipeline_runner.rs:
##########
@@ -569,3 +583,42 @@ pub fn run_throughput_pipeline(config: &PipelineConfig) -> Result<PipelineRunRes
 pub fn run_latency_pipeline(config: &PipelineConfig) -> Result<PipelineRunResult> {
     run_throughput_pipeline(config)
 }
+
+#[cfg(test)]
+mod tests {
+    use super::*;
+
+    fn assert_generate_and_inplace_match(encoding_method: &str) {
+        let config = PipelineConfig {
+            num_qubits: 5,
+            batch_size: 8,
+            encoding_method: encoding_method.to_string(),
+            seed: Some(123),
+            ..Default::default()
+        };
+
+        let vector_len = vector_len(config.num_qubits, &config.encoding_method);
+        let batch_idx = 7;

Review Comment:
   We can also test if adjacent batch is same of not.
   ```rust
   let batch0 = generate_batch(&config, 0, vector_len);
   let batch1 = generate_batch(&config, 1, vector_len);
   assert_ne!(batch0, batch1);
   ```



-- 
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