Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Execute a subset of Python on HPC platforms

License

NotificationsYou must be signed in to change notification settings

pypr/compyle

Repository files navigation

CI StatusCoverage StatusDocumentation Status

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

Users start with code implemented in a very restricted Python syntax, this codeis then automatically transpiled, compiled and executed to run on either one CPUcore, or multiple CPU cores (viaOpenMP) or on a GPU. Compyle offerssource-to-source transpilation, making it a very convenient tool for writing HPClibraries.

Some simple yet powerful parallel utilities are provided which can allow youto solve a remarkably large number of interesting HPC problems. Compyle alsofeatures 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 thePySPHproject where Compyle has its origins.

Installation

Compyle is itself largely pure Python but depends onnumpy and requireseitherCython orPyOpenCL orPyCUDA along with the respective backends of aC/C++ compiler, OpenCL and CUDA. If you are only going to execute code on aCPU 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_configimport numpy as np@annotatedef axpb(i, x, y, a, b):    y[i] = a*sin(x[i]) + bx = np.linspace(0, 1, 10000)y = np.zeros_like(x)a, b = 2.0, 3.0backend = 'cython'get_config().use_openmp = Truex, 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 withCython. 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 butthe next time, this is cached and will run much faster.

If you just change thebackend = 'opencl', the same exact code will beexecuted usingPyOpenCL and if you change the backend to'cuda', it willexecute via CUDA without any other changes to your code. This is obviously avery trivial example, there are more complex examples available as well.

Examples

Some simple examples and benchmarks are available in theexamples directory.

You may also run these examples on theGoogle Colab notebook


[8]ページ先頭

©2009-2025 Movatter.jp