Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'refs/heads/repa-3'

Conflicts:
	Data/Array/Accelerate/Repa.hs
  • Loading branch information...
commit 5ea4d40ebcca50d5b952e8783a56749cea4431a4 2 parents fa1252e + e6e67c3
@blambo authored
View
22 Data/Array/Accelerate/Repa.hs
@@ -32,16 +32,16 @@ import DynFlags
import Unsafe.Coerce
import System.IO
-import System.IO.Unsafe
import System.Directory (removeFile)
--- | Using the provided Accelerate program, run will compile, execute
--- and return the result of a given Accelerate program using Repa for
--- execution
-run :: (Arrays a, Repa.Shape sh, Repa.Elt e)
+-- | Using the Accelerate program given as an argument, run will compile,
+-- execute and return the result of a given Accelerate program using Repa
+-- for execution
+--
+run :: (Arrays a, Repa.Shape sh, Repa.Repr r e)
=> Smart.Acc a -- ^ The Accelerate program
- -> Repa.Array sh e
-run acc = unsafePerformIO $ do
+ -> IO (Repa.Array r sh e)
+run acc = do
-- Generate source code from Accelerate program
let src = accToRepa acc
-- Write source code to temporary file in /tmp
@@ -83,20 +83,22 @@ compile path = do
-- | Executes the given function in the given module, must already be
-- compiled and loaded
-exec :: (Repa.Shape sh, Repa.Elt e)
+--
+exec :: (Repa.Shape sh, Repa.Repr r e)
=> String -- ^ The module name
-> String -- ^ The function name
- -> Ghc (Repa.Array sh e)
+ -> Ghc (Repa.Array r sh e)
exec modName fnName = do
mod <- findModule (mkModuleName modName) Nothing
setContext [mod] []
value <- compileExpr (modName Prelude.++ "." Prelude.++ fnName)
- let value' = (unsafeCoerce value) :: Repa.Array sh e
+ let value' = (unsafeCoerce value) :: Repa.Array r sh e
return value'
-- | Converts an Accelerate program to a Repa program and returns the
-- source as a String
+--
accToRepa :: (Arrays a)
=> Smart.Acc a -- ^ The Accelerate program
-> String
View
30 Data/Array/Accelerate/Repa/Evaluations.hs
@@ -120,7 +120,6 @@ evalPreOpenAcc (Acond cond acc1 acc2) letLevel
$$ text "else" $$ (nest 1 arr2)
-
evalPreOpenAcc (Use arr@(Array sh e)) letLevel
= RepaAcc returnDoc
where
@@ -129,7 +128,7 @@ evalPreOpenAcc (Use arr@(Array sh e)) letLevel
arrData = text $ show $ arrL
listType = text $ (showsTypeRep $ typeOf $ arrL) ""
- returnDoc = text "fromList"
+ returnDoc = text "fromListUnboxed"
<+> parens shS
<+> parens (arrData <+> colon <> colon <+> listType)
@@ -138,7 +137,7 @@ evalPreOpenAcc (Unit e) letLevel
= RepaAcc returnDoc
where
exp = toDoc $ evalExp e letLevel
- returnDoc = text "fromList Z" <+> brackets exp
+ returnDoc = text "fromListUnboxed Z" <+> brackets exp
evalPreOpenAcc (Reshape e acc) letLevel
@@ -149,7 +148,6 @@ evalPreOpenAcc (Reshape e acc) letLevel
returnDoc = text "reshape" <+> parens exp <+> parens arr
-
evalPreOpenAcc (Generate sh f) letLevel
= RepaAcc returnDoc
where
@@ -160,7 +158,7 @@ evalPreOpenAcc (Generate sh f) letLevel
<+> parens exp
<+> parens fun
-
+-- Not sure why sliceIndex is not required?
evalPreOpenAcc (Replicate sliceIndex slix acc) letLevel
= RepaAcc $ returnDoc
where
@@ -169,6 +167,7 @@ evalPreOpenAcc (Replicate sliceIndex slix acc) letLevel
returnDoc = text "extend" <+> parens slixD <+> parens arrD
+-- Not sure why sliceIndex is not required?
evalPreOpenAcc (Index sliceIndex acc slix) letLevel
= RepaAcc $ returnDoc
where
@@ -187,7 +186,8 @@ evalPreOpenAcc (Map f acc) letLevel
<+> (parens fun
$$ parens arr)
-
+-- Reversing order of acc1 and acc2 seems to fix some issues, will need to
+-- test more extensively with differing typed arrays to insure no errors
evalPreOpenAcc (ZipWith f acc1 acc2) letLevel
= RepaAcc returnDoc
where
@@ -200,7 +200,8 @@ evalPreOpenAcc (ZipWith f acc1 acc2) letLevel
$$ parens arr2
$$ parens arr1)
-
+-- TODO: Specialise to parallel fold 'foldP' as Repa's restrictions for this
+-- fold is same as Accelerate's
evalPreOpenAcc (Fold f e acc) letLevel
= RepaAcc returnDoc
where
@@ -213,7 +214,7 @@ evalPreOpenAcc (Fold f e acc) letLevel
$$ parens exp
$$ parens arr)
-
+-- TODO: No foldr1 function in Repa 3, change to foldP?
evalPreOpenAcc (Fold1 f acc) letLevel
= RepaAcc $ returnDoc
where
@@ -235,7 +236,7 @@ evalPreOpenAcc (Fold1 f acc) letLevel
$$ newShapeD
$$ genElemD)
-
+-- TODO: Tidy generated code
evalPreOpenAcc (FoldSeg f e acc1 acc2) letLevel
= RepaAcc $ returnDoc
where
@@ -266,14 +267,15 @@ evalPreOpenAcc (FoldSeg f e acc1 acc2) letLevel
$$ text "in newVal"))
$$ text "in"
$$ nest 1 (text "traverse res (\\(Z:.i) -> (Z:.(i-1))) (\\orig (Z:.pos) -> orig (Z:.pos))"))
- $$ text "foldOne lookup (sh:.ix) ="
+ $$ text "foldOne lookup (sh:.ix) ="
<+> (text "let" <+> (text "start = starts ! (Z:.ix)"
$$ text "len = seg ! (Z:.ix)")
$$ text "in foldSeg' sh e start (start+len)")
- $$ text "foldSeg' sh val start end"
- $$ nest 1 (text "| start >= end = val"
+ $$ text "foldSeg' sh val start end"
+ $$ nest 1 (text "| start >= end = val"
$$ text "| otherwise = foldSeg' sh (f val (arr ! (sh:.start))) (start+1) end")
+-- TODO: Tidy up code
evalPreOpenAcc (Fold1Seg f acc1 acc2) letLevel
= RepaAcc $ returnDoc
where
@@ -310,8 +312,6 @@ evalPreOpenAcc (Fold1Seg f acc1 acc2) letLevel
$$ nest 1 (text "| start >= end = val"
$$ text "| otherwise = foldSeg' sh (f val (arr ! (sh:.start))) (start+1) end")
--- Current generated code will be grossly inefficient, will need to generate more
--- efficient code later, but currently working
evalPreOpenAcc (Scanl f e acc) letLevel
= RepaAcc returnDoc
where
@@ -644,7 +644,7 @@ evalOpenExp (Shape acc) lamL letL
RepaAcc arr = evalOpenAcc acc letL
evalOpenExp (Size acc) _lamL letL
- = RepaExp $ text "Repa.size" <+> parens arr
+ = RepaExp $ text "Repa.size $ Repa.extent" <+> parens arr
where
RepaAcc arr = evalOpenAcc acc letL
View
2  accelerate-repa.cabal
@@ -15,7 +15,7 @@ Category: Compilers/Interpreters, Concurrency, Data
Stability: Experimental
Library
- Build-depends: repa == 2.*,
+ Build-depends: repa == 3.*,
accelerate == 0.9.*,
base,
pretty == 1.1.*,
Please sign in to comment.
Something went wrong with that request. Please try again.