|
6 | 6 |
|
7 | 7 | module Main where
|
8 | 8 |
|
9 |
| -import Numeric.AD.Double |
10 |
| -import Criterion.Main |
11 | 9 | import Control.Monad
|
| 10 | +import Criterion |
| 11 | +import Criterion.Main |
| 12 | +import Criterion.Types |
| 13 | +import Numeric.AD.Double |
| 14 | +import Statistics.Types |
| 15 | +import Text.Printf |
12 | 16 | import Prelude hiding (init)
|
13 | 17 |
|
14 | 18 | import GHC.IsList
|
@@ -118,7 +122,7 @@ computeResistance
|
118 | 122 | -> Tube a
|
119 | 123 | -> Quanta a
|
120 | 124 | -> a
|
121 |
| -computeResistance floor tube quanta = |
| 125 | +computeResistance floor tube _quanta = |
122 | 126 | let geometry_coeff = 10.0
|
123 | 127 | -- f_coff = 0.3333333
|
124 | 128 |
|
@@ -294,21 +298,30 @@ timesteps :: Int
|
294 | 298 | timesteps = 1000
|
295 | 299 |
|
296 | 300 | printGradToCompare :: Bool
|
297 |
| -printGradToCompare = True |
| 301 | +printGradToCompare = False |
298 | 302 |
|
299 | 303 | main :: IO ()
|
300 | 304 | main = do
|
301 |
| - let params = init :: SimParams Double |
302 |
| - params' = unpack params |
303 |
| - fullPipe' = grad (fullPipe . pack) |
| 305 | + let simParams = init :: SimParams Double |
| 306 | + simParams' = unpack simParams |
| 307 | + fullPipe' = grad (fullPipe . pack) |
| 308 | + config = defaultConfig { verbosity = Quiet } |
304 | 309 |
|
305 | 310 | when printGradToCompare $
|
306 |
| - print (pack (fullPipe' params')) |
| 311 | + print (pack (fullPipe' simParams')) |
| 312 | + |
| 313 | + -- The default benchmarking setup will give more accurate information, but |
| 314 | + -- we'll prefer to just match the output of all benchmark programs instead |
| 315 | + -- defaultMain |
| 316 | + -- [ bench "primal" $ nf fullPipe simParams |
| 317 | + -- , bench "adjoint" $ nf fullPipe' simParams' |
| 318 | + -- ] |
| 319 | + |
| 320 | + result_forward <- benchmarkWith' config $ nf fullPipe simParams |
| 321 | + result_gradient <- benchmarkWith' config $ nf fullPipe' simParams' |
307 | 322 |
|
308 |
| - defaultMain |
309 |
| - [ bench "primal" $ nf fullPipe params |
310 |
| - , bench "adjoint" $ nf fullPipe' params' |
311 |
| - ] |
| 323 | + printf "average forward only time: %f seconds\n" result_forward.reportAnalysis.anMean.estPoint |
| 324 | + printf "average forward and backwards (gradient) time: %f seconds\n" result_gradient.reportAnalysis.anMean.estPoint |
312 | 325 |
|
313 | 326 |
|
314 | 327 | -- Helpers ---------------------------------------------------------------------
|
|
0 commit comments