Skip to content

fix(cpp): lower CUDA complex casts with cuComplex helpers - #17

Merged
GiggleLiu merged 4 commits into
mainfrom
fix/cuda-complex-casts
Aug 29, 2026
Merged

fix(cpp): lower CUDA complex casts with cuComplex helpers#17
GiggleLiu merged 4 commits into
mainfrom
fix/cuda-complex-casts

Conversation

@GiggleLiu

@GiggleLiu GiggleLiu commented Aug 29, 2026

Copy link
Copy Markdown

Observation

CUDA compilation fails when a scalar initializes a complex value. Zero fill, for example, generated:

cuDoubleComplex(uint32(0))

NVRTC rejects this because CUDA complex types are C structs without converting constructors. The same lowering also breaks scalar/complex and cf32/cf64 conversions.

Issue

Assign::format_scalar emitted TargetType(input) for conversions that involve CUDA complex types. Complex conversions must construct or extract components explicitly. Complex-to-bool also inspected only the real component, so 0 + 1i became false and disagreed with constant folding.

Fix

  • construct complex values with make_cuFloatComplex or make_cuDoubleComplex
  • convert complex precision component by component
  • extract the real component for numeric scalar casts
  • treat a complex bool as true when either component is nonzero, in codegen and constant folding
  • add regression tests for each conversion path

The PR also includes two mechanical fixes required by the current Clippy pass.

Verification

  • cargo test -p t4a-cubecl-cpp --lib
  • cargo test -p t4a-cubecl-ir --lib
  • cargo test -p t4a-cubecl-core --lib
  • cargo clippy --no-deps -- --deny warnings
  • cargo fmt --all -- --check
  • NVIDIA A800, CUDA 12.1: 45 existing complex tests passed
  • NVIDIA A800, CUDA 12.1: focused scalar, precision, real, and bool cast tests passed

@GiggleLiu
GiggleLiu merged commit 5756141 into main Aug 29, 2026
3 of 6 checks passed
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.

1 participant