[QDP] Add CUDA kernel tests for basis encoding#1325
Conversation
| let num_samples = 4usize; | ||
| let state_len = 4usize; | ||
| let num_qubits = 2u32; | ||
| let basis_indices: Vec<usize> = vec![0, 1, 2, 3]; |
There was a problem hiding this comment.
Can we have multiple test cases and hard testcase that test the limit and edge case of the code?
|
Please fix pre-commit |
400Ping
left a comment
There was a problem hiding this comment.
Thanks for adding kernel-level test coverage for basis encoding. I think this PR should be tightened in a few places:
-
Please reduce the duplicated test setup/assertion logic.
Most tests repeat CUDA device creation, allocation, launch, copy-back, and basis-state assertions. A small helper such ascuda_device_or_skip(),assert_basis_state_f64(),assert_basis_state_f32(), and table-driven cases for first/middle/last would make this much easier to maintain. -
Please add or clarify the batch-kernel edge cases.
The batch kernels rely onstate_len == 2^num_qubitsbecause they compute:sample_idx = global_idx >> num_qubitselement_idx = global_idx & (state_len - 1)
Right now the launcher only rejects zero
num_samples/state_len. If the intended contract is that callers must validatestate_len,num_qubits, and basis-index bounds before calling the launcher, please document that in the test or PR description. Otherwise, please add validation/tests for:- batch out-of-range basis index
state_len/num_qubitsmismatch- f32 batch zero
state_len
-
Please assert the imaginary part in the f32 batch test too.
test_basis_encode_batch_f32_basiccurrently checks onlyactual.x, while the f64 batch test checks both real and imaginary values.
|
@tongyu0924 thanks for the patch! nits: the state buffers are created with |
|
This pull request has been automatically marked as stale because it has not had any activity for 30 days. It will be closed in another 7 days if no further activity occurs. Thank you for your contribution. If you'd like to keep this open, leave any comment and the stale label will be removed. You can always ask for help on the Mahout dev mailing list or in GitHub Discussions. |
Changes
Why
basis.cuhad no test coverage.How
Add
tests/basis_encode.rscovering:state_len, zeronum_samplesChecklist