Skip to main content

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), 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.

import math

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

N = 128
A = np.random.rand(N).astype(np.float64)
B = np.zeros(N, dtype=np.float64)
vectorized_sin(A, B)

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.

Metadata

Release files for docc-compiler 0.8.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distributions (wheels)

Table of built distributions (wheels) for docc-compiler 0.8.3
File Actions
docc_compiler-0.8.3-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl CPython 3.14 CPython 3.14 Linux glibc 2.27+ x86-64, Linux glibc 2.28+ x86-64 Details for docc_compiler-0.8.3-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
docc_compiler-0.8.3-cp314-cp314-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl CPython 3.14 CPython 3.14 Linux glibc 2.27+ ARM64, Linux glibc 2.28+ ARM64 Details for docc_compiler-0.8.3-cp314-cp314-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl
docc_compiler-0.8.3-cp314-cp314-macosx_14_0_arm64.whl CPython 3.14 CPython 3.14 macOS 14.0+ ARM64 Details for docc_compiler-0.8.3-cp314-cp314-macosx_14_0_arm64.whl
docc_compiler-0.8.3-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl CPython 3.13 CPython 3.13 Linux glibc 2.27+ x86-64, Linux glibc 2.28+ x86-64 Details for docc_compiler-0.8.3-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
docc_compiler-0.8.3-cp313-cp313-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl CPython 3.13 CPython 3.13 Linux glibc 2.27+ ARM64, Linux glibc 2.28+ ARM64 Details for docc_compiler-0.8.3-cp313-cp313-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl
docc_compiler-0.8.3-cp313-cp313-macosx_14_0_arm64.whl CPython 3.13 CPython 3.13 macOS 14.0+ ARM64 Details for docc_compiler-0.8.3-cp313-cp313-macosx_14_0_arm64.whl
docc_compiler-0.8.3-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl CPython 3.12 CPython 3.12 Linux glibc 2.27+ x86-64, Linux glibc 2.28+ x86-64 Details for docc_compiler-0.8.3-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
docc_compiler-0.8.3-cp312-cp312-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl CPython 3.12 CPython 3.12 Linux glibc 2.27+ ARM64, Linux glibc 2.28+ ARM64 Details for docc_compiler-0.8.3-cp312-cp312-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl
docc_compiler-0.8.3-cp312-cp312-macosx_14_0_arm64.whl CPython 3.12 CPython 3.12 macOS 14.0+ ARM64 Details for docc_compiler-0.8.3-cp312-cp312-macosx_14_0_arm64.whl
docc_compiler-0.8.3-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl CPython 3.11 CPython 3.11 Linux glibc 2.27+ x86-64, Linux glibc 2.28+ x86-64 Details for docc_compiler-0.8.3-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
docc_compiler-0.8.3-cp311-cp311-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl CPython 3.11 CPython 3.11 Linux glibc 2.28+ ARM64, Linux glibc 2.27+ ARM64 Details for docc_compiler-0.8.3-cp311-cp311-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl
docc_compiler-0.8.3-cp311-cp311-macosx_14_0_arm64.whl CPython 3.11 CPython 3.11 macOS 14.0+ ARM64 Details for docc_compiler-0.8.3-cp311-cp311-macosx_14_0_arm64.whl

Total release size: 147.5 MB

Release files / docc_compiler-0.8.3-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl

Download URL docc_compiler-0.8.3-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Size 16.1 MB
Tags CPython 3.14 Linux glibc 2.27+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
da59f1ae968afe29a88bd91b4e7f3991ef67616bf39a6cfe8a96076c74b70c26
BLAKE2b-256 checksum
How to use checksums
d6a0b7229446acde36f0916f8d24a74d4685e2a6318f87bf79bf26442e136385
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.1.1 CPython/3.12.16

Release files / docc_compiler-0.8.3-cp314-cp314-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl

Download URL docc_compiler-0.8.3-cp314-cp314-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl
Size 15.1 MB
Tags CPython 3.14 Linux glibc 2.27+ ARM64 Linux glibc 2.28+ ARM64
SHA-256 checksum
How to use checksums
84c4cac0e2cce19f36b37f359088e8c8843652ff23afc59546ad96848914fcd9
BLAKE2b-256 checksum
How to use checksums
a65def8d720eb60c4d7e8bff1e73260f2d0fde5757066fc819d01f1e817ec81e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.1.1 CPython/3.12.16

Release files / docc_compiler-0.8.3-cp314-cp314-macosx_14_0_arm64.whl

Download URL docc_compiler-0.8.3-cp314-cp314-macosx_14_0_arm64.whl
Size 5.7 MB
Tags CPython 3.14 macOS 14.0+ ARM64
SHA-256 checksum
How to use checksums
746865f800baa0d4dab6698071bfd4458e5ed65d88b631cd010cca7e96f1d761
BLAKE2b-256 checksum
How to use checksums
e36afea3e262ca7f3fab405f233fa2a1d86d0d769a735760db71f780149d5498
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.1.1 CPython/3.12.16

Release files / docc_compiler-0.8.3-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl

Download URL docc_compiler-0.8.3-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Size 16.1 MB
Tags CPython 3.13 Linux glibc 2.27+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
857a17a6fda97c19797b799c0f8caee15308d7bce6ed7b0f220a58b8ff914b61
BLAKE2b-256 checksum
How to use checksums
6af48b847b70bb35b462fa47dd358763691017c058991900d531ac59688486d7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.1.1 CPython/3.12.16

Release files / docc_compiler-0.8.3-cp313-cp313-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl

Download URL docc_compiler-0.8.3-cp313-cp313-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl
Size 15.1 MB
Tags CPython 3.13 Linux glibc 2.27+ ARM64 Linux glibc 2.28+ ARM64
SHA-256 checksum
How to use checksums
61feb0917cbed95d8a3ec622db41541dcb322399e63666a16c204740ab98455f
BLAKE2b-256 checksum
How to use checksums
b9ff551016ce6e1a197553c50ecc068b413f97b06671f90335447580b66e0071
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.1.1 CPython/3.12.16

Release files / docc_compiler-0.8.3-cp313-cp313-macosx_14_0_arm64.whl

Download URL docc_compiler-0.8.3-cp313-cp313-macosx_14_0_arm64.whl
Size 5.7 MB
Tags CPython 3.13 macOS 14.0+ ARM64
SHA-256 checksum
How to use checksums
f6a4f8f6ef20e74c2f5c506e993e418d181c0c4b7394b89eebf163b469427eb5
BLAKE2b-256 checksum
How to use checksums
58f3b1ad074d1a943fc34602e5969c03cd7d9720db2e1a523b9abd6f0b683be3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.1.1 CPython/3.12.16

Release files / docc_compiler-0.8.3-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl

Download URL docc_compiler-0.8.3-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Size 16.1 MB
Tags CPython 3.12 Linux glibc 2.27+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
d7f50f7932cbfb23abd6ac8cc93f7bcc0b111f77b8962186c7d0dd7bf0ad4172
BLAKE2b-256 checksum
How to use checksums
eb6e9b73cadbbcc4fd7eef5f1b2e58c613e6f8005f155653c713043fff8cf8cb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.1.1 CPython/3.12.16

Release files / docc_compiler-0.8.3-cp312-cp312-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl

Download URL docc_compiler-0.8.3-cp312-cp312-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl
Size 15.1 MB
Tags CPython 3.12 Linux glibc 2.27+ ARM64 Linux glibc 2.28+ ARM64
SHA-256 checksum
How to use checksums
5a271ef09a40fdcc062ac6fbd8fbd5555b07072cc116f2e4fa31192825062732
BLAKE2b-256 checksum
How to use checksums
bad73e969dac683138b6e2adc6d4b4abcc4dc8204beecee0955750bba2b7ae0b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.1.1 CPython/3.12.16

Release files / docc_compiler-0.8.3-cp312-cp312-macosx_14_0_arm64.whl

Download URL docc_compiler-0.8.3-cp312-cp312-macosx_14_0_arm64.whl
Size 5.7 MB
Tags CPython 3.12 macOS 14.0+ ARM64
SHA-256 checksum
How to use checksums
5254e2b8fd167d97d4e46e317576b82698b170f52fd1f4a97b977d6d3dfb1edc
BLAKE2b-256 checksum
How to use checksums
2a97825e197fffa2f522e27a906be74f94734aa075ab6148ec500069badfc8cf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.1.1 CPython/3.12.16

Release files / docc_compiler-0.8.3-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl

Download URL docc_compiler-0.8.3-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Size 16.1 MB
Tags CPython 3.11 Linux glibc 2.27+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
230b94925e7e68132e133c9a8c14dfaaf16be66e54b930a6b6342448e5242a27
BLAKE2b-256 checksum
How to use checksums
ef5a9d979cf6b0ccfb116c7ca7bd909eaca5f8e30160511108f4ee1ffef38853
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.1.1 CPython/3.12.16

Release files / docc_compiler-0.8.3-cp311-cp311-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl

Download URL docc_compiler-0.8.3-cp311-cp311-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl
Size 15.1 MB
Tags CPython 3.11 Linux glibc 2.27+ ARM64 Linux glibc 2.28+ ARM64
SHA-256 checksum
How to use checksums
838955e944ce3f8a20e7ef4ed3dcc41abd73ad6e06a300b3ac3d692118bf91a8
BLAKE2b-256 checksum
How to use checksums
9a95fb7d871e0e174329035035fb5163ce40cad37349300f348fd452a87d7a88
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.1.1 CPython/3.12.16

Release files / docc_compiler-0.8.3-cp311-cp311-macosx_14_0_arm64.whl

Download URL docc_compiler-0.8.3-cp311-cp311-macosx_14_0_arm64.whl
Size 5.7 MB
Tags CPython 3.11 macOS 14.0+ ARM64
SHA-256 checksum
How to use checksums
4f9e71c3b6416c9f9b67706f724affa8d9cb7df74b5b45484fb05bc73cd88483
BLAKE2b-256 checksum
How to use checksums
ed5f8e240aea3f3137718a3097b770eead9db0a39422aaf062c0f658f3db396e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.1.1 CPython/3.12.16

Security for docc-compiler 0.8.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page