Live data from Hacker News

CλaSH – From Haskell to Hardware

clash-lang.org

11–20 of 56 posts

Re: CλaSH – From Haskell to Hardware

#11
This is very interesting. I have always felt that having a language that has immutable constructs translates very well into a hardware description language. This is because most of the hardware modules are immutable, except for state machines, which can be modelled using state monads(or something similar).

Considering the hardware tooling right now, I would love to see a language with more abstractions than verilog or vhdl. I would love to see programming languages, that just don't compile to system verilog / VHDL, but can directly move to synthesizing step. I have worked with Bluespec and I don't see that as the successor.

I would say, a language like haskell(or a derivative) can map to a hardware really well, and this is a very good attempt. Please pursue it / turn it into a product, so that hacking on hardware(a FPGA) is much more easier and beautiful.

Re: CλaSH – From Haskell to Hardware

#12
post #10

Earlier quoted context omitted.

> I'm actually generating nice Verilog specifications. Can I apply it somehow if I'm not working in Intel or something? What can I do with it? Throw it into an FPGA

And it would be significantly faster than if I would concentrate on optimizing the code for, say, executing it on GPU?

Depends on what you want to do.

It's not about faster, it's about the application, you can't plug a PC with a GPU to solve all problems.

FPGAs weren't created for bitcoin mining.

Re: CλaSH – From Haskell to Hardware

#13
When I was writing the chips from nand2tetris in HDL I noticed how cleanly they could be expressed with function composition in SML. I dismissed the ideas as a bit weird, if cool, but after a few weeks I came across HardCaml http://www.ujamjar.com/hardcaml/ and some references to HML (Hardware ML). Unfortunately only the thesis survives and not any actual code, but still.

The moral of the story is to take your weird ideas more seriously I guess ;-)

Re: CλaSH – From Haskell to Hardware

#14
post #10

Earlier quoted context omitted.

> I'm actually generating nice Verilog specifications. Can I apply it somehow if I'm not working in Intel or something? What can I do with it? Throw it into an FPGA

And it would be significantly faster than if I would concentrate on optimizing the code for, say, executing it on GPU?

Perhaps. Perhaps not. If you have an algorithm that is better implemented in hardware, you might well see better performance executing it on a GPU (for example, if you want to mine bitcoins).

Really, FPGAs are meant for prototyping hardware; you synthesize your ASIC onto the FPGA and check it for functionality.

Of course, there's a reason you're making that ASIC.

Re: CλaSH – From Haskell to Hardware

#15
There's been a few different proposals to use functional languages to write hardware: Chisel (https://chisel.eecs.berkeley.edu/) and Bluespec (http://www.bluespec.com/) are two others. They haven't really taken off because the productivity bottleneck in hardware is not in design but verification and specifically sequential verification. Combinational verification is quote easy, because modern SAT solvers can prove almost all combinational properties you can throw at them.

The trouble comes in when you start dealing with complex state machines with non-obvious invariants. I don't think these functional languages can really help too much here because unlike C or C++ in the software world, there isn't unnecessary complexity introduced by a language, e.g. verification becoming harder due to aliasing. It's the properties themselves that are complex. Lots of progress is happening though: Aaron Bradley's PDR (http://theory.stanford.edu/~arbrad/) and Arie Gurfinkel and Yakir Vizel's AVY (http://arieg.bitbucket.org/avy/) have made pretty major breakthroughs in proving a lot of complex sequential properties and these algorithms have made their way into industrial formal tools as well.

Re: CλaSH – From Haskell to Hardware

#16
Disclaimer: I haven't read through the details of the language yet.

> The merits of using a functional language to describe hardware comes from the fact that combinational circuits can be directly modeled as mathematical functions and that functional languages lend themselves very well at describing and (de-)composing mathematical functions.

Whenever I read something like this, I cannot really take the language or the language designer seriously. The complexity and difficulty of hardware design is not in the combinational part, it's in the sequential (i.e., state-carrying) part of the circuit [1]. One of the major drawbacks of Verilog, SystemVerilog, and VHDL, is that successive sequential statements have to be translated manually to state machines (at least for synthesizable code – simulation code does not suffer from this restriction) [2].

[1] Source: I'm an FPGA design engineer with a computer science background.

[2] There are of course languages with an improved design, but nearly all of them are research prototypes and unsuited for non-toy/example designs. The more innovative commercial products have hardly any marketshare, because electrical engineers seem to be extremely conservative [1].

Re: CλaSH – From Haskell to Hardware

#17
post #6

Earlier quoted context omitted.

The way I see it, it's Register Transfer Level, just written differently. Instead of writing: @always(clock) counter you write: counter = s where s = register 0 (s + 1) per http://hackage.haskell.org/package/clash-prelude-0.7.5/docs/... I agree, it is an interesting idea . I suspect that just having "Haskell" got the link a lot of upvotes :-) As stated on the "Why CλaSH", the advantage is obvious for combinational ci…

Helpful explanation. Thanks! Looking at this I have a very specific question, from a practical getting work done point of view, is this better than what we have, or just different to what we have. If the answer is "different" I don't mind, but it will hinder my adoption ;-) I guess this is why I want to see a side-by-side comparison of real hardware constructs. Things I use regularly. It would aid greatly in understa…

Well, when I used VHDL back in college, I noticed that it had a really hard time with math. So for example it could do look up tables all day (basically switch commands) but if you tried to encode that logic into the kind of math we're used to in a C-based language where A = B (insert operator here) C, it fell down hard and the circuit would be so unstable that it would only run a few cycles before spinning off into some exceptional state that was nothing like we expected.

I think that's because humans have a hard time considering the ramifications of things like boundary conditions and edge cases with respect to types. So maybe we can visualize one register being added to another, but we can't intuitively extrapolate what happens when one is signed and one is unsigned, or their widths are different, or one is floating point, etc etc etc. VHDL doesn't touch on all of these edge cases very well (because for one thing they are hard!) it just does exactly what it’s told. That often flies in the face of intuition, once we’ve analyzed the circuit and seen how much we underestimated the complexity of what we were asking. In other words elegant math doesn’t always translate to simple circuits, and vice versa. So it really needs a meta language that can grapple with these subtle nuances and compile to VHDL without a lot of friction.

Probably what’s going to happen is we’ll see DSP logic (and limited subsets of it like GPU shaders/OpenCL/CUDA) and VHDL/Verilog merge into a functional concurrent language that can cover all of it. It won’t be as explicit as Rust because it will infer what the user is after but allow for overriding default assumptions. It won’t have opaque syntax either like most functional languages today. I’m thinking probably it will look more like MATLAB/Octave but have access to some of the more concise notation of Mathematica. So think Excel except having cells arranged arbitrarily in some ND space rather than 2D, and we’ll be able to specify formulas on groups of cells rather than individually, and in any language we desire that’s then compiled to Lisp and either run on distributed economy hardware or translated to a hardware description language. CλaSH probably isn’t it, but its approach and open source license is certainly a start.

Realized I didn't answer the question - different yes, but probably not different enough to be compelling for mainstream use at this point. Without having ever used it, I have concerns that circuits will still fall down or take up gratuitous chip area because handling the edge cases is one of the more complex problems to solve, and I'm not convinced that functional programming alone is enough.

Re: CλaSH – From Haskell to Hardware

#18
post #14
post #10

Earlier quoted context omitted.

And it would be significantly faster than if I would concentrate on optimizing the code for, say, executing it on GPU?

Perhaps. Perhaps not. If you have an algorithm that is better implemented in hardware, you might well see better performance executing it on a GPU (for example, if you want to mine bitcoins). Really, FPGAs are meant for prototyping hardware; you synthesize your ASIC onto the FPGA and check it for functionality. Of course, there's a reason you're making that ASIC.

Or you don't do an ASIC and ship the FPGA. That's common as well (for the big manufacturers it's cheaper to do an ASIC, for the not so big, it's more common to sell the FPGA)

Re: CλaSH – From Haskell to Hardware

#19
post #6

Earlier quoted context omitted.

The way I see it, it's Register Transfer Level, just written differently. Instead of writing: @always(clock) counter you write: counter = s where s = register 0 (s + 1) per http://hackage.haskell.org/package/clash-prelude-0.7.5/docs/... I agree, it is an interesting idea . I suspect that just having "Haskell" got the link a lot of upvotes :-) As stated on the "Why CλaSH", the advantage is obvious for combinational ci…

Helpful explanation. Thanks! Looking at this I have a very specific question, from a practical getting work done point of view, is this better than what we have, or just different to what we have. If the answer is "different" I don't mind, but it will hinder my adoption ;-) I guess this is why I want to see a side-by-side comparison of real hardware constructs. Things I use regularly. It would aid greatly in understa…

Hard to say, it depends on what you consider better. It certainly is more concise than the equivalent Verilog (just like Haskell is more concise than pretty much any language I know). This seems especially true when you want to describe repetitive structures (such as their FIR filter).

CλaSH also has a much better type system than Verilog (again, thanks to Haskell), but if you wanted a good type system when describing hardware, you might as well just switch to VHDL ^^

My concern is with the description of state machines. You need to specify if you want a Mealy or a Moore machine, something that is usually implicit. And you're still describing the transfer function between states; CλaSH does not seem to allow you to describe your program in a structured way (such as loop until x becomes true, wait for 3 cycles, read z, while z > 0 decrement z, etc.)

Re: CλaSH – From Haskell to Hardware

#20
post #16

Disclaimer: I haven't read through the details of the language yet. > The merits of using a functional language to describe hardware comes from the fact that combinational circuits can be directly modeled as mathematical functions and that functional languages lend themselves very well at describing and (de-)composing mathematical functions. Whenever I read something like this, I cannot really take the language or th…

Interesting, I feel like you would like what we've done with the Cx language at Synflow. Probably the exact opposite of CλaSH, the language is sequential imperative (C-like even) and focuses on making the sequential part easier (Cx still has first class support for parallel tasks and hierarchical descriptions though). You have synchronous "for", "while", "if", this kind of thing :-) http://cx-lang.org Enjoy!
Post reply on HN