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.6-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (13.0 MB view details)

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

docc_compiler-0.0.6-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.6-cp314-cp314-macosx_14_0_arm64.whl (3.8 MB view details)

Uploaded CPython 3.14macOS 14.0+ ARM64

docc_compiler-0.0.6-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (13.0 MB view details)

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

docc_compiler-0.0.6-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.6-cp313-cp313-macosx_14_0_arm64.whl (3.7 MB view details)

Uploaded CPython 3.13macOS 14.0+ ARM64

docc_compiler-0.0.6-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (13.0 MB view details)

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

docc_compiler-0.0.6-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.6-cp312-cp312-macosx_14_0_arm64.whl (3.7 MB view details)

Uploaded CPython 3.12macOS 14.0+ ARM64

docc_compiler-0.0.6-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (13.0 MB view details)

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

docc_compiler-0.0.6-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.6-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.6-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for docc_compiler-0.0.6-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 9a15c7c2c9773a7b0901f471c0ca3605ce1d047ee2851e035a2acadaf4764e2a
MD5 b6c522396c84fded3008d6651f28f75e
BLAKE2b-256 73ca485ddae8b1a90e4b715da7d186e57394154d02ade30671dcf39a52302c57

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for docc_compiler-0.0.6-cp314-cp314-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 7760b972cd069be6397a27cee9edcd3d8c18005fdc24306e7cfe094aa50140b5
MD5 7f21a67fd7003994b7f8d8a584a83df4
BLAKE2b-256 b8db004d3bf1ff316f2b7468147f73efa1590dee14c889e09b7f1dc86af98bd4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for docc_compiler-0.0.6-cp314-cp314-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 c1668d30f46404172f093aa8c78dd7d5d2a61212689e0cf8202e57f43268e158
MD5 75ce66e02d7a8ab687c2143b20eb1f37
BLAKE2b-256 405e98b9029e70d642d285554d15e07fa74e81dd3bd5622f6e646552cc832882

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for docc_compiler-0.0.6-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 e7ac7db03e5942f896d1dc0b6583ba606402cee7a32bb638fc5dc0c72c70bf7f
MD5 f49927050a917bfc3493517deff23403
BLAKE2b-256 63a573d611ade6220b8bd0f4dc49a3f030074de0ad524e7eb761b20c04101c66

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for docc_compiler-0.0.6-cp313-cp313-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 3644355fbe12ecfe10a1698c191067325516164f3771012a0517fcd378e68096
MD5 a09ed8a3d2decbf6a33082de7e62960f
BLAKE2b-256 0b85ecfdc6c75bb2383748b9aa02250daf769d676e0f655b5e74bf1c0fe8c08a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for docc_compiler-0.0.6-cp313-cp313-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 5fe3f3c9a8477fd4d56f952528732edce81913254cb839940166a7bcffaca5f5
MD5 cdc30ba8dc694fa8e7f2eeeeb17b3185
BLAKE2b-256 697046fc1f0b555357d4ef28de6e1b44011ac33230f5bd705d150174b946aacc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for docc_compiler-0.0.6-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 d269e3865e312c7e67d0fa5d9cca5a43704bb87ac66de0371d1d875992e7d36c
MD5 a9bcd0d211202254dc7a24c492a71206
BLAKE2b-256 6c9a5f21feb2be9914bd12176ff5e0a8ff696fc4ff28d955edee89cb9e418ba5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for docc_compiler-0.0.6-cp312-cp312-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 79330c5995b5f9113dd8ffb7a763245bd2abbe34ee5889731e4603420aa8073c
MD5 5a876d3009f42c51c56a0af03fb4e9e0
BLAKE2b-256 de328b8ba4f00e11a0304be42e25a5b60ef258a119689725945356c065e00d2d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for docc_compiler-0.0.6-cp312-cp312-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 0649bdab7421b70bb9d2130c9e36f09a0ead24551f1aed170a43668bedeb047e
MD5 7735be3dd8103fd9e8b87c431abc2d69
BLAKE2b-256 c88fa3738f719b4311b917ae228ae3efde6bb8fce8459e159bc542ae30eb266b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for docc_compiler-0.0.6-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 192ebab15d70829c254584f0eb11854763dbdbc53d067c961b06e7b2c068ca02
MD5 fdd13d77d7087f63678007f261bab569
BLAKE2b-256 07f2a8cce4a6d39eb28bca9f69529feb695f8fabea3bfaf3cf5e5cd32fc71f37

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for docc_compiler-0.0.6-cp311-cp311-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 ff13279bea2084417a9b9f4132cd336141d298e5fe7d25f52f866693980243a1
MD5 20fc530632885c766f8de4dd2501ef5a
BLAKE2b-256 035501615963fc6ab4507797adf4bc42487082db72d8c17f5308af40092577ea

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for docc_compiler-0.0.6-cp311-cp311-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 9fa26879e00d426a17aba2aad050dd618ae599552ce41d6ab91fd53ac4beba50
MD5 1c0c66461d9842c1a74b9a8dbcaa25e7
BLAKE2b-256 94c14e8c4717a4c5e3a72b955097a3f2125f00de8a09957e253d4bb3879ae698

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