Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add errors and assertions to Acc computations #68

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions accelerate-llvm/src/Data/Array/Accelerate/LLVM/AST.hs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ data PreOpenAccCommand acc arch aenv a where
-> acc arch aenv arrs2
-> PreOpenAccCommand acc arch aenv arrs2

Aerror :: ArraysR arrs2
-> Message arrs1
-> acc arch aenv arrs1
-> PreOpenAccCommand acc arch aenv arrs2

Apply :: ArraysR bs
-> PreOpenAfun (acc arch) aenv (as -> bs)
-> acc arch aenv as
Expand Down Expand Up @@ -200,6 +205,7 @@ instance HasArraysR (acc arch) => HasArraysR (PreOpenAccCommand acc arch) where
arraysR (Apair a1 a2) = arraysR a1 `TupRpair` arraysR a2
arraysR Anil = TupRunit
arraysR (Atrace _ _ a2) = arraysR a2
arraysR (Aerror repr _ _) = repr
arraysR (Apply repr _ _) = repr
arraysR (Aforeign repr _ _ _) = repr
arraysR (Acond _ a1 _) = arraysR a1
Expand Down
1 change: 1 addition & 0 deletions accelerate-llvm/src/Data/Array/Accelerate/LLVM/CodeGen.hs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ llvmOfPreOpenAcc uid pacc aenv = evalCodeGen $
Apair{} -> unexpectedError
Anil -> unexpectedError
Atrace{} -> unexpectedError
Aerror{} -> unexpectedError
Use{} -> unexpectedError
Unit{} -> unexpectedError
Aforeign{} -> unexpectedError
Expand Down
1 change: 1 addition & 0 deletions accelerate-llvm/src/Data/Array/Accelerate/LLVM/Compile.hs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ compileOpenAcc = traverseAcc
Apair a1 a2 -> plain =<< liftA2 AST.Apair <$> travA a1 <*> travA a2
Anil -> plain $ pure AST.Anil
Atrace msg a1 a2 -> plain =<< liftA2 (AST.Atrace msg) <$> travA a1 <*> travA a2
Aerror repr msg a -> plain =<< liftA (AST.Aerror repr msg) <$> travA a

-- Foreign arrays operations
Aforeign repr ff afun a -> foreignA repr ff afun a
Expand Down
1 change: 1 addition & 0 deletions accelerate-llvm/src/Data/Array/Accelerate/LLVM/Embed.hs
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ liftPreOpenAccCommand arch pacc =
Apair a1 a2 -> [|| Apair $$(liftA a1) $$(liftA a2) ||]
Anil -> [|| Anil ||]
Atrace msg a1 a2 -> [|| Atrace $$(liftMessage (arraysR a1) msg) $$(liftA a1) $$(liftA a2) ||]
Aerror repr msg a -> [|| Aerror $$(liftArraysR repr) $$(liftMessage (arraysR a) msg) $$(liftA a) ||]
Apply repr f a -> [|| Apply $$(liftArraysR repr) $$(liftAF f) $$(liftA a) ||]
Acond p t e -> [|| Acond $$(liftE p) $$(liftA t) $$(liftA e) ||]
Awhile p f a -> [|| Awhile $$(liftAF p) $$(liftAF f) $$(liftA a) ||]
Expand Down
6 changes: 5 additions & 1 deletion accelerate-llvm/src/Data/Array/Accelerate/LLVM/Execute.hs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import Data.Array.Accelerate.AST.Idx
import Data.Array.Accelerate.AST.Var
import Data.Array.Accelerate.Analysis.Match
import Data.Array.Accelerate.Array.Data
import Data.Array.Accelerate.Interpreter ( evalPrim, evalPrimConst, evalCoerceScalar, atraceOp )
import Data.Array.Accelerate.Interpreter ( evalPrim, evalPrimConst, evalCoerceScalar, atraceOp, aerrorOp )
import Data.Array.Accelerate.Representation.Array
import Data.Array.Accelerate.Representation.Elt
import Data.Array.Accelerate.Representation.Shape
Expand Down Expand Up @@ -285,6 +285,10 @@ executeOpenAcc !topAcc !aenv = travA topAcc
a1' <- travA a1 >>= blockArrays repr >>= copyToHost repr
liftIO $ atraceOp msg a1'
travA a2
Aerror _ msg a1 -> do
let repr = arraysR a1
a1' <- travA a1 >>= blockArrays repr >>= copyToHost repr
aerrorOp msg a1'

-- We need quite some type applications in the rules for acond and awhile, and cannot use do notation.
-- For some unknown reason, GHC will "simplify" 'FutureArraysR arch a' to 'FutureR arch a', which is not sound.
Expand Down
1 change: 1 addition & 0 deletions accelerate-llvm/src/Data/Array/Accelerate/LLVM/Link.hs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ linkOpenAcc = travA
Acond p t e -> Acond p <$> travA t <*> travA e
Apair a1 a2 -> Apair <$> travA a1 <*> travA a2
Atrace msg a1 a2 -> Atrace msg <$> travA a1 <*> travA a2
Aerror repr msg a1 -> Aerror repr msg <$> travA a1
Anil -> return Anil
Reshape shr s ix -> Reshape shr s <$> pure ix
Aforeign s r f a -> Aforeign s r f <$> travA a
Expand Down