Skip to main content

KPU (Knowledge Processing Unit) Simulator Python API

Project description

KPU Python Package

High-level Python API for the KPU (Knowledge Processing Unit) simulator with decorator-based compilation.

Quick Start

import kpu
import numpy as np

# Define a neural network with @kpu.compile
@kpu.compile
def mlp(x, w1, w2):
    h = kpu.relu(x @ w1)
    return h @ w2

# Create tensors
x = kpu.Tensor(np.random.randn(32, 784).astype(np.float32))
w1 = kpu.Tensor(np.random.randn(784, 128).astype(np.float32))
w2 = kpu.Tensor(np.random.randn(128, 10).astype(np.float32))

# Execute (computes actual values in BEHAVIORAL mode)
result = mlp(x, w1, w2)
print(result.shape)  # (32, 10)

# Inspect generated DFX IR
print(mlp.get_dfx().to_json())

Features

  • Decorator-based compilation: Use @kpu.compile to compile Python functions to KPU programs
  • NumPy-compatible tensors: kpu.Tensor wraps NumPy arrays with compilation support
  • Multi-fidelity simulation:
    • BEHAVIORAL: Computes actual values (functional correctness)
    • TRANSACTIONAL: Statistical timing model
    • CYCLE_ACCURATE: Full timing simulation
  • DFX IR generation: Inspectable intermediate representation

Supported Operations

Matrix Operations

  • @ (matmul): Matrix multiplication
  • kpu.linear: Linear layer (y = x @ W^T + b)

Activation Functions

  • kpu.relu: Rectified Linear Unit
  • kpu.gelu: Gaussian Error Linear Unit
  • kpu.silu: Sigmoid Linear Unit (Swish)
  • kpu.sigmoid: Sigmoid
  • kpu.tanh: Hyperbolic tangent
  • kpu.softmax: Softmax

Elementwise Operations

  • +, -, *, /: Arithmetic operations
  • kpu.exp, kpu.log, kpu.sqrt: Math functions

Reduction Operations

  • kpu.sum, kpu.mean: Aggregations

Installation

# From the kpu-sim repository
cd python
pip install -e .

# Run tests
pytest tests/ -v

Examples

See examples/mnist_mlp.py for a complete MNIST classifier example.

Architecture

Python Code with @kpu.compile
        ↓
    Tracing (build OpGraph)
        ↓
    DFX IR Emission
        ↓
    Runtime Execution
    ├── BEHAVIORAL (pure Python, computes values)
    ├── TRANSACTIONAL (C++ bindings, statistical)
    └── CYCLE_ACCURATE (C++ bindings, full timing)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

stillwater_kpu-0.5.6.tar.gz (46.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

stillwater_kpu-0.5.6-py3-none-any.whl (44.0 kB view details)

Uploaded Python 3

File details

Details for the file stillwater_kpu-0.5.6.tar.gz.

File metadata

  • Download URL: stillwater_kpu-0.5.6.tar.gz
  • Upload date:
  • Size: 46.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for stillwater_kpu-0.5.6.tar.gz
Algorithm Hash digest
SHA256 c3ed468720f0459f2113bfc0c458ea2fbb26ad0381b31c76de1d3fb5747aa953
MD5 49d59071be6a9d7d8cd7685751ba19a6
BLAKE2b-256 7befe52c85f6ba1dba168585dd3c788450553285fc82f1f3588b233d818bbb90

See more details on using hashes here.

Provenance

The following attestation bundles were made for stillwater_kpu-0.5.6.tar.gz:

Publisher: python-publish.yml on stillwater-sc/kpu-sim

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file stillwater_kpu-0.5.6-py3-none-any.whl.

File metadata

  • Download URL: stillwater_kpu-0.5.6-py3-none-any.whl
  • Upload date:
  • Size: 44.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for stillwater_kpu-0.5.6-py3-none-any.whl
Algorithm Hash digest
SHA256 3b368f97b07f4b27adf2cee0d3448ee7adc8cf738da8562e08d6b7330e9c45ed
MD5 154cc36a42bf38d8392aeb7020b48f73
BLAKE2b-256 c2740cae7cdaadb0a967fe956a3f0cd0ae08d3a7e73a99a2062426ac3c078db5

See more details on using hashes here.

Provenance

The following attestation bundles were made for stillwater_kpu-0.5.6-py3-none-any.whl:

Publisher: python-publish.yml on stillwater-sc/kpu-sim

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page