task_scheduling.memory#
Unified memory allocators for the TS framework.
Provides declarative layout mechanisms for SMEM and TMEM: resources declare requirements as allocation objects, and allocators compute a flat layout with optional phase-based aliasing.
Typical usage:
allocator = SmemAllocator()
# Resources expose their allocations
for alloc in resource.get_smem_requirements():
allocator.add(alloc)
# Optional: alias allocations whose lifetimes don't overlap.
# Each inner list is a "phase" — allocations within a phase coexist
# and get sequential offsets. Different phases reuse the same
# physical region.
allocator.add_alias_group([
[smem_ab._alloc_a, smem_ab._alloc_b], # phase 1: coexist
[epilogue._alloc_scratch], # phase 2: reuses
])
allocator.compute_layout() # pure Python — sets .offset on each alloc
# allocator.allocate() called later at DSL-trace time to emit the
# cutlass.Array(..., space=cutlass.AddressSpace.smem) op.
Classes#
- SmemAllocation / TmemAllocation
Describe named SMEM (byte) or TMEM (column) regions. After
compute_layout(), the.offsetfield contains the offset from the base of the unified block.SmemAllocationaccepts an optionaldtypeandcount. Whendtypeis provided without explicitsize_bytes, the size is auto-computed ascount * dtype.width // 8. The stored dtype enablesSmemAllocator.get()to return a typed array without re-specifying the element type.- ResourceContext
Frozen context object embedded in
StageInfo. Carriessmem_baseandtmem_ptr_i32.- _LayoutAllocator
Base class with common declaration and layout logic.
- SmemAllocator / TmemAllocator
Concrete allocators for SMEM bytes (with alignment) and TMEM columns (no alignment).
SmemAllocatorcan also emit a singlecutlass.Array(..., space=cutlass.AddressSpace.smem)call at DSL-trace time.
- class cutlass.experimental.task_scheduling.memory.SmemAllocation(
- name: str,
- size_bytes: int = 0,
- alignment: int = 128,
- dtype: Any | None = None,
- count: int = 1,
Bases:
objectDeclares a named SMEM region.
- name#
Human-readable label for debugging.
- Type:
str
- size_bytes#
Required size in bytes. When 0 and
dtypeis provided, auto-computed ascount * dtype.width // 8.- Type:
int
- alignment#
Required alignment in bytes (default 128 for TMA).
- Type:
int
- dtype#
Optional element type. When set, enables
SmemAllocator.get()to return a typedcutlass.Arraywithout re-specifying the type.- Type:
Any
- count#
Number of elements (default 1). Used with
dtypeto auto-computesize_bytesand as the shape forget().- Type:
int
- offset#
Byte offset from SMEM base, set by
SmemAllocator.compute_layout().- Type:
int
- name: str#
- size_bytes: int = 0#
- alignment: int = 128#
- dtype: Any = None#
- count: int = 1#
- offset: int = 0#
- __init__(
- name: str,
- size_bytes: int = 0,
- alignment: int = 128,
- dtype: Any | None = None,
- count: int = 1,
- class cutlass.experimental.task_scheduling.memory.TmemAllocation(name: str, num_columns: int)#
Bases:
objectDeclares a named TMEM column region.
- name#
Human-readable label for debugging.
- Type:
str
- num_columns#
Number of TMEM columns required.
- Type:
int
- offset#
Column offset from TMEM base, set by
TmemAllocator.compute_layout().- Type:
int
- name: str#
- num_columns: int#
- offset: int = 0#
- __init__(name: str, num_columns: int) None#
- class cutlass.experimental.task_scheduling.memory.ResourceContext(
- smem_base: Any | None = None,
- tmem_ptr_i32: Any | None = None,
Bases:
objectRead-only context embedded in
StageInfo.- smem_base#
cutlass.Arraybase pointer for the unified SMEM allocation.Nonewhen noSmemAllocatoris in use.- Type:
Any
- tmem_ptr_i32#
Shared-memory
cutlass.Array[Int32, 1]written bynvvm.tcgen05_alloc. Resources use it to derive their TMEM addresses viatmem_ptr_i32.load()+ offset.Nonewhen TMEM is not in use.- Type:
Any
- smem_base: Any = None#
- tmem_ptr_i32: Any = None#
- __init__(
- smem_base: Any | None = None,
- tmem_ptr_i32: Any | None = None,
- class cutlass.experimental.task_scheduling.memory.SmemAllocator#
Bases:
_LayoutAllocatorSMEM layout allocator with alignment-aware bump allocation.
Collects
SmemAllocationobjects, computes a flat byte layout (with phase-based alias groups), and emits a singlecutlass.Array(..., space=cutlass.AddressSpace.smem)at DSL-trace time.Also tracks barrier SMEM consumed by pipeline resources (computed from
PipelineConfig.num_stageswhenbarrier_ptris not pre-allocated). Seebarrier_smem_bytes.Example — epilogue scratch reuses A+B SMEM:
allocator.add_alias_group([ [smem_ab._alloc_a, smem_ab._alloc_b], # phase 1: coexist [epilogue._alloc_scratch], # phase 2: reuses ])
- __init__() None#
- add_resource(resource: Any) None#
Register data allocations and accumulate barrier SMEM.
- Parameters:
resource (Any) – Resource exposing
get_smem_requirements()and, optionally, apipeline_configwhose barrier storage should be placed in the unified SMEM block.
Notes
Resources that belong to a
PipelineGroup(i.e.resource.pipeline_group is not None) have their barrier SMEM managed by the group, so individual barrier accounting is skipped. Calladd_pipeline_group()to register the group’s barrier requirements instead.
- add_pipeline_group(group: Any) None#
Register a
PipelineGroup’s barrier SMEM requirements.The group needs
(N + 1) × Sbarrier entries (N = number of members, S = pipeline stages): one barrier-set per member on the “many” side, plus one shared barrier-set.Individual members’ data SMEM should still be registered via
add_resource(). Their per-resource barrier accounting is automatically skipped (seeadd_resource).
- add_tmem_ptr(
- alloc: SmemAllocation,
Register the TMEM-pointer infrastructure slot.
- Parameters:
alloc (SmemAllocation) – SMEM allocation that stores the 32-bit TMEM base pointer.
- Returns:
The same allocation object after registration.
- Return type:
Notes
The allocation is added to the layout like any other, but is also remembered so that
TaskManager.setup_resources_and_taskscan automatically derive the typedcutlass.Arraypointer and populateResourceContext.tmem_ptr_i32without caller intervention.
- property tmem_ptr_alloc: SmemAllocation | None#
The TMEM-pointer allocation, or
Noneif not registered.
- property barrier_smem_bytes: int#
Total SMEM bytes used for pipeline mbarrier storage.
Counts
num_stages × 2 × 8for every resource whosePipelineConfig.barrier_ptrisNone(i.e. barrier storage will be allocated bycreate_pipeline).
- property smem_base: Any#
Unified SMEM base pointer (available after
allocate()).
- get(
- alloc: SmemAllocation,
Derive a typed
cutlass.Arrayusing the dtype/count stored on alloc.Must be called after
allocate(). Requiresalloc.dtypeto have been set when theSmemAllocationwas constructed. For reinterpret-cast access, useget_as_type()instead.
- get_as_type(
- alloc: SmemAllocation,
- dtype: Any,
- count: int = 1,
Derive a typed
cutlass.Arraywith a custom dtype (reinterpret cast).Must be called after
allocate(). Use when the desired access type differs from the allocation’s declared dtype, or when the allocation was declared with rawsize_bytesonly.
- get_typed_ptr(
- alloc: SmemAllocation,
- dtype: Any,
- count: int = 1,
Deprecated: use
get()orget_as_type()instead.
- property total_smem_bytes: int#
Total data SMEM bytes (excludes barriers, available after
compute_layout()).
- allocate() Any#
Emit a single
cutlass.Array(..., space=cutlass.AddressSpace.smem)for the unified layout.The allocation covers both data regions and pipeline barrier storage, so
create_pipeline()does not need to allocate barrier SMEM separately. Callassign_barrier_ptrs()after this method to pre-setbarrier_ptron each resource’sPipelineConfig.Returns the
cutlass.Arraybase pointer. Must be called at DSL-trace time (inside a@cute.kernelor@cute.jit).
- assign_barrier_ptrs() None#
Pre-assign barrier storage within the unified SMEM block.
For each resource that needs pipeline barriers, creates a
cute.Pointerinto the barrier region (after data) and replaces the resource’sPipelineConfigwith one that hasbarrier_ptrset. This preventscreate_pipeline()from allocating barrier SMEM separately.Also handles
PipelineGroupentries registered viaadd_pipeline_group(). Each group receives a single pointer spanning(N + 1) × Sbarrier entries.Must be called after
allocate()at DSL-trace time.
- class cutlass.experimental.task_scheduling.memory.TmemAllocator#
Bases:
_LayoutAllocatorTMEM column layout allocator (no hardware allocation).
Collects
TmemAllocationobjects and computes column offsets. Does not emit any allocation intrinsics — the kernel callsnvvm.tcgen05_allocmanually usingtotal_tmem_columns.Example:
tmem_alloc = TmemAllocator() tmem_alloc.add_resource(tmem_c_resource) tmem_alloc.compute_layout() num_cols = tmem_alloc.total_tmem_columns # pass to tcgen05_alloc
- property total_tmem_columns: int#
Total TMEM columns required (available after
compute_layout()).