Skip to main content

pto-kernels

PyPI version Python versions License

A collection of high-performance custom kernels for Ascend NPUs, built on top of pto-isa — the Parallel Tile Operation virtual instruction set architecture designed by Ascend CANN.

PTO focuses on tile-level operations, enabling efficient, composable kernel development targeting Huawei's Ascend AI processors, and ships as ready-to-use PyTorch (torch-npu) operators.


Why pto-kernels?

  • Fast — hand-tuned tile-level kernels for Ascend NPUs, benchmarked against torch-npu built-ins.
  • Drop-in — kernels are exposed as plain Python functions that operate on torch_npu tensors.
  • Broad coverage — everything from elementwise ops (abs, swiglu) to linear-algebra primitives (tri_inv, matmul) to gated-linear-attention building blocks (GDN, KDA chunked recurrence, WY representation, KKT).
  • Extensible — built on pto-isa, so new kernels can be written once at the tile level and reused across ops.

Installation

From PyPI (recommended)

Prebuilt wheels are published to PyPI for Python 3.10–3.12 on x86_64 and aarch64:

pip install pto-kernels

Requires a working torch-npu + Ascend CANN runtime environment to run kernels on-device; the package itself installs without one.

From source

Building from source is only needed for unreleased kernels or if you plan to contribute.

Prerequisites:

  • A configured torch-npu environment
  • Ascend toolkit installed at /usr/local/Ascend/ascend-toolkit
# One-time setup
make setup_once

# Install directly from GitHub
export CMAKE_GENERATOR="Unix Makefiles"
pip install -v git+https://github.com/huawei-csl/pto-kernels.git

Or build a wheel locally:

source /usr/local/Ascend/ascend-toolkit/set_env.sh
pip3 install -r requirements.txt
make wheel                          # produces pto_kernels-X.Y.Z-*.whl
pip install --force-reinstall pto_kernels-*.whl

Quickstart

import torch
import torch_npu  # noqa
from pto_kernels import pto_swiglu

x = torch.randn(4, 2048, device="npu", dtype=torch.float16)
y = pto_swiglu(x)  # fused SwiGLU on Ascend NPU

Available kernels

Category Kernels
Elementwise / activation pto_abs, pto_swiglu
Attention pto_flash_attention
Linear algebra pto_simple_matmul, pto_batch_matrix_square, pto_tri_inv, pto_tri_inv_ns, pto_tri_inv_rec_unroll, pto_tri_inv_trick
Scan / gather pto_scan_ul1, pto_csr_gather
GDN (Gated DeltaNet) pto_gdn_chunk_cumsum, pto_gdn_chunk_o, pto_gdn_scaled_dot_kkt, pto_gdn_wy_fast
KDA (Kimi Delta Attention) pto_kda_chunk_h, pto_kda_chunk_o, pto_kda_gate_cumsum, pto_kda_kkt, pto_kda_wy

More end-to-end usage patterns live under examples/ (JIT C++ kernels, AI CPU custom ops) and tests/ (correctness against reference/torch_npu implementations).


Testing

make test

Repository structure

pto-kernels/
├── csrc/                  # C++ kernel source files
├── python/pto_kernels/    # Python bindings and utilities
├── examples/jit_cpp/      # JIT compilation examples
├── examples/aicpu/        # AI CPU custom-op examples
├── tests/                 # Test suite
├── scripts/               # Helper scripts
├── doxygen/               # API documentation config
└── CMakeLists.txt         # CMake build configuration

Contributing

Contributions are welcome! Whether it's a new kernel, a bug fix, or a benchmark, please read CONTRIBUTING.md before opening a pull request.

Release process

See RELEASE.md for how new versions are cut and published.

License

BSD-3-Clause-Clear — see LICENSE for details.

Metadata

Release files for pto-kernels 0.1.7

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distributions (wheels)

Table of built distributions (wheels) for pto-kernels 0.1.7
File
pto_kernels-0.1.7-cp312-cp312-manylinux_2_34_x86_64.whl CPython 3.12 CPython 3.12 Linux glibc 2.34+ x86-64 Details
pto_kernels-0.1.7-cp312-cp312-manylinux_2_34_aarch64.whl CPython 3.12 CPython 3.12 Linux glibc 2.34+ ARM64 Details
pto_kernels-0.1.7-cp311-cp311-manylinux_2_34_x86_64.whl CPython 3.11 CPython 3.11 Linux glibc 2.34+ x86-64 Details
pto_kernels-0.1.7-cp311-cp311-manylinux_2_34_aarch64.whl CPython 3.11 CPython 3.11 Linux glibc 2.34+ ARM64 Details
pto_kernels-0.1.7-cp310-cp310-manylinux_2_34_x86_64.whl CPython 3.10 CPython 3.10 Linux glibc 2.34+ x86-64 Details
pto_kernels-0.1.7-cp310-cp310-manylinux_2_34_aarch64.whl CPython 3.10 CPython 3.10 Linux glibc 2.34+ ARM64 Details

Total release size: 54.0 MB

Release files / pto_kernels-0.1.7-cp312-cp312-manylinux_2_34_x86_64.whl

Download URL pto_kernels-0.1.7-cp312-cp312-manylinux_2_34_x86_64.whl
Size 9.0 MB
Tags CPython 3.12 Linux glibc 2.34+ x86-64
SHA-256 checksum
How to use checksums
d40438c17192c40ef9334ca967f8e8a2e2989c74234647bb0ec8cb9652a93d7b
BLAKE2b-256 checksum
How to use checksums
299b0bf57d417ea6edd1dee465207ceb4c04d821aab53045802e83da29c9d563
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.10.12

Release files / pto_kernels-0.1.7-cp312-cp312-manylinux_2_34_aarch64.whl

Download URL pto_kernels-0.1.7-cp312-cp312-manylinux_2_34_aarch64.whl
Size 9.0 MB
Tags CPython 3.12 Linux glibc 2.34+ ARM64
SHA-256 checksum
How to use checksums
8eb78d0e8583659678906097852c0270b8053701e71774a89b8fecfe4ab59745
BLAKE2b-256 checksum
How to use checksums
8f7be75e0c096b0022cad275d5529722c20d1ce6be15e39beeda96c1ef28e464
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.10.12

Release files / pto_kernels-0.1.7-cp311-cp311-manylinux_2_34_x86_64.whl

Download URL pto_kernels-0.1.7-cp311-cp311-manylinux_2_34_x86_64.whl
Size 9.0 MB
Tags CPython 3.11 Linux glibc 2.34+ x86-64
SHA-256 checksum
How to use checksums
ec44192025c91d3de9e28258ead579fcd3445b27d378010d2b2b0439fcbf4c14
BLAKE2b-256 checksum
How to use checksums
b626bf244a325abb842bcd98776dd71469179a005d26971fb410f080c4092962
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.10.12

Release files / pto_kernels-0.1.7-cp311-cp311-manylinux_2_34_aarch64.whl

Download URL pto_kernels-0.1.7-cp311-cp311-manylinux_2_34_aarch64.whl
Size 9.0 MB
Tags CPython 3.11 Linux glibc 2.34+ ARM64
SHA-256 checksum
How to use checksums
92865f774b0ff8381883d7452eee17e32e1a40265cf52d3639a0e7177b947179
BLAKE2b-256 checksum
How to use checksums
d5d9a317b472f866ce77630231bfb8d23e642aea421978d54998536b36de49a1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.10.12

Release files / pto_kernels-0.1.7-cp310-cp310-manylinux_2_34_x86_64.whl

Download URL pto_kernels-0.1.7-cp310-cp310-manylinux_2_34_x86_64.whl
Size 9.0 MB
Tags CPython 3.10 Linux glibc 2.34+ x86-64
SHA-256 checksum
How to use checksums
aff89d636b66a29b2de770a0f48521cc520cf1bee33df6894d869acb81034300
BLAKE2b-256 checksum
How to use checksums
4fa628adcf40898af4840656bf5c7a7aa1a6d1c06612d7861620ab534680dcab
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.10.12

Release files / pto_kernels-0.1.7-cp310-cp310-manylinux_2_34_aarch64.whl

Download URL pto_kernels-0.1.7-cp310-cp310-manylinux_2_34_aarch64.whl
Size 9.0 MB
Tags CPython 3.10 Linux glibc 2.34+ ARM64
SHA-256 checksum
How to use checksums
f6b1edd8870e8896add40d6a5ba966bb8d2defafcd74f35dcb0cc1ed53e5a4ab
BLAKE2b-256 checksum
How to use checksums
869e647270df95c499c7ebef42ea7742f5858a2abeeb33f16ebcbbaecadcbccd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.10.12

Release history Release notifications | RSS feed

This release

0.1.7 This release

6 release files

0.1.5

5 release files

0.1.4

6 release files

0.1.2

2 release files

0.1.1

3 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page