Roll out complex contract validation#1300
Open
shinaoka wants to merge 2 commits into
Open
Conversation
shinaoka
marked this pull request as ready for review
April 18, 2026 11:16
This was referenced Apr 18, 2026
shinaoka
marked this pull request as draft
April 18, 2026 11:35
shinaoka
force-pushed
the
codex/add-expm1-origin-main
branch
from
April 20, 2026 04:54
4fcc197 to
79fb9bf
Compare
shinaoka
marked this pull request as ready for review
April 22, 2026 23:03
Contributor
|
@shinaoka could you merge the changes from main? |
shinaoka
force-pushed
the
codex/add-expm1-origin-main
branch
from
June 4, 2026 22:43
79fb9bf to
c1cdda5
Compare
Contributor
Contributor
Author
|
OK, I will rebase this PR on origin/main once PR #1301 is merged. |
shinaoka
force-pushed
the
codex/add-expm1-origin-main
branch
from
June 10, 2026 12:48
c1cdda5 to
c3978c4
Compare
Contributor
Author
|
Done! |
shinaoka
force-pushed
the
codex/add-expm1-origin-main
branch
2 times, most recently
from
June 13, 2026 03:03
169b38f to
1ca00a3
Compare
shinaoka
force-pushed
the
codex/add-expm1-origin-main
branch
from
June 13, 2026 03:11
1ca00a3 to
b46318c
Compare
Contributor
Author
|
We are dogfooding the complex-number feature with |
Contributor
Author
|
How can I help you? |
Contributor
|
I'm not a reviewer, I was just going to test it locally since CI wasn't running. That being said, I requested a review on the discord. Should be getting a review pass in the next couple of days, the devs/maintainers have a lot going on right now afk. |
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.
Summary
Adds first-class interleaved complex number support (
Complex<f32>/Complex<f64>) to CubeCL with centralized contract validation, so backends without positive complex support fail up front rather than through missing lowering paths.This has been rebased onto current
upstream/main; the earlierexpm1prerequisite is already merged through #1301 and is no longer part of this PR's unique diff.The Complex Contract
Split into three traits:
ComplexCore:+,-,*,/, unary-,conj,real_val,imag_valComplexCompare:==,!=ComplexMath:abs,exp,log,sin,cos,sqrt,tanh,powfExplicitly rejected by the validator: ordering comparisons,
min/max/clamp, remainder / modulo, bitwise ops,log1p/expm1/is_nan/is_inf,fma, and scalar ABI shortcuts.Why Interleaved
For scientific computing, signal processing, and linear algebra workloads, complex numbers need to behave as a single tensor element type, not an ad hoc pair of real tensors. Interleaved (
(re, im)contiguous per element) is the right fit because:num_complex::Complex<f32>/Complex<f64>on the Rust sidecuComplex/cuDoubleComplexABIBackend Status
C32/C64ComplexCore+ComplexCompare+ComplexMathviacuComplex.h.ComplexUsagecapability defaults to the empty set, so unsupported combinations are reported at the frontend rather than through missing codegen. Positive implementations for these backends are intentional follow-up PRs.Included Regression Fix
This also fixes a pre-existing
cubecl-macrosreturn-position regression whereBlock::to_tokensbypassed theExpandmachinery when the return position was comptime-foldable to a constant. Coverage iskernel_if_literal_u32inruntime_tests/branch.rs, kept independent from complex types.Out of Scope
Vector<Complex<T>, N>and related vectorized complex pathsfmaon complexValidation
Locally verified with:
cargo +stable fmt --all --checkcargo +stable check --tests -p cubecl-core -p cubecl-cuda -p cubecl-cpu -p cubecl-wgpu -p cubecl-hipcargo +stable xtask check formatcargo +stable xtask check lintcargo +stable xtask check typoscargo +stable test -p cubecl-cpu complex_validation -- --nocapturecargo +stable test -p cubecl-wgpu complex_validation -- --nocapturecargo +stable test -p cubecl-cuda complex_ -- --nocaptureAttempted but blocked by local HIP link environment:
cargo +stable test -p cubecl-hip complex_validation -- --nocapturehipStreamWaitEvent,hipEventDestroy, andhiprtcCreateProgram.