ISARef Multi-ISA & Silicon Reference
45,419 ISA items · 105,907 timings · 913 microarchs · 15,555 chips · 105 sources
Arch:
Tier:

Tensix: SrcA and SrcB

T1 tenstorrent guide guide
Tenstorrent WormholeB0 Tensix — SrcA and SrcB
SourceTenstorrent Official Tensix ISA Documentation (Wormhole & Blackhole) (tenstorrent_tt_isa)
Reliability TierT1 — Official Specification
ISA / Silicon ScopeTenstorrent WormholeB0
Tenstorrent Wormhole B0 & Blackhole A0
License & VersionApache-2.0
main
Upstreamhttps://github.com/tenstorrent/tt-isa-documentation
ExtensionsTensix, WormholeB0

Summary

Each of SrcA and SrcB can be viewed as having 2 banks of 64 rows of 16 columns of 19-bit data. They are best considered as a temporary staging area for Matrix Unit (FPU) computation instruction operands: load up to 64 rows into each, execute some Matrix Unit (FPU) instructions to consume those rows, load up a completely new set of up to 64 rows into either (or both), execute some Matrix Unit (FPU) instructions to…

Reference Notes

# `SrcA` and `SrcB`

Each of `SrcA` and `SrcB` can be viewed as having 2 banks of 64 rows of 16 columns of 19-bit data. They are best considered as a temporary staging area for Matrix Unit (FPU) computation instruction operands: load up to 64 rows into each, execute some Matrix Unit (FPU) instructions to consume those rows, load up a completely new set of up to 64 rows into either (or both), execute some Matrix Unit (FPU) instructions to consume them, rinse and repeat. The two banks allow the Unpackers to be writing to one bank while the Matrix Unit (FPU) is using the other bank. Instruction descriptions assume the following definition of `SrcA` and `SrcB`:

```c
enum class SrcClient {
  MatrixUnit,
  Unpackers,
};
struct {
  SrcClient AllowedClient = SrcClient::Unpackers;
  uint19_t Rows[64][16];
} SrcA[2], SrcB[2];
```

Instruction descriptions use the shorthand `SrcA[Bank][Row][Column]` to mean `SrcA[Bank].Rows[Row][Column]`, and similarly for `SrcB`.

The functional units capable of accessing `SrcA` and `SrcB` all keep one bit of state for tracking which bank they're currently using:
```c
uint1_t MatrixUnit::SrcABank = 0;
uint1_t MatrixUnit::SrcBBank = 0;
uint1_t Unpackers[0]::SrcBank = 0; // For SrcA
uint1_t Unpackers[1]::SrcBank = 0; // For SrcB
```

Unpacker 0 also remembers whether the most recent [`UNPACR`](UNPACR_Regular.md) it executed wrote to `Dst` rather than `SrcA`:
```c
bool Unpackers[0]::WroteDst = false;
```

Each Unpacker has a row pointer per thread, which [`UNPACR`](UNPACR_Regular.md) adds to the row it writes in `SrcB` (and in `SrcA` when `SRCA_SET_SetOvrdWithAddr` is clear), and on Wormhole it remembers which thread's `UNPACR` most recently wrote datums through it:
```c
uint6_t Unpackers[0]::SrcRow[3] = {0, 0, 0}; // Indexed by thread
uint6_t Unpackers[1]::SrcRow[3] = {0, 0, 0};
uint2_t Unpackers[0]::WriteThread = 0; // Wormhole
uint2_t Unpackers[1]::WriteThread = 0;
```

When a bank is given to the Matrix Unit, by `UNPACR` with `FlipSrc`, by the set-dvalid form of [`UNPACR_NOP`](UNPACR_NOP_SETDVALID.md) or by [`SETDVALID`](SETDVALID.md), the row pointer that goes back to `SRCA_SET_Base` or `SRCB_SET_Base` (times 16) is, on Wormhole, that of `WriteThread`, read from `WriteThread`'s `ThreadConfig`, whichever thread gives the bank. For `UNPACR` with `FlipSrc` that is the issuing thread; for `UNPACR_NOP` or `SETDVALID` issued by a thread other than the one that last unpacked, the issuing thread's own row pointer is left as it is. This matters only when a thread's `SRCA_SET_Base` or `SRCB_SET_Base` is nonzero.

### Hardware bug: giving `SrcA` to the Matrix Unit after an `UNPACR` to `Dst`

On both Wormhole and Blackhole, while `Unpackers[0].WroteDst` is `true`, giving a `SrcA` bank to the Matrix Unit (FPU) is `UndefinedBehavior` if it is done by any of:
* An `UNPACR` to `Dst` with `FlipSrc` set. An `UNPACR` to `SrcA` with `FlipSrc` set is fine: it sets `WroteDst` to `false` before giving the bank.
* The set-dvalid form of [`UNPACR_NOP`](UNPACR_NOP_SETDVALID.md). On Blackhole, the same applies to the `UNPACR_NOP` flavor that sets data valid without clearing anything (clear-to-one with clear-to-one format 3), but not to an `UNPACR_NOP` that clears the unpacker's `SrcA` bank and gives it to the Matrix Unit in one instruction.
* [`SETDVALID`](SETDVALID.md) with its `SrcA` bit set.

The hardware keeps two copies of `Unpackers[0].SrcBank`: one picks the bank that `UNPACR` writes datums to, and the other picks the bank whose `AllowedClient` the Unpackers wait on and hand to the Matrix Unit. Giving a bank to the Matrix Unit normally flips both copies, but the cases above flip only the second one. The two copies then point at different banks: subsequent unpacks write their datums into the bank that the Matrix Unit owns (possibly while it is reading it), and the bank they give to the Matrix Unit holds stale data. A second such event flips the second copy back, and `CLEARDVALID` with its reset bit set zeroes both copies; neither changes `WroteDst`. Only `UNPACR` on unpacker 0 changes `WroteDst`, so it carries over from one kernel to the next.

To avoid the bug, software executes one `UNPACR` to `SrcA` after the last `UNPACR` to `Dst` and before giving `SrcA` to the Matrix Unit by `UNPACR_NOP` or `SETDVALID`. That `UNPACR` need not give the bank to the Matrix Unit, but it is an ordinary `UNPACR` to `SrcA` in every other respect (it writes its datums into the unpacker's `SrcA` bank, and every rule for `UNPACR` to `SrcA` applies to it). On Blackhole, giving `SrcA` with an `UNPACR_NOP` that also clears it avoids the bug without that `UNPACR`.

## Implied data format (Blackhole only)

On Blackhole, each `SrcA` and `SrcB` bank can carry an "implied" data format which (when enabled) overrides the configured `SrcAFmt` / `SrcBFmt` for Matrix Unit (FPU) instructions consuming that bank. The implied format is written by the Unpackers as part of populating a bank.

```c
uint4_t ImpliedSrcAFmt[2]; // Indexed by SrcA bank.
uint4_t ImpliedSrcBFmt[2]; // Indexed by SrcB bank.
```

Matrix Unit (FPU) instructions read the implied format in place of the configured format when the corresponding `ThreadConfig.DISABLE_IMPLIED_SRCA_FMT_Base` (for `SrcA`) or `ThreadConfig.DISABLE_IMPLIED_SRCB_FMT_Base` (for `SrcB`) bit is `false`. This mechanism does not exist on Wormhole; the configured format is always used there.

Each unpacker also remembers the output data format of the most recent [`UNPACR`](UNPACR_Regular.md) it executed, whether that `UNPACR` wrote `SrcA`, `SrcB` or `Dst`, and whether or not it gave a bank to the Matrix Unit:
```c
uint4_t Unpackers[0]::LastOutDataFormat = FP32;
uint4_t Unpackers[1]::LastOutDataFormat = FP32;
```

A bank's implied format is written when the bank is given to the Matrix Unit (FPU):
* By `UNPACR` with `FlipSrc`: that `UNPACR`'s output data format.
* By an [`UNPACR_NOP`](UNPACR_NOP.md) that clears the bank and gives it: the unpacker's configured output data format at that `UNPACR_NOP`.
* By the `UNPACR_NOP` flavor that only gives the bank (clear-to-one with clear-to-one format 3): `LastOutDataFormat` of that unpacker.
* By [`SETDVALID`](SETDVALID.md) (`UnsupportedFunctionality` on Blackhole): an `UnpredictableValue`. In practice it is `LastOutDataFormat` of that unpacker, as for the `UNPACR_NOP` flavor above, but `SETDVALID` does not wait for an `UNPACR` already sent to the unpacker to finish, and if one is still running the bank can get the format of the `UNPACR` before it.

So the format given with a bank by `SETDVALID` or the give-only `UNPACR_NOP` comes from whichever `UNPACR` that unpacker ran last, not from the bank's own data: a later change to the configured formats, an `UNPACR_NOP` that clears the bank, or an earlier `UNPACR` to the same bank doesn't affect it. [`CLEARDVALID`](CLEARDVALID.md) with its reset bit sets every bank's implied format to `FP32` and leaves `LastOutDataFormat` alone.

## Data types

Each datum in `SrcA` or `SrcB` is up to 19 bits wide, holding one of:
* **TF32 (1 sign bit, 8 bit exponent, 10 bit mantissa)**. FP32 can be converted to TF32, though the conversion involves throwing away the low 13 bits of mantissa.
* **BF16 (1 sign bit, 8 bit exponent, 7 bit mantissa)**. Unpackers can losslessly convert BFP8 / BFP4 / BFP2 to BF16. Internally, this type is overlaid onto TF32, with the three least significant bits of the TF32 mantissa set to zero.
* **FP16 (1 sign bit, 5 bit exponent, 10 bit mantissa)**. Unpackers can losslessly convert FP8 (1 sign bit, 5 bit exponent, 2 bit mantissa) to FP16. They can also losslessly convert BFP8a / BFP4a / BFP2a to FP16.
* **Integer "8" (1 sign bit, 10 bit magnitude)**. The range of this type is -1023 through +1023, albeit the majority of hardware conversions to/from this type involve a range of -127 through +127 or 0 through 255. Internally, this type is overlaid onto FP16, using a fixed raw exponent of 16 (or sometimes a raw exponent of 0 when the magnitude is zero).
* **Integer "16" (1 sign bit, 15 bit magnitude)**. This type is intended only for opaque data transfer of 16 bits; there are no computation instructions involving this type. If used for opaque data transfer, this type can be used to contain _any_ 16 bits, including unsigned 16-bit data.

Note that the coprocessor does not entirely conform to IEEE 754 for TF32 / BF16 / FP16. See [floating-point bit patterns](FloatBitPatterns.md) for details.

For matrix multiplication operations (`Dst += SrcB @ SrcA`), the supported data type _combinations_ are:

|[`Dst`](Dst.md) data type|+=|`SrcB` data type|@|`SrcA` data type|
|---|---|---|---|---|
|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.

## Data type bit layout

Most of the time, software does not need to care about the exact bit layout of types in `SrcA` or `SrcB`. Nevertheless, the information is provided here to clarify the semantics of what happens if software does an implicit `bitcast` from one type to another.

**TF32:**

![](../../../Diagrams/Out/Bits32_Src_TF32.svg)

**BF16:**

![](../../../Diagrams/Out/Bits32_Src_BF16.svg)

**FP16:**

![](../../../Diagrams/Out/Bits32_Src_FP16.svg)

The representation of infinity differs from IEEE 754, and NaN is not supported; see [FP16 bit patterns](FloatBitPatterns.md#fp16) for details.

**Integer "8":**

![](../../../Diagrams/Out/Bits32_Src_INT8.svg)

The low five bits usually contain the value `16`, but unp