Skip to main content

A JIT compiler for Numpy-based Python programs and bindings for stateful dataflow multigraphs (SDFG).

Project description

Python Bindings and Frontend

This component provides Python bindings via pybind11 to build SDFGs with Python. Additionally, this component provides the @native decorator, which automatically converts Python functions into SDFGs and codegens them for the available target.

  • Bindings: Build SDFGs programmatically with Python
  • AST Parser: Automatically compile Python/NumPy code to optimized native code
  • Targets: Support for CPU (sequential, OpenMP, SIMD via Highway), CUDA GPUs, and other accelerators

Build from Sources

To build the Python component from sources run pip on the component's directory:

pip install -e python/

Requirements

Python Dependencies

  • Python >= 3.11
  • NumPy >= 1.19.0

System Dependencies

The following system dependencies must be installed (same as core components):

sudo apt-get install -y libgmp-dev libzstd-dev
sudo apt-get install -y nlohmann-json3-dev
sudo apt-get install -y libboost-graph-dev libboost-graph1.74.0
sudo apt-get install -y libisl-dev

Compiler Requirements

Clang/LLVM 19 is required for code generation. Install it with:

# Ubuntu/Debian
sudo apt-get install -y clang-19 llvm-19

For CUDA support, you also need the NVIDIA CUDA Toolkit installed.

Usage

The @native Decorator

The @native decorator is the primary way to use the Python frontend. It automatically:

  1. Parses the Python function's AST
  2. Converts it to an SDFG representation
  3. Applies optimizations based on the target
  4. Compiles to native code
  5. Executes and returns results

Basic Example

from docc.python import native
import numpy as np

@native
def vector_add(A, B, C, N):
    for i in range(N):
        C[i] = A[i] + B[i]

# Usage
N = 1024
A = np.random.rand(N).astype(np.float64)
B = np.random.rand(N).astype(np.float64)
C = np.zeros(N, dtype=np.float64)

vector_add(A, B, C, N)  # JIT compiles and executes

Compilation Targets

The @native decorator accepts a target parameter to specify the code generation backend:

target="none" (Default)

No scheduling or optimization is applied. The SDFG is compiled as-is without parallelization. Useful for debugging or when you want to manually control the generated code.

@native(target="none")
def simple_loop(A, B, N):
    for i in range(N):
        B[i] = A[i] * 2.0

target="sequential"

Generates optimized sequential code with SIMD vectorization using Google Highway. This target automatically vectorizes eligible loops using portable SIMD intrinsics.

import math

@native(target="sequential")
def vectorized_sin(A, B):
    for i in range(A.shape[0]):
        B[i] = math.sin(A[i])

# Highway automatically vectorizes the sin computation
N = 128
A = np.random.rand(N).astype(np.float64)
B = np.zeros(N, dtype=np.float64)
vectorized_sin(A, B)

Supported Highway operations include:

  • Trigonometric: sin, cos, asin, acos, atan, atan2
  • Exponential: exp, log, log10, log2, pow
  • Hyperbolic: sinh, cosh, tanh, asinh, acosh, atanh
  • Other: sqrt, abs, floor, ceil, round

target="openmp"

Generates parallel code using OpenMP. Suitable for multi-core CPUs. Loops are automatically parallelized with appropriate scheduling.

@native(target="openmp", category="desktop")
def parallel_add(A, B, C, N):
    for i in range(N):
        C[i] = A[i] + B[i]

# Executes in parallel across CPU cores
N = 1000000
A = np.random.rand(N).astype(np.float64)
B = np.random.rand(N).astype(np.float64)
C = np.zeros(N, dtype=np.float64)
parallel_add(A, B, C, N)

target="cuda"

Generates CUDA code for NVIDIA GPUs. Loops are mapped to GPU thread blocks and threads.

@native(target="cuda", category="server")
def gpu_add(A, B, C, N):
    for i in range(N):
        C[i] = A[i] + B[i]

# Executes on GPU (data is automatically transferred)
N = 1024
A = np.random.rand(N).astype(np.float64)
B = np.random.rand(N).astype(np.float64)
C = np.zeros(N, dtype=np.float64)
gpu_add(A, B, C, N)

The category Parameter

The category parameter provides hints to the scheduler about the target hardware:

  • "edge"
  • "desktop"
  • "server"
@native(target="openmp", category="desktop")
def cpu_kernel(A, B):
    ...

@native(target="cuda", category="server")
def gpu_kernel(A, B):
    ...

Advanced: Manual Compilation

For more control, you can manually compile and cache the SDFG:

@native(target="openmp")
def my_kernel(A, B, C, N):
    for i in range(N):
        C[i] = A[i] + B[i]

# Pre-compile with sample arguments
compiled = my_kernel.compile(A, B, C, N)

# Reuse compiled version
result = compiled(A, B, C, N)

# Access the underlying SDFG
sdfg = my_kernel.last_sdfg

License

This component is part of docc and is published under the BSD-3-Clause license. See LICENSE for details.

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

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

docc_compiler-0.0.8-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (13.1 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

docc_compiler-0.0.8-cp314-cp314-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl (12.3 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.27+ ARM64manylinux: glibc 2.28+ ARM64

docc_compiler-0.0.8-cp314-cp314-macosx_14_0_arm64.whl (3.8 MB view details)

Uploaded CPython 3.14macOS 14.0+ ARM64

docc_compiler-0.0.8-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (13.1 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

docc_compiler-0.0.8-cp313-cp313-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl (12.3 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.27+ ARM64manylinux: glibc 2.28+ ARM64

docc_compiler-0.0.8-cp313-cp313-macosx_14_0_arm64.whl (3.8 MB view details)

Uploaded CPython 3.13macOS 14.0+ ARM64

docc_compiler-0.0.8-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (13.1 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

docc_compiler-0.0.8-cp312-cp312-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl (12.3 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.27+ ARM64manylinux: glibc 2.28+ ARM64

docc_compiler-0.0.8-cp312-cp312-macosx_14_0_arm64.whl (3.8 MB view details)

Uploaded CPython 3.12macOS 14.0+ ARM64

docc_compiler-0.0.8-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (13.1 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

docc_compiler-0.0.8-cp311-cp311-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl (12.3 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.27+ ARM64manylinux: glibc 2.28+ ARM64

docc_compiler-0.0.8-cp311-cp311-macosx_14_0_arm64.whl (3.8 MB view details)

Uploaded CPython 3.11macOS 14.0+ ARM64

File details

Details for the file docc_compiler-0.0.8-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for docc_compiler-0.0.8-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 911b895f498d9762334d8c8d0eef8a5a2945dc98d428390aff388e1529044993
MD5 684436009b22e324589368aa76e1c45d
BLAKE2b-256 c484374bce3581dcb137f208a9c22f6e95730a17588cd1787bbd0d5a9ceb2254

See more details on using hashes here.

File details

Details for the file docc_compiler-0.0.8-cp314-cp314-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for docc_compiler-0.0.8-cp314-cp314-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 45762b9db60bccfb355f5da7e0ed8a793fe50553ee60c10a17b991d75aca780d
MD5 e7c1e389b874bb5b0009f0b0882ab6b4
BLAKE2b-256 b56e911e4d95d2134a95dbfebda9ca4bb4c3a1ca3b65a212959e2951683b8846

See more details on using hashes here.

File details

Details for the file docc_compiler-0.0.8-cp314-cp314-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for docc_compiler-0.0.8-cp314-cp314-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 89d47e7ee800159b978090b9469fd980da7fc51f381fbccf0eb1bb34d660b5e4
MD5 02ff73f199cdd76787b1823bb8d5570f
BLAKE2b-256 6752ddf2dba9fea59512b743862bc3405412aa362528526ec4231747fba46d93

See more details on using hashes here.

File details

Details for the file docc_compiler-0.0.8-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for docc_compiler-0.0.8-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 f1cafa0af5c80998f3952e9df7d7161b37215de1179038e30a60ee53f5f8bbab
MD5 354701610cde2758fb5b3bd91a0c8a78
BLAKE2b-256 5cf5993b3112fd538760b77d1d029d50c5a8c3ab8aaa58529e2405ae6d22f928

See more details on using hashes here.

File details

Details for the file docc_compiler-0.0.8-cp313-cp313-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for docc_compiler-0.0.8-cp313-cp313-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 39bf0a115a07ac440e172c1bc232ea2354c673ceb1115cfa054addb30305cfcc
MD5 efe9307400c826245dcc328263eb1fe4
BLAKE2b-256 dc7d949d5a276bd4211f4168fe348c5592a20e0089bd86693782499de815c239

See more details on using hashes here.

File details

Details for the file docc_compiler-0.0.8-cp313-cp313-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for docc_compiler-0.0.8-cp313-cp313-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 56249cc53ecec1e2222f27ce1c24e9cc609ab01a6e6228b3c8d8d05aeb309a54
MD5 b4093e2e6def4da9e37944019d52e807
BLAKE2b-256 d110086d1edf12576e181ff028882e5391abe3685ec4c82b2d945c2d5c27ec18

See more details on using hashes here.

File details

Details for the file docc_compiler-0.0.8-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for docc_compiler-0.0.8-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 634e521c3727cd2cb6d21f44d3e7ec0062b9201f28c5da3b7e98b66c9ab35978
MD5 0e99913b40a238319631c222725b5231
BLAKE2b-256 b0a603a0080706ea7e5a9f62b23b67f4a9a9abc36d80b16d5993b23676960928

See more details on using hashes here.

File details

Details for the file docc_compiler-0.0.8-cp312-cp312-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for docc_compiler-0.0.8-cp312-cp312-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 44a1be635a0719b6ece24238dc68a0d5ac0c342696e0e3c5ebdbf14ac927cf4c
MD5 c90dddf711a77536a4565689d48c036b
BLAKE2b-256 60f220d6a27341492358662ce06dc2db7f18c5a09bf09648c848202de43110ac

See more details on using hashes here.

File details

Details for the file docc_compiler-0.0.8-cp312-cp312-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for docc_compiler-0.0.8-cp312-cp312-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 aec17680fdf3fa34e681fc6ee9f8c201be0a4cd60a49e4cdd3dfdb7860177d83
MD5 a50caf8830e0814a98b3bc467bf7f226
BLAKE2b-256 58d0e32b72ec5ae37b4c95257a33979eb55830697b13ed2b4ac65650d3fe63d0

See more details on using hashes here.

File details

Details for the file docc_compiler-0.0.8-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for docc_compiler-0.0.8-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 51455acf9e8e5b779220d51b4a03a33cf914bc34d40524cc4b0680b3b0643173
MD5 434369b427405e82f3be943ce6a51ba0
BLAKE2b-256 5006f51fa0c2a79192f846c70d170b3c540f38457e64f49accb0f8554492360c

See more details on using hashes here.

File details

Details for the file docc_compiler-0.0.8-cp311-cp311-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for docc_compiler-0.0.8-cp311-cp311-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 c1a474efef6435e80be201232c463260b3d95dd32e3e941c4c7f59928353502a
MD5 d0d94d934054260cf3d3d8cdb9db5191
BLAKE2b-256 5577549e456392a6b8942c6e44d645c3a0b5ff77503ae516aa1388ad206064ef

See more details on using hashes here.

File details

Details for the file docc_compiler-0.0.8-cp311-cp311-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for docc_compiler-0.0.8-cp311-cp311-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 9bb852d7124ebe5894a28e1bbb18417a863759aaa7d100bf9dda20cc50cd98d1
MD5 bb9a640feaf4d7264eff4bc5f8276e95
BLAKE2b-256 c2e565a34c5fd8d930dda897e87d2c0fc26caef86dcb00fe9100114bce7a2705

See more details on using hashes here.

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