96 points · by lelf · 6y ago · 40 comments
Slides from a clash talk I gave in probably 2016:
https://yager.io/talks/CLaSH.pdf
Simple non-pipelined CPU (I've been meaning to release part 2 for years but never got around to it):
https://yager.io/CPU/CPU1.html
SKI calculus processor on an FPGA:
https://yager.io/HaSKI/HaSKI.html
A superscalar out-of-order processor I built for a CPU design class at UT Austin:
https://github.com/wyager/Lambda17
(Take a look at Hardware.hs to see some of the cool parametric stuff you can do.)
Like I said, these are all with old versions of Clash - it's changed in the last few years, but I haven't done any HDL projects recently.
You mentioned LLVM, and I think of MLIR as sort of a successor to LLVM. I'm hopeful that a low-level HDL IR is standardized as an MLIR dialect, so the compiler ecosystem and the hardware ecosystem can start to unite.
[1] https://news.ycombinator.com/item?id=22825107 [2] https://news.ycombinator.com/item?id=22429107 [3] https://drive.google.com/file/d/1x7B0IRdcJ5JBQvfHbPUBcShbTFC...
Nowadays Chisel seems to be the best bet if you want a sane Verilog alternative (with functional-lang features) for your HDL needs. (https://www.chisel-lang.org/) It was originally a transpiler to Verilog, but recently it began to have its own IR code (FIRRTL) for optimization purposes.
It turns out that Haskell's non-strict semantics are a shockingly close match for the semantics of hardware (the only difference I'm aware of being pretty obscure, having to do with zero-width busses).
Doesn't Haskell need automatic memory management in order to implement higher-order functions, that being perhaps the most prominent difference in semantics between Haskell/Ocaml and Rust? Is Clash limited to first-class functions ala C?
Clash has been around for a while now.
Haskell is the only language I'm aware of that has semantics approaching those of hardware - in particular, purity and non-strict evaluation are absolutely required to match (or closely approximate) the semantics of digital hardware. (To get you started - bottom is equivalent to X in the HDL simulator nomenclature)
> Chisel or SpinalHDL... HDL based on OCaml or ML
Chisel is a shallow embedding. Not sure about SpinalHDL. Hardcaml is a shallow embedding. Very different approach from Clash, and I prefer Clash's deep/direct embedding approach.
This intersection is not likely to differ much from the empty set.
Haskell/ML syntax is hardly "new stuff".
> I think it's extremely unlikely you really get a large amount of adoption
Clash is used to manufacture production hardware by at least one of the top 5 largest companies in the world.
For most hardware designers though, it is new. Most hardware designers are EEs and not CS people. I know many designers that do not even want to learn a programming language like python which has a relatively easy to read syntax. ML/Functional Programming languages require a completely different mindset, just like hardware designing does if you come from programming languages.
I think the world is ripe for a new HDL. But the right foundations need to be there. It needs first class support with existing HDLs (VHDL, Verilog/SV). It needs to integrate with all the existing EDA tools in mixed language environments, and be easy to debug. Debugging is a huge problem in the "new HDL" space right now. Go look at Chisel. Google used it to design some of if not all of their TPU, but their Verif engineers had a really difficult time with the debug because it compiled to verilog, and then was difficult to reason about.
I have so many thoughts on this space and I want to make it better. It would be an absolute dream to develop a new HDL that enabled Hardware designers and Verif engineers to have all the superpowers that SWEs have in today's world. Being both proficient in various programming languages and Verilog/SV/UVM/etc, its so wild to see how big of a gap there is in productivity tools. Essentially SWEs have all the good stuff.
Have you written them down somewhere? Would be interested. Are you a HW designer?
> It would be an absolute dream to develop a new HDL that enabled Hardware designers and Verif engineers to have all the superpowers that SWEs have in today's world
Wasn't that the intention of SystemVerilog?
You don't have a notion of clock cycles, making timing, or fan-out load in distributed systems, so if you are going to try this you definitely need some extremely experienced digital logic designers and chip architects around to keep everyone on the rails, but in turn the CS folks are really good at producing useful abstractions that make architecture exploration easy while maintaining correctness.
TL;DR: I've found it easier to teach folks that know Haskell and distributed systems design about hardware constraints than to teach RTL designers about functional abstractions and been really productive with a mix of both groups.
Can you elaborate on that?