Skip to content

Commit 91a5450

Browse files
committed
rollback some of the splitting in the hope to get allocations back under control but to no avail
1 parent 47929b6 commit 91a5450

File tree

3 files changed

+68
-58
lines changed

3 files changed

+68
-58
lines changed

benchrunner/Benchrunner.hs

Lines changed: 58 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,71 @@ module Main where
55
import Data.List.Split ( splitOn )
66
import System.Environment ( getArgs )
77
import Control.Monad ( unless )
8+
import Control.DeepSeq ( NFData )
89

910
import qualified Array as A
11+
import Linear.Common
12+
13+
import ForeignFunctionImports as FFI
1014
import qualified Vector as V
1115
import Input
1216
import qualified Measure as M
1317
import Sort
1418
import Utils
1519
import qualified Microbench as MB
1620

21+
import qualified Insertion as I
22+
import qualified QuickSort as Q
23+
import qualified DpsMergeSort4 as DMS
24+
import qualified DpsMergeSort4Par as DMSP
25+
import qualified PiecewiseFallbackSort as PFS
26+
import qualified PiecewiseFallbackSortPar as PFSP
27+
import qualified Data.Vector.Algorithms.Insertion as ISDVS
28+
import qualified Data.Vector.Algorithms.Merge as MSDVS
29+
import qualified Data.Vector.Algorithms.Intro as QSDVS
30+
31+
--
32+
-- Table of sorting functions
33+
--
34+
35+
sortFn :: (Show a, A.HasPrimOrd a, NFData a) => SortAlgo -> ParOrSeq -> (A.Array a -. A.Array a)
36+
sortFn bench parorseq = case (bench,parorseq) of
37+
(Insertionsort, Seq) -> I.isort_top'
38+
(Quicksort, Seq) -> Q.quickSort'
39+
(Mergesort, Seq) -> DMS.msort
40+
(Mergesort, Par) -> DMSP.msort
41+
(Optsort, Seq) -> PFS.pfsort
42+
(Optsort, Par) -> PFSP.pfsort
43+
oth -> error $ "sortFn: unknown configuration: " ++ show oth
44+
{-# INLINABLE sortFn #-}
45+
46+
vectorSortFn :: SortAlgo -> ParOrSeq -> VecSort
47+
vectorSortFn bench parorseq = case (bench,parorseq) of
48+
(Insertionsort, Seq) -> ISDVS.sort
49+
(Mergesort, Seq) -> MSDVS.sort
50+
(Quicksort, Seq) -> QSDVS.sort
51+
oth -> error $ "sortFn: unknown configuration: " ++ show oth
52+
{-# INLINABLE vectorSortFn #-}
53+
54+
sortFnC :: SortAlgo -> FFI.SortFn
55+
sortFnC alg = case alg of
56+
Insertionsort -> FFI.c_insertionsort
57+
Mergesort -> FFI.c_mergesort
58+
Quicksort -> FFI.c_quicksort
59+
_ -> error "sortFnC: Csort not implemented!"
60+
{-# INLINABLE sortFnC #-}
61+
62+
sortFnCxx :: SortAlgo -> FFI.SortFnCxx
63+
sortFnCxx alg = case alg of
64+
Insertionsort -> FFI.cxx_int_insertionsort
65+
Mergesort -> FFI.cxx_int_mergesort
66+
Quicksort -> FFI.cxx_int_quicksort
67+
_ -> error "sortFnCxx: Csort not implemented!"
68+
{-# INLINABLE sortFnCxx #-}
69+
70+
--
71+
-- Select which benchmark to run
72+
--
1773

1874
-- dobench :: Benchmark -> ParOrSeq -> Maybe Int -> IO ()
1975
dobench :: Benchmark -> ParOrSeq -> Maybe Int -> Int -> IO ()
@@ -102,13 +158,13 @@ dobench bench parorseq mb_size iters = do
102158
pure (A.size arr, A.size res0, tmed0, tall0)
103159
CSort alg -> do
104160
arr <- getInputAsList alg mb_size
105-
(res0, tmed0, tall0) <- M.benchAndRunCSorts alg arr iters
161+
(res0, tmed0, tall0) <- M.benchAndRunCSorts (sortFnC alg) arr iters
106162
unless (isSorted (res0)) (error $ show bench ++ ": result not sorted.")
107163
putStrLn "Sorted: OK"
108164
pure (length arr, length res0, tmed0, tall0)
109165
CxxSort alg -> do
110166
arr <- getInputAsList alg mb_size
111-
(res0, tmed0, tall0) <- M.benchAndRunCxxSorts alg arr iters
167+
(res0, tmed0, tall0) <- M.benchAndRunCxxSorts (sortFnCxx alg) arr iters
112168
unless (isSorted (res0)) (error $ show bench ++ ": result not sorted.")
113169
putStrLn "Sorted: OK"
114170
pure (length arr, length res0, tmed0, tall0)

benchrunner/Measure.hs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import Data.Time.Clock (getCurrentTime, diffUTCTime)
1010

1111
import qualified Array as A
1212
import Foreign as F
13+
import ForeignFunctionImports as FFI
1314
import Sort
1415
import Utils
1516
import qualified Vector as V
@@ -155,11 +156,11 @@ benchAndRunDataVecSorts sortfn inVec iters = do
155156
-- [Int64]: sorted output array from the last iteration that was run
156157
-- Double: median runtime from the iterations that were run (selftimed)
157158
-- Double: Total time taken to run all the iterations (batchtime)
158-
benchAndRunCSorts :: SortAlgo -> [Int64] -> Int -> IO ([Int64], Double, Double)
159-
benchAndRunCSorts salg arr iters = do
159+
benchAndRunCSorts :: FFI.SortFn -> [Int64] -> Int -> IO ([Int64], Double, Double)
160+
benchAndRunCSorts fn arr iters = do
160161
!tups <- mapM (\_ -> do
161162
!ptr <- newArray arr
162-
res <- dotrialC salg (length arr) ptr
163+
res <- dotrialC fn (length arr) ptr
163164
pure res
164165
) [1..iters]
165166
let (results, times) = unzip tups
@@ -168,9 +169,8 @@ benchAndRunCSorts salg arr iters = do
168169
batchtime = sum times
169170
return $! (last results, selftimed, batchtime)
170171
where
171-
dotrialC alg arrLength ptr = do
172+
dotrialC fn arrLength ptr = do
172173
performMajorGC
173-
let fn = sortFnC alg
174174
t1 <- getCurrentTime
175175
!sortedPtr <- fn ptr (fromIntegral arrLength) (fromIntegral $ F.sizeOf (undefined :: Int64))
176176
t2 <- getCurrentTime
@@ -183,11 +183,11 @@ benchAndRunCSorts salg arr iters = do
183183
-- [Int64]: sorted output array from the last iteration that was run
184184
-- Double: median runtime from the iterations that were run (selftimed)
185185
-- Double: Total time taken to run all the iterations (batchtime)
186-
benchAndRunCxxSorts :: SortAlgo -> [Int64] -> Int -> IO ([Int64], Double, Double)
187-
benchAndRunCxxSorts salg arr iters = do
186+
benchAndRunCxxSorts :: FFI.SortFnCxx -> [Int64] -> Int -> IO ([Int64], Double, Double)
187+
benchAndRunCxxSorts fn arr iters = do
188188
!tups <- mapM (\_ -> do
189189
!ptr <- newArray arr
190-
res <- dotrialCxx salg (length arr) ptr
190+
res <- dotrialCxx fn (length arr) ptr
191191
pure res
192192
) [1..iters]
193193
let (results, times) = unzip tups
@@ -196,9 +196,8 @@ benchAndRunCxxSorts salg arr iters = do
196196
batchtime = sum times
197197
return $! (last results, selftimed, batchtime)
198198
where
199-
dotrialCxx alg arrLength ptr = do
199+
dotrialCxx fn arrLength ptr = do
200200
performMajorGC
201-
let fn = sortFnCxx alg
202201
t1 <- getCurrentTime
203202
!sortedPtr <- fn ptr (fromIntegral arrLength)
204203
t2 <- getCurrentTime

benchrunner/Sort.hs

Lines changed: 1 addition & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,10 @@
11
-- | Encode sorting functions as an ADT
22
module Sort where
33

4-
import qualified Insertion as I
5-
import qualified QuickSort as Q
6-
import qualified DpsMergeSort4 as DMS
7-
import qualified DpsMergeSort4Par as DMSP
8-
import qualified PiecewiseFallbackSort as PFS
9-
import qualified PiecewiseFallbackSortPar as PFSP
10-
import qualified Array as A
11-
import qualified Data.Vector.Unboxed as V
12-
import qualified Data.Vector.Algorithms.Insertion as ISDVS
13-
import qualified Data.Vector.Algorithms.Merge as MSDVS
14-
import qualified Data.Vector.Algorithms.Intro as QSDVS
15-
164
import Data.Int (Int64)
175
import Control.Monad.Primitive (PrimState)
186

7+
import qualified Data.Vector.Unboxed as V
198
import qualified Data.Vector.Unboxed.Mutable as MV
209
import qualified ForeignFunctionImports as FFI
2110
import Control.DeepSeq (NFData)
@@ -35,37 +24,3 @@ type MVec = MV.MVector (PrimState IO) Int64
3524
type Vec = V.Vector Int64
3625
type VecSort = MVec -> IO ()
3726

38-
sortFn :: (Show a, A.HasPrimOrd a, NFData a) => SortAlgo -> ParOrSeq -> (A.Array a -. A.Array a)
39-
sortFn bench parorseq = case (bench,parorseq) of
40-
(Insertionsort, Seq) -> I.isort_top'
41-
(Quicksort, Seq) -> Q.quickSort'
42-
(Mergesort, Seq) -> DMS.msort
43-
(Mergesort, Par) -> DMSP.msort
44-
(Optsort, Seq) -> PFS.pfsort
45-
(Optsort, Par) -> PFSP.pfsort
46-
oth -> error $ "sortFn: unknown configuration: " ++ show oth
47-
{-# INLINABLE sortFn #-}
48-
49-
vectorSortFn :: SortAlgo -> ParOrSeq -> VecSort
50-
vectorSortFn bench parorseq = case (bench,parorseq) of
51-
(Insertionsort, Seq) -> ISDVS.sort
52-
(Mergesort, Seq) -> MSDVS.sort
53-
(Quicksort, Seq) -> QSDVS.sort
54-
oth -> error $ "sortFn: unknown configuration: " ++ show oth
55-
{-# INLINABLE vectorSortFn #-}
56-
57-
sortFnC :: SortAlgo -> FFI.SortFn
58-
sortFnC alg = case alg of
59-
Insertionsort -> FFI.c_insertionsort
60-
Mergesort -> FFI.c_mergesort
61-
Quicksort -> FFI.c_quicksort
62-
_ -> error "sortFnC: Csort not implemented!"
63-
{-# INLINABLE sortFnC #-}
64-
65-
sortFnCxx :: SortAlgo -> FFI.SortFnCxx
66-
sortFnCxx alg = case alg of
67-
Insertionsort -> FFI.cxx_int_insertionsort
68-
Mergesort -> FFI.cxx_int_mergesort
69-
Quicksort -> FFI.cxx_int_quicksort
70-
_ -> error "sortFnCxx: Csort not implemented!"
71-
{-# INLINABLE sortFnCxx #-}

0 commit comments

Comments
 (0)