Comments (8)
It's odd that it says out of memory for only 2 Mb of memory. How much memory does the compiler use according to the operating system?
Regardless, the compilation system that the CLaSH compiler uses probably belongs to an exponential complexity class for certain use cases. So I won't know how easy it will be to fix this bug. Especially as I plan to completely overhaul the system within the next 6 months.
from clash-compiler.
I have 12G laptop, and it visibly goes up to the limits. So 2MB is just an allocation chunk in this case. Sure at least >=8GB of memory is used before the crash.
from clash-compiler.
Is there any way to avoid exponential blowup, possibly by decreasing optimization?
This case
expression is a simple ROM, so there is nothing to optimize, and nothing to keep in memory.
from clash-compiler.
Perhaps, but that's not how the compiler works. It tries to reach a normal form, and can only translate that normal form to VHDL/Verilog. The only true optimisation it does right now is common subexpression elimination.
As a work around, what you could do, is replace the inner case-statements by Vec
indexing, e.g.:
glyph 33 scanLine = (!! scanLine) --'!'
(0b0000001111000000
:> 0b0000011111100000
:> 0b0000111111110000
:> 0b0000111111110000
:> 0b0000111111110000
:> 0b0000111111110000
:> 0b0000011111100000
:> 0b0000001111000000
:> 0b0000001111000000
:> 0b0000001111000000
:> 0b0000000000000000
:> 0b0000000000000000
:> 0b0000001111000000
:> 0b0000001111000000
:> 0b0000000000000000
:> 0b0000000000000000
:> Nil)
from clash-compiler.
Actaully, if you turn it into code like:
glyph :: Unsigned 8 -> Unsigned 3 -> Unsigned 8
glyph c scanLine = (!! scanLine) $ (!! (c - 32)) --' '
( (0b0000000000000000
:> 0b0000000000000000
:> 0b0000000000000000
:> 0b0000000000000000
:> 0b0000000000000000
:> 0b0000000000000000
:> 0b0000000000000000
:> 0b0000000000000000
:> 0b0000000000000000
:> 0b0000000000000000
:> 0b0000000000000000
:> 0b0000000000000000
:> 0b0000000000000000
:> 0b0000000000000000
:> 0b0000000000000000
:> 0b0000000000000000
:> Nil)
:> --'!'
(0b0000001111000000
:> 0b0000011111100000
:> 0b0000111111110000
:> 0b0000111111110000
:> 0b0000111111110000
:> 0b0000111111110000
:> 0b0000011111100000
:> 0b0000001111000000
:> 0b0000001111000000
:> 0b0000001111000000
:> 0b0000000000000000
:> 0b0000000000000000
:> 0b0000001111000000
:> 0b0000001111000000
:> 0b0000000000000000
:> 0b0000000000000000
:> Nil)
....
:> Nil)
It has an even likelier chance that it won't use too much memory. Because the then the vector literal is one BIG constant, which is normal form. However.... it will still take a long time (45 seconds and 900 Mb on my machine) because every literal 0b0000001111000000
is internally seen as fromInteger $dUnsigned 0b0000001111000000
, where $dUnsigned
is a so-called class dictionary: a record data-type containing the functions of the class instance, in this case the functions of the Unsigned
instance for the Num
type-class.
from clash-compiler.
Workaround works great so far, but it would be nicer to treat the other case. (Multiway cases are going a long way in some projects.)
from clash-compiler.
As of 75a34ec, CLaSH no longer runs out of memory for this test-case... as long as you have 4GB or more...
Also note, that the GHC front-end, which CLaSH uses to go from Haskell to it's internal Core representation just creates really bad code for the given example. However, if we change the code to:
{-# LANGUAGE BinaryLiterals #-}
{-# LANGUAGE DataKinds #-}
module Font(glyph, topEntity) where
import CLaSH.Prelude
topEntity = glyph
glyph :: Unsigned 8 -> Unsigned 3 -> Unsigned 8
glyph x y = glyph' (fromEnum x) (fromEnum y)
glyph' :: Int -> Int -> Unsigned 8
glyph' 32 scanLine =case scanLine of --' '
0 -> 0b0000000000000000
We get much, MUCH, better case-statements out of GHC, and CLaSH finishes in less than 8s and using less than 600 MB.
from clash-compiler.
CLaSH now uses less than 800 MB, and finishes within 20s on my machine. I consider this issue solved.
from clash-compiler.
Related Issues (20)
- Clash sometimes duplicates clockWizard HOT 1
- Tutorial: some MAC's alternative specifications don't fit in its topEntity type signature HOT 1
- Expose `Clash.Class.Counter` methods HOT 6
- None of my code ends up in the synthesized Verilog output HOT 3
- VIO causes failure in `Clash.Netlist.BlackBox` HOT 2
- `IntegralTB` test fails with the SystemVerilog+Modelsim combination HOT 1
- PrimitiveGuard warnings are duplicated HOT 1
- BlackBoxHaskell blackboxes don't warn about potential primitive problems
- Clock primitive is duplicated HOT 4
- ILA ignores custom BitPack instances HOT 6
- Warn about out-of-range constants HOT 1
- Optimization flags are incompatible with the byte-code interpreter
- Bug: HDL generation failure with GHC 9.0.2, multiple hidden, synthesis attribute HOT 3
- Can't put synthesis attribute on output tuple
- Name duplication in generated Verilog for ClockWizard testbench HOT 3
- clash-lib doctest errors with GHC 9.4 on Debian HOT 5
- caseCon introduces free variables because of evaluator changes
- HDL generation failure with clash 1.8.1 ghc 9.4.7 HOT 14
- Example of a primitive in tutorial is outdated
- We should document `OPAQUE` for primitives
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from clash-compiler.