refactor(Type): retire type_promote_gpu_t, promote GPU Kron via to_cuda_t (#1003)#1106
Conversation
…da_t (#1003) type_promote_gpu_t was a parallel GPU-side promotion trait: it promoted two Type_list_gpu (CUDA-native) types via Type_class::type_promote on Type_list_gpu indices. The #1013 GPU arithmetic dispatch already retired this pattern for Add/Sub/Mul/Div/Cpr -- it keeps the logical dispatch on the ordinary Cytnx (host) value types with the shared type_promote_t and confines the CUDA-native complex representation to the kernel-launch boundary via to_cuda_t. Kron's GPU path was the last functional user of type_promote_gpu_t (through type_promote_from_gpu_pointer_t). Migrate Kron's GPU dispatch to the same pattern: visit the host value-type pointers (Tensor::ptr(), which has no device guard and views the managed storage), compute the promoted type with the same type_promote_from_pointer_t as the CPU path, and reinterpret_cast to to_cuda_t<...> at the cuKron_general call. Type_list_gpu is Type_list with std::complex -> cuda::std::complex, so the resulting kernel types are identical to what type_promote_gpu_t produced -- the cuKron kernels are unchanged. Remove type_promote_gpu_t, type_promote_from_gpu_pointer and type_promote_from_gpu_pointer_t from Type.hpp. Type_list_gpu / cy_typeid_gpu_v / gpu_ptr / gpu_ptr_as stay -- they are still used to hand CUDA-native pointers to kernels. Replace the two type_promote_gpu_t static_asserts in Type_test.cpp with the equivalent device-independent type_promote_t assertions (the promotion is a host value-type property; to_cuda_t is index-preserving, asserted alongside). Testing: added tests/gpu/linalg_test/Kron_test.cpp with independent hand-computed values -- real, Int16, and the ComplexFloat x Double -> ComplexDouble promotion that exercises the migrated path. build_gpu gpu_test_main (CUDA 13, RTX 4070 Ti) builds and Kron.* / GpuUnary.* / Type_test pass. CPU build is unaffected (all changes are within #ifdef UNI_GPU). Refs #1003. Completes the type_promote_gpu_t retirement goal of #1101. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
There was a problem hiding this comment.
Code Review
This pull request simplifies GPU type promotion by retiring the dedicated GPU-specific promotion traits (such as type_promote_gpu_t) in favor of using the shared, device-independent host type promotion (type_promote_from_pointer_t) and mapping to CUDA-native types via to_cuda_t at the kernel launch boundary. This refactoring is applied to the GPU path of linalg::Kron. Additionally, new GPU unit tests for Kron have been added to verify correctness and proper type promotion (e.g., ComplexFloat and Double promoting to ComplexDouble). I have no feedback to provide as there are no review comments.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1106 +/- ##
=======================================
Coverage 72.71% 72.71%
=======================================
Files 226 226
Lines 28151 28151
Branches 71 71
=======================================
Hits 20471 20471
Misses 7659 7659
Partials 21 21
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report in Codecov by Harness.
🚀 New features to boost your workflow:
|
Problem
type_promote_gpu_twas a parallel GPU-side promotion trait — it promoted twoType_list_gpu(CUDA-native) types viatype_promoteonType_list_gpuindices. The #1013 GPU arithmetic dispatch already retired this pattern for Add/Sub/Mul/Div/Cpr: it keeps the logical dispatch on the ordinary Cytnx host value types with the sharedtype_promote_tand confines the CUDA-native complex representation to the kernel-launch boundary viato_cuda_t.Kron's GPU path was the last functional user oftype_promote_gpu_t(viatype_promote_from_gpu_pointer_t). This completes the retirement goal of #1101 (without theType_test.cppcompile-break that PR was flagged for).Fix
KronGPU dispatch now visits the host value-type pointers (Tensor::ptr(), which has no device guard and views the managed storage), computes the promoted type with the sametype_promote_from_pointer_tas the CPU path, andreinterpret_casts toto_cuda_t<…>at thecuKron_generalcall. SinceType_list_gpuisType_listwithstd::complex → cuda::std::complex(index-preserving), the resulting kernel types are identical to whattype_promote_gpu_tproduced — thecuKronkernels are unchanged.type_promote_gpu_t,type_promote_from_gpu_pointer,type_promote_from_gpu_pointer_tfromType.hpp.Type_list_gpu/cy_typeid_gpu_v/gpu_ptr/gpu_ptr_asstay — still used to hand CUDA-native pointers to kernels.Type_test.cpp: replaced the twotype_promote_gpu_tstatic-asserts with the equivalent device-independenttype_promote_tasserts (the promotion is a host value-type property;to_cuda_tis index-preserving, asserted alongside).Testing
Added
tests/gpu/linalg_test/Kron_test.cppwith independent hand-computed values — real, Int16, and theComplexFloat × Double → ComplexDoublepromotion that exercises the migrated path.build_gpugpu_test_main, CUDA 13, RTX 4070 Ti):Kron.*all pass; the cytnx CUDA library compiles with the trait removed.test_mainunderUSE_CUDA=ON): compiles — the#ifdef UNI_GPUType_test.cppasserts are verified;TypeTest.*pass.#ifdef UNI_GPU.Refs #1003. Completes the
type_promote_gpu_tretirement goal of #1101.🤖 Generated with Claude Code