Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Synthesis time is linear in the size of Index #2875

Closed
rowanG077 opened this issue Jan 15, 2025 · 6 comments
Closed

Synthesis time is linear in the size of Index #2875

rowanG077 opened this issue Jan 15, 2025 · 6 comments

Comments

@rowanG077
Copy link
Member

The following:

foo
  :: forall
    (deadlinePicoSeconds :: Nat)
    (dom :: Domain)
   . (HiddenClockResetEnable dom)
  => (KnownNat (DomainPeriod dom))
  => (1 <= DomainPeriod dom)
  => (KnownNat deadlinePicoSeconds)
  => 1 <= DivRU deadlinePicoSeconds (DomainPeriod dom)
  => Signal dom Bool
  -> Signal dom Bool
foo activity =
  let initCnt = (0 :: Index (DivRU deadlinePicoSeconds (DomainPeriod dom)))
      cntr = register initCnt $ mux activity (pure 0) (satSucc SatWrap <$> cntr)
  in register False $ cntr .==. (pure maxBound)

topEntity = exposeClockResetEnable (foo @5_000_000_000_000 @System)

Takes a whopping 25 seconds to synthesize on my machine using GHC 9.6.6 and clash 1.8.2. As part of a larger circuit it never finished synthesizing.

@rowanG077
Copy link
Member Author

rowanG077 commented Jan 15, 2025

Normalization is not to blame, it's stuck at the Clash: Compiling ... stage. It's a regression as this exact same component had no trouble in clash 1.6.4 with GHC 9.0.2.

deadlinePicoSeconds influences how long it takes. It looks to be linear, a doubling of deadlinePicoSeconds doubles the time to synthesize.

@christiaanb
Copy link
Member

Does compiling the file with regular GHC to an .o object file also take longer when you use GHC 9.6.6 vs 9.0.2?

@rowanG077
Copy link
Member Author

rowanG077 commented Jan 15, 2025

Doesn't seem to be different. How large deadlinePicoSeconds is also doesn't factor into it. With both it's around 0.150 seconds.

Just to be clear. It takes so long after clash normalization has taken place. I see now that my original comment was ambiguous. This is the output:

GHC: Setting up GHC took: 0.040s
GHC: Compiling and loading modules took: 0.078s
Clash: Parsing and compiling primitives took 0.133s
GHC+Clash: Loading modules cumulatively took 0.497s
Clash: Compiling TopEntity.topEntity
Clash: Normalization took 0.012s
Clash: Netlist generation took 0.000s
-- Here it takes a ages
Clash: Compiling TopEntity.topEntity took 23.663s
Clash: Total compilation took 24.161s

@rowanG077
Copy link
Member Author

It's actually just literally how large the n is for an Index...

topEntity :: Index 1_000_000_000
topEntity = 0

Takes 5 seconds on my machine.

topEntity :: Index 5_000_000_000
topEntity = 0

Takes approx 27 seconds. Amazing.

@rowanG077 rowanG077 changed the title Seemingly innocent function takes very long to synthesize Synthesis time is linear in the size of Index Jan 15, 2025
@christiaanb
Copy link
Member

Probably a duplicate of #2813, in which case it will be fixed by #2816

@rowanG077
Copy link
Member Author

Yes this seems to be the case. I will close this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants