forked from ghc/packages-dph
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
146 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
{-# LANGUAGE ParallelArrays #-} | ||
{-# OPTIONS -fvectorise #-} | ||
module IndicesVectorised | ||
(indicesPA, indices) | ||
where | ||
import Data.Array.Parallel.Prelude | ||
import Data.Array.Parallel.Prelude.Int | ||
import qualified Prelude as P | ||
|
||
|
||
indicesPA :: PArray Int -> PArray Int -> PArray Int | ||
{-# NOINLINE indicesPA #-} | ||
indicesPA arr ixs | ||
= toPArrayP (indices (fromPArrayP arr) (fromPArrayP ixs)) | ||
|
||
|
||
indices :: [:Int:] -> [:Int:] -> [:Int:] | ||
indices arr ixs | ||
= treeLookup arr ixs | ||
|
||
{- | ||
= mapP (thing arr) ixs | ||
thing :: [:Int:] -> Int -> Int | ||
thing arr i | ||
= (sliceP i 1 arr) !: 0 | ||
-- arr !: i | ||
thingo :: [:Int:] -> [:Int:] -> [:Int:] | ||
thingo table is | ||
= go is | ||
where go is' | ||
= | ||
-} | ||
|
||
treeLookup :: [:Int:] -> [:Int:] -> [:Int:] | ||
{-# NOINLINE treeLookup #-} | ||
treeLookup table xx | ||
| lengthP xx == 1 | ||
= [: table !: (xx !: 0) :] | ||
|
||
| otherwise | ||
= let len = lengthP xx | ||
half = len `div` 2 | ||
s1 = sliceP 0 half xx | ||
s2 = sliceP half half xx | ||
in concatP (mapP (treeLookup table) [: s1, s2 :]) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
|
||
import Util | ||
import Timing | ||
import Randomish | ||
import System.Environment | ||
import Control.Exception | ||
import qualified IndicesVectorised as ID | ||
import qualified Data.Array.Parallel.PArray as P | ||
import qualified Data.Vector.Unboxed as V | ||
|
||
|
||
main | ||
= do args <- getArgs | ||
|
||
case args of | ||
[alg, count] -> run alg (read count) | ||
_ -> usage | ||
|
||
|
||
run "vectorised" count | ||
= do let arr = P.fromList [0 .. count - 1] | ||
arr `seq` return () | ||
|
||
(arrResult, tElapsed) | ||
<- time | ||
$ let arr' = ID.indicesPA arr arr | ||
in P.nf arr' `seq` return arr' | ||
|
||
print $ P.length arrResult | ||
putStr $ prettyTime tElapsed | ||
|
||
run _ _ | ||
= usage | ||
|
||
|
||
usage = putStr $ unlines | ||
[ "usage: indices <algorithm> <count>\n" | ||
, " algorithm one of " ++ show ["vectorised"] | ||
, ""] |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import Util | ||
import Timing | ||
import Randomish | ||
import System.Environment | ||
import Control.Exception | ||
import qualified RankVectorised as RD | ||
import qualified Data.Array.Parallel.PArray as P | ||
import qualified Data.Vector.Unboxed as V | ||
|
||
|
||
main | ||
= do args <- getArgs | ||
|
||
case args of | ||
[alg, count] -> run alg (read count) | ||
_ -> usage | ||
|
||
|
||
run "vectorised" count | ||
= do let arr = P.fromList [0 .. count - 1] | ||
arr `seq` return () | ||
|
||
(arrRanks, tElapsed) | ||
<- time | ||
$ let arr' = RD.ranksPA arr | ||
in P.nf arr' `seq` return arr' | ||
|
||
print $ P.length arrRanks | ||
putStr $ prettyTime tElapsed | ||
|
||
run _ _ | ||
= usage | ||
|
||
|
||
usage = putStr $ unlines | ||
[ "usage: rank <algorithm> <count>\n" | ||
, " algorithm one of " ++ show ["vectorised"] | ||
, ""] |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{-# LANGUAGE ParallelArrays #-} | ||
{-# OPTIONS -fvectorise #-} | ||
module RankVectorised | ||
(ranksPA) | ||
where | ||
import Data.Array.Parallel.Prelude | ||
import Data.Array.Parallel.Prelude.Int | ||
import qualified Prelude as P | ||
|
||
|
||
ranksPA :: PArray Int -> PArray Int | ||
{-# NOINLINE ranksPA #-} | ||
ranksPA ps | ||
= toPArrayP (ranks (fromPArrayP ps)) | ||
|
||
ranks :: [:Int:] -> [:Int:] | ||
{-# NOINLINE ranks #-} | ||
ranks arr = [: lengthP [: a | a <- arr, a < b :] | b <- arr :] | ||
|