Skip to content

refactor(Type): retire type_promote_gpu_t, promote GPU Kron via to_cuda_t (#1003)#1106

Merged
yingjerkao merged 1 commit into
masterfrom
refactor/1003-retire-type-promote-gpu-t
Jul 21, 2026
Merged

refactor(Type): retire type_promote_gpu_t, promote GPU Kron via to_cuda_t (#1003)#1106
yingjerkao merged 1 commit into
masterfrom
refactor/1003-retire-type-promote-gpu-t

Conversation

@yingjerkao

Copy link
Copy Markdown
Collaborator

Problem

type_promote_gpu_t was a parallel GPU-side promotion trait — it promoted two Type_list_gpu (CUDA-native) types via 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 (via type_promote_from_gpu_pointer_t). This completes the retirement goal of #1101 (without the Type_test.cpp compile-break that PR was flagged for).

Fix

  • Kron GPU 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 same type_promote_from_pointer_t as the CPU path, and reinterpret_casts to to_cuda_t<…> at the cuKron_general call. Since Type_list_gpu is Type_list with std::complex → cuda::std::complex (index-preserving), the resulting kernel types are identical to what type_promote_gpu_t produced — the cuKron kernels are unchanged.
  • Removed type_promote_gpu_t, type_promote_from_gpu_pointer, type_promote_from_gpu_pointer_t from Type.hpp. Type_list_gpu / cy_typeid_gpu_v / gpu_ptr / gpu_ptr_as stay — still used to hand CUDA-native pointers to kernels.
  • Type_test.cpp: replaced the two type_promote_gpu_t static-asserts with the equivalent device-independent type_promote_t asserts (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 × Double → ComplexDouble promotion that exercises the migrated path.

  • GPU (build_gpu gpu_test_main, CUDA 13, RTX 4070 Ti): Kron.* all pass; the cytnx CUDA library compiles with the trait removed.
  • CUDA test build (test_main under USE_CUDA=ON): compiles — the #ifdef UNI_GPU Type_test.cpp asserts are verified; TypeTest.* pass.
  • CPU unaffected — every change is within #ifdef UNI_GPU.

Refs #1003. Completes the type_promote_gpu_t retirement goal of #1101.

🤖 Generated with Claude Code

…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>

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

codecov Bot commented Jul 20, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 72.71%. Comparing base (014a386) to head (7cf1aac).
✅ All tests successful. No failed tests found.

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           
Flag Coverage Δ
cpp 72.83% <ø> (ø)
python 64.13% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
C++ backend 71.93% <ø> (ø)
Python bindings 77.70% <ø> (ø)
Python package 64.13% <ø> (ø)
Files with missing lines Coverage Δ
include/Type.hpp 97.91% <ø> (ø)
src/linalg/Kron.cpp 84.21% <ø> (ø)

Continue to review full report in Codecov by Harness.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 014a386...7cf1aac. Read the comment docs.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@yingjerkao
yingjerkao merged commit accf9ed into master Jul 21, 2026
19 checks passed
@yingjerkao
yingjerkao deleted the refactor/1003-retire-type-promote-gpu-t branch July 21, 2026 00:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants