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)

Example usage

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

Uploaded Source

Built Distribution

futhark_ffi-0.15.0-py3-none-any.whl (6.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: futhark_ffi-0.15.0.tar.gz
  • Upload date:
  • Size: 5.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.11.3

File hashes

Hashes for futhark_ffi-0.15.0.tar.gz
Algorithm Hash digest
SHA256 1279bcf7b3e1276eee1c79db28e62ca0f2dbd023d472f5e105cdad15869b6d61
MD5 4fcda2e60405d7d63c34ec0cf1aad32b
BLAKE2b-256 a738c6240d315acdc9ed50cf376d3ae9bab8f371e3a4b94c325d3790fd039e96

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for futhark_ffi-0.15.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e880d17e488842119956d36472e226b018b907d8c7336310c4c7ac821af0316c
MD5 cfdb2945ae051a074e619ffe10feaefb
BLAKE2b-256 0aeadcce87c5c5fa7fe88aafbae12ff4667d4e405fd6b50798aff47bc76c12f9

See more details on using hashes here.

Supported by

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