Skip to content

Add TGATHER indices part - #988

Open
frank-deng wants to merge 3 commits into
hw-native-sys:mainfrom
frank-deng:tgather
Open

Add TGATHER indices part#988
frank-deng wants to merge 3 commits into
hw-native-sys:mainfrom
frank-deng:tgather

Conversation

@frank-deng

Copy link
Copy Markdown
Contributor

No description provided.

def gather_dtype_signatures(dtypes=NUMERIC_DTYPES):
res = []
for dtype in dtypes:
for dtype_indices in ('i16', 'ui16', "f16", "bf16", "i32", "ui32", 'f32'):

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tgather的verifier只支持整形,是否要支持浮点类型需要确认下

@@ -3692,21 +3694,31 @@ struct PTOViewToMemrefPass

if (indices || tmp) {
auto indicesTy = dyn_cast<MemRefType>(indices.getType());

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里应该先判断indices是否存在,否则tmp存在而indices不存在的情况编译器会crash

}
}

// CHECK: TGATHER

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lit只check TGATHER op name,没有check tmp参数等是否符合预期

@@ -0,0 +1,14 @@
// RUN: ptoas --pto-arch=a5 %s 2>&1 | FileCheck %s

module {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

本PR的主要变更是把tmp变为可选参数,这里要有相应的正负例测试

Comment on lines +47 to +67
if pto.const_expr(elem_bytes == 2 and elem_bytes_s1 == 4):
indices_type = pto.ui32
lanes = pto.elements_per_vreg(indices_type)
for row in range(0, valid_rows, 1):
remained = valid_cols
for col in range(0, valid_cols, lanes):
indices_reg = pto.vlds(indices[row, col:])
mask, remained = pto.make_mask(indices_type, remained)
dst_reg = pto.vgather2_bc(src_ptr, pto.vbitcast(indices_reg, indices_type), mask)
pto.vsts(dst_reg, dst[row, col:], mask)
elif pto.const_expr(elem_bytes == 1):
packed_lanes = pto.elements_per_vreg(dtype) >> 1
result_elem = pto.ui16 if str(dtype) in ("ui8",) else pto.i16
result_ty = pto.vreg_type(packed_lanes, result_elem)
for row in range(0, valid_rows, 1):
remained = valid_cols
for col in range(0, valid_cols, packed_lanes):
indices_reg = pto.vlds(indices[row, col:])
mask, remained = pto.make_mask(result_elem, remained)
dst_reg = pto.vgather2(src_ptr, pto.vbitcast(indices_reg, pto.ui16), mask, result_vreg_type=result_ty)
pto.vsts(dst_reg, dst[row, col:], mask, dist=pto.VStoreDist.PK_B16)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里4个分支大部分逻辑是相同的,能否合并,降低维护难度

pto.vsts(dst_reg, dst[row, col:], mask)
elif pto.const_expr(elem_bytes == 1):
packed_lanes = pto.elements_per_vreg(dtype) >> 1
result_elem = pto.ui16 if str(dtype) in ("ui8",) else pto.i16

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

感觉用str(dtype)判断类型不太好,不能直接用dtype == pto.ui8判断吗?

Comment thread docs/PTO_IR_manual.md
| `cdst` | `Optional<pto.tile_buf>` | Secondary destination tile used only by compare form |
| `indices` | `Optional<pto.tile_buf>` | Index tile used only by index form |
| `tmp` | `Optional<pto.tile_buf>` | Temporary tile used by index form and compare form |
| `tmp` | `Optional<pto.tile_buf>` | Temporary tile used by compare form; optionally used by index form on A2/A3 (required), A5 (optional) |

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A2A3和A5的行为都需要lit用例看护

Comment thread docs/PTO_IR_manual.md
| `cdst` | `Optional<pto.tile_buf>` | Secondary destination tile used only by compare form |
| `indices` | `Optional<pto.tile_buf>` | Index tile used only by index form |
| `tmp` | `Optional<pto.tile_buf>` | Temporary tile used by index form and compare form |
| `tmp` | `Optional<pto.tile_buf>` | Temporary tile used by compare form; optionally used by index form on A2/A3 (required), A5 (optional) |

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zhangstevenunity IR手册修改,请review是否合理

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants