[QDP] Delegate GPU pointer encoding to QuantumEncoder trait#1006
Open
viiccwen wants to merge 2 commits intoapache:mainfrom
Open
[QDP] Delegate GPU pointer encoding to QuantumEncoder trait#1006viiccwen wants to merge 2 commits intoapache:mainfrom
viiccwen wants to merge 2 commits intoapache:mainfrom
Conversation
guan404ming
approved these changes
Feb 4, 2026
Member
There was a problem hiding this comment.
I think this computes L2 norms (expensive) just to check finiteness (cheap side effect). Maybe we could introduce a dedicated check_finite_batch kernel would be more direct. I think we could do it in a follow up and please correct me if I'm wrong. Thanks!
Contributor
Author
|
I'll fix conflict later :) |
c2f3827 to
84a57bd
Compare
Contributor
Author
|
cc @guan404ming |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Purpose of PR
Refactors
qdp/qdp-core/src/lib.rsso that GPU-pointer encoding (encode_from_gpu_ptrandencode_batch_from_gpu_ptr) is delegated to theQuantumEncodertrait instead of being implemented in largematchblocks inside the engine. This aligns the design with the existing host-sideencode()andencode_batch()flow and reduces duplication.Changes
1. QuantumEncoder trait (
gpu/encodings/mod.rs)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>NotImplementederror.2. Encoder implementations
gpu/encodings/amplitude.rs): Implementedencode_from_gpu_ptrandencode_batch_from_gpu_ptr(logic moved from lib.rs: norm kernel, amplitude kernel, sync, validation).gpu/encodings/angle.rs): Same; angle validation andlaunch_angle_encode/launch_angle_encode_batchwith stream.gpu/encodings/basis.rs): Same;launch_basis_encode_batchfor both single (num_samples=1) and batch.3. QdpEngine (
lib.rs)encode_from_gpu_ptr_with_stream: Replaced the largematch 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 usingencode_batch_from_gpu_ptr; kept thenum_samples == 0check in the engine before calling the encoder.Related Issues or PRs
Closes #1005
Changes Made
Breaking Changes
Checklist