Last active
December 31, 2015 00:49
-
-
Save alpmestan/7909698 to your computer and use it in GitHub Desktop.
accelerate internal error
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import qualified Data.Array.Accelerate as A | |
import qualified Data.Array.Accelerate.CUDA as A | |
-- (v1 `outer` v2) . (v1 - v2) | |
h :: A.Vector Double -> A.Vector Double -> A.Vector Double | |
h v1 v2 = A.run $ accOuter v1' v2' `accApply` A.zipWith (-) v1' v2' | |
where !v1' = A.use v1 | |
!v2' = A.use v2 | |
-- outer product | |
accOuter :: A.Acc (A.Vector Double) -> A.Acc (A.Vector Double) | |
-> A.Acc (A.Array A.DIM2 Double) | |
accOuter xs ys = A.zipWith (*) xsRepl ysRepl | |
where | |
n = A.size xs | |
m = A.size ys | |
xsRepl = A.replicate (A.lift (A.Z A.:. A.All A.:. m )) xs | |
ysRepl = A.replicate (A.lift (A.Z A.:. n A.:. A.All)) ys | |
-- matrix vector mult | |
accApply :: A.Acc (A.Array A.DIM2 Double) -> A.Acc (A.Vector Double) -> A.Acc (A.Vector Double) | |
accApply m v = let A.Z A.:. rows A.:. _ = A.unlift (A.shape m) :: A.Z A.:. A.Exp Int A.:. A.Exp Int | |
in A.generate (A.index1 rows) | |
(\ix -> A.the (v `accDot` takeRow (A.unindex1 ix) m)) | |
-- get a whole row from a matrix | |
takeRow :: A.Exp Int -> A.Acc (A.Array A.DIM2 Double) -> A.Acc (A.Vector Double) | |
takeRow n mat = | |
let A.Z A.:. _ A.:. cols = A.unlift (A.shape mat) :: A.Z A.:. A.Exp Int A.:. A.Exp Int | |
in A.backpermute (A.index1 cols) | |
(\ix -> A.index2 n (A.unindex1 ix)) | |
mat | |
-- dot product for vectors | |
accDot :: A.Acc (A.Array A.DIM1 Double) -> A.Acc (A.Array A.DIM1 Double) -> A.Acc (A.Scalar Double) | |
accDot xs ys = A.sum (A.zipWith (*) xs ys) | |
-- then, criterion calls h: | |
-- ... | |
-- bgroup "accelerate" [ bench "100" $ whnf (h a1) a2 ] | |
-- ... | |
-- where | |
-- !a1 = (A.Z A.:. 100) `A.fromList` [1..100] | |
-- !a2 = (A.Z A.:. 100) `A.fromList` [0..99] | |
-- the error | |
{- | |
benchmarking accelerate/100 | |
mats: | |
*** Internal error in package accelerate *** | |
*** Please submit a bug report at https://github.com/AccelerateHS/accelerate/issues | |
./Data/Array/Accelerate/Trafo/Sharing.hs:447 (convertSharingExp): inconsistent valuation @ shared 'Exp' tree with stable name 72; | |
env' = [74] | |
-} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment