aboutsummaryrefslogtreecommitdiff
path: root/src/Data/Array
diff options
context:
space:
mode:
authorTom Smeding <tom@tomsmeding.com>2025-03-18 22:32:16 +0100
committerTom Smeding <tom@tomsmeding.com>2025-03-18 22:32:16 +0100
commitcb758277b3fa2d74551c45340b8ff0539713078c (patch)
tree4adb951118b70613b49f638c539282a8d28da2f0 /src/Data/Array
parent27c2823387b21e8ed801e4d8eeb0b3e5588a2920 (diff)
Arith statistics collection from C
Diffstat (limited to 'src/Data/Array')
-rw-r--r--src/Data/Array/Mixed/Internal/Arith.hs14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/Data/Array/Mixed/Internal/Arith.hs b/src/Data/Array/Mixed/Internal/Arith.hs
index 9c560d6..27ebb64 100644
--- a/src/Data/Array/Mixed/Internal/Arith.hs
+++ b/src/Data/Array/Mixed/Internal/Arith.hs
@@ -27,6 +27,7 @@ import Foreign.Storable (Storable(sizeOf), peek, poke)
import GHC.TypeLits
import GHC.TypeNats qualified as TypeNats
import Language.Haskell.TH
+import System.IO (hFlush, stdout)
import System.IO.Unsafe
import Data.Array.Mixed.Internal.Arith.Foreign
@@ -603,6 +604,19 @@ $(fmap concat . forM typesList $ \arithtype -> do
,do body <- [| \sn -> vectorDotprodInnerOp sn id id $mul_op (scaleFromSVStrided $c_scale_op) $c_red_op $c_op |]
return $ FunD name [Clause [] (NormalB body) []]])
+foreign import ccall unsafe "oxarrays_stats_enable" c_stats_enable :: Int32 -> IO ()
+foreign import ccall unsafe "oxarrays_stats_print_all" c_stats_print_all :: IO ()
+
+statisticsEnable :: Bool -> IO ()
+statisticsEnable b = c_stats_enable (if b then 1 else 0)
+
+-- | Consumes the log: one particular event will only ever be printed once,
+-- even if statisticsPrintAll is called multiple times.
+statisticsPrintAll :: IO ()
+statisticsPrintAll = do
+ hFlush stdout -- lower the chance of overlapping output
+ c_stats_print_all
+
-- This branch is ostensibly a runtime branch, but will (hopefully) be
-- constant-folded away by GHC.
intWidBranch1 :: forall i n. (FiniteBits i, Storable i)