Skip to main content

CI Status Coverage Status Documentation Status

Compyle allows users to execute a restricted subset of Python (almost similar to C) on a variety of HPC platforms. Currently we support multi-core CPU execution using Cython, and for GPU devices we use OpenCL or CUDA.

Users start with code implemented in a very restricted Python syntax, this code is then automatically transpiled, compiled and executed to run on either one CPU core, or multiple CPU cores (via OpenMP) or on a GPU. Compyle offers source-to-source transpilation, making it a very convenient tool for writing HPC libraries.

Some simple yet powerful parallel utilities are provided which can allow you to solve a remarkably large number of interesting HPC problems. Compyle also features JIT transpilation making it easy to use.

Documentation and learning material is also available in the form of:

While Compyle seems simple it is not a toy and is used heavily by the PySPH project where Compyle has its origins.

Installation

Compyle is itself largely pure Python but depends on numpy and requires either Cython or PyOpenCL or PyCUDA along with the respective backends of a C/C++ compiler, OpenCL and CUDA. If you are only going to execute code on a CPU then all you need is Cython.

You should be able to install Compyle by doing:

$ pip install compyle

A simple example

Here is a very simple example:

from compyle.api import Elementwise, annotate, wrap, get_config
import numpy as np

@annotate
def axpb(i, x, y, a, b):
    y[i] = a*sin(x[i]) + b

x = np.linspace(0, 1, 10000)
y = np.zeros_like(x)
a, b = 2.0, 3.0

backend = 'cython'
get_config().use_openmp = True
x, y = wrap(x, y, backend=backend)
e = Elementwise(axpb, backend=backend)
e(x, y, a, b)

This will execute the elementwise operation in parallel using OpenMP with Cython. The code is auto-generated, compiled and called for you transparently. The first time this runs, it will take a bit of time to compile everything but the next time, this is cached and will run much faster.

If you just change the backend = 'opencl', the same exact code will be executed using PyOpenCL and if you change the backend to 'cuda', it will execute via CUDA without any other changes to your code. This is obviously a very trivial example, there are more complex examples available as well.

Examples

Some simple examples and benchmarks are available in the examples directory.

You may also run these examples on the Google Colab notebook

Release files for compyle 0.9.1

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

Source distribution (sdist)

Source distribution for compyle 0.9.1
File Size Uploaded
compyle-0.9.1.tar.gz 134.2 kB Details

Release files / compyle-0.9.1.tar.gz

Download URL compyle-0.9.1.tar.gz
Size 134.2 kB
Tags Source
SHA-256 checksum
How to use checksums
121095845ec249f3df7079dce3f2f2ad9ea1b64c632b86ee6c5e2f588ebb28e9
BLAKE2b-256 checksum
How to use checksums
fe56dd24e40e7860cf5e9d8f78d35dacbf37b2a89abc221a57e326c3ad16d6d7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.11.11

Release history Release notifications | RSS feed

This release

0.9.1 This release

1 release file

0.9

1 release file

0.8.1

1 release file

0.8

1 release file

0.7

1 release file

0.6

1 release file

0.5

1 release file

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