MVMUL
tenstorrent_tt_isa)Tenstorrent Wormhole B0 & Blackhole A0
main
userTensix, Matrix Unit, BlackholeA0, WormholeB0Summary
An aligned 8x16 matrix from SrcB is multiplied with an aligned 16x16 matrix from SrcA, and the resultant 8x16 matrix added element-wise to an aligned 8x16 block of Dst. The hardware multipliers consume at most 5 bits of SrcA magnitude/mantissa and at most 7 bits of SrcB magnitude/mantissa, so software may wish to execute up to four separate fidelity phases, subject to the precision of the input data and the desired…
Syntax / Encoding
TT_MVMUL(((/* bool */ FlipSrcB) << 1) +
/* bool */ FlipSrcA,
/* bool */ BroadcastSrcBRow,
/* u2 */ AddrMod,
/* u10 */ DstRow)
Binary Encodings (2)
| Width | Format | Bit Pattern | Mask / Match |
|---|---|---|---|
| 32 | Tensix-32b | 00100110xxxxxxxxxxxxxxxxxxxxxxxx | 0xff000000 / 0x26000000 |
| 32 | Tensix-32b (Blackhole) | 00100110xxxxxxxxxxxxxxxxxxxxxxxx | 0xff000000 / 0x26000000 |
Reference Notes
# `MVMUL` (`Dst += SrcB @ SrcA` matrix multiply)
**Summary:** An aligned 8x16 matrix from [`SrcB`](SrcASrcB.md) is multiplied with an aligned 16x16 matrix from [`SrcA`](SrcASrcB.md), and the resultant 8x16 matrix added element-wise to an aligned 8x16 block of [`Dst`](Dst.md). The hardware multipliers consume at most 5 bits of `SrcA` magnitude/mantissa and at most 7 bits of `SrcB` magnitude/mantissa, so software may wish to execute up to four separate fidelity phases, subject to the precision of the input data and the desired output precision. To get the effect of `Dst = SrcB @ SrcA` (i.e. `=` rather than `+=`), [`ZEROACC`](ZEROACC.md) can be used prior to `MVMUL`, as `MVMUL` reads undefined rows as zero.
The supported data type combinations are:
|[`Dst` data type](Dst.md#data-types)|+=|[`SrcB` data type](SrcASrcB.md#data-types)|@|[`SrcA` data type](SrcASrcB.md#data-types)|
|---|---|---|---|---|
|8x16 matrix of either FP32 or BF16|+=|8x16 matrix of either TF32 or BF16|@|16x16 matrix of either TF32 (†) or BF16|
|8x16 matrix of either FP32 or FP16|+=|8x16 matrix of FP16|@|16x16 matrix of FP16 (†)|
|8x16 matrix of integer "32"|+=|8x16 matrix of integer "8"|@|16x16 matrix of integer "8" (‡)|
(†) For `SrcA`, the least significant bit of the FP16 or TF32 mantissa is ignored in multiplication operations.
(‡) For `SrcA`, the most significant two bits of the integer "8" magnitude are ignored in multiplication operations, leaving just the low eight bits of magnitude. The usable values are therefore -255 through +255.
There is also support for broadcasting a 1x16 row of `SrcB`, albeit in a slightly odd way: it'll be broadcasted up to a 7x16 matrix, and then half the rows set to zero, multiplied with a 16x16 matrix from `SrcA` as per usual, and added to a 7x16 matrix in `Dst`. Equivalently, this can be seen as starting with a 1x16 row, multiplying it with a 16x16 matrix, then doing the exotic broadcast and zeroing, then adding to `Dst`. If this mode is used, the data movement pattern is:

The broadcast mode also has an unusual interaction with the `Dst` valid bits (see [`ZEROACC`](ZEROACC.md)): the set of rows whose valid bit is updated is _not_ the set of rows written. Hardware marks the whole upper half of the aligned 8x16 block of `Dst` as valid, plus the single row `DstRow`. The consequences are:
* `DstRow + 2` is written, but its valid bit is not updated, so it continues to read as zero if it was undefined beforehand.
* The two rows of the upper half which are _not_ written become defined, so they read back whatever they happened to contain beforehand, which is `UnpredictableValue()` if they have never been written.
Software which wants a single well-defined result row should therefore read it from `DstRow`, `DstRow + 4`, or `DstRow + 6`, and should not assume anything about the contents of the other rows of the block. Unlike the data path, this valid bit update is sensitive to bits 2 and 1 of `DstRow`, so a `DstRow` with either of those bits set is `UnsupportedFunctionality`.
**Backend execution unit:** [Matrix Unit (FPU)](MatrixUnit.md)
## Syntax
```c
TT_MVMUL(((/* bool */ FlipSrcB) << 1) +
/* bool */ FlipSrcA,
/* bool */ BroadcastSrcBRow,
/* u2 */ AddrMod,
/* 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
|| SrcB[MatrixUnit.SrcBBank].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.
// Note: Blackhole implied format behavior for SrcB not fully characterized
uint4_t SrcAStyle;
bool UseDst32b;
uint4_t SrcAFmt = ConfigState.ALU_FORMAT_SPEC_REG_SrcA_override ? ConfigState.ALU_FORMAT_SPEC_REG_SrcA_val : ConfigState.ALU_FORMAT_SPEC_REG0_SrcA;
uint4_t SrcBFmt = ConfigState.ALU_FORMAT_SPEC_REG_SrcB_override ? ConfigState.ALU_FORMAT_SPEC_REG_SrcB_val : ConfigState.ALU_FORMAT_SPEC_REG1_SrcB;
if ((TTArchitecture == Blackhole) && !ThreadConfig[CurrentThread].DISABLE_IMPLIED_SRCA_FMT_Base) {
SrcAFmt = ImpliedSrcAFmt[MatrixUnit.SrcABank];
}
if ((TTArchitecture == Blackhole) && !ThreadConfig[CurrentThread].DISABLE_IMPLIED_SRCB_FMT_Base) {
SrcBFmt = ImpliedSrcBFmt[MatrixUnit.SrcBBank];
}
if (ThreadConfig[CurrentThread].FP16A_FORCE_Enable) {
UnsupportedFunctionality(); // No known usage, confidence in specification below is weak
SrcAStyle = FP16;
UseDst32b = false;
} else if (ConfigState.ALU_ACC_CTRL_INT8_math_enabled) {
SrcAStyle = INT8;
UseDst32b = true;
} else {
if (SrcAFmt in {FP32, BF16, BFP8, BFP4, BFP2, INT32, INT16}) {
SrcAStyle = BF16;
} else if (SrcAFmt in {FP16, FP8, BFP8a, BFP4a, BFP2a, INT8}) {
SrcAStyle = FP16;
} else /* SrcAFmt == TF32 */ {
SrcAStyle = TF32;
}
UseDst32b = ConfigState.ALU_ACC_CTRL_Fp32_enabled;
}
bool FlushDenormals = !ConfigState.ALU_ACC_CTRL_Zero_Flag_disabled_src; // Note: behavior has yet to be fully characterized
if (!FlushDenormals) {
UnsupportedFunctionality(); // Asymmetric "keep SrcB denormals" mode that cannot represent 0.0 should not be used
}
// Determine the row range.
unsigned NumRows = BroadcastSrcBRow ? 7 : 8;
uint6_t SrcARow = RWCs[CurrentThread].SrcA & 0x30;
uint6_t SrcBRow = RWCs[CurrentThread].SrcB & (BroadcastSrcBRow ? 0x3f : 0x38);
DstRow += ThreadConfig[CurrentThread].DEST_TARGET_REG_CFG_MATH_Offset;
DstRow += RWCs[CurrentThread].Dst + ConfigState.DEST_REGW_BASE_Base;
if (BroadcastSrcBRow && (DstRow & 6)) {
// The data path masks bits 2 and 1 of DstRow away, but the DstRowVal