Skip to content

Feature/gm vectorized ldg stg#897

Open
kuri780 wants to merge 20 commits into
hw-native-sys:mainfrom
kuri780:feature/gm-vectorized-ldg-stg
Open

Feature/gm vectorized ldg stg#897
kuri780 wants to merge 20 commits into
hw-native-sys:mainfrom
kuri780:feature/gm-vectorized-ldg-stg

Conversation

@kuri780

@kuri780 kuri780 commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

● Summary

Add packed vector type support for pto.ldg / pto.stg, enabling GM load/store to directly operate on vector<2xf16>, vector<2xbf16>, and vector<2xf32>. Covers the full stack:
ODS definition, IR verification, LLVM/CANN900 lowering, and ptodsl type exposure.

Motivation

pto.ldg / pto.stg currently only support scalar types. In SIMT scenarios, loading/storing two f16/bf16/f32 elements at once (e.g., f32x2 vector add) can replace two scalar
memory operations with a single intrinsic, reducing instruction count and improving bandwidth utilization.

Changes

ODS & IR (include/PTO/IR/VPTOOps.td, lib/PTO/IR/VPTO.cpp)

  • Updated pto.ldg / pto.stg descriptions to document supported scalar and vector types
  • Clarified offset semantics: element-level index (for vector<2xf32>, offset=1 advances by 8 bytes)
  • Alignment constraint: vector<2xf32> requires 8-byte alignment

LLVM Lowering (lib/PTO/Transforms/VPTOLLVMEmitter.cpp)

5 sites extended, following the existing scalar branch pattern:

  • Callee selection: vector<2xf16/2xbf16> → s32/b32, vector<2xf32> → s64/b64
  • Call result type: 32-bit vector → i32, 64-bit vector → i64
  • Result/value conversion: bitcast between intrinsic scalar result and vector type

CANN900 Lowering (lib/PTO/Transforms/VPTOCANN900LLVMEmitter.cpp)

  • Vector type callee/result/value handling, kept in sync with the LLVM emitter

ptodsl (ptodsl/ptodsl/_types.py, ptodsl/ptodsl/pto.py)

  • Added VectorType import; _classify_storage_dtype recognizes vector types as "compute"
  • Exposed f16x2, bf16x2, f32x2 type descriptors

Docs

  • docs/isa/micro-isa/17-simt.md: SIMT micro-instruction doc update
  • ptodsl/docs/user_guide/13-simt-micro-ops.md: ptodsl user guide update

Test

  • test/vpto/cases/micro-op/simt/simt-vector-ldg-stg-core/: SIMT device test — 2 lanes, each performing two f32x2 vector adds via pto.ldg/pto.stg. Verified end-to-end on CANN
    SIM (compile → link → run → compare passed).

Lowering strategy

pto.ldg %ptr[%idx] : !pto.ptr<vector<2xf32>, gm> → vector<2xf32>

%call = llvm.call @llvm.hivm.ldg.cache.s64(%ptr, %c0) : (!llvm.ptr<1>, i32) → i64
%val = llvm.bitcast %call : i64 → vector<2xf32>

Vectors are lowered through the existing scalar intrinsic infrastructure: the total bit width determines the intrinsic suffix (s32/b32 for 32-bit, s64/b64 for 64-bit), and
bitcast bridges the scalar intrinsic interface to the MLIR vector type.

kuri780 and others added 14 commits July 1, 2026 15:58
…store)

Extend verifyLdgStgAccess to accept vector<2xf16>, vector<2xbf16>,
and vector<2xf32> in addition to existing scalar types.

Extend buildL1CacheLoadCallee / buildL1CacheStoreCallee,
getLdgCallResultType, convertLdgCallResult, and convertStgValue
in both VPTOLLVMEmitter and VPTOCANN900LLVMEmitter to map
vector types to hardware intrinsics by total bit width:
  - vector<2xf16/2xbf16> → 32-bit → s32/b32 intrinsics → i32 bitcast
  - vector<2xf32>        → 64-bit → s64/b64 intrinsics → i64 bitcast

Co-Authored-By: Claude <noreply@anthropic.com>
Positive test (simt_lowlevel_vector_ldg_stg_vpto_llvm.pto):
  - vector<2xf16> -> s32/b32 intrinsics + i32<->vector bitcast
  - vector<2xbf16> -> s32/b32 intrinsics + i32<->vector bitcast
  - vector<2xf32> -> s64/b64 intrinsics + i64<->vector bitcast
  - static constant offset and dynamic runtime offset
  - default cache policy

Negative test (simt_lowlevel_ldst_policy_negative.pto):
  - Remove vector<2xf32> (now valid), keep UB addr space rejection
  - Add vector<4xf32>, vector<3xf16>, vector<2xi32> rejection
  - Add stg UB addr space rejection
  - Split into independent functions for isolated verification

Co-Authored-By: Claude <noreply@anthropic.com>
1. Remove --implicit-check-not=error from negative tests (was conflicting
   with verifier error diagnostics).
2. Split the monolithic negative test into three focused files:
   - simt_lowlevel_ldst_policy_negative.pto: ldg on non-GM pointer
   - simt_lowlevel_vector_ldg_stg_negative.pto: illegal vector types
     (vector<4xf32>, vector<3xf16>, vector<2xi32> ldg and stg)
   - simt_lowlevel_stg_policy_negative.pto: stg on non-GM pointer
3. Change positive test dynamic offset from i32 to i64:
   - arith.index_castui i32->index  →  arith.index_cast i64->index
   - Remove llvm.zext i32->i64 CHECK (no longer emitted)
   - Verify runtime i64 flows directly into vector GEP

Co-Authored-By: Claude <noreply@anthropic.com>
…case

1. vector_ldg_stg_negative.pto: reduce from 4 to 1 representative case
   (vector<4xf32> ldg) to avoid fragile multi-error diagnostics.

2. vector_ldg_stg_vpto_llvm.pto: extract dynamic i64 offset into a
   dedicated function (@vector_ldg_stg_dyn_offset) with no static
   non-zero constants.  This guarantees the llvm.getelementptr CHECK
   matches the runtime i64 index, not a static GEP from the main kernel.

Co-Authored-By: Claude <noreply@anthropic.com>
- Add f32x2 = VectorType.get([2], F32Type.get()) to _types.py
- Export f32x2 from pto.py
- Update ldg/stg ODS descriptions: remove "scalar only", add vector types
  and offset/alignment contract
- Update SIMT ISA docs (17-simt.md) with vector type support and offset
  semantics (element-level offset, 8-byte alignment for vector<2xf32>)
- Update PTODSL user guide (13-simt-micro-ops.md) with f32x2 example
  and offset contract documentation
- Add simt_gm_vector_ldst compile test with i64 dynamic offset
- Add 3 reference examples:
  - example_simtvf_vector_add.py: basic f32x2 load/store
  - example_simtvf_multi_kernel.py: multi-kernel f32x2 pipeline
  - example_int64_stride_vectorize_load.py: stride-based vectorized
    load with i64 offset and alignment contract documentation

Co-Authored-By: Claude <noreply@anthropic.com>
- Add VectorType handling to _classify_storage_dtype so
  pto.ptr(pto.f32x2, "gm") resolves without TypeError.
- Add f32x2 to _types.__all__ and expected_public_exports.
- Fix example_int64_stride_vectorize_load.py: replace
  non-existent scalar.convert() with scalar.index_cast().
- Add if __name__ == "__main__" compile entry to all three
  examples so they serve as self-verifying compile tests.

Co-Authored-By: Claude <noreply@anthropic.com>
f16x2  = VectorType.get([2], F16Type.get())
bf16x2 = VectorType.get([2], BF16Type.get())

Backend verifier and lowering already support vector<2xf16> and
vector<2xbf16>; this completes the PTODSL type descriptor surface.

Co-Authored-By: Claude <noreply@anthropic.com>
Rewrite example_int64_stride_vectorize_load.py to demonstrate the
canonical stride contract:

  1. pto.addptr(base, scalar_offset) — advance scalar f32 pointer
  2. pto.castptr(scalar_addr, vector_type) — reinterpret as vector ptr
  3. pto.ldg(vector_addr, 0) — load with zero offset

This guarantees the stride is applied in f32 units, avoiding
double-multiplication that would occur if the scalar offset were
passed directly to a vector-typed ldg.

Add PTO IR lit test (simt_lowlevel_vector_stride_contract_vpto_llvm.pto)
that verifies the contract lowering through the VPTO backend:
  - static stride: addptr + castptr + ldg/stg
  - dynamic i64 stride: runtime offset flows into addptr GEP on f32,
    castptr adds zero-offset GEP, ldg consumes the result
  - no second GEP with runtime index appears in ldg

Co-Authored-By: Claude <noreply@anthropic.com>
1. Fix lit test CHECK: use CHECK-NOT to verify no second runtime-index GEP
   appears after the addptr GEP (the offset is consumed by addptr; ldg
   gets constant 0).  Remove the brittle check for the castptr GEP which
   may be optimized away under opaque pointers.

2. Fix example_int64_stride_vectorize_load.py: each thread now writes
   to dst[tid] instead of racing on dst[0].

3. Update alignment contract documentation: explicitly state both
   conditions — base address % 8 == 0 AND scalar_stride % 2 == 0 —
   are the caller's responsibility.

Co-Authored-By: Claude <noreply@anthropic.com>
Capture the addptr GEP for clarity and add CHECK-NOT to ensure no
second GEP with a runtime index appears in the ldg path.  The
castptr GEP (offset 0) may survive lowering as a zero-offset type
reinterpretation under opaque pointers, so the ldg operand check
uses a wildcard to avoid coupling to the intermediate SSA value.

Co-Authored-By: Claude <noreply@anthropic.com>
Capture addptr GEP result as %[[ADDR]].  Add CHECK-NOT for ldg
referencing the original base pointer (%arg0), in addition to the
existing CHECK-NOT that guards against a second runtime-index GEP.
Together these verify:
  1. Runtime offset appears only in addptr (f32 GEP).
  2. ldg does not fall back to the raw base pointer.
Castptr may introduce a zero-offset GEP for type reinterpretation
under opaque pointers; the test avoids coupling to that intermediate
SSA value while still guarding against the critical contract breaks.

Co-Authored-By: Claude <noreply@anthropic.com>
Replace fragile CHECK-NOT guards with explicit capture-and-match of
the complete lowering chain:
  %[[ADDR]]   — addptr GEP f32 with runtime i64 index
  %[[ZERO]]   — castptr constant zero
  %[[VEC_ADDR]] — castptr zero-offset GEP vector<2xf32>
  ldg consumes %[[VEC_ADDR]]

This directly proves the stride contract: runtime offset is consumed
by addptr; castptr reinterprets the pointer type with offset 0; ldg
sees the final vector pointer.  No CHECK-NOT needed.

Co-Authored-By: Claude <noreply@anthropic.com>
Remove all lit tests, ptodsl examples, and test modifications from the
vector ldg/stg feature branch.  Replace them with a single SIMT device
test under test/vpto/cases/micro-op/simt/simt-vector-ldg-stg-core/.

The test runs 2 lanes, each performing f32x2 vector add via pto.ldg/stg.
Verified on CANN SIM: compile + link + run + compare passed.

Co-Authored-By: Claude <noreply@anthropic.com>
Match the existing codebase style where other type branches don't have
explanatory comments.

Co-Authored-By: Claude <noreply@anthropic.com>
@reedhecre

reedhecre commented Jul 2, 2026

Copy link
Copy Markdown

Codex Review

该评论由 review 机器人自动更新。

  • PR: Feature/gm vectorized ldg stg #897 Feature/gm vectorized ldg stg
  • Author: kuri780
  • Base/Head: main / feature/gm-vectorized-ldg-stg
  • Head SHA: 592a96dc733b
  • Trigger: PR 有新提交
  • Generated At: 2026-07-09T06:40:43Z
  • Previous Head SHA: 2a723ce8b8eb
  • Status: failed at codex-review (exit=1)

Summary

Review failed at stage codex-review: exit=1

Findings

未生成结构化 findings,因为 review 过程提前失败。

Log Tail

 .../simt-vector-ldg-stg-bf16x2-core/compare.py     | 33 ++++++++
 .../simt/simt-vector-ldg-stg-bf16x2-core/golden.py | 92 ++++++++++++++++++++
 .../simt-vector-ldg-stg-bf16x2-core/kernel.pto     | 80 ++++++++++++++++++
 .../simt-vector-ldg-stg-bf16x2-core/launch.cpp     | 18 ++++
 .../simt/simt-vector-ldg-stg-bf16x2-core/main.cpp  | 58 +++++++++++++
 .../simt/simt-vector-ldg-stg-f16x2-core/compare.py | 33 ++++++++
 .../simt/simt-vector-ldg-stg-f16x2-core/golden.py  | 72 ++++++++++++++++
 .../simt/simt-vector-ldg-stg-f16x2-core/kernel.pto | 80 ++++++++++++++++++
 .../simt/simt-vector-ldg-stg-f16x2-core/launch.cpp | 18 ++++
 .../simt/simt-vector-ldg-stg-f16x2-core/main.cpp   | 58 +++++++++++++
 .../simt/simt-vector-ldg-stg-f32x2-core/compare.py | 33 ++++++++
 .../simt/simt-vector-ldg-stg-f32x2-core/golden.py  | 72 ++++++++++++++++
 .../simt/simt-vector-ldg-stg-f32x2-core/kernel.pto | 80 ++++++++++++++++++
 .../simt/simt-vector-ldg-stg-f32x2-core/launch.cpp | 18 ++++
 .../simt/simt-vector-ldg-stg-f32x2-core/main.cpp   | 57 +++++++++++++
 .../compare.py                                     | 69 +++++++++++++++
 .../golden.py                                      | 91 ++++++++++++++++++++
 .../kernel.pto                                     | 73 ++++++++++++++++
 .../launch.cpp                                     | 22 +++++
 .../main.cpp                                       | 97 ++++++++++++++++++++++
 33 files changed, 1474 insertions(+), 27 deletions(-)
===== END STAGE clone rc=0 @ 2026-07-09 14:40:35 =====

===== STAGE codex-review @ 2026-07-09 14:40:35 =====
set -euo pipefail
cd '/tmp/ptoas-pr-review-monitor/runs/20260709_144028_pr897/repo'
'codex' exec -C '/tmp/ptoas-pr-review-monitor/runs/20260709_144028_pr897/repo' -s read-only -c 'model_provider="codereview"' -c 'model="gpt-5.4"' -c 'model_reasoning_effort="xhigh"' --output-schema '/tmp/ptoas-pr-review-monitor/runs/20260709_144028_pr897/review_schema.json' -o '/tmp/ptoas-pr-review-monitor/runs/20260709_144028_pr897/codex_last_message.json' --color never - < '/tmp/ptoas-pr-review-monitor/runs/20260709_144028_pr897/review_prompt.txt'
[monitor] stage timeout: 1800s
OpenAI Codex v0.115.0 (research preview)
--------
workdir: /tmp/ptoas-pr-review-monitor/runs/20260709_144028_pr897/repo
model: gpt-5.4
provider: codereview
approval: never
sandbox: read-only
reasoning effort: xhigh
reasoning summaries: none
session id: 019f459b-566a-7510-a09d-9e7d86b73ff5
--------
user
你现在在审查 GitHub PR。

仓库:hw-native-sys/PTOAS
PR:#897 Feature/gm vectorized ldg stg
作者:kuri780
base branch:origin/main
head branch:HEAD(当前已 checkout 到 PR head)

要求:
1. 只审查这个 PR 相对 origin/main 的改动,必要时可以看上下文文件。
2. 重点找真实的 correctness / regression / contract mismatch / CI / runtime / compatibility 问题。
3. 不要提纯风格建议,不要提低价值猜测。
4. 严格按优先级输出:
   - P1:高概率会导致错误结果、编译/运行失败、严重回归、发布阻断
   - P2:重要缺陷、行为回归、遗漏校验/测试、较大兼容性问题
   - P3:次要但明确可改的问题
5. 如果没有问题,summary 直接写:未检查到 PR #897 存在问题,并返回 findings=[]。
6. 如果有问题,summary 简洁概括,findings 里每条都要给出:
   - severity
   - title
   - body(说明为什么是问题,尽量具体)
   - file(尽量给相对路径)
   - line(能确定就填整数,否则 null)

建议先查看:
- git status --short
- git diff --stat origin/main...HEAD
- git diff --unified=80 origin/main...HEAD

最终输出必须严格匹配 JSON schema。

mcp startup: no servers
Reconnecting... 1/5 (unexpected status 403 Forbidden: {"code":"INSUFFICIENT_BALANCE","message":"Insufficient account balance"}, url: https://codex.0u0o.com/responses, cf-ray: a1855691e8165389-LAX, request id: 88c86422-8125-4901-8287-91de34d11cef)
Reconnecting... 2/5 (unexpected status 403 Forbidden: {"code":"INSUFFICIENT_BALANCE","message":"Insufficient account balance"}, url: https://codex.0u0o.com/responses, cf-ray: a1855694ba122b83-LAX, request id: c1aa016e-a32b-47c1-9ba3-094997c010e5)
Reconnecting... 3/5 (unexpected status 403 Forbidden: {"code":"INSUFFICIENT_BALANCE","message":"Insufficient account balance"}, url: https://codex.0u0o.com/responses, cf-ray: a18556987fc72f1a-LAX, request id: 6e99afe7-870d-4493-86eb-590091fa126a)
Reconnecting... 4/5 (unexpected status 403 Forbidden: {"code":"INSUFFICIENT_BALANCE","message":"Insufficient account balance"}, url: https://codex.0u0o.com/responses, cf-ray: a185569e7aed4800-LAX, request id: c9cd51ad-5f37-4179-a6f0-1740656ab94e)
Reconnecting... 5/5 (unexpected status 403 Forbidden: {"code":"INSUFFICIENT_BALANCE","message":"Insufficient account balance"}, url: https://codex.0u0o.com/responses, cf-ray: a18556a94fa5e9df-LAX, request id: 4893f886-ba6b-440f-8fdf-542fac6e6f3b)
ERROR: unexpected status 403 Forbidden: {"code":"INSUFFICIENT_BALANCE","message":"Insufficient account balance"}, url: https://codex.0u0o.com/responses, cf-ray: a18556bcdfa8196e-LAX, request id: dd061c1b-848b-4452-b063-3c636815df35
Warning: no last agent message; wrote empty content to /tmp/ptoas-pr-review-monitor/runs/20260709_144028_pr897/codex_last_message.json
===== END STAGE codex-review rc=1 @ 2026-07-09 14:40:43 =====

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request adds support for packed vector types (vector<2xf16>, vector<2xbf16>, and vector<2xf32>) to the global memory load (pto.ldg) and store (pto.stg) operations, updating documentation, verification, lowering emitters, and the Python DSL, alongside adding a new integration test. The review feedback suggests ensuring that vector types are explicitly verified as non-scalable to prevent downstream compiler crashes, and handling shape mismatches gracefully in the test comparison script to avoid runtime crashes.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread lib/PTO/IR/VPTO.cpp Outdated
Comment on lines +21 to +28
if not ok:
idxs = np.nonzero(~np.isclose(golden, out, rtol=0, atol=0))[0]
idx = int(idxs[0]) if idxs.size else 0
print(
f"[ERROR] mismatch at idx={idx}, golden={float(golden[idx]):.6f}, out={float(out[idx]):.6f}"
)
if strict:
sys.exit(2)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

If golden.shape != out.shape, calling np.isclose(golden, out) will raise a ValueError and crash the script. We should handle shape mismatches gracefully by printing a clear error message before attempting element-wise comparison.

Suggested change
if not ok:
idxs = np.nonzero(~np.isclose(golden, out, rtol=0, atol=0))[0]
idx = int(idxs[0]) if idxs.size else 0
print(
f"[ERROR] mismatch at idx={idx}, golden={float(golden[idx]):.6f}, out={float(out[idx]):.6f}"
)
if strict:
sys.exit(2)
if not ok:
if golden.shape != out.shape:
print(f"[ERROR] shape mismatch: golden shape {golden.shape} vs out shape {out.shape}")
else:
idxs = np.nonzero(~np.isclose(golden, out, rtol=0, atol=0))[0]
idx = int(idxs[0]) if idxs.size else 0
print(
f"[ERROR] mismatch at idx={idx}, golden={float(golden[idx]):.6f}, out={float(out[idx]):.6f}"
)
if strict:
sys.exit(2)

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Comment thread lib/PTO/Transforms/VPTOCANN900LLVMEmitter.cpp Outdated
…te negative test

- Add isPTOPackedFloatVectorType() in PTOTypeUtils, matching verifier:
  rank==1, dim==2, elem in {f16, bf16, f32}
- Replace bare VectorType dyn_cast + totalBits checks in both emitters
  (10 sites across VPTOLLVMEmitter and VPTOCANN900LLVMEmitter) with the
  new helper, so unsupported vector types fall through to failure/default
- Rename simt-vector-ldg-stg-core -> simt-vector-ldg-stg-f32x2-core
- Add simt-vector-ldg-stg-f16x2-core and simt-vector-ldg-stg-bf16x2-core
  device tests with golden/compare validation
- Update simt_lowlevel_ldst_policy_negative: remove now-valid vector ldg,
  keep GM-pointer-required checks for both ldg and stg

Co-Authored-By: Claude <noreply@anthropic.com>
Comment thread ptodsl/ptodsl/_types.py
IntegerType,
ShapedType,
Type,
VectorType,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

这里要和孙可欣对齐下,她的联调分支上应该已经定义了VectorType,你们的定义需要统一

@zhangstevenunity zhangstevenunity 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.

Review: GM vectorized pto.ldg / pto.stg

Reviewed the full stack (ODS -> verifier -> LLVM/CANN900 emitters -> ptodsl -> docs -> tests). The design is sound and the implementation is a faithful, minimal extension.

Why it's correct: pto.ldg/pto.stg are lowered through the existing scalar GM intrinsics selected purely by total bit width. vector<2xf16>/vector<2xbf16> (32-bit) reuse the same s32/b32 intrinsic as scalar f32, and vector<2xf32> (64-bit) reuses the same s64/b64 path as scalar f64. The only new work is a width->intrinsic map plus an i32/i64 <-> vector bitcast, mirroring the scalar branches exactly. The element-level offset (GEP strides by the vector's byte size) and 8-byte-alignment-is-caller's-contract story match how scalar f64 already behaves, so no new alignment hazard is introduced. CI is green: build-and-test compiles it and vpto-sim-validation actually compiled+linked+ran+compared the three new device tests on the host SIM.

No blocking issues. A few non-blocking notes (2 inline):

  • Helper is looser than the verifier it mirrors (inline on PTOTypeUtils.cpp). Gemini's !isScalable() fix landed in the verifier, but the shared isPTOPackedFloatVectorType helper - the single gate used across the 10 emitter sites - still doesn't reject scalable vectors. Latent only (verifier blocks it first today), but worth tightening so the helper is self-sufficient.
  • Negative regression coverage was dropped (inline on the negative lit test). The verifier's new type restriction (rank==1, dim==2, elem in {f16,bf16,f32}) now has no test guarding it. KurrinQu asked about this; the illegal-vector-type cases were removed rather than kept.
  • compare.py (all three tests): Gemini's shape-mismatch note still applies to the diagnostic branch (~np.isclose / golden != out can raise on mismatched shapes). Purely cosmetic on the failure path - it still fails-closed with a non-zero exit - so non-blocking.
  • ptodsl _classify_storage_dtype: returns "compute" for any scalar-element vector, broader than the backend's dim-2 {f16,bf16,f32}. The backend still rejects the rest, so this only shifts validation later; fine as-is.
  • Merge coordination: Zhendong404 flagged a parallel integration branch that also defines VectorType / the f*x2 descriptors - worth aligning before merge to avoid duplicate/conflicting type descriptors.

Comment thread lib/PTO/IR/PTOTypeUtils.cpp Outdated
// stg requires GM pointer — UB pointer must fail.
pto.stg %val, %ub_i32[%c0] l1cache(cache) l2cache(nmfv) : !pto.ptr<i32, ub>, i32
// ldg requires GM pointer — UB pointer must fail.
%bad_ldg = pto.ldg %ub_i32[%c0] l1cache(cache) l2cache(nmfv) : !pto.ptr<i32, ub> -> i32

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.

After this rewrite the only negative coverage is the GM-pointer requirement. The core new constraint - the verifier's type restriction (rank==1, dim==2, element in {f16,bf16,f32}) - now has no regression test anywhere; the earlier vector<4xf32> / vector<3xf16> / vector<2xi32> cases were removed. A single minimal case (e.g. pto.ldg of vector<2xi32> or vector<4xf32> on a GM pointer, // CHECK: currently supports) would guard against a future loosening of the verifier and directly documents the accepted set. KurrinQu raised this thread; suggest keeping at least one illegal-vector-type check rather than dropping them entirely.

Comment thread lib/PTO/IR/PTOTypeUtils.cpp Outdated
return isa<F4E1M2x2Type, F4E2M1x2Type>(t);
}

bool mlir::pto::isPTOPackedFloatVectorType(Type t) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

2xfp8e4m3, 2xfp8e5m2, 2xhif8 以及整形也可以支持下

kuri780 and others added 4 commits July 8, 2026 15:08
Co-authored-by: zhangstevenunity <128771452+zhangstevenunity@users.noreply.github.com>
…integer types

- Rename isPTOPackedFloatVectorType → isPTOPackedLdgStgVectorType
- Extend helper to accept fp8 (f8E4M3FN/f8E5M2), hif8, i8/i16/i32 element types
- Gate total bits to 16/32/64 (reject vector<2xi64> at 128 bits)
- Use getPTOStorageElemBitWidth for custom PTO type element width
- Add 16-bit total path in both emitters: s16/b16 intrinsics, trunc+bitcast
- Update verifier to reuse helper, update error message
- Update docs to list all supported packed vector types
- Add positive lit test and negative verifier test

Co-Authored-By: Claude <noreply@anthropic.com>
- Accept !pto.hif8x2 in isPTOPackedLdgStgVectorType as a 16-bit packed type
- Add getPTOPackedLdgStgTotalBits helper to compute total bits for both
  VectorType and non-VectorType packed types (avoids cast<VectorType> crash)
- Update both emitters (5 sites each) to use the new helper
- Update VPTO.cpp verifier error message, ODS docs, and 17-simt.md
  to list !pto.hif8x2 and all supported packed types
- Remove unparseable vector<2x!pto.hif8> from docs and error messages
- Enhance lit test: add !pto.hif8x2 case, fp8 bitcast CHECK lines

Co-Authored-By: Claude <noreply@anthropic.com>
- Add simt-vector-ldg-stg-mixed-lowp-int-copy-core SIMT runtime test
  covering !pto.hif8x2, vector<2xi8>, vector<2xf8E4M3FN>, vector<2xf8E5M2>
  roundtrip copy (s16/b16 path) — all 4 types pass on NPU simulator

- Fix lit test CI failure: remove fragile LLVM dialect type name checks
  (!llvm.vec<2 x float8e4m3> etc.) that differ across build configs.
  Replace with stable structural checks (trunc pattern + intrinsic names).

Co-Authored-By: Claude <noreply@anthropic.com>
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.

6 participants