You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
cuTile: integer-to-integer conversions, and arithmetic on generic scalars #1659
TBDNot yet triaged; scope or disposition undecidedcutile-rsTile programming model: cutile crates, compiler, macros, IR, kernels, and bookenhancementNew feature or request
Two gaps make kernels that are generic over an integer element type awkward to write. Neither is a miscompile; the code is rejected.
convert_scalar and convert_tile only convert to and from floats. Converting between integer types is rejected by the JIT:
let zero:K = convert_scalar(0i32);// K = u32: Unsupported conversion "i32" -> "u32"let zero:K = convert_scalar(0u32);// K = u64: Unsupported conversion "u32" -> "u64"
So a kernel generic over K: ElementType can't make a K constant from a literal. We pass key_zero, key_one and a digit mask as kernel arguments instead.
A generic K scalar has no arithmetic.ElementType doesn't imply Add or Sub, so key_one - key_one fails in Rust's type checker, while the same thing on a Tile<K, _> works. We broadcast to tiles to derive constants.
Proposed API / behavior
let zero:K = convert_scalar(0u32);// integer widening, narrowing, signedness changeslet mask:K = convert_scalar(7i32);let none:K = mask + one;// scalar arithmetic on generic element types
Conversions could follow Rust's as rules for integers, or use explicit exti/trunci-style semantics.
Alternatives considered
Host-supplied constants and tile arithmetic, as described above. It works, but every generic kernel then carries extra parameters, and the reason isn't obvious to readers.
Additional context
Seen at cuda-rust ad0a42c while writing src/gpu/cutile.rs in range-set-blaze. The comment at the top of the kernels module describes the workaround.
AI contribution: drafted with Claude Code (Anthropic); I reviewed it before posting.
I'd like to take part 1, the integer-to-integer conversions, if that's welcome.
I reproduced it on main (a4a939a), compile-only. convert_scalar and convert_tile reject every integer pair I tried: i32 → u32, u32 → u64, i32 → i8, i32 → i64 and i64 → i32. The last two hit the existing "not yet implemented" TODO in compile_intrinsic.rs. i32 → f32 works, and so does calling exti directly on a tile.
My plan is to follow Rust's as rules, using ops cuTile already has:
widening: exti, sign-extending a signed source and zero-extending an unsigned one;
narrowing: trunci with no overflow flag, so it wraps like as;
same width (i32 ↔ u32): no op, since both are i32 in Tile IR; only the Rust type changes.
Tests: compile tests that check the emitted ops, and a GPU test that compares the results with as on the host, including negative values and values that don't fit. I can run the GPU tests on sm_86.
I'd leave part 2 (arithmetic on a generic scalar) to you, since it changes what ElementType implies.
TBDNot yet triaged; scope or disposition undecidedcutile-rsTile programming model: cutile crates, compiler, macros, IR, kernels, and bookenhancementNew feature or request
Activity
veljjanoski commentedon Oct 28, 2026
I'd like to take part 1, the integer-to-integer conversions, if that's welcome.
I reproduced it on
main(a4a939a), compile-only.convert_scalarandconvert_tilereject every integer pair I tried:i32 → u32,u32 → u64,i32 → i8,i32 → i64andi64 → i32. The last two hit the existing "not yet implemented" TODO incompile_intrinsic.rs.i32 → f32works, and so does callingextidirectly on a tile.My plan is to follow Rust's
asrules, using ops cuTile already has:exti, sign-extending a signed source and zero-extending an unsigned one;trunciwith no overflow flag, so it wraps likeas;i32 ↔ u32): no op, since both arei32in Tile IR; only the Rust type changes.Tests: compile tests that check the emitted ops, and a GPU test that compares the results with
ason the host, including negative values and values that don't fit. I can run the GPU tests on sm_86.I'd leave part 2 (arithmetic on a generic scalar) to you, since it changes what
ElementTypeimplies.