A Python library using the Futhark C backend via CFFI
Python library using the Futhark C backend via CFFI
Futhark provides several compiler backends,
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 both
futhark opencl and
futhark c. Futhark arrays are mapped to and from Numpy arrays. Multiple outputs and multi-dimensional arrays are supported.
Install Futhark, then simply
pip install futhark-ffi
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)
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
|Filename, size||File type||Python version||Upload date||Hashes|
|Filename, size futhark_ffi-0.10.2-py3-none-any.whl (4.8 kB)||File type Wheel||Python version py3||Upload date||Hashes View|
|Filename, size futhark_ffi-0.10.2.tar.gz (4.1 kB)||File type Source||Python version None||Upload date||Hashes View|
Hashes for futhark_ffi-0.10.2-py3-none-any.whl