Skip to content

build: upgrade PTOAS to LLVM 21.1.8#796

Open
TaoTao-real wants to merge 20 commits into
hw-native-sys:mainfrom
TaoTao-real:codex/upgrade-llvm21
Open

build: upgrade PTOAS to LLVM 21.1.8#796
TaoTao-real wants to merge 20 commits into
hw-native-sys:mainfrom
TaoTao-real:codex/upgrade-llvm21

Conversation

@TaoTao-real

@TaoTao-real TaoTao-real commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Upgrade PTOAS build, docs, CI, Docker, and wheel workflows to llvmorg-21.1.8.
  • Port LLVM/MLIR API usage for LLVM 21, including free-function cast helpers, bufferization, memref layout, SCF/control-flow, LLVM inline asm, and EmitC lvalue handling.
  • Preserve Bisheng low-precision HIVM textual LLVM IR ABI for f8/f4/hif8 intrinsics after LLVM 21 carrier lowering.
  • Keep PTOAS Python bindings on pybind11/PybindAdaptors while adding nanobind for LLVM 21 MLIR Python builds.
  • Preserve the installed Python layout: _pto under mlir/_mlir_libs and pto.py/_pto_ops_gen.py under mlir/dialects.

Motivation

  • Architect request: move PTOAS mainline to LLVM 21 only, with target version fixed at llvmorg-21.1.8.

Design

  • No LLVM 19 compatibility macros are kept; the tree now targets LLVM 21.
  • Added low-precision type helpers used by LLVM 21/A5 paths.
  • Rewrites final emitted .ll text for @llvm.hivm.* low-precision intrinsic declarations/calls from LLVM 21 i8 carrier vectors back to Bisheng ABI type names only at object-emission output time.
  • Updated EmitC lowering for LLVM 21 lvalue semantics, including address-of operands for TQuant INT8_ASYM.
  • Split A5-only MX ptobc roundtrip coverage from the generic recent-ops fixture.
  • Normalized LLVM build library rpath handling for macOS _pto installation.

Testing

  • Local LLVM 21 build: llvmorg-21.1.8 with mlir;clang, shared libs, MLIR Python bindings, nanobind, pybind11<3.
  • Local PTOAS build: cmake --build build-llvm21 --target ptoas ptobc _pto.
  • Install: cmake --build build-llvm21 --target install.
  • ctest: ctest --test-dir build-llvm21 --output-on-failure, 27/27 passed.
  • lit: cmake --build build-llvm21 --target check-pto --parallel 8, 601/601 passed.
  • Python smoke: import mlir.ir; from mlir.dialects import pto; pto.register_dialect(...), passed.
  • Samples: bash test/samples/runop.sh --enablebc all, OK=265 FAIL=0 SKIP=16.
  • Targeted low-precision LLVM IR smoke: vcvt-low-precision-special, vcvt-low-precision-roundtrip, simt-packed-math-core generated expected f8/f4/hif8 HIVM ABI text and no low-precision i8 carrier declarations.
  • A3 board validation: not run locally because the configured A3 SSH key is unavailable and ~/.ssh/id_ed25519 is rejected by the remote host.

Risk / Rollback

  • Risk: broad build-system and LLVM/MLIR API migration can expose platform-specific CI/wheel issues; low-precision textual ABI rewrite is scoped to @llvm.hivm.* output .ll emission.
  • Rollback: revert this PR to return to the previous LLVM dependency baseline.

Review Focus

  • LLVM 21-only CMake/CI/Docker dependency updates and Python dependency handling.
  • EmitC lvalue changes around variables, loads, and address-of lowering.
  • Low-precision HIVM .ll ABI preservation for Bisheng verifier compatibility.
  • Python package install/import layout remaining compatible with existing mlir.dialects.pto usage.
  • ptobc roundtrip stability and separated MX fixture coverage.

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

Copy link
Copy Markdown

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 upgrades the project's LLVM/MLIR dependency from version 19.1.7 to 21.1.8, updating the build configurations, Dockerfiles, documentation, and Python bindings (including adding nanobind) accordingly. It also adapts the C++ codebase to LLVM 21 API changes, such as using getStridesAndOffset as a member function of MemRefType and replacing applyPatternsAndFoldGreedily with applyPatternsGreedily. The review feedback correctly points out that PointerUnion::dyn_cast is deprecated and removed in LLVM 21, suggesting the use of ofr.get<Value>() instead of ofr.dyn_cast<Value>() in InferPTOLayout.cpp and PTOToEmitC.cpp where the underlying type has already been verified.

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.

return std::nullopt;
}
return getConstInt(ofr.get<Value>());
return getConstInt(ofr.dyn_cast<Value>());

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

In LLVM 21, the PointerUnion::dyn_cast member function is deprecated and removed. Since we have already verified that ofr is not an Attribute using ofr.is<Attribute>(), we can safely use ofr.get<Value>() directly. This avoids deprecation warnings and is more efficient.

Suggested change
return getConstInt(ofr.dyn_cast<Value>());
return getConstInt(ofr.get<Value>());

return intAttr.getInt();
} else {
Value v = ofr.get<Value>();
Value v = ofr.dyn_cast<Value>();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

In LLVM 21, the PointerUnion::dyn_cast member function is deprecated and removed. Since we have already verified that ofr is not an Attribute using ofr.is<Attribute>(), we can safely use ofr.get<Value>() directly. This avoids deprecation warnings and is more efficient.

Suggested change
Value v = ofr.dyn_cast<Value>();
Value v = ofr.get<Value>();

@reedhecre

reedhecre commented Jun 11, 2026

Copy link
Copy Markdown

Codex Review

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

  • PR: build: upgrade PTOAS to LLVM 21.1.8 #796 build: upgrade PTOAS to LLVM 21.1.8
  • Author: TaoTao-real
  • Base/Head: main / codex/upgrade-llvm21
  • Head SHA: 6318ad7e2309
  • Trigger: PR 有新提交
  • Generated At: 2026-06-12T01:16:14Z
  • Previous Head SHA: 1ddd67ede9f7
  • Status: failed at codex-review (exit=1)

Summary

Review failed at stage codex-review: exit=1

Findings

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

Log Tail

 test/samples/Qwen3DecodeA5/down_proj_residual.pto  |  36 +-
 test/samples/Qwen3DecodeA5/out_proj_residual.pto   |  36 +-
 .../Qwen3DecodeA5/qwen3_decode_incore_1.pto        |  36 +-
 .../Qwen3DecodeA5/qwen3_decode_incore_10.pto       |  48 +--
 .../Qwen3DecodeA5/qwen3_decode_incore_11.pto       |  48 +--
 .../Qwen3DecodeA5/qwen3_decode_incore_2.pto        |  72 ++--
 .../Qwen3DecodeA5/qwen3_decode_incore_4.pto        |  24 +-
 .../Qwen3DecodeA5/qwen3_decode_incore_6.pto        |  24 +-
 .../known_unsupported/cann-9.0.0-beta.1-sim.txt    |  28 ++
 .../scripts/run_host_vpto_validation_parallel.sh   | 100 +++++-
 tilelang-dsl/python/tilelang_dsl/kernel.py         |  21 +-
 tools/ptoas/ObjectEmission.cpp                     | 151 ++++++--
 tools/ptoas/ObjectEmission.h                       |   9 +
 tools/ptoas/driver.cpp                             |  50 ++-
 tools/ptoas/ptoas.cpp                              | 265 +++++++++++++-
 tools/ptoas/ptoas.h                                |   1 +
 tools/ptobc/src/mlir_encode.cpp                    |  35 +-
 tools/ptobc/src/ptobc_decode_print.cpp             |   3 +-
 .../ptobc/testdata/recent_mx_ops_v0_roundtrip.pto  |  26 ++
 tools/ptobc/testdata/recent_ops_v0_roundtrip.pto   |  12 -
 tools/ptobc/tests/recent_ops_v0_encode.sh          |  11 +-
 95 files changed, 2132 insertions(+), 794 deletions(-)
===== END STAGE clone rc=0 @ 2026-06-12 09:15:34 =====

===== STAGE codex-review @ 2026-06-12 09:15:34 =====
set -euo pipefail
cd '/tmp/ptoas-pr-review-monitor/runs/20260612_091526_pr796/repo'
'codex' exec -C '/tmp/ptoas-pr-review-monitor/runs/20260612_091526_pr796/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/20260612_091526_pr796/review_schema.json' -o '/tmp/ptoas-pr-review-monitor/runs/20260612_091526_pr796/codex_last_message.json' --color never - < '/tmp/ptoas-pr-review-monitor/runs/20260612_091526_pr796/review_prompt.txt'
OpenAI Codex v0.115.0 (research preview)
--------
workdir: /tmp/ptoas-pr-review-monitor/runs/20260612_091526_pr796/repo
model: gpt-5.4
provider: codereview
approval: never
sandbox: read-only
reasoning effort: xhigh
reasoning summaries: none
session id: 019eb966-125f-7eb3-b159-6f9d7c9ed50b
--------
user
你现在在审查 GitHub PR。

仓库:hw-native-sys/PTOAS
PR:#796 build: upgrade PTOAS to LLVM 21.1.8
作者:TaoTao-real
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 #796 存在问题,并返回 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 502 Bad Gateway: Upstream service temporarily unavailable, url: https://codex.0u0o.com/responses, request id: 288e252d-75a3-4812-8156-9245c9f9c3a2)
Reconnecting... 2/5 (unexpected status 502 Bad Gateway: Upstream service temporarily unavailable, url: https://codex.0u0o.com/responses, request id: 2ef8e783-5003-47a4-a66d-fa08428e858d)
Reconnecting... 3/5 (unexpected status 502 Bad Gateway: Upstream service temporarily unavailable, url: https://codex.0u0o.com/responses, request id: 4b90d13e-d639-451a-8cd3-838abbe8fffd)
Reconnecting... 4/5 (unexpected status 502 Bad Gateway: Upstream service temporarily unavailable, url: https://codex.0u0o.com/responses, request id: 41ff8980-b0f0-4e95-bf9f-9f02e848171d)
Reconnecting... 5/5 (unexpected status 502 Bad Gateway: Upstream service temporarily unavailable, url: https://codex.0u0o.com/responses, request id: a48755e4-ce3f-4be3-9236-44a7d9a7a91d)
ERROR: unexpected status 502 Bad Gateway: Upstream service temporarily unavailable, url: https://codex.0u0o.com/responses, request id: a39c9309-3f61-4f2e-b5d3-78bce9eeb49b
Warning: no last agent message; wrote empty content to /tmp/ptoas-pr-review-monitor/runs/20260612_091526_pr796/codex_last_message.json
===== END STAGE codex-review rc=1 @ 2026-06-12 09:16:14 =====

@TaoTao-real

Copy link
Copy Markdown
Contributor Author

LLVM21 follow-up pushed in 413a0cf.\n\nWhat changed:\n- Replaced remaining removed LLVM21 float8 member predicates with PTO low-precision type helpers.\n- Removed obsolete LLVM dialect low-precision/fixed-vector type names from VPTO emitters.\n- Lowered low-precision VPTO vreg payloads through the i8 carrier ABI to avoid LLVM21-invalid f8/i8 vector bitcasts.\n\nLocal validation:\n- cmake --build build-llvm21 --target ptoas ptobc _pto\n- cmake --build build-llvm21 --target install\n- ctest --test-dir build-llvm21 --output-on-failure: 27/27 passed\n- Python smoke: import mlir.ir; from mlir.dialects import pto\n- llvm-lit build-llvm21/test/lit/vpto: 241/241 passed\n- bash test/samples/runop.sh --enablebc all: OK=265 FAIL=0 SKIP=16\n\nA3/A5 simulator and wheel checks are left to CI/self-hosted runners because this local machine does not have the required Ascend simulator/toolchain environment.

@TaoTao-real TaoTao-real force-pushed the codex/upgrade-llvm21 branch from 06afb3d to 1a4e222 Compare June 11, 2026 21:35
@TaoTao-real TaoTao-real force-pushed the codex/upgrade-llvm21 branch from 6d7fd3f to 80ac38f Compare June 11, 2026 23:53
@TaoTao-real TaoTao-real force-pushed the codex/upgrade-llvm21 branch from 1ddd67e to 6318ad7 Compare June 12, 2026 01:13
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