Update buildbot
[packages/dph.git] / dph-buildbot / src / Benchmarks.hs
1 {-# OPTIONS -fno-warn-type-defaults #-}
2
3 module Benchmarks where
4 import Config
5 import BuildBox
6 import Control.Monad
7 import qualified BuildBox.Data.Log as Log
8
9 -- | DPH benchmark configuation.
10 benchmarksDPH :: Config -> [Benchmark]
11 benchmarksDPH config
12
13 -- dot product --------------------------------------------------------
14 = (let run n = bench config
15 ("dph.dotp.vectorised.par.N" ++ show n)
16 ("dph-examples/dist/build/dph-dotp/dph-dotp vectorised 10000000 +RTS -N" ++ show n)
17 in map run [1, 2, 4, 8])
18
19 ++ [ bench config
20 "dph.dotp.vectorised.seq.N4"
21 "dph-examples/dist/build/dph-dotp-seq/dph-dotp-seq vectorised 10000000 +RTS -N4"
22
23 , bench config
24 "dph.dotp.vector.seq.N4"
25 "dph-examples/dist/build/dph-dotp/dph-dotp vector 10000000 +RTS -N4" ]
26
27
28 -- sum of squares ---------------------------------------------------
29 ++ (let run n = bench config
30 ("dph.sumsq.vectorised.par.N" ++ show n)
31 ("dph-examples/dist/build/dph-sumsq/dph-sumsq vectorised 100000000 +RTS -N" ++ show n)
32 in map run [1, 2, 4, 8])
33
34 ++ [ bench config
35 "dph.sumsq.vectorised.seq.N4"
36 "dph-examples/dist/build/dph-sumsq-seq/dph-sumsq-seq vectorised 100000000 +RTS -N4"
37
38 , bench config
39 "dph.sumsq.vector.seq.N4"
40 "dph-examples/dist/build/dph-sumsq/dph-sumsq vector 100000000 +RTS -N4" ]
41
42
43 -- evens ------------------------------------------------------------
44 ++ (let run n = bench config
45 ("dph.evens.vectorised.par.N" ++ show n)
46 ("dph-examples/dist/build/dph-evens/dph-evens vectorised 10000000 +RTS -N" ++ show n)
47 in map run [1, 2, 4, 8])
48
49 ++ [ bench config
50 "dph.evens.vectorised.seq.N4"
51 "dph-examples/dist/build/dph-evens-seq/dph-evens-seq vectorised 10000000 +RTS -N4"
52
53 , bench config
54 "dph.evens.vector.seq.N4"
55 "dph-examples/dist/build/dph-evens-seq/dph-evens-seq vector 10000000 +RTS -N4" ]
56
57
58 {- -- primes ------------------------------------------------------------
59 ++ (let run n = bench config
60 ("dph.primes.vectorised.par.N" ++ show n)
61 ("dph-examples/dist/build/dph-primes/dph-primes vectorised 20000000 +RTS -N" ++ show n)
62 in map run [1, 2, 4, 8])
63
64 ++ [ bench config
65 "dph.primes.vectorised.seq.N4"
66 "dph-examples/dist/build/dph-primes-seq/dph-primes-seq vectorised 20000000 +RTS -N4"
67
68 , bench config
69 "dph.primes.vector.seq.N4"
70 "dph-examples/dist/build/dph-primes-seq/dph-primes-seq vector 20000000 +RTS -N4" ]
71 -}
72
73 -- quicksort --------------------------------------------------------
74 ++ (let run n = bench config
75 ("dph.quicksort.vectorised.par.N" ++ show n)
76 ("dph-examples/dist/build/dph-quicksort/dph-quicksort 100000 +RTS -N" ++ show n)
77 in map run [1, 2, 4, 8])
78
79
80 -- quickhull --------------------------------------------------------
81 ++ (let run n = bench config
82 ("dph.quickhull.vectorised.par.N" ++ show n)
83 ("dph-examples/dist/build/dph-quickhull/dph-quickhull 1000000 +RTS -K20M -N" ++ show n)
84 in map run [1, 2, 4, 8])
85
86
87 ++ [ bench config
88 "dph.quickhull.vectorised.seq.N4"
89 "dph-examples/dist/build/dph-quickhull-seq/dph-quickhull-seq 1000000 +RTS -N4 -K40M"
90
91 , bench config
92 "dph.quickhull.vector-immutable.seq.N4"
93 "dph-examples/dist/build/dph-quickhull-vector/dph-quickhull-vector split 1000000 +RTS -N4"
94
95 , bench config
96 "dph.quickhull.vector-mutable.seq.N4"
97 "dph-examples/dist/build/dph-quickhull-vector/dph-quickhull-vector vector 1000000 +RTS -N4"
98
99 , bench config
100 "dph.quickhull.vector-forkIO.par.N4"
101 "dph-examples/dist/build/dph-quickhull-vector/dph-quickhull-vector io 1000000 +RTS -N4"
102
103 , bench config
104 "dph.quickhull.vector-forkIO.par.N8"
105 "dph-examples/dist/build/dph-quickhull-vector/dph-quickhull-vector io 1000000 +RTS -N8"
106
107 , benchUp config
108 "dph.quickhull.c.seq"
109 (inDir "dph-examples/spectral/QuickHull/c" $ qssystem "make")
110 "dph-examples/spectral/QuickHull/c/quickhull 1000000" ]
111
112 {- -- nbody ------------------------------------------------------------
113 ++ (let run n = bench config
114 ("dph.nbody.vectorised.par.N" ++ show n)
115 ("dph-examples/dist/build/dph-nbody/dph-nbody --max-steps 10 -b 100 -s nested-bh +RTS -N" ++ show n)
116
117 in map run [1, 2, 4])
118
119 ++ [ bench config
120 "dph.nbody.vectorised.seq.N4"
121 "dph-examples/dist/build/dph-nbody/dph-nbody --max-steps 10 -b 100 -s nested-bh +RTS -N4"
122
123 , bench config
124 "dph.nbody.vector.seq.N4"
125 "dph-examples/dist/build/dph-nbody/dph-nbody --max-steps 10 -b 100 -s vector-bh +RTS -N4"
126 ]
127 -}
128
129 -- | Repa benchmark configuration.
130 benchmarksRepa :: Config -> [Benchmark]
131 benchmarksRepa config
132 = -- mmult --------------------------------------------------------------
133 (let mmult = "repa-examples/dist/build/repa-mmult/repa-mmult"
134 run n = bench config
135 ("repa.mmult.par.N" ++ show n)
136 (mmult ++ " -random 1024 1024 -random 1024 1024 +RTS -N" ++ show n)
137
138 in [run 1, run 2, run 4, run 8])
139
140 ++ [ benchUp config
141 "repa.mmult.c.seq"
142 (inDir "repa-examples" $ qssystem "make dist/build/repa-mmult-c/repa-mmult-c")
143 "repa-examples/dist/build/repa-mmult-c/repa-mmult-c -random 1024 1024 -random 1024 1024" ]
144
145
146 -- laplace ------------------------------------------------------------
147 ++ (let laplace = "repa-examples/dist/build/repa-laplace/repa-laplace"
148 input = "repa-examples/examples/Laplace/data/pls-400x400.bmp"
149 inputgz = input ++ ".gz"
150
151 run n = benchUp config
152 ("repa.laplace.par.N" ++ show n)
153 (do ensureDir "output"
154 check $ HasExecutable laplace
155 whenM (test $ HasFile inputgz)
156 $ qssystem $ "gzip -d " ++ inputgz)
157 (laplace ++ " get 1000 " ++ input ++ " output/laplace.bmp +RTS -qg -N" ++ show n)
158
159 in [run 1, run 2, run 4, run 6, run 8])
160
161 ++ [ benchUp config
162 "repa.laplace.c.seq"
163 (inDir "repa-examples" $ qssystem "make dist/build/repa-laplace-c/repa-laplace-c")
164 "repa-examples/dist/build/repa-laplace-c/repa-laplace-c 400 400 1000 output/laplace_c-seq.ppm" ]
165
166
167 -- blur ---------------------------------------------------------------
168 ++ (let blur = "repa-examples/dist/build/repa-blur/repa-blur"
169 input = "repa-examples/data/lena.bmp"
170 inputgz = input ++ ".gz"
171
172 run n = benchUp config
173 ("repa.blur.par.N" ++ show n)
174 (do ensureDir "output"
175 check $ HasExecutable blur
176 whenM (test $ HasFile inputgz)
177 $ qssystem $ "gzip -d " ++ inputgz)
178 (blur ++ " 5 " ++ input ++ " output/lena-blur.bmp +RTS -qg -N" ++ show n)
179
180 in map run [1, 2, 4, 6, 8])
181
182
183 -- edgedetect ---------------------------------------------------------
184 ++ (let edgedetect = "repa-examples/dist/build/repa-edgedetect/repa-edgedetect"
185 input = "repa-examples/data/lena.bmp"
186 inputgz = input ++ ".gz"
187
188 run n = benchUp config
189 ("repa.edgedetect.par.N" ++ show n)
190 (do ensureDir "output"
191 check $ HasExecutable edgedetect
192 whenM (test $ HasFile inputgz)
193 $ qssystem $ "gzip -d " ++ inputgz)
194 (edgedetect ++ " " ++ input ++ " output/lena-edgedetect.bmp +RTS -qg -N" ++ show n)
195
196 in map run [1, 2, 4, 6, 8])
197
198
199 -- fft2d-highpass -----------------------------------------------------
200 ++ (let fft2d = "repa-examples/dist/build/repa-fft2d-highpass/repa-fft2d-highpass"
201 input = "repa-examples/data/lena.bmp"
202 inputgz = input ++ ".gz"
203
204 run n = benchUp config
205 ("repa.fft2d.par.N" ++ show n)
206 (do ensureDir "output"
207 check $ HasExecutable fft2d
208 whenM (test $ HasFile inputgz)
209 $ qssystem $ "gzip -d " ++ inputgz)
210 (fft2d ++ " 1 " ++ input ++ " output/fft2d.bmp +RTS -qg -N" ++ show n)
211 in map run [1, 2, 4, 6, 8])
212
213
214 -- fft3d-highpass -----------------------------------------------------
215 ++ (let fft3d = "repa-examples/dist/build/repa-fft3d-highpass/repa-fft3d-highpass"
216
217 run n = benchUp config
218 ("repa.fft3d.par.N" ++ show n)
219 (ensureDir "output/fft3d")
220 (fft3d ++ " 128 output/fft3d/slice +RTS -qg -N" ++ show n)
221
222 in map run [1, 2, 4, 6, 8])
223
224
225
226 -- | Define a plain benchmark with no setup or teardown command
227 bench :: Config -> String -> String -> Benchmark
228 bench config name cmd
229 = Benchmark
230 name
231 (return ())
232 (systemWithTimings (configVerbose config) cmd)
233 (return [])
234
235
236 -- | Define a benchmark with a setup command
237 benchUp :: Config -> String -> Build () -> String -> Benchmark
238 benchUp config name cmdUp cmdBench
239 = Benchmark
240 name
241 cmdUp
242 (systemWithTimings (configVerbose config) cmdBench)
243 (return [])
244
245
246 -- | Run a system command, expecing it to print the kernel timings to stdout.
247 -- We ignore whatever is printed to stderr.
248 systemWithTimings :: Bool -> String -> Build [WithUnits (Aspect Single)]
249 systemWithTimings verbose cmd
250 = do when verbose
251 $ outLn $ "\n " ++ cmd
252
253 (code, logOut, logErr)
254 <- systemTeeLog False cmd Log.empty
255
256 if code == ExitSuccess
257 then return $ parseTimings (Log.toString logOut)
258 else throw $ ErrorSystemCmdFailed cmd code logOut logErr
259
260
261 -- | Parse kernel timings from a repa example program.
262 -- Format is elapsedTime/systemTime in milliseconds.
263 parseTimings :: String -> [WithUnits (Aspect Single)]
264 parseTimings str
265 = let (lElapsed : _) = lines str
266 thing = dropWhile (/= '=') lElapsed
267
268 elapsedTime
269 = case thing of
270 [] -> error $ "parseTimings: no time in " ++ show thing
271 _ -> tail thing
272
273 in [ Time KernelWall `secs` (read elapsedTime / 1000) ]
274
275