halide-haskell: Haskell bindings to Halide

[ bsd3, language, library, program ] [ Propose Tags ]

Halide is a programming language designed to make it easier to write high-performance image and array processing code on modern machines. Rather than being a standalone programming language, Halide is embedded in C++. This means you write C++ code that builds an in-memory representation of a Halide pipeline using Halide's C++ API. You can then compile this representation to an object file, or JIT-compile it and run it in the same process.

This package provides Haskell bindings that allow to write Halide embedded in Haskell without C++.

The best way to learn Halide is to have a look at the tutorials. Reference documentation is provided by the haddocks of the Language.Halide module.


[Skip to Readme]

Modules

[Index] [Quick Jump]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.0.1.0, 0.0.2.0
Change log CHANGELOG.md
Dependencies base (>=4.16.0.0 && <5), bytestring (>=0.11.1.0 && <0.12), constraints (>=0.13.4 && <0.14), filepath (>=1.4.2.1 && <2.0), halide-haskell, inline-c (>=0.9.1.6 && <0.10), inline-c-cpp (>=0.5.0.0 && <0.6), primitive (>=0.7.3.0 && <0.8), template-haskell (>=2.18.0.0 && <3.0), temporary (>=1.3 && <2.0), text (>=1.2.5.0 && <3.0), unix (>=2.7.2.2 && <3.0), vector (>=0.12.3.0 && <0.13), Win32 [details]
License BSD-3-Clause
Copyright 2022-2023 Tom Westerhout
Author Tom Westerhout
Maintainer Tom Westerhout <14264576+twesterhout@users.noreply.github.com>
Category Language
Home page https://github.com/twesterhout/halide-haskell
Bug tracker https://github.com/twesterhout/halide-haskell/issues
Source repo head: git clone https://github.com/twesterhout/halide-haskell.git
Uploaded by tom_westerhout at 2023-03-08T16:54:22Z
Distributions
Reverse Dependencies 2 direct, 0 indirect [details]
Executables getting-started, halide-haskell
Downloads 93 total (10 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs uploaded by user
Build status unknown [no reports yet]

Readme for halide-haskell-0.0.1.0

[back to package description]

halide-haskell

GitHub CI Hackage BSD-3-Clause license

Halide is a programming language designed to make it easier to write high-performance image and array processing code on modern machines. Rather than being a standalone programming language, Halide is embedded in C++. This means you write C++ code that builds an in-memory representation of a Halide pipeline using Halide's C++ API. You can then compile this representation to an object file, or JIT-compile it and run it in the same process.

This package provides Haskell bindings that allow to write Halide embedded in Haskell without C++ 😋.

🚀 Getting started

As a simple example, here's how you could implement array addition with halide-haskell:

{-# LANGUAGE AllowAmbiguousTypes, DataKinds, OverloadedStrings #-}
import Language.Halide

-- The algorithm
mkArrayPlus = compile $ \a b -> do
  -- Create an index variable
  i <- mkVar "i"
  -- Define the resulting function. We call it "out".
  -- In pseudocode it's equivalent to the following: out[i] = a[i] + b[i]
  out <- define "out" i $ a ! i + b ! i
  -- Perform a fancy optimization and use SIMD: we split the loop over i into
  -- an inner and an outer loop and then vectorize the inner loop
  inner <- mkVar "inner"
  split TailAuto i (i, inner) 4 out >>= vectorize inner

-- Example usage of our Halide pipeline
main :: IO ()
main = do
  let a, b :: [Float]
      a = [1, 2, 3, 4, 5]
      b = [6, 7, 8, 9, 10]
  -- Compile the code
  arrayPlus <- mkArrayPlus
  -- We tell Halide to treat our list as a one-dimensional buffer
  withHalideBuffer @1 @Float a $ \a' ->
    withHalideBuffer b $ \b' ->
      -- allocate a temporary buffer for the output
      allocaCpuBuffer [length a] $ \out' -> do
        -- execute the kernel -- it is a normal function call!
        arrayPlus a' b' out'
        -- print the result
        print =<< peekToList out'

For more examples, have a look a the tutorials.

🔨 Contributing

Currently, the best way to get started is to use Nix:

nix develop

This will drop you into a shell with all the necessary tools to build the code such that you can do

cabal build

and

cabal test