Skip to content
Merged
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
cbaff1f
rebased
castigli Jun 11, 2026
98ced35
description of new pipeline
castigli Jun 11, 2026
6c4fafb
fixes after rebase
castigli Jun 30, 2026
3d30420
add binary e2e tests
castigli Jul 1, 2026
3883ae6
update readme
castigli Jul 1, 2026
8f4a25e
all binary ops without scratchpad
castigli Jul 1, 2026
76d15b7
better tests
castigli Jul 2, 2026
26aeced
roundtrip and verifyier
castigli Jul 2, 2026
3ccb0de
cover unaligned tadd
castigli Jul 2, 2026
5c0367b
shift ops
castigli Jul 3, 2026
41ad438
fix xor
castigli Jul 3, 2026
b268b81
A5 allocator
castigli Jul 3, 2026
65909eb
fixes for A5 allocator
castigli Jul 3, 2026
b8476e0
Merge pull request #1 from castigli/extend-a2a3-llvm
castigli Jul 3, 2026
8ef0813
unary ops
castigli Jul 4, 2026
61c34fb
addrelu
castigli Jul 4, 2026
fec8a73
fix
castigli Jul 6, 2026
2531922
cleanup
castigli Jul 6, 2026
67d947e
trecip
castigli Jul 6, 2026
382bb92
tlog
castigli Jul 7, 2026
9a9e269
merge main
castigli Jul 7, 2026
7ba6761
address review
castigli Jul 7, 2026
44bc1c6
fix a2a3 review and CI issues
castigli Jul 8, 2026
616d7fb
fix ptoas target arch resolution
castigli Jul 8, 2026
93332f8
restore emitc memory planning passes
castigli Jul 9, 2026
c80521f
trigger CI
castigli Jul 10, 2026
7f54d1f
merge main
castigli Jul 10, 2026
2ca1095
fix(vpto): use storage bit-width helper for low-precision CBuf loads
castigli Jul 14, 2026
f1012ca
Merge remote-tracking branch 'origin/main' into feature/a2a3-llvm
castigli Jul 15, 2026
a815184
Merge remote-tracking branch 'origin/main' into feature/a2a3-llvm
castigli Jul 15, 2026
4190014
fix(vpto): address A2/A3 review findings
castigli Jul 15, 2026
4d106d6
test(vpto): avoid CANN dependency in IR lit tests
castigli Jul 16, 2026
a29fe7a
ci: limit wheel build parallelism
castigli Jul 16, 2026
e3d4462
test(vpto): make wrapper expansion checks order-independent
castigli Jul 16, 2026
69be84f
Merge remote-tracking branch 'origin/main' into feature/a2a3-llvm
castigli Jul 20, 2026
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
57 changes: 42 additions & 15 deletions _ptoas_build_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,41 @@
from pathlib import Path

_REPO = Path(__file__).parent.resolve()
_LLVM_BUILD_DIR = Path(
os.environ.get("LLVM_BUILD_DIR",
"/llvm-workspace/llvm-project/build-shared")
)

def _find_llvm_dir():
"""Return an LLVM install or build-tree prefix, resolving in order:

1. ``LLVM_BUILD_DIR`` / ``LLVM_INSTALL_DIR`` env vars
2. Auto-detect common install locations by probing ``lib/cmake/llvm``
3. Default build-tree path
"""
for key in ("LLVM_BUILD_DIR", "LLVM_INSTALL_DIR"):
if key in os.environ:
return Path(os.environ[key])

for cand in ("/usr/local/llvm", "/usr/local/Ascend/latest/compiler",
"/opt/llvm"):
if (Path(cand) / "lib" / "cmake" / "llvm").is_dir():
return Path(cand)

return Path("/llvm-workspace/llvm-project/build-shared")


_LLVM_BUILD_DIR = _find_llvm_dir()
_PTO_INSTALL_DIR = Path(
os.environ.get("PTO_INSTALL_DIR", str(_REPO / "install"))
)
_BUILD_DIR = Path(os.environ.get("PTO_BUILD_DIR", str(_REPO / "build")))
_PTODSL_SOURCE_ROOT = _REPO / "ptodsl"
_MLIR_PY_PKG = (
_LLVM_BUILD_DIR / "tools" / "mlir" / "python_packages" / "mlir_core"
)
_MLIR_PY_PKG = None
if "MLIR_PYTHON_PACKAGE_DIR" in os.environ:
_MLIR_PY_PKG = Path(os.environ["MLIR_PYTHON_PACKAGE_DIR"])
elif "LLVM_INSTALL_DIR" in os.environ:
_MLIR_PY_PKG = Path(os.environ["LLVM_INSTALL_DIR"]) / "python_packages" / "mlir_core"
else:
_installed = _LLVM_BUILD_DIR / "python_packages" / "mlir_core"
_build_tree = _LLVM_BUILD_DIR / "tools" / "mlir" / "python_packages" / "mlir_core"
_MLIR_PY_PKG = _installed if _installed.exists() else _build_tree
_WHEEL_DIST_DIR = _BUILD_DIR / "wheel-dist"


Expand Down Expand Up @@ -124,7 +147,7 @@ def _should_use_linux_hardening_cache() -> bool:
return sys.platform.startswith("linux")


def _cmake_configure_and_build():
def _cmake_configure_and_build(skip_install=False):
"""CMake configure + build + install."""
_BUILD_DIR.mkdir(parents=True, exist_ok=True)

Expand All @@ -136,6 +159,7 @@ def _cmake_configure_and_build():
"cmake", "-GNinja",
f"-S{_REPO}", f"-B{_BUILD_DIR}",
"-DCMAKE_BUILD_TYPE=Release",
"-DPTO_ENABLE_PYTHON_BINDING=ON",
f"-DLLVM_DIR={_LLVM_BUILD_DIR}/lib/cmake/llvm",
f"-DMLIR_DIR={_LLVM_BUILD_DIR}/lib/cmake/mlir",
f"-DPython3_ROOT_DIR={sys.prefix}",
Expand All @@ -161,10 +185,11 @@ def _cmake_configure_and_build():

subprocess.check_call(cmake_cmd)
subprocess.check_call(["cmake", "--build", str(_BUILD_DIR)])
subprocess.check_call(
["cmake", "--build", str(_BUILD_DIR), "--target", "install"]
)
_assert_installed_ptodsl_payload()
if not skip_install:
subprocess.check_call(
["cmake", "--build", str(_BUILD_DIR), "--target", "install"]
)
_assert_installed_ptodsl_payload()


def build_wheel(wheel_directory, config_settings=None, metadata_directory=None):
Expand Down Expand Up @@ -209,7 +234,7 @@ def build_editable(wheel_directory, config_settings=None, metadata_directory=Non
the installed/runtime build outputs. No files are copied into
site-packages except the .pth file itself.
"""
_cmake_configure_and_build()
_cmake_configure_and_build(skip_install=True)
_assert_editable_ptodsl_source()

version = os.environ.get("PTOAS_PYTHON_PACKAGE_VERSION", "0.1.0")
Expand All @@ -221,9 +246,11 @@ def build_editable(wheel_directory, config_settings=None, metadata_directory=Non
# Prefer the repository PTODSL sources so editable installs pick up
# local Python edits instead of staged/install-tree copies.
str(_PTODSL_SOURCE_ROOT),
# Installed PTOAS runtime overlay (mlir.dialects.pto, _pto, TileOps).
# Handwritten Python sources (pto/dialects/pto.py, etc.).
str(_REPO / "python"),
# Installed PTOAS runtime overlay (TileOps/resources when present).
str(_PTO_INSTALL_DIR),
# Keep the in-tree extension/staging output last as a fallback.
# Generated files (_pto.so, _pto_ops_gen.py) under mlir/ namespace.
str(_BUILD_DIR / "python"),
]

Expand Down
2 changes: 1 addition & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ RUN bisheng $BISHENG_OPTS ./tmatmulk.cpp -o ./matmul_kernel.so
# add torch_npu to faciliate on-device testing during `docker run` (not used at build stage)
# for available versions see https://pypi.org/project/torch-npu/#history
RUN pip install --no-cache-dir torch==2.9.0 --index-url https://download.pytorch.org/whl/cpu \
&& pip install --no-cache-dir torch-npu==2.9.0 \
&& pip install --no-cache-dir torch-npu==2.9.0.post2 \
&& pip install --no-cache-dir numpy pyyaml

WORKDIR /sources/test/
Expand Down
84 changes: 84 additions & 0 deletions docker/Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# PTOAS development environment with NPU support (CANN 9.0.0)
#
# Usage:
# docker build -f docker/Dockerfile.dev -t ptoas-dev-cann900 .
#
# This image provides the toolchain for building and running PTOAS on NPU.
# It does NOT contain PTOAS itself -- mount PTOAS source at /workspace and
# run `pip install -e .` inside the container.

# ---- Base: CANN 9.0.0 (provides bisheng, CANN runtime, Python 3.12) ----
FROM quay.io/ascend/cann:9.0.0-910b-ubuntu22.04-py3.12

# ---- Build args (matching CI) ----
ARG LLVM_REPO=https://github.com/vpto-dev/llvm-project.git
ARG LLVM_REF=feature-vpto-llvm21
ARG PTO_ISA_REPO=https://gitcode.com/cann/pto-isa.git
ARG PTO_ISA_COMMIT=662d7f2a916d6bbde3109ce4a16ed5c28f5d900a

# ---- Paths ----
ENV LLVM_SOURCE_DIR=/opt/llvm-project
ENV LLVM_BUILD_DIR=/opt/llvm-project/build
ENV LLVM_INSTALL_DIR=/usr/local/llvm
ENV ASCEND_HOME_PATH=/usr/local/Ascend/cann-9.0.0
ENV PTO_LIB_PATH=/opt/pto-isa

# =========================================================================
# 1. System dependencies
# =========================================================================
RUN apt-get update && apt-get install -y --no-install-recommends \
cmake ninja-build git build-essential clang lld \
libedit-dev zlib1g-dev libxml2-dev libzstd-dev \
&& rm -rf /var/lib/apt/lists/*

# =========================================================================
# 2. Python dependencies
# =========================================================================
RUN pip install --no-cache-dir 'pybind11<3' numpy pyyaml pytest nanobind

# =========================================================================
# 3. Build LLVM/MLIR (vpto fork, feature-vpto branch)
# =========================================================================
RUN git clone --depth 1 --branch "${LLVM_REF}" "${LLVM_REPO}" "${LLVM_SOURCE_DIR}"

WORKDIR ${LLVM_SOURCE_DIR}

RUN cmake -G Ninja -S llvm -B "${LLVM_BUILD_DIR}" \
-DLLVM_ENABLE_PROJECTS="mlir;clang" \
-DBUILD_SHARED_LIBS=ON \
-DLLVM_ENABLE_ASSERTIONS=ON \
-DMLIR_ENABLE_BINDINGS_PYTHON=ON \
-DPython3_EXECUTABLE=python3 \
-DCMAKE_BUILD_TYPE=Release \
-DLLVM_TARGETS_TO_BUILD="host" \
-DCMAKE_INSTALL_PREFIX="${LLVM_INSTALL_DIR}" \
-DLLVM_INSTALL_UTILS=ON

RUN ninja -C "${LLVM_BUILD_DIR}"

RUN cmake --install "${LLVM_BUILD_DIR}"

# =========================================================================
# 4. Clone pto-isa (headers for bisheng compilation of generated kernels)
# =========================================================================
RUN git clone "${PTO_ISA_REPO}" "${PTO_LIB_PATH}" \
&& cd "${PTO_LIB_PATH}" && git checkout "${PTO_ISA_COMMIT}"

# =========================================================================
# 5. Torch + torch-npu (for on-device kernel launch)
# =========================================================================
RUN pip install --no-cache-dir torch==2.9.0 --index-url https://download.pytorch.org/whl/cpu \
Comment thread
castigli marked this conversation as resolved.
&& pip install --no-cache-dir torch-npu==2.9.0.post2

# =========================================================================
# 6. Environment
# =========================================================================
ENV PATH="${LLVM_INSTALL_DIR}/bin:${ASCEND_HOME_PATH}/compiler/bin:${PATH}"
ENV LD_LIBRARY_PATH="${LLVM_INSTALL_DIR}/lib:${ASCEND_HOME_PATH}/lib64:${ASCEND_HOME_PATH}/lib64/plugin/opskernel:${ASCEND_HOME_PATH}/lib64/plugin/nnengine:${ASCEND_HOME_PATH}/opp/built-in/op_impl/ai_core/tbe/op_tiling/lib/linux/aarch64:${LD_LIBRARY_PATH}"
ENV MLIR_PYTHON_ROOT="${LLVM_INSTALL_DIR}/python_packages/mlir_core"

ENV BISHENG_OPTS="-I${PTO_LIB_PATH}/include/pto -fPIC -shared -O2 -std=c++17 --npu-arch=dav-2201 -DMEMORY_BASE"

WORKDIR /workspace

CMD ["/bin/bash"]
Loading