Skip to main content

A Python library using the Futhark C backend via CFFI

Project description

futhark-ffi

Test

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)

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.13.0.tar.gz (5.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

futhark_ffi-0.13.0-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

File details

Details for the file futhark_ffi-0.13.0.tar.gz.

File metadata

  • Download URL: futhark_ffi-0.13.0.tar.gz
  • Upload date:
  • Size: 5.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.6.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.9.6

File hashes

Hashes for futhark_ffi-0.13.0.tar.gz
Algorithm Hash digest
SHA256 df6e8097682b5fcbe4e102457b2a0e1f540a2ff6290db47cce982bb43ac5d76d
MD5 ad7648bf1b128b1d96c473c92722bd1e
BLAKE2b-256 c6546c6acca432ac326f008dc03735766cc37bba72aba38aaf4358f1bd832a59

See more details on using hashes here.

File details

Details for the file futhark_ffi-0.13.0-py3-none-any.whl.

File metadata

  • Download URL: futhark_ffi-0.13.0-py3-none-any.whl
  • Upload date:
  • Size: 6.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.6.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.9.6

File hashes

Hashes for futhark_ffi-0.13.0-py3-none-any.whl
Algorithm Hash digest
SHA256 bb29b2521437a48340bb942acd1593cd2b382b01c5a9a4e8b89616be9c973a61
MD5 198492cc321d6006dcaffb445c273d3a
BLAKE2b-256 bd3ecec5fed8995c21e389630ef584112b5ced4e091242f89651d010e2133cc8

See more details on using hashes here.

Supported by

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