Skip to main content

Execute a subset of Python on HPC platforms

Project description

Travis Status Appveyor 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 execution using Cython, and OpenCL and CUDA for GPU devices.

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. CPy 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 if you wish making it easy to use.

Documentation is available at: https://compyle.readthedocs.io

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

compyle-0.5.tar.gz (86.2 kB view details)

Uploaded Source

File details

Details for the file compyle-0.5.tar.gz.

File metadata

  • Download URL: compyle-0.5.tar.gz
  • Upload date:
  • Size: 86.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.18.4 setuptools/38.5.2 requests-toolbelt/0.8.0 tqdm/4.19.5 CPython/3.6.0

File hashes

Hashes for compyle-0.5.tar.gz
Algorithm Hash digest
SHA256 8fa33611c956a3189f054c72a41c5c6e6ba00bc4d1f166798c6849c12c499e57
MD5 289c624e657e75975c1d31fafaeabc95
BLAKE2b-256 fca84560a11c0d1a33e02022fb63bb363c943f133c5cf13eb9c2e2ea5903a06b

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page