viiccwen opened a new pull request, #995:
URL: https://github.com/apache/mahout/pull/995
### Purpose of PR
This PR extends `GpuStateVector` in qdp-core to support both Float32 and
Float64 precision, so that state vectors can be allocated in single precision
when desired (e.g. for memory savings or float32 GPU interop). It does not add
new public encoding APIs; it only adds the ability to create and use Float32
state vectors.
### Changes
#### `qdp/qdp-core/src/gpu/memory.rs`
- **`BufferStorage`**: Added `ptr_f32() -> Option<*mut CuComplex>` for F32
buffers.
- **`GpuStateVector::new`**: Signature changed from `new(device, qubits)` to
`new(device, qubits, precision: Precision)`.
- Allocates `CuComplex` for `Precision::Float32` and `CuDoubleComplex` for
`Precision::Float64`.
- Non-Linux stub updated to accept `precision` and return the same error.
- **`GpuStateVector`**: Added `ptr_f32() -> Option<*mut CuComplex>`.
#### Call site updates (pass `Precision::Float64`)
- **`lib.rs`**: Both amplitude and angle paths in
`encode_from_gpu_ptr_with_stream` now call `GpuStateVector::new(&self.device,
num_qubits, Precision::Float64)`.
- **`gpu/encodings/amplitude.rs`**, **angle.rs**, **basis.rs**, **iqp.rs**:
Encoder `encode` paths call `GpuStateVector::new(..., Precision::Float64)`.
#### Tests
- **`tests/dlpack.rs`**:
- `test_dlpack_single_shape` updated to use `GpuStateVector::new(&device,
num_qubits, Precision::Float64)`.
- Added `test_dlpack_single_shape_f32`: creates a Float32 state vector,
asserts `ptr_f32().is_some()` and `ptr_f64().is_none()`, and checks
`to_dlpack()`.
### Related Issues or PRs
Closes #994
### Changes Made
<!-- Please mark one with an "x" -->
- [ ] Bug fix
- [x] New feature
- [x] Refactoring
- [ ] Documentation
- [x] 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. -->
- [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
- [ ] 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]