tilelang.contrib.cutedsl.utils¶
Utility functions for CuTeDSL backend.
Provides common helpers used across the CuTeDSL codegen: bitcast, tensor construction, warp election, barrier sync, and FP16 packing.
Attributes¶
Classes¶
Functions¶
|
Return the pointer behind value. |
|
|
|
Reinterpret the bits of a value as a different type. |
|
Reinterpret a scalar Float4E2M1FN value as its zero-extended 4-bit code. |
|
|
|
value as a TensorSSA, zero padded to lanes elements if given. |
|
|
|
|
|
Give tensor the element type dtype. |
|
|
|
|
|
|
|
|
|
Synchronize at a CTA barrier, as tl::__sync_thread_partial (bar.sync id, count). |
|
Arrive at a named barrier without waiting. |
|
|
|
|
|
Pack two half-precision (fp16) values into a single 32-bit value. |
|
Pack the raw bytes of four 8-bit values into one 32-bit word. |
Module Contents¶
- tilelang.contrib.cutedsl.utils.BYTES_PER_TENSORMAP = 128¶
- tilelang.contrib.cutedsl.utils.as_pointer(value)¶
Return the pointer behind value.
Generated CuTeDSL code passes buffer views (
cute.Tensor) where the pointer itself is meant, so unwrap.iteratorwhen the value has one.
- tilelang.contrib.cutedsl.utils.BYTES_PER_POINTER = 8¶
- class tilelang.contrib.cutedsl.utils.Float4E2M1FN_unpack¶
Bases:
cutlass.base_dsl.typing.Float
- tilelang.contrib.cutedsl.utils.type_map¶
- tilelang.contrib.cutedsl.utils.recast_ptr(ptr, swizzle_=None, dtype=None)¶
- tilelang.contrib.cutedsl.utils.bitcast(value, target_dtype)¶
Reinterpret the bits of a value as a different type. Equivalent to C’s (*(target_type *)(&value)).
- Parameters:
value – Source value (Numeric type from CuTeDSL)
target_dtype – Target type (CuTeDSL type like Int8, Float16, etc.)
- Returns:
Value reinterpreted as target type
- tilelang.contrib.cutedsl.utils.f4e2m1_to_uint8(value, *, loc=None, ip=None)¶
Reinterpret a scalar Float4E2M1FN value as its zero-extended 4-bit code.
LLVM bitcast cannot change the element width, so go through the integer representation of the FP4 value (the same unrealized cast the tensor helpers use) and zero-extend it into a byte.
- tilelang.contrib.cutedsl.utils.cast_tensor(value, dtype)¶
- tilelang.contrib.cutedsl.utils.as_tensor_ssa(value, lanes=None)¶
value as a TensorSSA, zero padded to lanes elements if given.
A narrow vector that is not 32-bit wide is loaded into a padded tensor, but one computed elementwise keeps its own width; padding makes both forms fit the padded vector that narrow casts need.
- tilelang.contrib.cutedsl.utils.as_rmem_tensor(value, shape, dtype)¶
- tilelang.contrib.cutedsl.utils.make_filled_tensor(shape, value, dtype=None)¶
- tilelang.contrib.cutedsl.utils.typed_tensor(tensor, dtype=None)¶
Give tensor the element type dtype.
MLIR integers are signless, so a pointer to unsigned elements comes back typed as signed (a
Uint8buffer’s iterator is anInt8pointer) and a tensor built on it loads signed values: widening, comparison, division and right shift then treat200as-56. The element type survives only on the tensor wrapper, so reattach it there.
- tilelang.contrib.cutedsl.utils.make_tensor(iterator, layout, dtype=None)¶
- tilelang.contrib.cutedsl.utils.make_tensor_at_offset(ptr, offset, shape, div_by=1, dtype=None)¶
- Parameters:
ptr (cutlass.cute.Pointer)
- tilelang.contrib.cutedsl.utils.handle_add_byte_offset(handle, byte_offset)¶
- tilelang.contrib.cutedsl.utils.shuffle_elect(thread_extent)¶
- tilelang.contrib.cutedsl.utils.sync_thread_partial(barrier_id=None, thread_count=None)¶
Synchronize at a CTA barrier, as tl::__sync_thread_partial (bar.sync id, count).
The CUDA template defaults the count to 0, which
bar.synctreats as all CTA threads; a missing or static zero count emits the count-less form.
- tilelang.contrib.cutedsl.utils.named_barrier_arrive(barrier_id, thread_count, *, loc=None, ip=None)¶
Arrive at a named barrier without waiting.
Matches tl::__named_barrier_arrive: bar.arrive (barrier.cta.arrive.aligned).
- tilelang.contrib.cutedsl.utils.warpgroup_reg_alloc(reg_count)¶
- tilelang.contrib.cutedsl.utils.warpgroup_reg_dealloc(reg_count)¶
- tilelang.contrib.cutedsl.utils.pack_half2(x, y)¶
Pack two half-precision (fp16) values into a single 32-bit value. Corresponds to CUDA’s __pack_half2 intrinsic.
This packs two fp16 values into a single int32 by treating the fp16 bits as raw data and concatenating them.
- tilelang.contrib.cutedsl.utils.pack_b8x4(x0, x1, x2, x3, *, loc=None, ip=None)¶
Pack the raw bytes of four 8-bit values into one 32-bit word.
Matches tl::pack_b8x4:
(x3 << 24) | (x2 << 16) | (x1 << 8) | x0over the bit patterns, so int8/uint8 and FP8 values pack the same way.- Return type:
cutlass.base_dsl.typing.Int32