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.

Release files for docc-compiler 0.8.1

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.1
File
docc_compiler-0.8.1-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
docc_compiler-0.8.1-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
docc_compiler-0.8.1-cp314-cp314-macosx_14_0_arm64.whl CPython 3.14 CPython 3.14 macOS 14.0+ ARM64 Details
docc_compiler-0.8.1-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
docc_compiler-0.8.1-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
docc_compiler-0.8.1-cp313-cp313-macosx_14_0_arm64.whl CPython 3.13 CPython 3.13 macOS 14.0+ ARM64 Details
docc_compiler-0.8.1-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl CPython 3.12 CPython 3.12 Linux glibc 2.28+ x86-64, Linux glibc 2.27+ x86-64 Details
docc_compiler-0.8.1-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
docc_compiler-0.8.1-cp312-cp312-macosx_14_0_arm64.whl CPython 3.12 CPython 3.12 macOS 14.0+ ARM64 Details
docc_compiler-0.8.1-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl CPython 3.11 CPython 3.11 Linux glibc 2.28+ x86-64, Linux glibc 2.27+ x86-64 Details
docc_compiler-0.8.1-cp311-cp311-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl CPython 3.11 CPython 3.11 Linux glibc 2.27+ ARM64, Linux glibc 2.28+ ARM64 Details
docc_compiler-0.8.1-cp311-cp311-macosx_14_0_arm64.whl CPython 3.11 CPython 3.11 macOS 14.0+ ARM64 Details

Total release size: 136.8 MB

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

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

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

Download URL docc_compiler-0.8.1-cp314-cp314-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl
Size 14.2 MB
Tags CPython 3.14 Linux glibc 2.27+ ARM64 Linux glibc 2.28+ ARM64
SHA-256 checksum
How to use checksums
d12ddb748245bbdfe03e9e5d7e01db096b5aacb0876e02f233c9d5981e6d70cc
BLAKE2b-256 checksum
How to use checksums
44a66ba3978b5c838d4d28c79cdf49322b07842a60c6f245ff501fc0a5c61f95
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.1.1 CPython/3.12.14

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

Download URL docc_compiler-0.8.1-cp314-cp314-macosx_14_0_arm64.whl
Size 5.0 MB
Tags CPython 3.14 macOS 14.0+ ARM64
SHA-256 checksum
How to use checksums
6e1c1d7c78b972fc900f420f7db6af087f3abafd269aed983a9e3344d3dfcb8f
BLAKE2b-256 checksum
How to use checksums
19ecca7e2664ecdda60c8bdcac2fa71e93c4924b1b47fcdbad1daf4dff248cb6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.1.1 CPython/3.12.14

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

Download URL docc_compiler-0.8.1-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Size 15.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
1268eb012278600dc453b9f14616124d8527807e17b6fcf65d9720a1032409ee
BLAKE2b-256 checksum
How to use checksums
e2897e3c14c8b336f72628ec091fee2664922fdf2d1466105d6280a227cb80ec
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.1.1 CPython/3.12.14

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

Download URL docc_compiler-0.8.1-cp313-cp313-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl
Size 14.2 MB
Tags CPython 3.13 Linux glibc 2.27+ ARM64 Linux glibc 2.28+ ARM64
SHA-256 checksum
How to use checksums
c8a1237d1df2694714e1c85120d9d8eeb69294806eadf6f4c824fabce8c0bf36
BLAKE2b-256 checksum
How to use checksums
27702131acc6caaa0fb9317fd862babdecfaeafbc7e54eb60ed72fd4a5cba0b7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.1.1 CPython/3.12.14

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

Download URL docc_compiler-0.8.1-cp313-cp313-macosx_14_0_arm64.whl
Size 5.0 MB
Tags CPython 3.13 macOS 14.0+ ARM64
SHA-256 checksum
How to use checksums
5866ba93af7192fec7187dab105353ad5680c887bc5838671bfc2580e5dda0f6
BLAKE2b-256 checksum
How to use checksums
2c91d3ad8c58027381aff87b21606d7dc217ed96a490856b2c071e824cc8f186
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.1.1 CPython/3.12.14

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

Download URL docc_compiler-0.8.1-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Size 15.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
c36b7dbe8917bb51a5b653c91c6c3772c7734dc125b630eea4e5469b7614ca81
BLAKE2b-256 checksum
How to use checksums
3b92eedce0aa27bb0504346e6f591ea92d3c865607373ee47e45acafad92c4be
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.1.1 CPython/3.12.14

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

Download URL docc_compiler-0.8.1-cp312-cp312-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl
Size 14.2 MB
Tags CPython 3.12 Linux glibc 2.27+ ARM64 Linux glibc 2.28+ ARM64
SHA-256 checksum
How to use checksums
27e819e9bd01368e717ed6ef582e8dbe7e4875c82722965c6dc3af68917f1804
BLAKE2b-256 checksum
How to use checksums
93b776832f04cda6c040ec4c95e83da24def48d6d20323e06041eade97d53fab
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.1.1 CPython/3.12.14

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

Download URL docc_compiler-0.8.1-cp312-cp312-macosx_14_0_arm64.whl
Size 5.0 MB
Tags CPython 3.12 macOS 14.0+ ARM64
SHA-256 checksum
How to use checksums
4696c47143c3a4f4ef56856a4afd2cedc1c7e4af001093cfcb245f241c80d4a1
BLAKE2b-256 checksum
How to use checksums
007c3f320a90de99f113be2597fd5bb0df39186f6ce5353965bfc7ab0985a0aa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.1.1 CPython/3.12.14

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

Download URL docc_compiler-0.8.1-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Size 15.0 MB
Tags CPython 3.11 Linux glibc 2.27+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
08c463bed5dc8d1b56482bed664bcbf544d337fe8bf090fe8b2cae88e6e96f2c
BLAKE2b-256 checksum
How to use checksums
70271490dd65be101773536b16d24fd4861e3d53ddc17edc0265982a11afaf22
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.1.1 CPython/3.12.14

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

Download URL docc_compiler-0.8.1-cp311-cp311-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl
Size 14.1 MB
Tags CPython 3.11 Linux glibc 2.27+ ARM64 Linux glibc 2.28+ ARM64
SHA-256 checksum
How to use checksums
49f04be553775b90f2f881f7f50a92f4227588937c781e7e2d0b483fd2e7d20c
BLAKE2b-256 checksum
How to use checksums
38357bde621e6d60bacf5051d48a63be20dbc5968f5b79f01ae9f2d6649b71e2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.1.1 CPython/3.12.14

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

Download URL docc_compiler-0.8.1-cp311-cp311-macosx_14_0_arm64.whl
Size 5.0 MB
Tags CPython 3.11 macOS 14.0+ ARM64
SHA-256 checksum
How to use checksums
66af17cd16fd72470dcd5aab49dc9144d7e202201be67d3905ade21d272715a7
BLAKE2b-256 checksum
How to use checksums
90988872a274844b7c961481df479d37abb1613212ac7c4368f61ad36670abf1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.1.1 CPython/3.12.14

Release history Release notifications | RSS feed

This release

0.8.1 This release

12 release files

0.8.0

12 release files

0.7.0

12 release files

0.6.0

8 release files

0.0.8

12 release files

0.0.5

12 release files

0.0.4

12 release files

0.0.2

8 release files

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