Skip to content

Commit

Permalink
Fix issue #11. At least in a narrow sense.
Browse files Browse the repository at this point in the history
This is only part of the story, however.  We've still managed to introduce all the
following test failures with the new policy on treating unit arrays:

----------------------------------------

run test 12/67 p11:: [Failed]
ERROR: repackAcc2: ran out of input arrays.

run test 13/67 p11b:: [Failed]
ERROR: repackAcc2: ran out of input arrays.

run test 14/67 p11c:: [Failed]
ERROR: repackAcc2: ran out of input arrays.

----------------------------------------

run test 23/67 p13j:: [Failed]
ERROR: packArray: given a AccArray of the wrong type, expected Int received 2 payloads:
ArrayPayloadUnit 1
ArrayPayloadInt (array (0,0) [(0,-5764607523034234880)])

 dimension: []

----------------------------------------

run test 64/67 p5:: [Failed]
ERROR: packArray: given a AccArray of the wrong type, expected Int received 3 payloads:
ArrayPayloadUnit 1
ArrayPayloadInt (array (0,0) [(0,-6917529027641081856)])
ArrayPayloadUnit 1

----------------------------------------
  • Loading branch information
rrnewton committed Feb 23, 2014
1 parent dfa8318 commit 93ec220
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -581,13 +581,13 @@ tupleTy ls = S.TTuple ls
-- convertConst :: Sug.Elt t => Sug.EltRepr t -> S.Const
convertConst :: TupleType a -> a -> S.Const
convertConst ty0 c0 =
(\x -> x `seq` trace ("Converting tuple const: "++show ty0++" -> "++show x) x) $
(\x -> x `seq` maybtrace ("Converting tuple const: "++show ty0++" -> "++show x) x) $
branch ty0 c0
where
-- Follow the leftmost side
spine :: TupleType a -> a -> [S.Const]
spine ty c =
(\x -> x `seq` trace (" *: Spine "++show ty++" -> "++show x) x) $
-- (\x -> x `seq` maybtrace (" *: Spine "++show ty++" -> "++show x) x) $
case ty of
UnitTuple -> []
PairTuple ty1 ty0 -> let (c1,c0) = c
Expand All @@ -597,7 +597,7 @@ convertConst ty0 c0 =

branch :: TupleType a -> a -> S.Const
branch ty c =
(\x -> x `seq` trace (" *: Branch "++show ty++" -> "++show x) x) $
-- (\x -> x `seq` maybtrace (" *: Branch "++show ty++" -> "++show x) x) $
case ty of
UnitTuple -> S.Tup []
-- This begins a new tuple:
Expand Down Expand Up @@ -979,18 +979,20 @@ repackAcc dummy simpls =
in ((res1,res2), rst')
Sug.ArraysRarray | (_ :: Sug.ArraysR (Sug.Array sh elt)) <- arrR ->
case simpls of
[] -> error$"repackAcc2: ran out of input arrays.\n"
ls ->
-- Once we have peeled off "one" array, we still need to unzip the tupled elements.
let elTy = Sug.eltType (undefined::elt)
elWid = eltWidth elTy
zipped = SA.concatAccArrays$ take elWid ls
in ((packArray zipped) :: (Sug.Array sh elt),
in
((packArray zipped) :: (Sug.Array sh elt),
drop elWid ls)
oth -> error$"repackAcc2: ran out of input arrays.\n"

-- How many scalar components are there in an element type?
eltWidth :: forall a . TupleType a -> Int
eltWidth UnitTuple = 0
-- FIXME: consolidate this policy by using flattenTy here explicitly:
eltWidth UnitTuple = 1 -- [2014.02.23] Changing this policy, not getting RID of unit.s
eltWidth (PairTuple a b) = eltWidth a + eltWidth b
eltWidth (SingleTuple _) = 1

Expand Down
6 changes: 4 additions & 2 deletions backend-kit/tests/UnitTests.hs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ zPacked1 = packArray unitArray
case_zPacked = assertEqual "zPacked " "Array (Z :. 10) [Z,Z,Z,Z,Z,Z,Z,Z,Z,Z]" (show zPacked1)

zPacked2 :: Array (Z :. Int) Z
zPacked2 = repackAcc (undefined :: A.Acc (A.Array (Z :. Int) Z)) [unitArray]
-- zPacked2 = repackAcc (undefined :: A.Acc (A.Array (Z :. Int) Z)) [unitArray]
zPacked2 = repackAcc (A.use zPacked1) [unitArray]

main :: IO ()
main = do
Expand All @@ -45,4 +46,5 @@ main = do

putStrLn$ "zpacked "++ show zPacked1

putStrLn$ "zpacked2 "++ show zPacked2
putStrLn "zPacked2:"
print zPacked2

0 comments on commit 93ec220

Please sign in to comment.