TLX API Quick Reference
Warp Specialization
| Function |
Description |
Arch |
tlx.async_tasks() |
Context manager wrapping all async task regions |
Both |
tlx.async_task([task_ids]) |
Assign code to specific task IDs (e.g., [0] = producer, [1,2] = consumers) |
Both |
tlx.async_task(num_warps=N, num_regs=R) |
Explicit warp/register allocation for a task |
Both |
tlx.async_task("default", num_regs=R) |
Default task for code outside explicit tasks |
Both |
tlx.async_task_replica_id() |
Returns replica ID inside an async region |
Both |
Warp specialization skeleton
with tlx.async_tasks():
with tlx.async_task([0]): # Producer
# TMA loads
with tlx.async_task([1, 2]): # Consumers
# MMA compute
Memory Barriers
mbarrier (shared-memory allocated)
| Function |
Description |
Arch |
tlx.alloc_barriers(num_barriers, arrive_count=1) |
Allocate SMEM barriers and initialize with arrive count |
Both |
tlx.barrier_expect_bytes(bar, bytes, pred=None) |
Set expected transaction byte count on barrier |
Both |
tlx.barrier_wait(bar, phase, pred=None) |
Wait until barrier phase flips (LOCAL mbarrier only) |
Both |
tlx.barrier_arrive(bar, arrive_count=1, remote_cta_rank=None) |
Signal arrival at barrier. remote_cta_rank signals a barrier in a remote CTA — only valid when ctas_per_cga > 1, causes "Unexpected buffer remote view in 1cta mode" otherwise. Guard with if USE_2CTA: when kernel supports both modes. |
Both |
tlx.cluster_barrier() |
Full cluster-wide synchronization barrier |
Both |
arrive_count rules:
- Implicit arrive from
barrier_expect_bytes: use arrive_count=1
barrier_arrive inside tlx.async_task: arrive_count = number of warp groups
barrier_arrive outside tlx.async_task: arrive_count=1 (only tid==0 arrives)
Named barriers (hardware-allocated, indices 0–15)
| Function |
Description |
Arch |
tlx.named_barrier_wait(bar_id, num_threads) |
Wait until num_threads arrive at bar_id |
NVIDIA |
tlx.named_barrier_arrive(bar_id, num_threads) |
Signal arrival at bar_id |
NVIDIA |
num_threads must be a multiple of 32 (warp size). Typically num_warp_groups * warps_per_group * 32.
Used for PingPong scheduling to prevent tensor core contention between consumer warp groups.
Memory Operations
SMEM / TMEM allocation
| Function |
Description |
Arch |
tlx.local_alloc(shape, dtype, num, storage=smem, reuse=None, layout=None) |
Allocate buffered tensor in SMEM or TMEM |
Both (TMEM: Blackwell) |
tlx.storage_alias_spec(storage=smem, buffer_size_bytes=None) |
Define shared buffer region for multiple local_alloc calls via reuse |
Both |
tlx.local_view(buf, index) |
Get view of a single buffer from a multi-buffered tensor |
Both |
tlx.local_slice(buf, start, end) |
Slice a sub-range of a buffered tensor |
Both |
tlx.subslice(tensor, dim, start, size) |
Subslice a tensor along a dimension |
Both |
tlx.local_load(buf) |
Load from SMEM/TMEM buffer into registers |
Both |
tlx.local_store(val, buf) |
Store from registers into SMEM/TMEM buffer |
Both |
tlx.local_trans(buf) |
Transpose a shared memory buffer |
Both |
tlx.local_reinterpret(buf, dtype) |
Reinterpret buffer with a different dtype |
Both |
tlx.remote_view(buf, remote_cta_rank) |
Get view of buffer in a remote CTA's SMEM |
Both |
tlx.remote_shmem_store(val, buf) |
Store to remote CTA's shared memory |
Both |
tlx.async_remote_shmem_store(val, buf) |
Async store to remote CTA's shared memory |
Both |
tlx.tmem_copy(src, dst) |
Copy between TMEM buffers |
Blackwell |
tlx.fence_async_shared() |
Memory fence for async shared memory operations |
Both |
Storage kinds: tlx.storage_kind.smem, tlx.storage_kind.tmem (Blackwell), tlx.storage_kind.smemCluster
TMA (Tensor Memory Accelerator)
| Function |
Description |
Arch |
tlx.make_tensor_descriptor(ptr, shape, strides, block_shape) |
Create TMA descriptor from pointer (host-side) |
Hopper+ |
tlx.allocate_tensor_descriptor(ptr, shape, strides, block_shape, swizzle_mode) |
Allocate and fill TMA descriptor in SMEM |
Hopper+ |
tlx.reinterpret_tensor_descriptor(desc, dtype) |
Reinterpret TMA descriptor with different dtype |
Hopper+ |
tlx.async_descriptor_load(desc, indices, barrier=None) |
Async TMA load from global → SMEM, tracked by barrier |
Hopper+ |
tlx.async_descriptor_store(desc, val, indices) |
Async TMA store from registers → global |
Hopper+ |
tlx.async_descriptor_store_wait() |
Wait for all pending TMA stores to complete |
Hopper+ |
tlx.async_load(ptr, buf, barrier) |
Async bulk copy global → SMEM (cp.async) |
Hopper+ |
tlx.async_load_commit_group() |
Commit async load group |
Hopper+ |
tlx.async_load_wait_group(n) |
Wait for async load groups (n pending allowed) |
Hopper+ |
Matrix Multiply (MMA)
| Function |
Description |
Arch |
tlx.async_dot(A, B, acc=None, use_acc=None, mBarriers=[], two_ctas=False) |
Warp-group MMA: D = A @ B + C. Maps to wgmma (Hopper) or tcgen05.mma (Blackwell) |
Both |
tlx.async_dot_scaled(A, B, acc, A_scale, A_format, B_scale, B_format, ...) |
Scaled MMA with FP8 inputs: D = (Ascale_A) @ (Bscale_B) + D |
Blackwell |
tlx.async_dot_wait(pendings, inp) |
Wait for N pending async dot operations to complete |
Both |
tlx.tcgen05_commit(mBarrier, two_ctas=False) |
Make mbarrier track completion of prior tcgen05 ops. Use a SEPARATE mbarrier from async_dot |
Blackwell |
Minimum tile sizes for async_dot: M ≥ 64, K ≥ 16, N ≥ 32
Pair-CTA MMA (two_ctas=True): M must be 128 per CTA.
Multi-CTA (Cluster) Kernels
ctas_per_cga=(N,1,1) in triton.Config sets the cluster size. The grid
specifies total CTAs; hardware divides by ctas_per_cga to get the number
of clusters. E.g., grid=(2,1,1) with ctas_per_cga=(2,1,1) = 1 cluster of
2 CTAs.
input_precision options: tf32, tf32x3, ieee
CLC (Cluster Launch Control) — Blackwell only
| Function |
Description |
tlx.clc_create_context(num_consumers, num_stages=1) |
Create CLC pipeline context (allocates barriers + response buffers) |
tlx.clc_producer(context, p_producer, multi_ctas=False, k=0) |
Issue CLC try_cancel request from CTA 0 |
tlx.clc_consumer(context, p_consumer, multi_ctas=False, k=0) |
Decode tile ID from CLC response, signal completion. Returns tile_id or -1 |
For 2-CTA mode: set multi_ctas=True (uses "arrive remote, wait local" pattern).
Utility
| Function |
Description |
Arch |
tlx.cluster_cta_rank() |
Unique CTA ID within a cluster (all dims) |
Both |
tlx.thread_id(axis) |
Thread ID along axis 0, 1, or 2 |
Both |
tlx.dtype_of(tensor_or_desc) |
Get element type of tensor or tensor descriptor |
Both |
tlx.size_of(dtype) |
Size of dtype in bytes |
Both |
tlx.get_fp8_format_name(dtype) |
Get FP8 format string ("e5m2" or "e4m3") for scaled MMA |
Both |
tlx.clock64() |
64-bit hardware clock value (for timing) |
Both |
tlx.stoch_round(src, dst_ty, rand_bits) |
Hardware stochastic rounding FP32 → FP8/BF16/F16 |
Blackwell |
Common patterns
Producer-consumer with mbarrier (pipelined GEMM)
bars_full = tlx.alloc_barriers(num_stages, arrive_count=1) # TMA arrives implicitly
bars_empty = tlx.alloc_barriers(num_stages, arrive_count=num_consumers)
# Producer: TMA load → signal full
tlx.barrier_expect_bytes(bar_full, nbytes)
tlx.async_descriptor_load(desc, indices, barrier=bar_full)
# Consumer: wait full → MMA → signal empty
tlx.barrier_wait(bar_full, phase)
tlx.async_dot(A, B, acc)
tlx.barrier_arrive(bar_empty)
PingPong with named barriers
# Consumer 0 waits for Consumer 1, then issues MMA
tlx.named_barrier_wait(9, 256) # 256 = 2 warp groups * 4 warps * 32 threads
qk = tlx.async_dot(q, k)
tlx.named_barrier_arrive(10, 256)
# Consumer 1 waits for Consumer 0's MMA to finish
tlx.named_barrier_arrive(9, 256)
tlx.named_barrier_wait(10, 256)
qk = tlx.async_dot(q, k)
Deep-dive docs
- API reference:
third_party/tlx/README.md
- Barriers:
third_party/tlx/doc/tlx_barriers.md
- Placeholder layouts:
third_party/tlx/doc/PlaceholderLayouts.md
- Storage alias design:
third_party/tlx/doc/storage_alias_spec_design.md
Converted and distributed by TomeVault — claim your Tome and manage your conversions.
1---2name: facebookexperimental-triton-tlx-api-reference3description: TLX API Quick Reference4---56# TLX API Quick Reference78## Warp Specialization910| Function | Description | Arch |11|---|---|---|12| `tlx.async_tasks()` | Context manager wrapping all async task regions | Both |13| `tlx.async_task([task_ids])` | Assign code to specific task IDs (e.g., `[0]` = producer, `[1,2]` = consumers) | Both |14| `tlx.async_task(num_warps=N, num_regs=R)` | Explicit warp/register allocation for a task | Both |15| `tlx.async_task("default", num_regs=R)` | Default task for code outside explicit tasks | Both |16| `tlx.async_task_replica_id()` | Returns replica ID inside an async region | Both |1718### Warp specialization skeleton1920```python21with tlx.async_tasks():22 with tlx.async_task([0]): # Producer23 # TMA loads24 with tlx.async_task([1, 2]): # Consumers25 # MMA compute26```2728## Memory Barriers2930### mbarrier (shared-memory allocated)3132| Function | Description | Arch |33|---|---|---|34| `tlx.alloc_barriers(num_barriers, arrive_count=1)` | Allocate SMEM barriers and initialize with arrive count | Both |35| `tlx.barrier_expect_bytes(bar, bytes, pred=None)` | Set expected transaction byte count on barrier | Both |36| `tlx.barrier_wait(bar, phase, pred=None)` | Wait until barrier phase flips (LOCAL mbarrier only) | Both |37| `tlx.barrier_arrive(bar, arrive_count=1, remote_cta_rank=None)` | Signal arrival at barrier. `remote_cta_rank` signals a barrier in a remote CTA — **only valid when ctas_per_cga > 1**, causes "Unexpected buffer remote view in 1cta mode" otherwise. Guard with `if USE_2CTA:` when kernel supports both modes. | Both |38| `tlx.cluster_barrier()` | Full cluster-wide synchronization barrier | Both |3940**arrive_count rules:**41- Implicit arrive from `barrier_expect_bytes`: use `arrive_count=1`42- `barrier_arrive` inside `tlx.async_task`: `arrive_count` = number of warp groups43- `barrier_arrive` outside `tlx.async_task`: `arrive_count=1` (only tid==0 arrives)4445### Named barriers (hardware-allocated, indices 0–15)4647| Function | Description | Arch |48|---|---|---|49| `tlx.named_barrier_wait(bar_id, num_threads)` | Wait until num_threads arrive at bar_id | NVIDIA |50| `tlx.named_barrier_arrive(bar_id, num_threads)` | Signal arrival at bar_id | NVIDIA |5152`num_threads` must be a multiple of 32 (warp size). Typically `num_warp_groups * warps_per_group * 32`.5354Used for PingPong scheduling to prevent tensor core contention between consumer warp groups.5556## Memory Operations5758### SMEM / TMEM allocation5960| Function | Description | Arch |61|---|---|---|62| `tlx.local_alloc(shape, dtype, num, storage=smem, reuse=None, layout=None)` | Allocate buffered tensor in SMEM or TMEM | Both (TMEM: Blackwell) |63| `tlx.storage_alias_spec(storage=smem, buffer_size_bytes=None)` | Define shared buffer region for multiple `local_alloc` calls via `reuse` | Both |64| `tlx.local_view(buf, index)` | Get view of a single buffer from a multi-buffered tensor | Both |65| `tlx.local_slice(buf, start, end)` | Slice a sub-range of a buffered tensor | Both |66| `tlx.subslice(tensor, dim, start, size)` | Subslice a tensor along a dimension | Both |67| `tlx.local_load(buf)` | Load from SMEM/TMEM buffer into registers | Both |68| `tlx.local_store(val, buf)` | Store from registers into SMEM/TMEM buffer | Both |69| `tlx.local_trans(buf)` | Transpose a shared memory buffer | Both |70| `tlx.local_reinterpret(buf, dtype)` | Reinterpret buffer with a different dtype | Both |71| `tlx.remote_view(buf, remote_cta_rank)` | Get view of buffer in a remote CTA's SMEM | Both |72| `tlx.remote_shmem_store(val, buf)` | Store to remote CTA's shared memory | Both |73| `tlx.async_remote_shmem_store(val, buf)` | Async store to remote CTA's shared memory | Both |74| `tlx.tmem_copy(src, dst)` | Copy between TMEM buffers | Blackwell |75| `tlx.fence_async_shared()` | Memory fence for async shared memory operations | Both |7677**Storage kinds:** `tlx.storage_kind.smem`, `tlx.storage_kind.tmem` (Blackwell), `tlx.storage_kind.smemCluster`7879### TMA (Tensor Memory Accelerator)8081| Function | Description | Arch |82|---|---|---|83| `tlx.make_tensor_descriptor(ptr, shape, strides, block_shape)` | Create TMA descriptor from pointer (host-side) | Hopper+ |84| `tlx.allocate_tensor_descriptor(ptr, shape, strides, block_shape, swizzle_mode)` | Allocate and fill TMA descriptor in SMEM | Hopper+ |85| `tlx.reinterpret_tensor_descriptor(desc, dtype)` | Reinterpret TMA descriptor with different dtype | Hopper+ |86| `tlx.async_descriptor_load(desc, indices, barrier=None)` | Async TMA load from global → SMEM, tracked by barrier | Hopper+ |87| `tlx.async_descriptor_store(desc, val, indices)` | Async TMA store from registers → global | Hopper+ |88| `tlx.async_descriptor_store_wait()` | Wait for all pending TMA stores to complete | Hopper+ |89| `tlx.async_load(ptr, buf, barrier)` | Async bulk copy global → SMEM (cp.async) | Hopper+ |90| `tlx.async_load_commit_group()` | Commit async load group | Hopper+ |91| `tlx.async_load_wait_group(n)` | Wait for async load groups (n pending allowed) | Hopper+ |9293## Matrix Multiply (MMA)9495| Function | Description | Arch |96|---|---|---|97| `tlx.async_dot(A, B, acc=None, use_acc=None, mBarriers=[], two_ctas=False)` | Warp-group MMA: D = A @ B + C. Maps to wgmma (Hopper) or tcgen05.mma (Blackwell) | Both |98| `tlx.async_dot_scaled(A, B, acc, A_scale, A_format, B_scale, B_format, ...)` | Scaled MMA with FP8 inputs: D = (A*scale_A) @ (B*scale_B) + D | Blackwell |99| `tlx.async_dot_wait(pendings, inp)` | Wait for N pending async dot operations to complete | Both |100| `tlx.tcgen05_commit(mBarrier, two_ctas=False)` | Make mbarrier track completion of prior tcgen05 ops. Use a SEPARATE mbarrier from async_dot | Blackwell |101102**Minimum tile sizes for async_dot:** M ≥ 64, K ≥ 16, N ≥ 32103104**Pair-CTA MMA (two_ctas=True):** M must be 128 per CTA.105106## Multi-CTA (Cluster) Kernels107108`ctas_per_cga=(N,1,1)` in triton.Config sets the cluster size. The grid109specifies **total CTAs**; hardware divides by ctas_per_cga to get the number110of clusters. E.g., grid=(2,1,1) with ctas_per_cga=(2,1,1) = 1 cluster of1112 CTAs.112113114**input_precision options:** `tf32`, `tf32x3`, `ieee`115116## CLC (Cluster Launch Control) — Blackwell only117118| Function | Description |119|---|---|120| `tlx.clc_create_context(num_consumers, num_stages=1)` | Create CLC pipeline context (allocates barriers + response buffers) |121| `tlx.clc_producer(context, p_producer, multi_ctas=False, k=0)` | Issue CLC try_cancel request from CTA 0 |122| `tlx.clc_consumer(context, p_consumer, multi_ctas=False, k=0)` | Decode tile ID from CLC response, signal completion. Returns tile_id or -1 |123124For 2-CTA mode: set `multi_ctas=True` (uses "arrive remote, wait local" pattern).125126## Utility127128| Function | Description | Arch |129|---|---|---|130| `tlx.cluster_cta_rank()` | Unique CTA ID within a cluster (all dims) | Both |131| `tlx.thread_id(axis)` | Thread ID along axis 0, 1, or 2 | Both |132| `tlx.dtype_of(tensor_or_desc)` | Get element type of tensor or tensor descriptor | Both |133| `tlx.size_of(dtype)` | Size of dtype in bytes | Both |134| `tlx.get_fp8_format_name(dtype)` | Get FP8 format string ("e5m2" or "e4m3") for scaled MMA | Both |135| `tlx.clock64()` | 64-bit hardware clock value (for timing) | Both |136| `tlx.stoch_round(src, dst_ty, rand_bits)` | Hardware stochastic rounding FP32 → FP8/BF16/F16 | Blackwell |137138## Common patterns139140### Producer-consumer with mbarrier (pipelined GEMM)141142```python143bars_full = tlx.alloc_barriers(num_stages, arrive_count=1) # TMA arrives implicitly144bars_empty = tlx.alloc_barriers(num_stages, arrive_count=num_consumers)145146# Producer: TMA load → signal full147tlx.barrier_expect_bytes(bar_full, nbytes)148tlx.async_descriptor_load(desc, indices, barrier=bar_full)149150# Consumer: wait full → MMA → signal empty151tlx.barrier_wait(bar_full, phase)152tlx.async_dot(A, B, acc)153tlx.barrier_arrive(bar_empty)154```155156### PingPong with named barriers157158```python159# Consumer 0 waits for Consumer 1, then issues MMA160tlx.named_barrier_wait(9, 256) # 256 = 2 warp groups * 4 warps * 32 threads161qk = tlx.async_dot(q, k)162tlx.named_barrier_arrive(10, 256)163164# Consumer 1 waits for Consumer 0's MMA to finish165tlx.named_barrier_arrive(9, 256)166tlx.named_barrier_wait(10, 256)167qk = tlx.async_dot(q, k)168```169170## Deep-dive docs171172- API reference: `third_party/tlx/README.md`173- Barriers: `third_party/tlx/doc/tlx_barriers.md`174- Placeholder layouts: `third_party/tlx/doc/PlaceholderLayouts.md`175- Storage alias design: `third_party/tlx/doc/storage_alias_spec_design.md`176177---178> Converted and distributed by [TomeVault](https://tomevault.io/claim/facebookexperimental) — claim your Tome and manage your conversions.179<!-- tomevault:4.0:skill_md:2026-04-11 -->