Open1
Haskell accelerate with GPU
{-# LANGUAGE CPP, BangPatterns #-}
{-# LANGUAGE FlexibleContexts #-}
{-# OPTIONS_GHC -Wall -fno-warn-name-shadowing #-}
import Data.Array.Accelerate as A
import Data.Array.Accelerate.LLVM.PTX
-- | Dot product of two vectors using Accelerate
dotp :: (A.Num a, A.Elt a) => Acc (Vector a) -> Acc (Vector a) -> Acc (Scalar a)
dotp xs ys = fold (+) 0 (A.zipWith (*) xs ys)
main :: IO ()
main = do
-- Define two vectors
let a = fromList (Z :. 10) [1..10] :: Vector Int
let b = fromList (Z :. 10) [1..10] :: Vector Int
-- Compute the dot product on the GPU
let result = run $ dotp (use a) (use b)
-- Print the result
print result