viiccwen opened a new pull request, #1006:
URL: https://github.com/apache/mahout/pull/1006

   ### Purpose of PR
   
   Refactors `qdp/qdp-core/src/lib.rs` so that GPU-pointer encoding 
(`encode_from_gpu_ptr` and `encode_batch_from_gpu_ptr`) is delegated to the 
`QuantumEncoder` trait instead of being implemented in large `match` blocks 
inside the engine. This aligns the design with the existing host-side 
`encode()` and `encode_batch()` flow and reduces duplication.
   
   ### Changes
   
   #### 1. QuantumEncoder trait (`gpu/encodings/mod.rs`)
   
   - Added two optional trait methods (Linux-only, with default implementations 
that return `NotImplemented`):
     - `encode_from_gpu_ptr(device, input_d, input_len, num_qubits, stream) -> 
Result<GpuStateVector>`
     - `encode_batch_from_gpu_ptr(device, input_batch_d, num_samples, 
sample_size, num_qubits, stream) -> Result<GpuStateVector>`
   - Encoders that do not implement these (e.g. IQP) get the default and return 
a clear `NotImplemented` error.
   
   #### 2. Encoder implementations
   
   - **AmplitudeEncoder** (`gpu/encodings/amplitude.rs`): Implemented 
`encode_from_gpu_ptr` and `encode_batch_from_gpu_ptr` (logic moved from lib.rs: 
norm kernel, amplitude kernel, sync, validation).
   - **AngleEncoder** (`gpu/encodings/angle.rs`): Same; angle validation and 
`launch_angle_encode` / `launch_angle_encode_batch` with stream.
   - **BasisEncoder** (`gpu/encodings/basis.rs`): Same; 
`launch_basis_encode_batch` for both single (num_samples=1) and batch.
   
   #### 3. QdpEngine (`lib.rs`)
   
   - `encode_from_gpu_ptr_with_stream`: Replaced the large `match 
method.as_str() { "amplitude" => ..., "angle" => ..., "basis" => ..., _ => ... 
}` with:
     - `get_encoder(encoding_method)?`
     - `encoder.encode_from_gpu_ptr(&self.device, input_d, input_len, 
num_qubits, stream)?`
     - `state_vector.to_precision(&self.device, self.precision)?`
     - `Ok(state_vector.to_dlpack())`
   - `encode_batch_from_gpu_ptr_with_stream`: Same pattern using 
`encode_batch_from_gpu_ptr`; kept the `num_samples == 0` check in the engine 
before calling the encoder.
   - Removed the inline TODOs that asked for this refactor.
   
   
   ### Related Issues or PRs
   Closes #1005
   
   ### Changes Made
   <!-- Please mark one with an "x"   -->
   - [ ] Bug fix
   - [ ] New feature
   - [x] Refactoring
   - [ ] Documentation
   - [x] Test
   - [ ] CI/CD pipeline
   - [ ] Other
   
   ### Breaking Changes
   <!-- Does this PR introduce a breaking change? -->
   - [x] Yes
   - [ ] 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. -->
   
   - [x] Added or updated unit tests for all changes
   - [ ] Added or updated documentation for all changes
   - [x] Successfully built and ran all unit tests or manual tests locally
   - [x] PR title follows "MAHOUT-XXX: Brief Description" format (if related to 
an issue)
   - [x] 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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to