Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions docs/isa/blockIntro/tma_block/header.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ The header of the data transfer block needs to define which data transfer operat
## Assembly format

```asm
TileOp <LB0:arg0, LB1:arg1, LB2:arg2, DataType>, SrcTile0<.reuse>, ..., SrcTile7<.reuse>, DepSrc0, DepSrc1, DepSrc2, [BGetList],
TileOp <LB0:arg0, LB1:arg1, LB2:arg2, DataType>, SrcTile0<.reuse>, ..., SrcTile7<.reuse>, DepSrc, [BGetList],
->DstTile0<TileSize0>, ..., DstTile3<TileSize3>, [BSetList], DepDst
```

Expand All @@ -24,7 +24,7 @@ Each parameter is explained as follows:
| **TileSize0, ..., TileSize3** | Indicates the space size of each output Tile register respectively. The parameter can be passed through a `立即数` or `全局寄存器`. | Depends on DstTile |
| **[BGetList]** | Global register [GGPR](../../register/common/ggpr.md) input list. | Yes |
| **[BSetList]** | Global register [GGPR](../../register/common/ggpr.md) output list. | Yes |
| **DepSrc0, DepSrc1, DepSrc2** | Up to three dependency-source slots that refer to previous block-instruction outputs to `D`. | Yes |
| **DepSrc** | Indicates the dependence of this block instruction on the previous block instruction output to D. | Yes |
| **DepDst** | Indicates the barrier of this block instruction to the block instruction that references this identifier in subsequent sequences. | Yes |

## Encoding method
Expand All @@ -42,7 +42,7 @@ A complete data transfer block instructionheader needs to be split into the foll
- [B.IOR](../../header/B.IOR.md) `RegSrc0, RegSrc1, RegSrc2, ->RegDst0`
-...
- [B.IOR](../../header/B.IOR.md) `RegSrc9, RegSrc10, RegSrc11, ->RegDst4`
- [B.IOD](../../header/B.IOD.md) `DepSrc0, DepSrc1, DepSrc2, ->DepDst`
- [B.IOD](../../header/B.IOD.md) `DepSrc, ->DepDst`

Among them, the encoding format of the BSTART.TMA instruction is as follows:![BSTART.TMA](../../../figs/bitfield/svg/BlockHeader_32bit/BSTART.TMA.svg)

Expand All @@ -56,8 +56,8 @@ Among them, the function field is used to encode specific TileOp information. Th
| 3 | - | Reserved |
| 4 | [MGATHER](../../header/tileblock/MGATHER.md) | Gather data in discrete memory space into Tile registers. |
| 5 | [MSCATTER](../../header/tileblock/MSCATTER.md) | Store the data in the Tile register into discrete memory space. |
| 6 | [MGATHER.MASK](../../header/tileblock/MGATHER.MASK.md) | Masked memory gather. Reads only lanes whose mask bit is set. |
| 7 | [MSCATTER.MASK](../../header/tileblock/MSCATTER.MASK.md) | Masked memory scatter. Writes only lanes whose mask bit is set. |
| 6 | [MGATHER.MASK](../../header/tileblock/MGATHER.MASK.md) | Masked memory gather, only gathers when the corresponding mask bit is 1. |
| 7 | [MSCATTER.MASK](../../header/tileblock/MSCATTER.MASK.md) | Masked memory scatter, only scatters when the corresponding mask bit is 1. |
| 8-31 | Temporarily reserved |

The DataType field is encoded as follows:
Expand All @@ -71,4 +71,4 @@ The DataType field is encoded as follows:
| 4 | FP16 | 12 | e1m2x2 | 20 | S4x2 | 28 | U4x2 |
| 5 | BF16 | 13 | e8m0 | 21 | reserve | 29 | reserve |
| 6 | HiF8 | 14 | HiF4x2 | 22 | reserve | 30 | reserve |
| 7 | e4m3 | 15 | reserve | 23 | reserve | 31 | invalid |
| 7 | e4m3 | 15 | reserve | 23 | reserve | 31 | invalid |
10 changes: 5 additions & 5 deletions docs/zh/isa/blockIntro/tma_block/header.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
## 汇编格式

```asm
TileOp <LB0:arg0, LB1:arg1, LB2:arg2, DataType>, SrcTile0<.reuse>, ..., SrcTile7<.reuse>, DepSrc0, DepSrc1, DepSrc2, [BGetList],
TileOp <LB0:arg0, LB1:arg1, LB2:arg2, DataType>, SrcTile0<.reuse>, ..., SrcTile7<.reuse>, DepSrc, [BGetList],
->DstTile0<TileSize0>, ..., DstTile3<TileSize3>, [BSetList], DepDst
```

Expand All @@ -24,7 +24,7 @@ TileOp <LB0:arg0, LB1:arg1, LB2:arg2, DataType>, SrcTile0<.reuse>, ..., SrcTile7
| **TileSize0, ..., TileSize3** | 分别指示每个输出Tile寄存器的空间大小,可以通过一个 `立即数`或者`全局寄存器`传参。 | 取决于DstTile |
| **[BGetList]** | 全局寄存器[GGPR](../../register/common/ggpr.md)输入列表。 | 是 |
| **[BSetList]** | 全局寄存器[GGPR](../../register/common/ggpr.md)输出列表。 | 是 |
| **DepSrc0, DepSrc1, DepSrc2** | 表示本块指令最多显式记录 3 个前序 `D` 依赖槽位。 | 是 |
| **DepSrc** | 表示本块指令对前序输出至D的块指令的依赖。 | 是 |
| **DepDst** | 表示本块指令对后序引用该标识的块指令的屏障。 | 是 |

## 编码方式
Expand All @@ -42,7 +42,7 @@ TileOp <LB0:arg0, LB1:arg1, LB2:arg2, DataType>, SrcTile0<.reuse>, ..., SrcTile7
- [B.IOR](../../header/B.IOR.md) `RegSrc0, RegSrc1, RegSrc2, ->RegDst0`
- ...
- [B.IOR](../../header/B.IOR.md) `RegSrc9, RegSrc10, RegSrc11, ->RegDst4`
- [B.IOD](../../header/B.IOD.md) `DepSrc0, DepSrc1, DepSrc2, ->DepDst`
- [B.IOD](../../header/B.IOD.md) `DepSrc, ->DepDst`

其中,BSTART.TMA指令的编码格式如下:

Expand All @@ -58,8 +58,8 @@ TileOp <LB0:arg0, LB1:arg1, LB2:arg2, DataType>, SrcTile0<.reuse>, ..., SrcTile7
| 3 | - | 保留 |
| 4 | [MGATHER](../../header/tileblock/MGATHER.md) | 将离散的内存空间中的数据聚集到Tile寄存器中。 |
| 5 | [MSCATTER](../../header/tileblock/MSCATTER.md) | 将Tile寄存器中的数据存储到离散的内存空间。 |
| 6 | [MGATHER.MASK](../../header/tileblock/MGATHER.MASK.md) | 带掩码的内存聚集,仅当 MaskTile 中对应标志位为 1 时才执行聚集。 |
| 7 | [MSCATTER.MASK](../../header/tileblock/MSCATTER.MASK.md) | 带掩码的内存分散,仅当 MaskTile 中对应标志位为 1 时才执行分散。 |
| 6 | [MGATHER.MASK](../../header/tileblock/MGATHER.MASK.md) | 带掩码的内存聚集,仅当MaskTile中对应标志位为1时才执行聚集。 |
| 7 | [MSCATTER.MASK](../../header/tileblock/MSCATTER.MASK.md) | 带掩码的内存分散,仅当MaskTile中对应标志位为1时才执行分散。 |
| 8-31 | 暂时保留 |

DataType字段编码方式如下:
Expand Down
76 changes: 46 additions & 30 deletions docs/zh/isa/header/tileblock/MGATHER.MASK.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@

**带掩码的内存聚集(Masked Gather from Memory to Tile)**

`MGATHER.MASK` 是 `MGATHER` 的掩码变体,在其间接寻址聚集语义的基础上
增加了逐元素谓词控制。除基地址寄存器(`RegSrc`)和偏移量 Tile
(`SrcTile`)外,该指令额外接受一个掩码 Tile(`MaskTile`),其中每个
元素为 1 bit 的标志位,与 `SrcTile` 中的 offset 一一对应。
`MGATHER.MASK` 是 `MGATHER` 的掩码变体,在其间接寻址聚集语义的基础上增加了逐元素谓词控制。除基地址寄存器(`RegSrc`)和偏移量 Tile(`SrcTile`)外,该指令额外接受一个掩码 Tile(`MaskTile`),其中每个元素为 1 bit 的标志位,与 SrcTile 中的 offset 一一对应。

当掩码位为 `1` 时,硬件从 `baseAddress + offset` 读取一个 `DataType`
元素并写入 `DstTile`;当掩码位为 `0` 时,硬件跳过该位置的访存,并向
目标位置写入 `PadValue`。
执行时,对于 SrcTile 中位于 `(i, j)` 处的 offset 值 `off`,硬件首先检查 MaskTile 对应位置的掩码位:
- 若掩码为 `1`,则执行聚集操作:从内存地址 `baseAddress + off` 处读取一个 `DataType` 类型的数据元素,写入 DstTile 的 `(i, j)` 位置;
- 若掩码为 `0`,则跳过该位置,不产生内存访问,DstTile 的 `(i, j)` 位置写入 `PadValue` 填充值。

这一机制允许软件通过掩码动态控制哪些内存位置参与聚集,适用于需要条件性数据收集的场景(如稀疏矩阵中仅加载非零元素对应的数据)。

## 汇编语法

Expand All @@ -23,48 +22,65 @@ MGATHER.MASK <LB0:Col, LB1:Row, DataType, PadValue>, SrcTile<.reuse>, MaskTile<.

| 参数 | 说明 | 是否可选 |
|------|-----|-----------|
| **Col** | Tile 中数据的列数,也是输入 Tile 中 offset 的列数。通过 `LB0` 传入。 | 否 |
| **Row** | Tile 中数据的行数,也是输入 Tile 中 offset 的行数。通过 `LB1` 传入。 | 是,默认为 1 |
| **Col** | Tile寄存器中数据的列数,也是输入Tile中offset的列数。该值可以通过全局寄存器[GGPR](../../register/common/ggpr.md)加`立即数`的方式进行设置,并存储到LB0寄存器。 | 否 |
| **Row** | Tile寄存器中数据的行数,也是输入Tile中offset的行数。该值可以通过全局寄存器[GGPR](../../register/common/ggpr.md)加`立即数`的方式进行设置,并存储到LB1寄存器。 | 是,默认为1 |
| **DataType** | 从内存中收集的元素的数据类型/格式。 | 否 |
| **PadValue** | 掩码为 `0` 时写入目标 Tile 的填充值。可选值为 `Null`、`Zero`、`Max`、`Min`。 | 是,默认 `Null` |
| **RegSrc** | 输入全局寄存器 GGPR,用于存储收集数据的内存基地址 `baseAddress`。 | 否 |
| **SrcTile** | 输入 Tile 寄存器,用于存储一组基于 `baseAddress` 的偏移量。 | 否 |
| **MaskTile** | 输入 Tile 寄存器,用于存储 1 bit 掩码。 | 否 |
| **DstTile** | 输出 Tile 寄存器,用于存储聚集得到的数据。 | 否 |
| **Size** | 输出 Tile 的大小,必须等于 `Row * Col * sizeof(DataType)`。 | 否 |
| **PadValue** | DstTile 中掩码为 `0` 的位置的填充值。可选类型包括:`Null`(不填充或保留随机值)、`Zero`(填充零值)、`Max`(填充当前数据格式下的最大值)、`Min`(填充当前数据格式下的最小值)。 | 是,默认 Null |
| **RegSrc** | 输入全局寄存器GGPR,用于存储收集数据的内存基地址baseAddress。 | 否 |
| **SrcTile** | 输入Tile 寄存器,用于存储一组基于baseAddress的偏移(offset)。 | 否 |
| **MaskTile** | 输入Tile 寄存器,用于存储掩码标志位。每个元素为1bit,值为`1`表示对应offset有效,执行聚集操作;值为`0`表示对应offset无效,跳过聚集。 | 否 |
| **DstTile** | 输出Tile 寄存器,用于存储聚集得到的数据。 | 否 |
| **Size** | 指示输出Tile寄存器的大小。该值等于Row * Col * sizeof(DataType) | 否 |

其中DataType的可选类型如下表:

| 数据位宽 | 类型列表 |
|----------|------------|
| b64 | S64, U64, FP64 |
| b32 | S32, U32, FP32, TF32, HF32 |
| b16 | S16, U16, FP16, BF16 |
| b8 | S8, U8, FP8(E4M3, E5M2), E8M0, HiF8, HiF4x2, E1M2x2, E2M1x2, S4x2, U4x2 |

`SrcTile` 中 offset 的位宽由写入该 Tile 时使用的元素位宽决定,规范形式
支持 `u16`、`u32` 和 `u64`。
---

## 编码格式

该 TileOp 编码为以下指令
该TileOp编码为以下指令

- [BSTART.TMA](../../blockIntro/tma_block/header.md) `MGATHER.MASK, DataType`
- [B.DATR](../../header/B.DATR.md) `PadValue` *(可选)*
- [B.DIM](../../header/B.DIM.md) `reg, imm, ->LB0` *(`Col`)*
- [B.DIM](../../header/B.DIM.md) `reg, imm, ->LB1` *(`Row`)*
- [B.DATR](../../header/B.DATR.md) `PadValue` *(注:可缺省该指令)*
- [B.DIM](../../header/B.DIM.md) `reg, imm, ->LB0` *(注:Col)*
- [B.DIM](../../header/B.DIM.md) `reg, imm, ->LB1` *(注:Row)*
- [B.IOT](../../header/B.IOT.md) `SrcTile<.reuse>, MaskTile<.reuse>, last, ->DstTile<Size>`
- [B.IOR](../../header/B.IOR.md) `RegSrc`
- [B.IOR](../../header/B.IOR.md) `RegSrc` *(注:base)*

---

## 执行模型

本指令执行过程通过伪代码示意如下:

```c
void MGATHER_MASK(Tile dst, Scalar base, Tile src, Tile mask) {
for (int i = 0; i < Row; ++i) {
for (int j = 0; j < Col; ++j) {
// dst:用于存储聚集数据的输出Tile
// base: 收集数据的基地址
// src: 存储离散的地址偏移的输入Tile
// mask: 存储掩码标志位的输入Tile,1bit/元素
void MGATHER_MASK(Tile __out__ dst, Scalar __in__ base, Tile __in__ src, Tile __in__ mask) {
for (int i = 0; i < Row; i++)
for (int j = 0; j < Col; j++) {
if (mask[i][j] == 1) {
offset_t offset = src[i][j];
offset_t offset = src[i][j]; // offset宽度由src的元素位宽决定(u64/u32/u16)
dst[i][j] = Memory[base + offset];
} else {
dst[i][j] = PadValue;
dst[i][j] = PadValue; // 掩码为0的位置写入PadValue
}
}
}
}
```

## 注意事项

- `MaskTile` 按每元素 1 bit 解释。
- 掩码为 `0` 的位置不产生访存。
- `Size` 必须等于 `Row * Col * sizeof(DataType)`。
- 输入数据块(SrcTile)中 `[0, Row) × [0, Col)` 范围内的所有 offset 元素均参与聚集操作。
- SrcTile 中 offset 的位宽取决于写入该 Tile 时的元素位宽定义,支持 **u64**、**u32** 或 **u16** 格式,硬件根据 SrcTile 的实际元素位宽进行解析。
- 输入掩码Tile(MaskTile)中每个元素为 **1 bit**,与 SrcTile 的 `[0, Row) × [0, Col)` 区域一一对应。掩码值为 `1` 时执行对应位置的聚集,为 `0` 时跳过该位置,不产生内存访问,对应位置写入 `PadValue` 填充值。
Loading