A Python library using the Futhark C backend via CFFI
Project description
futhark-ffi
Python library using the Futhark C backend via CFFI
Futhark provides several compiler backends, for example futhark opencl
which is a C backend, and futhark pyopencl
which is a Python
backend based on PyOpenCL. However, the host-side code of the Python
backend is quite slow, leading to a lot of overhead when small,
frequent kernels are used.
A solution to reduce this overhead is to use CFFI to used the C backend from Python, greatly reducing the calling overhead. The OpenCL code is the same, so this is not interesting for long-running kernels.
This library supports the following Futhark backends: c
, opencl
,
multicore
, and cuda
.
Futhark arrays are mapped to and from Numpy arrays. Multiple outputs and multi-dimensional arrays are supported.
Installation
Install Futhark, then simply
pip install futhark-ffi
Usage
Generate a C library, and build a Python binding for it
futhark opencl --library test.fut
build_futhark_ffi test
Use the Python wrapper
import numpy as np
import _test
from futhark_ffi import Futhark
test = Futhark(_test)
res = test.test3(np.arange(10))
test.from_futhark(res)
Example usage
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for futhark_ffi-0.14.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 405a356e6590972b3a3165f8b8518e002996779a10b3a4164b69ec01c01f8975 |
|
MD5 | 0fda91f656b9d405567d7750eee8670c |
|
BLAKE2b-256 | f377a666064262abe80b2737600f4097d480afb6e2e94466638a4a23de99605f |