Skip to content
Merged
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
4 changes: 2 additions & 2 deletions .github/workflows/build_wheel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ permissions:

env:
LLVM_REPOSITORY: https://github.com/LinxISA/llvm-project.git
LLVM_COMMIT: 1245c0f89aab24104ea935fa686a0ac5ad9ab2c9
LLVM_COMMIT: b7c83f68bf84125e696a70bec4b665c70a3b584d

jobs:
build_wheel:
Expand Down Expand Up @@ -82,7 +82,7 @@ jobs:
- name: Install Python dependencies
run: |
export PATH="${PY_PATH}/bin:$PATH"
pip install --no-cache-dir numpy nanobind typing_extensions setuptools wheel auditwheel
pip install --no-cache-dir numpy 'nanobind>=2.9,<3' typing_extensions setuptools wheel auditwheel

- name: Set build directories
run: |
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/build_wheel_mac.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ permissions:

env:
LLVM_REPOSITORY: https://github.com/LinxISA/llvm-project.git
LLVM_COMMIT: 1245c0f89aab24104ea935fa686a0ac5ad9ab2c9
LLVM_COMMIT: b7c83f68bf84125e696a70bec4b665c70a3b584d

jobs:
build_wheel:
Expand Down Expand Up @@ -83,7 +83,7 @@ jobs:

- name: Install Python dependencies
run: |
pip install --no-cache-dir numpy nanobind typing_extensions setuptools wheel delocate
pip install --no-cache-dir numpy 'nanobind>=2.9,<3' typing_extensions setuptools wheel delocate

- name: Set build directories
run: |
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ jobs:
runs-on: ubuntu-22.04
env:
LLVM_REPOSITORY: https://github.com/LinxISA/llvm-project.git
LLVM_COMMIT: 1245c0f89aab24104ea935fa686a0ac5ad9ab2c9
LLVM_COMMIT: b7c83f68bf84125e696a70bec4b665c70a3b584d
LLVM_DIR: ${{ github.workspace }}/llvm-project/llvm/build-shared
PTO_INSTALL_DIR: ${{ github.workspace }}/install
MLIR_PYTHONPATH: ${{ github.workspace }}/llvm-project/llvm/build-shared/tools/mlir/python_packages/mlir_core
Expand All @@ -119,7 +119,7 @@ jobs:
clang lld \
libedit-dev zlib1g-dev libxml2-dev libzstd-dev
python3 -m pip install --upgrade pip
python3 -m pip install nanobind typing_extensions numpy
python3 -m pip install 'nanobind>=2.9,<3' typing_extensions numpy

- name: Define payload paths
shell: bash
Expand Down Expand Up @@ -232,7 +232,7 @@ jobs:
include/PTO/IR/PTOOps.td \
tools/ptobc/generated/ptobc_opcodes_v0.h
ctest --test-dir build --output-on-failure \
-R 'pto_isa_v0581_contract_check|ptobc_v0580_ops_v0_encode|ptobc_v0581_contract_encode|ptobc_tpartarg_v0_encode'
-R 'pto_isa_v0583_contract_check|ptobc_v0580_ops_v0_encode|ptobc_v0583_contract_encode|ptobc_tpartarg_v0_encode'

- name: Run sample tests (py -> pto -> cpp)
shell: bash
Expand Down
16 changes: 13 additions & 3 deletions .github/workflows/isa_contract.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
name: PTO ISA v0.58.1 contract
name: PTO ISA v0.58.3 contract

on:
push:
tags:
- linxisa-v0.58.1
- linxisa-v0.58.3
pull_request:
paths:
- docker/**
- .dockerignore
- .github/workflows/isa_contract.yml
- include/PTO/IR/**
- lib/PTO/IR/**
- lib/PTO/Transforms/PTOToEmitC.cpp
- test/lit/pto/v0583_**
- tools/check_v058_pto_manifest.py
- tools/test_check_v058_pto_manifest.py
- tools/pto_isa_v0_58_3_**
- tools/ptobc/**
- tools/check_release_delivery_contract.py
- tools/test_release_delivery_contract.py
workflow_dispatch:
Expand All @@ -22,7 +30,9 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: Check exact PTO ISA contract
run: python3 tools/check_v058_pto_manifest.py --ptoas-root .
run: |
python3 tools/check_v058_pto_manifest.py --ptoas-root .
python3 tools/test_check_v058_pto_manifest.py

docker-builder:
runs-on: ubuntu-latest
Expand Down
46 changes: 44 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,12 @@ if(BUILD_TESTING)
enable_testing()
find_package(Python3 COMPONENTS Interpreter REQUIRED)
add_test(
NAME pto_isa_v0581_contract_check
NAME pto_isa_v0583_contract_check
COMMAND ${Python3_EXECUTABLE}
${CMAKE_CURRENT_SOURCE_DIR}/tools/check_v058_pto_manifest.py
--ptoas-root ${CMAKE_CURRENT_SOURCE_DIR})
add_test(
NAME pto_isa_v0581_contract_check_negative
NAME pto_isa_v0583_contract_check_negative
COMMAND ${Python3_EXECUTABLE}
${CMAKE_CURRENT_SOURCE_DIR}/tools/test_check_v058_pto_manifest.py)
add_test(
Expand Down Expand Up @@ -173,6 +173,48 @@ if(BUILD_TESTING)
NAME emitc_lvalue_contract_check
COMMAND ${Python3_EXECUTABLE}
${CMAKE_CURRENT_SOURCE_DIR}/tools/check_emitc_lvalue_contract.py)
option(PTOAS_ENABLE_LINX_TILEOP_INTEGRATION
"Compile generated Linx MX C++ with the exact target toolchain and TileOP" OFF)
set(PTOAS_LINX_LLVM_BUILD "" CACHE PATH "Exact merged Linx LLVM build")
set(PTOAS_LINX_SYSROOT "" CACHE PATH "Phase-C Linx musl+libc++ sysroot")
set(PTOAS_LINX_TILEOP_ROOT "" CACHE PATH "Exact merged Linx TileOP checkout")
set(PTOAS_EXPECTED_LLVM_COMMIT
"b7c83f68bf84125e696a70bec4b665c70a3b584d" CACHE STRING
"Reviewed merged Linx LLVM commit")
set(PTOAS_EXPECTED_LLVM_TREE
"c11bd80c7dd34ed4438de1da6bde0a01eae8c76d" CACHE STRING
"Reviewed merged Linx LLVM tree")
set(PTOAS_EXPECTED_TILEOP_COMMIT
"bd1ecca97ca47da0edc462c1ce19749c6940780e" CACHE STRING
"Reviewed merged Linx TileOP commit")
set(PTOAS_EXPECTED_TILEOP_TREE
"854c463c21f9b758186b718105f4b035019cdd30" CACHE STRING
"Reviewed merged Linx TileOP tree")
if(PTOAS_ENABLE_LINX_TILEOP_INTEGRATION)
foreach(required_var IN ITEMS
PTOAS_LINX_LLVM_BUILD PTOAS_LINX_SYSROOT PTOAS_LINX_TILEOP_ROOT
PTOAS_EXPECTED_LLVM_COMMIT PTOAS_EXPECTED_LLVM_TREE
PTOAS_EXPECTED_TILEOP_COMMIT PTOAS_EXPECTED_TILEOP_TREE)
if(NOT DEFINED ${required_var} OR "${${required_var}}" STREQUAL "")
message(FATAL_ERROR
"${required_var} is required for the Linx TileOP integration gate")
endif()
endforeach()
add_test(
NAME linx_mx_tileop_compile_check
COMMAND ${CMAKE_COMMAND} -E env
PTOAS_BIN=$<TARGET_FILE:pto-opt>
LINX_LLVM_BUILD=${PTOAS_LINX_LLVM_BUILD}
LINX_SYSROOT=${PTOAS_LINX_SYSROOT}
TILEOP_ROOT=${PTOAS_LINX_TILEOP_ROOT}
EXPECTED_LLVM_COMMIT=${PTOAS_EXPECTED_LLVM_COMMIT}
EXPECTED_LLVM_TREE=${PTOAS_EXPECTED_LLVM_TREE}
EXPECTED_TILEOP_COMMIT=${PTOAS_EXPECTED_TILEOP_COMMIT}
EXPECTED_TILEOP_TREE=${PTOAS_EXPECTED_TILEOP_TREE}
bash ${CMAKE_CURRENT_SOURCE_DIR}/tools/check_linx_mx_tileop_compile.sh)
set_tests_properties(linx_mx_tileop_compile_check PROPERTIES
LABELS "linx-target-integration")
endif()
add_subdirectory(tools/ptobc/tests)
endif()

Expand Down
40 changes: 35 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
## 1. 项目简介 (Introduction)

**ptoas** (`ptoas`) 是一个基于 LinxISA 受控 **LLVM/MLIR**
(ISA release `linxisa-v0.58.1`,LLVM commit
`1245c0f89aab24104ea935fa686a0ac5ad9ab2c9`)构建的专用编译器工具链,
(ISA release `linxisa-v0.58.3`,LLVM commit
`b7c83f68bf84125e696a70bec4b665c70a3b584d`)构建的专用编译器工具链,
专为 **PTO Bytecode** (Programming Tiling Operator Bytecode) 设计。

作为连接上层 AI 框架与底层各类NPU/GPGPU/CPU硬件,`ptoas` 采用 **Out-of-Tree** 架构构建,提供了完整的 C++ 与 Python 接口,主要职责包括:
Expand Down Expand Up @@ -41,7 +41,7 @@ PTOAS/
## 3. 构建指南 (Build Instructions)

⚠️ **重要提示**:本项目严格依赖 LinxISA LLVM
`1245c0f89aab24104ea935fa686a0ac5ad9ab2c9`。`linxisa-v0.58.1`
`b7c83f68bf84125e696a70bec4b665c70a3b584d`。`linxisa-v0.58.3`
是 ISA release tag,不是 PTOAS 产品版本;不要替换为同名上游 LLVM tag。


Expand Down Expand Up @@ -92,7 +92,7 @@ python3 -m pip install nanobind numpy
cd $WORKSPACE_DIR
git clone https://github.com/LinxISA/llvm-project.git
cd $LLVM_SOURCE_DIR
git checkout --detach 1245c0f89aab24104ea935fa686a0ac5ad9ab2c9
git checkout --detach b7c83f68bf84125e696a70bec4b665c70a3b584d

# 2. 配置 CMake (构建动态库并启用 Python 绑定)
cmake -G Ninja -S llvm -B $LLVM_BUILD_DIR \
Expand Down Expand Up @@ -221,7 +221,7 @@ ptoas --version
```

`ptoas --version` 中的 `0.41` 是 PTOAS 产品版本;括号中的 `PTO ISA
0.58.1` 是独立的 ISA contract 版本。`linx` target 对齐受管的
0.58.3` 是独立的 ISA contract 版本。`linx` target 对齐受管的
`Linx-TileOP-API`:生成代码包含
`jcore/template_asm.hpp`,只接受 v0.58 公共 PTO 操作目录,并在 lowering
前拒绝仅属于 A3/A5 方言面的操作。
Expand Down Expand Up @@ -253,6 +253,36 @@ python3 ./tmatmulk.py > ./tmatmulk.pto
$PTO_SOURCE_DIR/build/tools/ptoas/ptoas ./tmatmulk.pto -o ./tmatmulk.cpp
```

Linx MX 的真实 C++ 集成门禁默认不启用,因为它必须同时绑定精确的 Linx
LLVM 构建、musl+libc++ sysroot 和 `Linx-TileOP-API` checkout。该门禁不会使用
host shim 或替换 `jcore/template_asm.hpp` 的 stub。依赖准备好后,使用已审核并
合并的 commit/tree 配置独立构建目录:

```bash
cmake -G Ninja -S . -B build-linx-integration \
-DLLVM_DIR=$LLVM_BUILD_DIR/lib/cmake/llvm \
-DMLIR_DIR=$LLVM_BUILD_DIR/lib/cmake/mlir \
-DPTOAS_ENABLE_LINX_TILEOP_INTEGRATION=ON \
-DPTOAS_LINX_LLVM_BUILD=$LINX_LLVM_BUILD \
-DPTOAS_LINX_SYSROOT=$LINX_SYSROOT \
-DPTOAS_LINX_TILEOP_ROOT=$TILEOP_ROOT \
-DPTOAS_EXPECTED_LLVM_COMMIT=b7c83f68bf84125e696a70bec4b665c70a3b584d \
-DPTOAS_EXPECTED_LLVM_TREE=c11bd80c7dd34ed4438de1da6bde0a01eae8c76d \
-DPTOAS_EXPECTED_TILEOP_COMMIT=bd1ecca97ca47da0edc462c1ce19749c6940780e \
-DPTOAS_EXPECTED_TILEOP_TREE=854c463c21f9b758186b718105f4b035019cdd30
ninja -C build-linx-integration ptoas
ctest --test-dir build-linx-integration \
-L linx-target-integration --output-on-failure
```

门禁先核对两个 checkout 的 commit/tree,再由真实 Linx `clang++` 和指定
sysroot 对 PTOAS 生成的 TMATMUL/TGEMV base、ACC、BIAS 的 zero/A-only/
B-only/both 四种形式分别执行 `-fsyntax-only` 和目标对象编译。缺少路径、
identity 不匹配或真实 TileOP 签名/约束不接受生成代码时,门禁都会失败。
门禁最后还运行 TileOP 的 phase-C link smoke,并用
`verify_pto_identity.py` 核对每个 Linx ELF 中唯一且精确的 PTO 0.58.3
identity note。

### 5.4 上板验证

该流程用于将 `test/samples` 下生成的 `.cpp`(ptoas 输出)自动生成 NPU 验证用例,并在 NPU 上运行。下面示例直接复用 5.3 里生成的 `MatMul/tmatmulk.cpp`。
Expand Down
9 changes: 9 additions & 0 deletions ReleaseNotes.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# PTOAS (PTO Assembler & Optimizer)

## Unreleased: PTO ISA 0.58.3 alignment

- Locks the exact PTO-SPEC v0.58.3 release identity and all four catalogs.
- Adds Linx CUBE CELL layouts (`cube_m16`, `cube_m32`, `cube_n8`) and
fail-closed CUBE operand verification.
- Updates TGEMV/TGEMVMX operand order and distinct ACC/BIAS TileOP calls.
- Records TLOAD/TSTORE byte row-stride roles and verifies the 0.58.3
B.IOT/B.IOS/B.FPATR/DTYPE_NONE hard-break fields.

## 版本
- 版本号:v0.1.0
- 发布日期:2026-02-14
Expand Down
7 changes: 5 additions & 2 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ ARG ARCH
# NOTE: change $PY_VER for different Python versions (3.8 - 3.14 available)
ARG PY_VER=cp311-cp311
ARG LLVM_REPOSITORY=https://github.com/LinxISA/llvm-project.git
ARG LLVM_COMMIT=1245c0f89aab24104ea935fa686a0ac5ad9ab2c9
ARG LLVM_COMMIT=b7c83f68bf84125e696a70bec4b665c70a3b584d

## -- usually no need to change below --

Expand All @@ -20,7 +20,10 @@ ENV PATH="${PY_PATH}/bin:${PATH}"

# dependency
RUN dnf install -y ninja-build cmake git ccache gcc-c++ lld zip binutils patchelf chrpath && dnf clean all
RUN pip install --no-cache-dir numpy nanobind setuptools wheel auditwheel
# LLVM 23's MLIR Python build requires the nanobind 2.9 CMake contract.
# PTOAS itself also supports nanobind 3 in the hosted prebuilt-LLVM lanes, but
# this source-build stage must stay below the nanobind 3 hard break.
RUN pip install --no-cache-dir numpy 'nanobind>=2.9,<3' setuptools wheel auditwheel

COPY cmake/LinuxHardeningCache.cmake /tmp/LinuxHardeningCache.cmake

Expand Down
4 changes: 2 additions & 2 deletions docker/check_ptoas_cli_identity.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ if [[ "$VERSION_OUTPUT" == *$'\n'* || "$VERSION_OUTPUT" == *$'\r'* ]]; then
fi

if [[ -n "$PTOAS_VERSION" ]]; then
EXPECTED_VERSION_OUTPUT="ptoas ${PTOAS_VERSION} (PTO ISA 0.58.1)"
EXPECTED_VERSION_OUTPUT="ptoas ${PTOAS_VERSION} (PTO ISA 0.58.3)"
if [[ "$VERSION_OUTPUT" != "$EXPECTED_VERSION_OUTPUT" ]]; then
echo "Error: expected '${EXPECTED_VERSION_OUTPUT}', got '${VERSION_OUTPUT}'" >&2
exit 1
fi
else
EXPECTED_VERSION_OUTPUT="ptoas ${PTOAS_RELEASE_VERSION} (PTO ISA 0.58.1)"
EXPECTED_VERSION_OUTPUT="ptoas ${PTOAS_RELEASE_VERSION} (PTO ISA 0.58.3)"
if [[ "$VERSION_OUTPUT" != "$EXPECTED_VERSION_OUTPUT" ]]; then
echo "Error: invalid packaged ptoas identity '${VERSION_OUTPUT}'" >&2
exit 1
Expand Down
Loading
Loading