Skip to main content

A Python library using the Futhark C backend via CFFI

Project description

futhark-pycffi

Python library using the Futhark C backend via CFFI

Futhark provides several compilers, 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. Input arrays should be in contiguous C order.

Usage

Generate a C library, and build a Python binding for it

futhark-opencl --library test.fut
python build_futhark_ffi.py 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)

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

futhark_ffi-0.6.1b1.tar.gz (3.8 kB view hashes)

Uploaded source

Built Distributions

futhark_ffi-0.6.1b1-py3.6.egg (8.8 kB view hashes)

Uploaded 3 6

futhark_ffi-0.6.1b1-py3-none-any.whl (4.5 kB view hashes)

Uploaded py3

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page