Skip to content

feat(vpto): add raw L1 fill primitive - #1235

Merged
Zhendong404 merged 5 commits into
hw-native-sys:mainfrom
jimmychou0:zjm/raw-fill-l1
Aug 17, 2026
Merged

feat(vpto): add raw L1 fill primitive#1235
Zhendong404 merged 5 commits into
hw-native-sys:mainfrom
jimmychou0:zjm/raw-fill-l1

Conversation

@jimmychou0

@jimmychou0 jimmychou0 commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Summary

  • add the pto.raw_fill_l1 public wrapper and canonical pto.create_cbuf_matrix raw op for MAT/L1 fills
  • verify MAT address space, 16/32-bit fill views, control-field bounds, and write effects; normalize pointers and lower both LLVM emission paths to llvm.hivm.SET.L1.2D
  • expose the PTODSL surface and document the micro-ISA contract
  • classify raw L1 fill as a Cube micro-op so unannotated VPTO modules infer Cube kernel kind

Validation

  • 144: rebuilt PTOASCompiler and pto-test-opt
  • 144: llvm-lit -sv build-fill/test/lit/vpto --filter raw_fill_l1 (5 passed)
  • local existing artifacts: ptodsl/tests/test_jit_compile.py
  • local existing artifacts: ptodsl/tests/test_vector_cube_ops.py (54 passed)
  • git diff --check

Notes

@jimmychou0
jimmychou0 marked this pull request as ready for review August 13, 2026 01:30
@@ -899,6 +899,46 @@ Cube compute step; it does not issue those transfers itself.

---

#### `pto.raw_fill_l1(dst: PtrType, byte_offset: int, raw_value: int, repeat_times: int, block_num_32b: int, dst_gap_32b: int, fill_word_bits: int) -> None`

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.

从repeat_times开始的参数应该强制使用keyword,否则很难分辨参数含义了

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

已改为 keyword-only,并补充了位置参数拒绝测试

Comment thread ptodsl/ptodsl/_ops.py Outdated
@@ -5322,6 +5264,21 @@ def mte_gm_l1(source, destination, len_burst, *, nburst, loops=None):
)


@_explicit_mode_only("pto.raw_fill_l1(...)")
def raw_fill_l1(dst, byte_offset, raw_value, repeat_times, block_num_32b,
dst_gap_32b, fill_word_bits):

@Zhendong404 Zhendong404 Aug 13, 2026

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.

fill_word_bits只支持16/32,需要在这里检查,避免漏到后面报错;其他约束检查也尽量提前

@jimmychou0 jimmychou0 Aug 14, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

在 PTODSL 侧要求静态 Python int,仅接受 16/32。几何字段的静态非负、上限和 offset 对齐也前置检查

Comment thread include/PTO/IR/VPTOOps.td
def PTO_RawFillL1Op : PTO_MicroOp<"raw_fill_l1", [
CubeMicroOpInterface,
DeclareOpInterfaceMethods<MemoryEffectsOpInterface>
]> {

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.

fill_word_bits 用 i64 SSA 操作数表达一个纯编译期约束,是本 PR 类型设计上最值得商榷的点。 它的合法值只有 16/32,且 verifier 强制要求 matchPattern(m_ConstantInt),也就是说它语义上就是 attribute,却被建模成运行时 value:
产生了一个本可静态消除的错误类别("must be a compile-time constant");
assembly format 里每个类型都要打印,IR 噪声大;
建议改为 I64Attr(或 I64EnumAttr<"16,32">,连 verifier 里的取值检查都省掉),DSL 侧传 Python int 即可,不必 _coerce_i64。

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

已修改。fill_word_bits 已改为 I64Attr,PTODSL 侧直接构造
IntegerAttr,不再作为运行时 SSA operand 或经 _coerce_i64 传递。
verifier 保留 16/32 取值校验,并继续校验其与 ui16/ui32 destination
view 一致;assembly format 也相应简化。

@mouliangyu mouliangyu left a comment

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.

发现一个需要修复的行为问题:pto.raw_fill_l1 允许任意非负 byte_offset,并在 wrapper expansion 中直接将其加到 L1 destination 上;但底层 CREATE.CBUF.MATRIX / SET_L1_2D 的 L1 地址需要 32B 对齐。

请在 verifier 中拒绝已知常量的非 32B 对齐 offset,并在文档中将动态 offset 的 32B 对齐作为调用者前置条件;建议补一个 byte_offset = 2 的负例。当前仅检查了非负性,会让该输入通过并生成未对齐访问。

@mouliangyu mouliangyu left a comment

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.

复核最新提交 232f29e:此前反馈的 32B 对齐约束已在 PTO IR verifier、PTODSL 静态参数校验、文档及 lit 负例中落实;fill_word_bits 属性化后的 wrapper、指针规范化与两条 LLVM emitter 调用链也保持一致。批准。

@jimmychou0
jimmychou0 requested a review from Zhendong404 August 17, 2026 00:40
@Zhendong404
Zhendong404 merged commit 42ce8aa into hw-native-sys:main Aug 17, 2026
11 checks passed
@reedhecre

Copy link
Copy Markdown

A3 板测失败

  • 触发方式:merged
  • 源码提交:42ce8aa1b7aa
  • 结果汇总:OK 0 / FAIL 0 / SKIP 0
  • 日志:/home/zhongxuan/ptoas-board-monitor/runtime/logs/20260816_200705_merged_pr1235.log
  • 失败阶段:sample-build-and-test / exit=1

日志尾部

t_sync_basic-pto.cpp
Sync(test_set_wait_unified_api.py) OK   generated: test_set_wait_unified_api-pto.cpp
Sync(test_tmov_col_major_16x1_align_a5.pto) SKIP requires --pto-arch=a5
Sync(test_tmov_col_major_16x1_align_a5.py) SKIP requires --pto-arch=a5
Sync(test_tmov_row_major_1x16_control_a5.pto) SKIP requires --pto-arch=a5
Sync(test_tmov_row_major_1x16_control_a5.py) SKIP requires --pto-arch=a5
Sync(tmatmulk_autosync.py) OK   generated: tmatmulk_autosync-pto.cpp
TileSetGetValue(tile_getval_mat_invalid.py) XFAIL ptobc encode failed as expected
TileSetGetValue(tileSetGetValue.py) OK   generated: tileSetGetValue-pto.cpp
TInsert(tinsert_fp.py) OK   generated: tinsert_fp-pto.cpp
TInsert(tinsert.py) OK   generated: tinsert-pto.cpp
Tpows(tpows.py) OK   generated: tpows-pto.cpp
Tpow(tpow.py) OK   generated: tpow-pto.cpp
TPrefetchAsync(tprefetch_async_binding.py) OK   generated: tprefetch_async_binding-pto.cpp
TPrefetch(tprefetch.py) OK   generated: tprefetch-pto.cpp
TquantMxDn(tquant_mx_dn.pto) FAIL ptoas failed: tquant_mx_dn.pto
Trans(trans.py) OK   generated: trans-pto.cpp
Trap(trap.py) OK   generated: trap-pto.cpp
TTri(ttri.py) OK   generated: ttri-pto.cpp
VectorAddition(vadd_pto_ir.py) OK   generated: vadd_pto_ir-pto.cpp
VectorAddition(vadd_validshape_hyper.py) OK   generated: vadd_validshape_hyper-pto.cpp
VectorAddition(vectorAddition.py) OK   generated: vectorAddition-pto.cpp
Xors(xors.py) OK   generated: xors-pto.cpp
Xor(xor.py)  OK   generated: xor-pto.cpp
-----------------------------
OK=358  FAIL=1  SKIP=504
=============================
BOARD_CASE_MANIFEST=/home/zhongxuan/ptoas-board-monitor/runtime/runs/20260816_200705_merged_pr1235/payload/test/samples/expected_npu_validation_cases.txt (345 cases)
===== END STAGE sample-build-and-test rc=1 @ 2026-08-16 20:21:50 =====

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.

[Feature] [阻塞] 新增与 create_cbuf_matrix 等价的原生 L1/CBUF 填充操作

4 participants