You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@mahout.apache.org by "400Ping (via GitHub)" <gi...@apache.org> on 2025/12/10 10:46:26 UTC

[PR] [QDP] GPU/Cuda kernel Optimizations [mahout]

400Ping opened a new pull request, #706:
URL: https://github.com/apache/mahout/pull/706

   ### Purpose of PR
   <!-- Describe what this PR does. -->
   
   - Parallel normalization kernel
   - Coalesced memory access patterns
   - Warp-level optimizations
   - Stream support for async execution
   
   ### Related Issues or PRs
   <!-- Add links to related issues or PRs. -->
   <!-- - Closes #123  -->
   <!-- - Related to #123   -->
   Closes #692 
   ### Changes Made
   <!-- Please mark one with an "x"   -->
   - [ ] Bug fix
   - [x] New feature
   - [ ] Refactoring
   - [ ] Documentation
   - [ ] Test
   - [ ] CI/CD pipeline
   - [ ] Other
   
   ### Breaking Changes
   <!-- Does this PR introduce a breaking change? -->
   - [ ] Yes
   - [x] No
   
   ### Checklist
   <!-- Please mark each item with an "x" when complete -->
   <!-- If not all items are complete, please open this as a **Draft PR**.
   Once all requirements are met, mark as ready for review. -->
   
   - [ ] Added or updated unit tests for all changes
   - [ ] Added or updated documentation for all changes
   - [ ] Successfully built and ran all unit tests or manual tests locally
   - [ ] PR title follows "MAHOUT-XXX: Brief Description" format (if related to an issue)
   - [ ] Code follows ASF guidelines
   


-- 
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: dev-unsubscribe@mahout.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [QDP] GPU/Cuda kernel Optimizations [mahout]

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

   Results:
   ```
   $ cargo test -p qdp-kernels
      Compiling qdp-kernels v0.1.0 (/home/jay/work/mahout/qdp/qdp-kernels)
       Finished `test` profile [unoptimized + debuginfo] target(s) in 0.95s
        Running unittests src/lib.rs (target/debug/deps/qdp_kernels-834ef57a7b7278e2)
   
   running 0 tests
   
   test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
   
        Running tests/amplitude_encode.rs (target/debug/deps/amplitude_encode-fd9fbfcddfc28d91)
   
   running 10 tests
   test test_amplitude_encode_zero_norm_error ... ok
   test test_amplitude_encode_negative_norm_error ... ok
   test test_amplitude_encode_basic ... ok
   test test_l2_norm_batch_kernel_stream ... ok
   test test_l2_norm_single_kernel ... ok
   test test_amplitude_encode_odd_input_length ... ok
   test test_amplitude_encode_small_input_large_state ... ok
   test test_amplitude_encode_vectorized_load ... ok
   test test_amplitude_encode_power_of_two ... ok
   test test_amplitude_encode_large_state ... ok
   
   test result: ok. 10 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.11s
   
      Doc-tests qdp_kernels
   
   running 0 tests
   
   test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
   ```


-- 
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: dev-unsubscribe@mahout.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [QDP] GPU/Cuda kernel Optimizations [mahout]

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

   ```
   $ cargo test -p qdp-kernels
       Finished `test` profile [unoptimized + debuginfo] target(s) in 0.02s
        Running unittests src/lib.rs (target/debug/deps/qdp_kernels-834ef57a7b7278e2)
   
   running 0 tests
   
   test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
   
        Running tests/amplitude_encode.rs (target/debug/deps/amplitude_encode-fd9fbfcddfc28d91)
   
   running 10 tests
   test test_amplitude_encode_negative_norm_error ... ok
   test test_amplitude_encode_zero_norm_error ... ok
   test test_amplitude_encode_small_input_large_state ... ok
   test test_amplitude_encode_odd_input_length ... ok
   test test_l2_norm_batch_kernel_stream ... ok
   test test_amplitude_encode_power_of_two ... ok
   test test_l2_norm_single_kernel ... ok
   test test_amplitude_encode_large_state ... ok
   test test_amplitude_encode_vectorized_load ... ok
   test test_amplitude_encode_basic ... ok
   
   test result: ok. 10 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.15s
   
      Doc-tests qdp_kernels
   
   running 0 tests
   
   test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
   ```


-- 
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: dev-unsubscribe@mahout.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [QDP] GPU/Cuda kernel Optimizations [mahout]

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

   @rich7420 fixed.
   Results:
   ```
   $ cargo build --release
      Compiling pyo3-build-config v0.27.1
      Compiling qdp-kernels v0.1.0 (/home/jay/work/mahout/qdp/qdp-kernels)
      Compiling pyo3-macros-backend v0.27.1
      Compiling pyo3-ffi v0.27.1
      Compiling pyo3 v0.27.1
      Compiling qdp-core v0.1.0 (/home/jay/work/mahout/qdp/qdp-core)
      Compiling pyo3-macros v0.27.1
      Compiling qdp-python v0.1.0 (/home/jay/work/mahout/qdp/qdp-python)
       Finished `release` profile [optimized] target(s) in 31.17s
   ```


-- 
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: dev-unsubscribe@mahout.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [QDP] GPU/Cuda kernel Optimizations [mahout]

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

   cc @guan404ming @rich7420 


-- 
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: dev-unsubscribe@mahout.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [QDP] GPU/Cuda kernel Optimizations [mahout]

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

   Thanks @400Ping for the patch!
   I got errors in local test please fix it.
   
   ```
   cargo build --release
      Compiling pyo3-build-config v0.27.1
      Compiling qdp-kernels v0.1.0 (/home/rich-wsl/mahout/qdp/qdp-kernels)
      Compiling pyo3-macros-backend v0.27.1
      Compiling pyo3-ffi v0.27.1
      Compiling pyo3 v0.27.1
      Compiling qdp-core v0.1.0 (/home/rich-wsl/mahout/qdp/qdp-core)
   error[E0596]: cannot borrow `buffer` as mutable, as it is not declared as mutable
      --> qdp-core/src/gpu/encodings/amplitude.rs:200:22
       |
   200 |                     *buffer.device_ptr_mut() as *mut f64,
       |                      ^^^^^^ cannot borrow as mutable
       |
   help: consider changing this to be mutable
       |
   190 |             let mut buffer = device.alloc_zeros::<f64>(num_samples)
       |                 +++
   
   error[E0596]: cannot borrow `norm_buffer` as mutable, as it is not declared as mutable
      --> qdp-core/src/gpu/encodings/amplitude.rs:399:18
       |
   399 |                 *norm_buffer.device_ptr_mut() as *mut f64,
       |                  ^^^^^^^^^^^ cannot borrow as mutable
       |
   help: consider changing this to be mutable
       |
   390 |         let mut norm_buffer = device.alloc_zeros::<f64>(1)
       |             +++
   
   For more information about this error, try `rustc --explain E0596`.
   error: could not compile `qdp-core` (lib) due to 2 previous errors
   warning: build failed, waiting for other jobs to finish...
   ```


-- 
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: dev-unsubscribe@mahout.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [QDP] GPU/Cuda kernel Optimizations [mahout]

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


##########
qdp/qdp-core/src/gpu/encodings/amplitude.rs:
##########
@@ -65,6 +69,7 @@ impl QuantumEncoder for AmplitudeEncoder {
             // For small data (< 1MB), use synchronous path to avoid stream overhead
             // For large data, use dual-stream async pipeline for maximum throughput
             const ASYNC_THRESHOLD: usize = 1024 * 1024 / std::mem::size_of::<f64>(); // 1MB threshold
+            const GPU_NORM_THRESHOLD: usize = 4096; // heuristic: amortize kernel launch

Review Comment:
   nit: maybe we could do more test to find the optimized one in the future.



##########
qdp/qdp-core/src/gpu/encodings/amplitude.rs:
##########
@@ -65,6 +69,7 @@ impl QuantumEncoder for AmplitudeEncoder {
             // For small data (< 1MB), use synchronous path to avoid stream overhead
             // For large data, use dual-stream async pipeline for maximum throughput
             const ASYNC_THRESHOLD: usize = 1024 * 1024 / std::mem::size_of::<f64>(); // 1MB threshold
+            const GPU_NORM_THRESHOLD: usize = 4096; // heuristic: amortize kernel launch

Review Comment:
   Or even more dynamically determine this one.



-- 
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: dev-unsubscribe@mahout.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [QDP] GPU/Cuda kernel Optimizations [mahout]

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


-- 
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: dev-unsubscribe@mahout.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [QDP] GPU/Cuda kernel Optimizations [mahout]

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

   overall LGTM
   


-- 
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: dev-unsubscribe@mahout.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [QDP] GPU/Cuda kernel Optimizations [mahout]

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

   > Thanks @400Ping for the patch!
   > 
   > I got errors in local test please fix it.
   > 
   > 
   > 
   > ```
   > 
   > cargo build --release
   > 
   >    Compiling pyo3-build-config v0.27.1
   > 
   >    Compiling qdp-kernels v0.1.0 (/home/rich-wsl/mahout/qdp/qdp-kernels)
   > 
   >    Compiling pyo3-macros-backend v0.27.1
   > 
   >    Compiling pyo3-ffi v0.27.1
   > 
   >    Compiling pyo3 v0.27.1
   > 
   >    Compiling qdp-core v0.1.0 (/home/rich-wsl/mahout/qdp/qdp-core)
   > 
   > error[E0596]: cannot borrow `buffer` as mutable, as it is not declared as mutable
   > 
   >    --> qdp-core/src/gpu/encodings/amplitude.rs:200:22
   > 
   >     |
   > 
   > 200 |                     *buffer.device_ptr_mut() as *mut f64,
   > 
   >     |                      ^^^^^^ cannot borrow as mutable
   > 
   >     |
   > 
   > help: consider changing this to be mutable
   > 
   >     |
   > 
   > 190 |             let mut buffer = device.alloc_zeros::<f64>(num_samples)
   > 
   >     |                 +++
   > 
   > 
   > 
   > error[E0596]: cannot borrow `norm_buffer` as mutable, as it is not declared as mutable
   > 
   >    --> qdp-core/src/gpu/encodings/amplitude.rs:399:18
   > 
   >     |
   > 
   > 399 |                 *norm_buffer.device_ptr_mut() as *mut f64,
   > 
   >     |                  ^^^^^^^^^^^ cannot borrow as mutable
   > 
   >     |
   > 
   > help: consider changing this to be mutable
   > 
   >     |
   > 
   > 390 |         let mut norm_buffer = device.alloc_zeros::<f64>(1)
   > 
   >     |             +++
   > 
   > 
   > 
   > For more information about this error, try `rustc --explain E0596`.
   > 
   > error: could not compile `qdp-core` (lib) due to 2 previous errors
   > 
   > warning: build failed, waiting for other jobs to finish...
   > 
   > ```
   
   Noted. I have a sync not long after, will fix this afterwards.


-- 
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: dev-unsubscribe@mahout.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [QDP] GPU/Cuda kernel Optimizations [mahout]

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

   Sorry for the confusion but I means the e2e benchmark~


-- 
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: dev-unsubscribe@mahout.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [QDP] GPU/Cuda kernel Optimizations [mahout]

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

   Great one, thanks!


-- 
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: dev-unsubscribe@mahout.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [QDP] GPU/Cuda kernel Optimizations [mahout]

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

   Could you help run the benchmark and attach the result? Thanks!


-- 
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: dev-unsubscribe@mahout.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org