Installation and Environment¶
PyPTO-Lib is a source repository rather than an installable Python package.
Run its scripts from the repository root with that root on PYTHONPATH.
Four external components sit under it, and the PyPTO checkout you select pins every one of them:
| Component | How it is installed | Version source |
|---|---|---|
| PyPTO | pip install the checkout |
the checkout you clone |
| simpler | pip install PyPTO's runtime/ |
PyPTO's runtime/ submodule |
| PTOAS | binary release under PTOAS_ROOT |
PyPTO's toolchain/versions.env |
| PTO ISA | cloned automatically on first use | PyPTO's runtime/pto_isa.pin |
Install what the selected PyPTO revision points at. Do not copy a PTOAS version or a PTO ISA commit from an old log or hard-code one in a setup script.
Prerequisites¶
- Python 3.10 or newer, Git, CMake, Ninja, and a C++17 compiler —
pip installbuilds PyPTO's C++ core. - Simulator platforms compile C++23:
gcc-15andg++-15must resolve to GCC 15 or newer (gcc-15 -dumpversion). - Real-device runs additionally need CANN and an Ascend device matching the
platform passed to
-p. Simulator runs need neither.
Python environment¶
From the PyPTO-Lib repository root:
python3 -m venv .venv
source .venv/bin/activate
python -m pip install --upgrade pip
python -m pip install scikit-build-core nanobind cmake ninja
python -m pip install torch --index-url https://download.pytorch.org/whl/cpu
export PYTHONPATH="$PWD${PYTHONPATH:+:$PYTHONPATH}"
Install torch before PyPTO, and from the CPU index: PyPTO resolves
torch>=2.0.0 to the default wheel otherwise, which drags in the whole CUDA
stack that nothing here uses. PYTHONPATH is the only variable the repository
itself needs — entry scripts import the golden/ harness from the repository
root while running from their own directory.
CANN (real devices only)¶
Skip this section for a simulator-only environment.
Driver and firmware belong to the machine, need root, and are normally already
there — they are what provides npu-smi. Check before installing anything; if
this fails, the host is missing the Ascend HDK packages and that is an
administrator task:
The toolkit is what PyPTO-Lib builds against, and a plain user can install it.
Download Ascend-cann-toolkit_<version>_linux-<arch>.run from the
community release page,
matching the driver above (cat /usr/local/Ascend/driver/version.info); device
runs in this repository currently use CANN 9.0.0.
# Packages the .run installer checks for
python -m pip install attrs numpy decorator sympy cffi pyyaml pathlib2 psutil protobuf scipy requests absl-py
chmod +x Ascend-cann-toolkit_<version>_linux-<arch>.run
./Ascend-cann-toolkit_<version>_linux-<arch>.run --install
# A root install lands in /usr/local/Ascend/ascend-toolkit/latest
export CANN_ROOT="$HOME/Ascend/ascend-toolkit/latest"
source "$CANN_ROOT/set_env.sh"
set_env.sh exports ASCEND_HOME_PATH, where simpler looks for the two
compilers it builds the onboard runtime with. Both must be present, or simpler
builds the simulator platforms only and every device platform is rejected
later:
test -x "$ASCEND_HOME_PATH/bin/ccec" # AICore
test -f "$ASCEND_HOME_PATH/tools/hcc/bin/aarch64-target-linux-gnu-g++" # AICPU
The toolkit is the only CANN package needed: PyPTO-Lib generates and assembles
its own kernels, and the runtime links only ACL and HCCL, so
Ascend-cann-kernels-* and NNAL are not required.
PyPTO and the runtime¶
git clone --recurse-submodules https://github.com/hw-native-sys/pypto.git ../pypto
export PYPTO_ROOT="$(cd ../pypto && pwd)"
python -m pip install --no-build-isolation "$PYPTO_ROOT"
# Default to simulation; select a2a3 or a5 for a device, or a5sim for A5 simulation.
RUNTIME_PLATFORM=a2a3sim
python -m pip install --no-build-isolation "$PYPTO_ROOT/runtime" \
--config-settings="build.targets=build_package_${RUNTIME_PLATFORM}"
runtime/ is the simpler submodule this PyPTO revision pins; installing from
that path keeps build and runtime at the same revision. The explicit build target
includes both the Python binding and the selected platform's runtime binaries.
Choose the NPU architecture and device/simulator mode, not the host CPU
architecture: aarch64 and x86_64 do not distinguish A2/A3 from A5.
An unrestricted install can also build A5 on an A2/A3 host. A5 onboard builds
require a CANN SDK with HCCL channel-config APIs, including
HcclChannelAcquireWithConfig; selecting a2a3 or a simulator target avoids
requiring those APIs for a job that does not use A5. A5 jobs still need a
compatible SDK.
CI passes this choice through the setup action's runtime-platform input for
both wheel builds and direct installs. The simpler wheel cache includes the
selected platform and, for device builds, the CANN SDK identity.
For device targets, source CANN before installing the runtime. The simpler
installer builds the selected onboard binaries with the compilers it finds at
install time. Simulator targets do not require CANN. To switch targets, select
the new RUNTIME_PLATFORM and rerun the targeted runtime installation above.
PTOAS¶
Take the pinned version from the same PyPTO checkout and unpack that release:
version=$(grep '^PTOAS_VERSION=' "$PYPTO_ROOT/toolchain/versions.env" | cut -d= -f2)
echo "$version" # e.g. v0.57
curl -fL -O "https://github.com/hw-native-sys/PTOAS/releases/download/$version/ptoas-bin-$(uname -m).tar.gz"
mkdir -p ../ptoas-bin
tar -xzf "ptoas-bin-$(uname -m).tar.gz" -C ../ptoas-bin
export PTOAS_ROOT="$(cd ../ptoas-bin && pwd)"
The bundle carries its own CPython, so it need not match the venv's Python; the
release also ships cp310–cp312 wheels, which work when installed into a
dedicated venv that PTOAS_ROOT then points at. While PTOAS_ROOT is set only
that directory is searched, so a ptoas earlier on PATH cannot shadow the
pinned one.
PTO ISA¶
Nothing to clone by hand, and nothing to point at. simpler owns the single
managed checkout — build/pto-isa under the installed simpler_setup package
— and $PYPTO_ROOT/runtime/pto_isa.pin is the only thing that selects its
revision. PyPTO delegates to that resolver rather than keeping one of its own:
pypto.runtime.pto_isa_include_dir() returns the include directory a kernel
needs. PTO_ISA_ROOT is exported with the resolved path but never read back,
so setting it cannot substitute a different tree.
The checkout is cloned on first use, so the first device build in a fresh
environment pauses on a git clone — on a slow or blocked network that looks
like a hang. Seeding that path with a symlink to an existing pto-isa at the
pinned commit avoids the wait; a checkout that is dirty or off the pin is
re-cloned rather than reused in place.
Verify¶
Check the imports, then run the smoke test for the selected RUNTIME_PLATFORM:
For a simulator target (a2a3sim or a5sim):
For a device target (a2a3 or a5), use a shell carrying PYTHONPATH,
PTOAS_ROOT, and the same CANN environment simpler was built against:
The selected example ends in a [RUN] PASS line after exercising the front end,
PTOAS, and the installed runtime on the selected simulator or device.
Then proceed to Run your first kernel.
Troubleshooting¶
| Symptom | Check |
|---|---|
ModuleNotFoundError: golden |
Run from the repository root and export that root in PYTHONPATH. |
ModuleNotFoundError: pypto |
Activate the intended environment and reinstall the selected PyPTO checkout. |
RuntimeError: pybind11 pip package not found, from a pypto under $CANN_ROOT/python/site-packages |
CANN 9.2 and newer ship their own pypto, and set_env.sh puts that directory on PYTHONPATH ahead of your environment. Check with python -c 'import pypto; print(pypto.__file__)', then put your own site-packages first on PYTHONPATH — the selected checkout is the only pypto this repository builds against. |
| PTOAS cannot be found | PTOAS_ROOT must be exported and hold ptoas.sh (bundle) or bin/ptoas (wheel venv). |
The first device build stalls on a git clone |
It is fetching pto-isa. On a blocked network, seed the checkout the error names, or symlink an existing clone. |
Simulator compilation cannot find g++-15 |
Install GCC 15, or provide gcc-15 / g++-15 wrappers for the active compiler. |
A device platform is rejected, or the onboard runtime will not initialize, while a2a3sim works |
simpler was installed without CANN. Source set_env.sh, confirm the two compilers above, then reinstall $PYPTO_ROOT/runtime. |