PTX ISA v9.4

9.7.18.7. Tensor Memory Allocation and Management Instructions

9.7.18.7.1. Tensorcore 5th Generation Instructions: tcgen05.alloc, tcgen05.dealloc, tcgen05.relinquish_alloc_permit

tcgen05.alloc, tcgen05.dealloc, tcgen05.relinquish_alloc_permit

Dynamic Tensor Memory allocation management instructions

Syntax

ptx
tcgen05.alloc{.exclusive}.cta_group.sync.aligned{.shared::cta}.b32  [dst], nCols;

tcgen05.dealloc{.exclusive}.cta_group.sync.aligned.b32              taddr, nCols;

tcgen05.relinquish_alloc_permit.cta_group.sync.aligned;

.cta_group = { .cta_group::1, .cta_group::2 }

Description

tcgen05.alloc is a blocking instruction which dynamically allocates the specified number of columns in the Tensor Memory and writes the address of the allocated Tensor Memory into shared memory at the location specified by address operand dst. The tcgen05.alloc blocks if the requested amount of Tensor Memory is not available and unblocks as soon as the requested amount of Tensor Memory becomes available for allocation.

tcgen05.dealloc is a potentially blocking instruction which deallocates the Tensor Memory specified by the Tensor Memory address taddr. The operand taddr must point to a previous Tensor Memory allocation. If .cta_group::2 is specified,

  • issuing warp and peer CTA warp must synchronize Tensor Memory accesses before attempting to collectively deallocate the Tensor Memory, and
  • tcgen05.dealloc may block to collectively performs the deallocation with the other peer CTA's warp.

All of the Tensor Memory that was allocated using tcgen05.alloc instruction in a kernel, must be explicitly deallocated using tcgen05.dealloc before the kernel exits.

The unsigned 32-bit operand nCols specify the number of columns to be allocated or de-allocated. The unit of allocation and de-allocation is 32 columns and all of lanes per column. The number of columns allocated should not increase between any two allocations in the execution order within the CTA.

If .exclusive is not specified, the operand nCols must be a power of 2, in the range [32, 512]. If .exclusive is specified, nCols must be a multiple of 32, in the range [32, 512] on target sm_100f, or the range [32, 576] on target sm_107f.

Table 58 shows the valid values of nCols.

Table 58 nCols values for Non-exclusive and Exclusive allocation

Allocation Kind nCols Minimum nCols Maximum nCols Modulus nCols Popcount
Non-exclusive 32 512 32 = 1 (Power of two)
Exclusive (.exclusive) 32 sm_100, sm_103, sm_110 -> 512; sm_107 -> 576 32 (No restriction)

Instruction tcgen05.relinquish_alloc_permit specifies that the CTA of the executing thread is relinquishing the right to allocate Tensor Memory. So, it is illegal for a CTA to perform tcgen05.alloc after any of its constituent threads execute tcgen05.relinquish_alloc_permit.

If no state space is specified then Generic Addressing is used. If the address specified by dst does not fall within the address window of .shared::cta state space then the behavior is undefined.

The optional .exclusive qualifier describes an effect on the allocation permit.

  • When .exclusive is not specified, the allocation is non-exclusive. The instruction uses the allocation permit, but does not claim ownership of it. Multiple non-exclusive allocations may exist simultaneously.
  • When .exclusive is specified, the allocation is exclusive. The instruction claims ownership of the allocation permit. No other allocation may exist at the same time as an exclusive allocation. An exclusive allocation typically occupies all Tensor Memory capacity, but it may occupy less.
  • Memory must be deallocated with .exclusive if and only if it is allocated with .exclusive.

Exclusive Allocation:

A tcgen05.alloc.exclusive operation makes an exclusive allocation, taking control of Tensor Memory and of the allocation permit. This must be the only live allocation, until it is deallocated with a corresponding tcgen05.dealloc.exclusive operation.

An exclusive allocation operation blocks until there is no other live allocation. Until the sole live allocation is deallocated, no other CTA may allocate, whether exclusively or nonexclusively. The sole allocation must be deallocated by a matching tcgen05.dealloc.exclusive with the same number of columns, at which point the allocation permit becomes available again.

An exclusive allocation operation may allocate a number of columns that is not a power of 2.

If .cta_group::1 is specified, ownership of the sole allocation is held by a single CTA. If .cta_group::2 is specified, ownership is held jointly by both peer CTAs.

Qualifier .cta_group specifies the number of CTAs involved in the allocation and de-allocation operation. When .cta_group::1 is specified, one warp from the CTA must perform the allocation and de-allocation. When .cta_group::2 is specified, one warp from each of the peer CTAs must collectively perform the allocation and de-allocation. Refer to the Issue Granularity section. When .cta_group::2 is specified, the issuing warp must make sure that peer CTA is launched and its warps eventually participate in collective operations.

All tcgen05 instructions within a kernel must specify the same value for the .cta_group qualifier.

The mandatory .sync qualifier indicates that the instruction causes the executing thread to wait until all threads in the warp execute the same instruction before resuming execution.

The mandatory .aligned qualifier indicates that all threads in the warp must execute the same instruction. In conditionally executed code, the instruction should only be used if it is known that all threads in the warp evaluate the condition identically, otherwise behavior is undefined.

The behavior of the instruction is undefined if all the threads in the warp do not use the same values of nCols, or if any thread in the warp has exited.

The store operation in tcgen05.alloc is treated as a weak memory operation in the Memory Consistency Model.

PTX ISA Notes

Introduced in PTX ISA version 8.6.

Support for qualifier .exclusive introduced in PTX ISA version 9.4.

Target ISA Notes

Supported on following architectures:

  • sm_100a
  • sm_101a (Renamed to sm_110a from PTX ISA version 9.0)
  • And is supported on following family-specific architectures from PTX ISA version 8.8:
  • sm_100f or higher in the same family
  • sm_101f or higher in the same family (Renamed to sm_110f from PTX ISA version 9.0)
  • sm_110f or higher in the same family

Qualifier .exclusive supported on following family-specific architectures:

  • sm_100f or higher in the same family
  • sm_110f or higher in the same family

Examples

ptx
// Example 1: Non-exclusive allocation and deallocation for 1-CTA

tcgen05.alloc.cta_group::1.sync.aligned.shared::cta.b32 [sMemAddr1], 32;
ld.shared.b32 taddr, [sMemAddr1];
// use taddr ...
// more allocations and its usages ...
tcgen05.dealloc.cta_group::1.sync.aligned.b32  taddr, 32;
// more deallocations ...
tcgen05.relinquish_alloc_permit.cta_group::1.sync.aligned;

// Example 2: Exclusive allocation and deallocation for 2-CTA

// Following instructions are performed by current warp and the warp in the peer-CTA:
tcgen05.alloc.cta_group::2.sync.aligned.shared::cta.b32 [sMemAddr2], 32;
ld.shared.b32 taddr, [sMemAddr2];
// use taddr ...
// more allocations and its usages ...
tcgen05.dealloc.cta_group::2.sync.aligned.b32  taddr, 32;
// more deallocations ...
tcgen05.relinquish_alloc_permit.cta_group::2.sync.aligned;

// Example 3: Exclusive allocation and deallocation for 2-CTA

.reg .b32 sMemAddr, taddr;
.reg .u32 nCols;

mov.u32 nCols, 576;

tcgen05.alloc.exclusive.cta_group::2.sync.aligned.shared::cta.b32 [sMemAddr], nCols;
// ...
tcgen05.dealloc.exclusive.cta_group::2.sync.aligned.b32 taddr, nCols;
// ...
tcgen05.relinquish_alloc_permit.cta_group::2.sync.aligned;
esc
Type to search across all documentation