-
Notifications
You must be signed in to change notification settings - Fork 156
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
Clash unnecessarily unrolls replicate
when used with blockRam
#621
Comments
When run with
And then seems to repeat When run with |
@leonschoorl |
@leonschoorl: On If I hardcode Clash not to do that, compilation is successful on However, in this case, the HDL generated by the blackbox for replicate actually adheres to the grammar. We need to find a way to encode this, so Clash won’t unroll the replicate. p.s. I discovered this by compiling with |
@christiaanb Do you have any idea when this could be fixed? Not to pressure you guys but I need to decide whether I will implement alternatives or wait for this issue to be fixed. |
No comment on when it'll be fixed, but I can write a small workaround for you. Are you using VHDL, Verilog, or SystemVerilog? |
Thank you! I'm using VHDL. |
replicate
when used with blockRam
I can't really test the hack, as I've botched my Clash 0.99.3 installation, but I believe this should work. I've probably made a number of small typos / forgot imports. In your current working directory, put BlockRam1.json and BlockHack.hs. You should be able to use |
@martijnbastiaan
to
and
changed to
I haven't yet tested further then that it loads in clashi and can do this at the earliest next week but very nice of you guys to help so quickly 👍 ! |
Since my original design didn't compile in clash 0.99.3 I have updated the version we use internally to the current master branch with some help from @leonschoorl. I had to modify the workaround primitive created by @martijnbastiaan sligthly to make it compile. I added the
|
@rowanG077 I've added |
The compiler still hangs even using your blockram workaround. |
Actually I think there is another issue besides the blockram workaround not working. If I set the blockram However If I replace
with
and also remove the
The code compiles. When I then change
back to
Then it won't finish compiling. It gets stuck the same way as the previous gist I posted. |
@martijnbastiaan @leonschoorl Although not an issue in this use-case (or at not least, not yet), clash-compiler/clash-lib/src/Clash/Core/Type.hs Lines 436 to 437 in 39d9dbf
|
The BlockHack @martijnbastiaan provided here didn't work correctly, it still had the same fundamental problem of wanting to to create a huge Vec at compile time. But there is now a proper implementation of blockRam1 was added to master in 39d9dbf --- MinimalExample.hs.orig 2019-06-26 15:11:09.129281531 +0200
+++ MinimalExample.hs 2019-06-26 15:21:00.289273674 +0200
@@ -10,7 +10,6 @@
module MinimalExample where
import Clash.Prelude
-import BlockRamHack
import Data.Maybe
import GHC.Generics (Generic)
@@ -101,9 +100,9 @@
(wordsAddressSize :: Nat)
(fifoSizeWords :: Nat)
(domain :: Domain)
- (gated :: ClockKind)
+ (conf :: DomainConfiguration)
(synchronous :: ResetKind)
- . ( HiddenClockReset domain gated synchronous
+ . ( HiddenClockResetEnable domain conf
, KnownNat writePortWidth
, KnownNat readPortWidth
, KnownNat portWidth
@@ -119,11 +118,11 @@
-> Signal domain (FifoOutput writePortWidth readPortWidth)
fifo input = fifoOutput <$> mealyOutput
where
- mem :: HiddenClock domain gated
+ mem :: HiddenClock domain conf
=> Signal domain (Unsigned wordsAddressSize)
-> Signal domain (Maybe (Unsigned wordsAddressSize, BitVector portWidth))
-> Signal domain (BitVector portWidth)
- mem = blockRam1 (SNat :: SNat fifoSizeWords) 0
+ mem = blockRam1 ClearOnReset (SNat :: SNat fifoSizeWords) 0
initialState :: FifoState writePortWidth readPortWidth
initialState = FifoStateDetermineFifoDepth
@@ -145,10 +144,9 @@
{ t_name = "MinimalExample"
, t_inputs = [ PortName "clk"
, PortName "rst"
- , PortProduct ""
- [ PortName "pop"
- , PortName "writeRequest"
- , PortName "writeData" ] ]
+ , PortName "pop"
+ , PortName "writeRequest"
+ , PortName "writeData" ]
, t_output = PortProduct ""
[ PortName "dataAvailable"
, PortName "data"
@@ -156,8 +154,8 @@
, PortName "writeCapacity" ]
}) #-}
topEntity
- :: Clock System 'Source
- -> Reset System 'Asynchronous
+ :: Clock System
+ -> Reset System
-> Signal System Bool
-> Signal System Bool
-> Signal System (BitVector 128)
@@ -169,7 +167,7 @@
fifoInput :: Signal System (FifoInput 128 24)
fifoInput = FifoInput <$> pop <*> writeDataM <*> pure 100
- fifoOutput = exposeClockReset fifo clk rst fifoInput
+ fifoOutput = exposeClockResetEnable fifo clk rst enableGen fifoInput
dataValid = isJust <$> fifoData <$> fifoOutput
readData = maybe 0 id <$> fifoData <$> fifoOutput (Be sure to remove the Then we run into what Christiaan mentioned, Clash doesn't handle I've added this in the fix-type-families branch. |
Hi!
I'm using clash 0.99.3.
I'm working on implementing a fifo buffer using the blockrams that can have a read port and a write port that have have different widths. The efficiency of the usage of blockram elements on my FPGA are dependent on the size of the port that is chosen. To optimize this I calculate at the type level what an oke port width would be so I can still efficiently use the memory. See below for the types I create.
I then go on to use these types in my fifo function. In
clashi
this works fine and I can fully test my FiFo. However when compiling it will take forever. Something I tested is that if I changeto
Which is the value that is calculated during compilation for a
writePortWidth
of 128 and areadPortWidth
of 24 which I use in my topEntity. Then the compilation errors out with the messageCannot reduce an integer
.Below is a complete example with topEntity that shows this issue.
The text was updated successfully, but these errors were encountered: