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.5-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.5-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.5-cp314-cp314-macosx_14_0_arm64.whl (3.7 MB view details)

Uploaded CPython 3.14macOS 14.0+ ARM64

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

Uploaded CPython 3.13macOS 14.0+ ARM64

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

Uploaded CPython 3.12macOS 14.0+ ARM64

docc_compiler-0.0.5-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.5-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.5-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.5-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for docc_compiler-0.0.5-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 6aabedd9ea555624ed12952e398147f3276e06bf7781d062decb93e46efeb5d3
MD5 871142d9cacc741eaaf966feea3fb784
BLAKE2b-256 cfb306f5ac5b2d3154017f81fd40fdcd37cd520e5572c40449ec6ea434efe560

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for docc_compiler-0.0.5-cp314-cp314-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 6a2d37230738fab1a72583931843cd2660a4292b598a5de08da7e8b063845190
MD5 d0ca6277959ea4410170c63a3785c54d
BLAKE2b-256 abc78a8b8c493e275eb7c23d3cdde8a156526dac8db35d7247eb2a8f4aac512c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for docc_compiler-0.0.5-cp314-cp314-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 d57784d6da2234a8d82e4fd6f7276319148986bc59fbe4687514c12c2d3a9151
MD5 0d3f5d2ecbbf3e18b796cf43657ef7e2
BLAKE2b-256 592d1d4685cdf21a3c4542ea6e4ec48dfb95b1a43669c3a110b95ea30ca161b2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for docc_compiler-0.0.5-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 03d302b0a38d464919219de91a1532d7ef1d14bf7b96aa4ed75341af14ebb1e2
MD5 66e26d1b7794c6e236c7e967d697bd64
BLAKE2b-256 7ecdc4ba0bc289adbffd64768d0b9bf4d5cb0a71b5645c2d2497e945b5d42404

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for docc_compiler-0.0.5-cp313-cp313-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 0be706ece8030cf9cc6eb025123b64e2c5e530290eddb7c694ace0c70d095f90
MD5 47f760c8ed2d0b5033d73ba93bea9d23
BLAKE2b-256 cb4768ee3f23660c561bc35b639bd17ee95503e5bcc42a00c6745720a585c615

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for docc_compiler-0.0.5-cp313-cp313-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 ca9b2d6a31ec36106fa7b2b620f067076efc280983beb666e6b55da26a7ab7cc
MD5 4c83af05505cff9b8c133c0d861131aa
BLAKE2b-256 2de9754b60228b1f97c1e66697adf67954e773245badbf8c46e8f4bdb72ed8bf

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for docc_compiler-0.0.5-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 629e77c750cab38d8555bdd22461cc5ba240daf92f458c404a27a2c76e3a1a8c
MD5 788d0fba95867c054c1460c17c4148af
BLAKE2b-256 ac42a82934e7754036fce54c6c5c4df2e1ad635f25d4bbe3e3d996001bb0476c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for docc_compiler-0.0.5-cp312-cp312-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 316b2227d10131deb59ff941cc205cb962727d17becd7701bb6856390e6a4a03
MD5 aacd894f38a086595a8d4643810bd987
BLAKE2b-256 35634cad9bec5e7dd57da11b0fb31d7156f6de59a23cbf7efff3f384ec5898f2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for docc_compiler-0.0.5-cp312-cp312-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 6cfce089a2029801043c7694030cda4e0c7bd9517bdd8159a64b83af44c7dec6
MD5 d6bc2a9c5f6919d021eeeaa8819e92f0
BLAKE2b-256 b1f2af56e9046ab0ecc4061af70c026dd8106b5b41c289db1562cd4b77b3759d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for docc_compiler-0.0.5-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 3decef7c3f74832088dd060f1e6d07898c1429a815b57a680a74ae47a5fa183f
MD5 2542cca6b71fb27ca39f95e94c6a6a26
BLAKE2b-256 ff4255e90c5da6389012b54864f57a6e7669b4d32d1a4bbf69c947363da142a1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for docc_compiler-0.0.5-cp311-cp311-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 aef00063415f7338e3557dddb58622cec281798f85e716332ff1f157237a2ecb
MD5 2ed5e777606dfff6aa103739c720e095
BLAKE2b-256 c0c9fd868e07073a59b9af4a279c5a7dc059f6bb11a6add7488f00f53f91f3e4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for docc_compiler-0.0.5-cp311-cp311-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 8e86cbb7354aa49c4173f0bea7122327fed8202dd15015608a16d717b6b58846
MD5 a04b614188dd7105c9419b4af408d49b
BLAKE2b-256 0a164ddbd0e769b5cc66314a9d94dfe405149da2a915df095ed7e679d871f7e2

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