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
  • SciPy >= 1.7.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.4-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (12.8 MB view details)

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

docc_compiler-0.0.4-cp314-cp314-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl (12.1 MB view details)

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

docc_compiler-0.0.4-cp314-cp314-macosx_14_0_arm64.whl (3.7 MB view details)

Uploaded CPython 3.14macOS 14.0+ ARM64

docc_compiler-0.0.4-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (12.8 MB view details)

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

docc_compiler-0.0.4-cp313-cp313-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl (12.1 MB view details)

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

docc_compiler-0.0.4-cp313-cp313-macosx_14_0_arm64.whl (3.7 MB view details)

Uploaded CPython 3.13macOS 14.0+ ARM64

docc_compiler-0.0.4-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (12.8 MB view details)

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

docc_compiler-0.0.4-cp312-cp312-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl (12.1 MB view details)

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

docc_compiler-0.0.4-cp312-cp312-macosx_14_0_arm64.whl (3.7 MB view details)

Uploaded CPython 3.12macOS 14.0+ ARM64

docc_compiler-0.0.4-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (12.8 MB view details)

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

docc_compiler-0.0.4-cp311-cp311-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl (12.1 MB view details)

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

docc_compiler-0.0.4-cp311-cp311-macosx_14_0_arm64.whl (3.7 MB view details)

Uploaded CPython 3.11macOS 14.0+ ARM64

File details

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

File metadata

File hashes

Hashes for docc_compiler-0.0.4-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 78d368d8f820cb793b0b8ef87f0c0bbd068cd5cf644e92ae569d28abe86fafca
MD5 7999ae73fb1a756ee1e75fd8a371df1c
BLAKE2b-256 013d025f08344c9b6a3e12d98c4cf6f5e2dac48b854e8c524c53e68e9ac585a5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for docc_compiler-0.0.4-cp314-cp314-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 178bc44eb97f4cd2bc277127bd309834aee64e4e832ffbb466dd949b0ef2cce6
MD5 97f52874b9a8028a84cc48967afbdc4b
BLAKE2b-256 99d980a97c3b2ee4bad3b4173aed8fe328a83795b6f7f2aa579e34b301307e42

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for docc_compiler-0.0.4-cp314-cp314-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 c587f916a04f08e3f8ddfdf977915d0cc7a117ead3107a280c6a69d16f1c1c18
MD5 76371c9132f26a7c7a9d917991a3367a
BLAKE2b-256 a38d62485141e814df3f2babdee5fc022c4df04b72138d75913b45eb19c56da1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for docc_compiler-0.0.4-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 84e738f2f4d0e4202b5a1106224101ae3a9b4f727efd7fc8b0c96317882a54c4
MD5 227eddedbbdc1a355ddb2cf8885863fa
BLAKE2b-256 d768dc12a7d4c0ceccd67199fe1971f92d468506a2f5f1bd4a40bb4c5bc3933a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for docc_compiler-0.0.4-cp313-cp313-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 42df7bc7a61072d8bbee6c62ffe86612fedd329ce5884c2e379af2c06c1bd35b
MD5 aaa63d8ecf0e6493650bb26de91b7828
BLAKE2b-256 fb95ed315dbcaebd90e958d18e1a4ce0355767efaefdf460f1904eec73fb55a6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for docc_compiler-0.0.4-cp313-cp313-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 a6965a5fa06d80a4c137c5ccbcdeff4393911caf3abc0e0d1eb2f3eddc311e85
MD5 0e25bb129c90f65ff4c7f6521b9c5c5c
BLAKE2b-256 7b6bab954342c847c5bb9c6f014ed04248e675c3fd6afbe4fc0d08888c3bef1f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for docc_compiler-0.0.4-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 f152b3c4a42fad7461f354dc44dbd5333dbb06e2c195651bc6f46fc4671b4c36
MD5 09afbffad1aa5b9a9b50f6b9e5369e96
BLAKE2b-256 e51b97b0342cc93e459b35c6239ca9605afcbb7e5e308c74db705434f3be1fe1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for docc_compiler-0.0.4-cp312-cp312-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 ba7ef14470db9a4bd8948fcb2d48ccc87cf121dfc4260d8a21611fd667aa4392
MD5 3ddb5938aae91a35efbae091e381aa39
BLAKE2b-256 0418ce01068f3d3fca0f3dce6a472c242901d60dbc0b0116cb6b23ee5b8c9369

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for docc_compiler-0.0.4-cp312-cp312-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 ade0f6965f9474249dcff945b05032232965af17d211c15e637c00e2c89f2520
MD5 a92893463df738fbb54f5f63a6e8cb3a
BLAKE2b-256 4c362dd9e935e2f3ff1ddc5eecb97b608c6167fc5d59c825c82656e16aec84b5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for docc_compiler-0.0.4-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 9db9b5b246b1dfbc6993f6c996757d5f5c4072351b54f3b4d1a3b034f9d160d8
MD5 08b0684911887e4f59cb473348710831
BLAKE2b-256 84f586fd361387ad7d0c1e0172e09d4c57dc914af993144ea2f3c4c9ef540a25

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for docc_compiler-0.0.4-cp311-cp311-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 dacc6038ee7f0ed1f5e5128a1020998087bb7564f69f8306883dd80eeb253cc3
MD5 208a54b2864c7e20d9697b1aea77d6de
BLAKE2b-256 82c321f8b18eddcf0a468a9acb93e5d981ff0cbf9a31962dea5bfd55b9f7224d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for docc_compiler-0.0.4-cp311-cp311-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 5ed3d242699b278211c482a63f4a497c70bf3d2dc9facac899061f3b5e559828
MD5 340e539e59983b3da9bef3cc2c25c971
BLAKE2b-256 447ff6f056b88c322c26c39ac63bbf570f90001c7ef2e9a4dec8761f9b3ffe7d

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