Accelerator/Haskell API for GPGPU/FPGA code generation

101 views
Skip to first unread message

Satnam

unread,
Nov 15, 2010, 9:15:47 AM11/15/10
to parallel-haskell
I thought I would give this mailing list a heads up on a project I am
doing which allows Haskell programs to dynamically generate GPU
programs that can execute on just about any GPU (under Windows via
DirectX 9) and some of the same parallel descriptions can also be
turned into circuits for implementation on Xilinx FPGAs. Here’s a
concrete example of a trivial program that illustrates how Accelerator
is used:


module Main
where

import Accelerator

x = fpa ([1.0, 2.0, 3.0, 4.0, 5.0]::[Float])
y = fpa ([6.0, 7.0, 8.0, 9.0, 10.0]::[Float])

z :: Expr FPA1D
z = x + y

main :: IO ()
main
= do dx9Target <- c_DX9Target_Create
r::[Float] <- acceleratorCompute dx9Target z
putStrLn (show r)

The program imports the Accelerator library, defines a couple of data-
parallel arrays x and y, defines a computation to perform on the GPU
i.e. z = x + y and then executes them on the DirectX9 target and
writes out the result:

$ ./AddArrays
[7.0,9.0,11.0,13.0,15.0]

i.e. when the program runs the computation is run on the GPU (with the
GPU code being JIT-ed).

You could also create an FPGA circuit for this computation:

module Main
where

import Accelerator

x = fpa ([1.0, 2.0, 3.0, 4.0, 5.0]::[Float])
y = fpa ([6.0, 7.0, 8.0, 9.0, 10.0]::[Float])

z :: Expr FPA1D
z = x + y

main :: IO ()
main
= do dx9Target <- c_DX9Target_Create
r::[Float] <- acceleratorCompute dx9Target z
putStrLn (show r)


and when you run this the program generates some VHDL files which can
be used to make an FPGA implementation:

$ ./AddArraysFPGA
Input nodes: 2[1] 3[2]
Reused data nodes:
ExpID: 1 referenced at nodes 2 min dxy = (0, 0) max dxy = (0, 0)
ExpID: 2 referenced at nodes 3 min dxy = (0, 0) max dxy = (0, 0)
End of data reuse report.
Generated adder.vhd
Generated adder_package.vhd


A less trivial example is a 1D convolver:

convolve2D :: [Float] -> Expr FPA2D -> Expr FPA2D
convolve2D kernel input
= convy
where
convy = foldl (+) 0.0 [float (kernel!!i) * shift [-i, 0] input | i
<- [0..length kernel-1]]
convx = foldl (+) 0.0 [float (kernel!!i) * shift [0, -i] input | i
<- [0..length kernel-1]]

I am hoping to make a release on Hackage for the Accelerator/Haskell
API and then also work on higher level layers on top of this API
(Vector? NDP?). Happy to get ideas/feedback/connections etc.


Cheers,

Satnam
http://research.microsoft.com/~satnams




Reply all
Reply to author
Forward
0 new messages