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

Uploaded CPython 3.14macOS 14.0+ ARM64

docc_compiler-0.0.7-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.7-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.7-cp313-cp313-macosx_14_0_arm64.whl (3.8 MB view details)

Uploaded CPython 3.13macOS 14.0+ ARM64

docc_compiler-0.0.7-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.7-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.7-cp312-cp312-macosx_14_0_arm64.whl (3.8 MB view details)

Uploaded CPython 3.12macOS 14.0+ ARM64

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

File metadata

File hashes

Hashes for docc_compiler-0.0.7-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 8731aa9a4151706ffa0883c8b313ee36587c99deeb6a4570b24cf76a6ac0230c
MD5 5e204edf2d4804c51344e79a9e35e4bc
BLAKE2b-256 da86a5e5dea743d796932ebe451c66da26f14a8c254fc05558c739b1e8ce67e5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for docc_compiler-0.0.7-cp314-cp314-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 61ed45aaa3fa69937d20203fb3787ce3db9f60c5b0884cf3c82c5b009719399d
MD5 2c699ecb605665445ee534f02be47c9d
BLAKE2b-256 cead36c18d263b70600c5da5e41cd52c025892d2c4920ace9dcd5032ddf029d8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for docc_compiler-0.0.7-cp314-cp314-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 c1193de2e9f7198e40861d00e6f4a6d52c902d25614faac52acbbc2bbd879ea0
MD5 8888a02b76cd5bf60e1459ee20fea34d
BLAKE2b-256 3500424af83eb87aa9f3ddc6ee12bb0d055a464ffb75974f4e080dc493c9198e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for docc_compiler-0.0.7-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 a539f8335f92a7b106c2428eae94a6495177b7587c070627b1a87c22c6c39c3e
MD5 c878aaffb5e9266efe300762abbbbcb9
BLAKE2b-256 16b5e04e4ec16f7af3315ab678751d097d9195b13c048cc9042e6b04238821da

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for docc_compiler-0.0.7-cp313-cp313-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 59d9996077a269c53c0cb75871e70d53eb0e1c1489c956f77a7395fab358d8bd
MD5 7050d0a07ea9dd6b52f31defc8db13af
BLAKE2b-256 7b98a825e26ceb6100973aa2888aa0ff46743a0bcc9c26abe760f664ca3838d9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for docc_compiler-0.0.7-cp313-cp313-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 d81c7e7e909e8445046e36789d496a71af9cdc300aa7b806d65c0c72b108ed95
MD5 c12689e5a19517146a9cffedf9924779
BLAKE2b-256 cc460d88f35bf2052e44e3986a3ba5e1d018c0ebe11339f06fd9d2eea0b6a3f2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for docc_compiler-0.0.7-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 e4dab0768f92fcfa591b2640a195d8a9a471e1f71da91a9764aaefdb5457a408
MD5 d8d2bb89bb1888106a07d11ecf2b0008
BLAKE2b-256 3ba428afc19014409dcc74803f80de46e3c91c19a5fb9a5db97b9d3493588b16

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for docc_compiler-0.0.7-cp312-cp312-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 0682c32d7a53f918f54b62288e76d9586a55623c0e5621f4e02c7c3f7b4c4a0a
MD5 13ec6f0480865830c354fd024777ca9a
BLAKE2b-256 8d9a081bfd4431f2dd0b581be8c58e2c6fa3781847ec18396d374e37714c5553

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for docc_compiler-0.0.7-cp312-cp312-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 c62dc8d3f652cae5d665e6bfe44dcdb425befc5ed3a8522743db9e2a0aa0f104
MD5 cd1b30bdd7fed6d61fb37826b4324ccd
BLAKE2b-256 d8ae1c1012a69c8f9249685156b835ed876d65370d764f89f4bb775df777a253

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for docc_compiler-0.0.7-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 669bbd98fe4c8a0d1e175807045c968b46cf775ebcd728695260919a31bad4f6
MD5 cf1e7d3cbe21b478c19ce05f96fc736e
BLAKE2b-256 93dbdc28bdd9a7d55f4cf59ddb93fc0011ef9d5ba0f3d82ed7a8c3b7888d89ac

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for docc_compiler-0.0.7-cp311-cp311-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 21fa97f257d474081bfd543d1884fa229c4410f618fc307099073323e9590131
MD5 f3b7a0e921dbb3b20e567c0a36dccac2
BLAKE2b-256 f16a88519b71f4bd5f5f2158fe8c8a0b96a9d9cc490d2c1769a16bf0de00dac6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for docc_compiler-0.0.7-cp311-cp311-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 8b2b27ab602f11842b15fb49ed94805bc9e48f9f3bc2055572d2ead666a3f767
MD5 a58a713fb54e9570fe915699f470b2a5
BLAKE2b-256 2cf2b34795dce4cfef7b34f607f27bf44d4ae0ecc77f2cbdb6f24429fbe80236

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