MOVA2D
tenstorrent_tt_isa)Tenstorrent Wormhole B0 & Blackhole A0
main
userTensix, Matrix Unit, WormholeB0Summary
Move one row of datums from SrcA to Dst, or move an aligned block of eight rows of datums from SrcA to Dst. To bridge the gap between SrcA data types and Dst data types, TF32 / BF16 in SrcA can be converted to FP32 in Dst, and any of BF16 / FP16 / Integer "8" in SrcA can be passed through unchanged to Dst. If used with care, software can also use a pair of MOVA2D instructions to lanewise combine two spans of 16-bit…
Syntax / Encoding
TT_MOVA2D(/* bool */ UseDst32bLo,
/* u6 */ SrcRow,
/* u2 */ AddrMod,
(/* bool */ Move8Rows) << 1,
/* u10 */ DstRow)
Binary Encodings (2)
| Width | Format | Bit Pattern | Mask / Match |
|---|---|---|---|
| 32 | Tensix-32b | 00010010xxxxxxxxxxxxxxxxxxxxxxxx | 0xff000000 / 0x12000000 |
| 32 | Tensix-32b (Blackhole) | 00010010xxxxxxxxxxxxxxxxxxxxxxxx | 0xff000000 / 0x12000000 |
Reference Notes
# `MOVA2D` (Move one row or eight rows from `SrcA` to `Dst`)
**Summary:** Move one row of datums from `SrcA` to `Dst`, or move an aligned block of eight rows of datums from `SrcA` to `Dst`. To bridge the gap between [`SrcA` data types](SrcASrcB.md#data-types) and [`Dst` data types](Dst.md#data-types), TF32 / BF16 in `SrcA` can be converted to FP32 in `Dst`, and any of BF16 / FP16 / Integer "8" in `SrcA` can be passed through unchanged to `Dst`. If used with care, software can also use a pair of `MOVA2D` instructions to lanewise combine two spans of 16-bit data in `SrcA` to form a single span of 32-bit data in `Dst`.
**Backend execution unit:** [Matrix Unit (FPU)](MatrixUnit.md)
## Syntax
```c
TT_MOVA2D(/* bool */ UseDst32bLo,
/* u6 */ SrcRow,
/* u2 */ AddrMod,
(/* bool */ Move8Rows) << 1,
/* u10 */ DstRow)
```
## Encoding

On Blackhole, `AddrMod` is a `u3` rather than a `u2`, giving this encoding:

## Functional model
This instruction will, if necessary, spend time waiting at the Wait Gate before being dispatched to the Matrix Unit (FPU):
```c
while (SrcA[MatrixUnit.SrcABank].AllowedClient != MatrixUnit) {
wait;
}
```
Once dispatched to the Matrix Unit (FPU):
```c
uint1_t StateID = ThreadConfig[CurrentThread].CFG_STATE_ID_StateID;
auto& ConfigState = Config[StateID];
// Determine the data formats.
uint4_t SrcAFmt = ConfigState.ALU_FORMAT_SPEC_REG_SrcA_override ? ConfigState.ALU_FORMAT_SPEC_REG_SrcA_val : ConfigState.ALU_FORMAT_SPEC_REG0_SrcA;
if ((TTArchitecture == Blackhole) && !ThreadConfig[CurrentThread].DISABLE_IMPLIED_SRCA_FMT_Base) {
SrcAFmt = ImpliedSrcAFmt[MatrixUnit.SrcABank];
}
bool Use8bExponent;
bool UseDst32b;
if (ThreadConfig[CurrentThread].FP16A_FORCE_Enable) {
UnsupportedFunctionality(); // No known usage, confidence in specification below is weak
Use8bExponent = false;
UseDst32b = false;
} else {
if ((TTArchitecture == Blackhole) && ConfigState.ALU_ACC_CTRL_Fp32_enabled) {
// On Blackhole, MOV[DBG][A,B]2D pretend that SrcAFmt is TF32 whenever fp32 accumulation
// is enabled, so that the move writes 32-bit Dst datums at 32-bit Dst addresses (matching
// what the rest of Dst is using). Wormhole lacks this, so on Wormhole a move with fp32
// accumulation enabled and SrcAFmt != TF32 writes a 16-bit datum at a 16-bit Dst address.
SrcAFmt = TF32;
}
if (ConfigState.ALU_ACC_CTRL_Fp32_enabled || ConfigState.ALU_ACC_CTRL_INT8_math_enabled) {
// Note that ALU_ACC_CTRL_INT8_math_enabled does _not_ cause 32-bit Dst datums to be
// written, even though integer "32" math elsewhere uses 32-bit Dst datums.
Use8bExponent = true;
} else if (SrcAFmt in {FP32, TF32, BF16, BFP8, BFP4, BFP2, INT32, INT16}) {
Use8bExponent = true;
} else {
Use8bExponent = false;
}
UseDst32b = (SrcAFmt == TF32);
}
bool FlushDenormals = !ConfigState.ALU_ACC_CTRL_Zero_Flag_disabled_src;
if ((UseDst32b || UseDst32bLo) != (ConfigState.ALU_ACC_CTRL_Fp32_enabled ||
ConfigState.ALU_ACC_CTRL_INT8_math_enabled)) {
if (UseDst32bLo && !UseDst32b) {
// Data is written as below, but DstRowValid is updated at the wrong row (see below)
NonContractualBehavior();
} else {
UndefinedBehavior(); // DstRowValid update addressing is incorrect in this case
}
}
// Determine the row range.
unsigned NumRows;
DstRow += ThreadConfig[CurrentThread].DEST_TARGET_REG_CFG_MATH_Offset;
DstRow += RWCs[CurrentThread].Dst + ConfigState.DEST_REGW_BASE_Base;
SrcRow += RWCs[CurrentThread].SrcA;
if (Move8Rows) {
NumRows = 8;
DstRow &= 0x3f8;
SrcRow &= 0x38;
} else {
if ((TTArchitecture == Blackhole) && (AddrMod & 1)) {
// On Blackhole, the low bit of AddrMod also selects a four-row mode: in practice the move
// copies the aligned group of four rows of SrcA to the aligned group of four rows of Dst,
// setting the DstRowValid of exactly those four rows (and AddrMod still advances the RWCs).
UnsupportedFunctionality();
}
NumRows = 1;
DstRow &= 0x3ff;
SrcRow &= 0x3f;
if (SrcRow & 0x10) {
// Erratum (Wormhole and Blackhole): in practice, SrcA rows 16 through 31 and 48 through 63 move
// as zeros. The eight-row form is unaffected.
UnsupportedFunctionality();
}
}
// Actually copy the row(s).
for (; NumRows; --NumRows, ++DstRow, ++SrcRow) {
for (unsigned Column = 0; Column < 16; ++Column) {
if (LaneConfig[Column / 2].BLOCK_DEST_MOV.Bit[Column & 1]) continue;
uint19_t SrcAVal = SrcA[MatrixUnit.SrcABank][SrcRow][Column];
if (FlushDenormals && !(SrcAVal & 0xff)) SrcAVal = 0;
SrcAVal = TruncateSrc(SrcAVal, SrcAFmt);
uint16_t Val16b = Use8bExponent ? RemoveLowMantissa(SrcAVal) : RemoveHighExponent(SrcAVal);
if (UseDst32b) {
if (UseDst32bLo) {
UndefinedBehavior(); // Write data will be corrupted on Blackhole (HW erratum TEN-4245); Wormhole behavior is unlikely to be useful
}
uint16_t LowMantissa = ((SrcAVal >> 8) & 7) << 13; // The bits removed by RemoveLowMantissa.
// Dst holds TF32 as Sign,HiMan(7b),Exp(8b),LoMan(3b),Zeros(13b)
// This is compatible with Dst FP32, where Zeros extends LoMan.
Dst32b[DstRow][Column] = (uint32_t(Val16b) << 16) | LowMantissa;
} else if (UseDst32bLo) {
// This is unlikely to be useful, unless software is deliberately
// packing two bf16 or fp16 values into 32 bits and storing them in Dst32b.
// To store a pair of 16b values, first use MOVA2D with SrcAFmt=TF32 to
// store the high 16b, then use MOVA2D with SrcAFmt!=TF32 and
// UseDst32bLo=true to store the low 16b. If the first MOVA2D uses any other
// SrcAFmt, then a mixture of Dst16b and Dst32b accesses will occur, which
// can be made to work, but software needs to really know what it is doing.
Dst32b[DstRow][Column] = (Dst32b[DstRow][Column] & 0xffff0000) | V