Skip to content

Commit aaf1559

Browse files
authored
Fix bitrot in profiling code (#1845)
The clash-profile-normalization-run broke at run time because the deserialized data had a different type signature then the serialiazed data in clash-profile-normalization-prepare. This was broken by the refactor in: df551ec There is now one type alias shared by both, resulting in compile errors in both files in future refactors like this. Also I've remove the unused tuple element leading to this mess. And while it wasn't broken, apply the same security measures to clash-profile-netlist-*
1 parent b48575b commit aaf1559

File tree

7 files changed

+25
-42
lines changed

7 files changed

+25
-42
lines changed

benchmark/profiling/prepare/clash-profiling-prepare.cabal

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ library
1616
Exposed-Modules: SerialiseInstances
1717
build-depends: base >= 4.10 && < 5,
1818
binary >= 0.8.5 && < 0.11,
19+
containers >= 0.5.4.0 && < 0.7,
1920
hashable >= 1.1.2.3 && < 1.4,
20-
template-haskell >= 2.12.0.0 && < 2.18,
2121
unordered-containers >= 0.2.3.3 && < 0.3,
2222

2323
clash-lib,
@@ -29,10 +29,7 @@ executable clash-profile-normalization-prepare
2929
ghc-options: -Wall -Wcompat
3030
build-depends: base,
3131
binary,
32-
bytestring >= 0.10.0.2 && < 0.11,
33-
directory >= 1.3.0.0 && < 1.4,
34-
filepath >= 1.4 && < 1.5,
35-
ghc >= 8.6.0 && < 9.1,
32+
bytestring,
3633

3734
clash-lib,
3835
clash-benchmark,
@@ -44,10 +41,7 @@ executable clash-profile-netlist-prepare
4441
ghc-options: -Wall -Wcompat
4542
build-depends: base,
4643
binary,
47-
bytestring >= 0.10.0.2 && < 0.11,
48-
directory >= 1.3.0.0 && < 1.4,
49-
filepath >= 1.4 && < 1.5,
50-
ghc >= 8.6.0 && < 9.1,
44+
bytestring,
5145

5246
clash-lib,
5347
clash-benchmark,

benchmark/profiling/prepare/instances/SerialiseInstances.hs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,17 @@ import Clash.Annotations.Primitive (PrimitiveGuard)
1111
import qualified Clash.Annotations.BitRepresentation.Internal as CP
1212

1313
import qualified Clash.Primitives.Types as CL
14-
import qualified Clash.Netlist.Types as CL (BlackBox)
14+
import qualified Clash.Netlist.Types as CL (BlackBox, TopEntityT)
1515
import qualified Clash.Netlist.BlackBox.Types as CL
1616

1717
import qualified Data.HashMap.Strict as HM
1818

19+
import Clash.Annotations.BitRepresentation.Internal (CustomReprs)
20+
import Clash.Core.Var (Id)
21+
import Clash.Core.TyCon (TyConMap,TyConName)
22+
import Clash.Driver.Types (BindingMap)
23+
import Data.IntMap.Strict (IntMap)
24+
1925

2026
-- | Like C.CompiledPrimitive but without the functions BlackBoxFunction so we can serialise it
2127
type CompiledPrimitive' = CL.Primitive CL.BlackBoxTemplate CL.BlackBox () ()
@@ -37,3 +43,9 @@ instance Binary CP.ConstrRepr'
3743
instance (Binary k, Binary v, Eq k, Hashable k) => Binary (HM.HashMap k v) where
3844
put = put . HM.toList
3945
get = HM.fromList <$> get
46+
47+
-- data that's serialised to file between profile-normalization-prepare and profile-normalization-run
48+
type NormalizationInputs = (BindingMap,TyConMap,IntMap TyConName,CompiledPrimMap',CustomReprs,[Id],Id)
49+
50+
-- data that's serialised to file between profile-netlist-prepare and profile-netlist-run
51+
type NetlistInputs = (BindingMap,[CL.TopEntityT],CompiledPrimMap',TyConMap,CustomReprs,Id)

benchmark/profiling/prepare/profile-netlist-prepare.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,10 @@ main = do
2323
prepareFile :: [FilePath] -> FilePath -> IO ()
2424
prepareFile idirs fIn = do
2525
putStrLn $ "Preparing: " ++ fIn
26-
let fOut = fIn ++ ".bin"
26+
let fOut = fIn ++ ".net.bin"
2727
inp <- runNormalisationStage idirs fIn
2828
let (transformedBindings,topEntities,primMap,tcm,reprs,topEntity) = inp
29+
inp' :: NetlistInputs
2930
inp' = (transformedBindings,topEntities,fmap (fmap removeBBfunc) primMap,tcm,reprs,topEntity)
3031
putStrLn $ "Serialising to : " ++ fOut
3132
B.writeFile fOut $ encode inp'

benchmark/profiling/prepare/profile-normalization-prepare.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ prepareFile idirs fIn = do
2525
let fOut = fIn ++ ".bin"
2626
inp <- runInputStage idirs fIn
2727
let (bindingsMap,tcm,tupTcm,_topEntities,primMap,reprs,topEntityNames,topEntity) = inp
28-
inp' = (bindingsMap,tcm,tupTcm,_topEntities, fmap (fmap removeBBfunc) primMap, reprs,topEntityNames,topEntity)
28+
inp' :: NormalizationInputs
29+
inp' = (bindingsMap,tcm,tupTcm, fmap (fmap removeBBfunc) primMap, reprs,topEntityNames,topEntity)
2930
putStrLn $ "Serialising to : " ++ fOut
3031
B.writeFile fOut $ encode inp'
3132
putStrLn "Done"

benchmark/profiling/run/clash-profiling.cabal

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,7 @@ executable clash-profile-normalization-run
2323
binary >= 0.8.5 && < 0.11,
2424
bytestring >= 0.10.0.2 && < 0.11,
2525
concurrent-supply >= 0.1.7 && < 0.2,
26-
containers >= 0.5.4.0 && < 0.7,
2726
deepseq >= 1.4 && < 1.5,
28-
directory >= 1.3.0.0 && < 1.4,
29-
filepath >= 1.4 && < 1.5,
30-
mtl >= 2.1.2 && < 2.3,
31-
text >= 1.2.2 && < 1.3,
32-
unordered-containers >= 0.2.3.3 && < 0.3,
3327

3428
clash-benchmark,
3529
clash-ghc,
@@ -50,13 +44,9 @@ executable clash-profile-netlist-run
5044
binary >= 0.8.5 && < 0.11,
5145
bytestring >= 0.10.0.2 && < 0.11,
5246
concurrent-supply >= 0.1.7 && < 0.2,
53-
containers >= 0.5.4.0 && < 0.7,
5447
deepseq >= 1.4 && < 1.5,
55-
directory >= 1.3.0.0 && < 1.4,
5648
filepath >= 1.4 && < 1.5,
57-
mtl >= 2.1.2 && < 2.3,
58-
text >= 1.2.2 && < 1.3,
59-
unordered-containers >= 0.2.3.3 && < 0.3,
49+
text >= 1.2.2 && < 1.3,
6050

6151
clash-benchmark,
6252
clash-ghc,

benchmark/profiling/run/profile-netlist-run.hs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
import Clash.Annotations.BitRepresentation.Internal (CustomReprs)
21
import Clash.Backend
32
import Clash.Core.Name
4-
import Clash.Core.TyCon
53
import Clash.Core.Var
64
import Clash.Core.VarEnv (mkVarEnv)
75
import Clash.Driver.Types
@@ -57,14 +55,8 @@ benchFile idirs src = do
5755

5856
setupEnv
5957
:: FilePath
60-
-> IO (BindingMap
61-
,[TopEntityT]
62-
,CompiledPrimMap'
63-
,TyConMap
64-
,CustomReprs
65-
,Id
66-
)
58+
-> IO NetlistInputs
6759
setupEnv src = do
68-
let bin = src ++ ".bin"
60+
let bin = src ++ ".net.bin"
6961
putStrLn $ "Reading from: " ++ bin
7062
decode <$> B.readFile bin

benchmark/profiling/run/profile-normalization-run.hs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
{-# LANGUAGE CPP #-}
22

3-
import Clash.Annotations.TopEntity
4-
import Clash.Annotations.BitRepresentation.Internal (CustomReprs)
5-
import Clash.Core.TyCon
6-
import Clash.Core.Var
73
import Clash.Driver
84
import Clash.Driver.Types
95

@@ -16,7 +12,6 @@ import Clash.GHC.Evaluator
1612
import qualified Control.Concurrent.Supply as Supply
1713
import Control.DeepSeq (deepseq)
1814
import Data.Binary (decode)
19-
import Data.IntMap.Strict (IntMap)
2015
import Data.List (partition)
2116
import System.Environment (getArgs)
2217

@@ -41,7 +36,7 @@ benchFile idirs src = do
4136
supplyN <- Supply.newSupply
4237
env <- setupEnv src
4338
putStrLn $ "Doing normalization of " ++ src
44-
let (bindingsMap,tcm,tupTcm,_topEntities,primMap,reprs,topEntityNames,topEntity) = env
39+
let (bindingsMap,tcm,tupTcm,primMap,reprs,topEntityNames,topEntity) = env
4540
primMap' = fmap (fmap unremoveBBfunc) primMap
4641
res :: BindingMap
4742
res = normalizeEntity reprs bindingsMap primMap' tcm tupTcm typeTrans
@@ -53,9 +48,7 @@ benchFile idirs src = do
5348
topEntityNames (opts idirs) supplyN topEntity
5449
res `deepseq` putStrLn ".. done\n"
5550

56-
setupEnv :: FilePath -> IO (BindingMap,TyConMap,IntMap TyConName
57-
,[(Id, Maybe TopEntity, Maybe Id)],CompiledPrimMap'
58-
,CustomReprs,[Id],Id)
51+
setupEnv :: FilePath -> IO NormalizationInputs
5952
setupEnv src = do
6053
let bin = src ++ ".bin"
6154
putStrLn $ "Reading from: " ++ bin

0 commit comments

Comments
 (0)