Live data from Hacker News

CλaSH – From Haskell to Hardware

clash-lang.org

51–56 of 56 posts

Re: CλaSH – From Haskell to Hardware

#51

Earlier quoted context omitted.

1. So I've actually never used multiple clock domains with/ CLaSH. [The inverted clock I mentioned went to the RAM megafunction, which was instantiated in Verilog. For testing purposes my RAM (in CLaSH) had zero-cycle-delay reads, which is what the RAM w/ phase-shifted clock was supposed to simulate. Also the circuit topology is the same either way (but for the inverter on the clock), just the circuit "works" for dif…

I ask about clock domains because you stated real world designs are by and large synchronous. The issue is when we have data crossing clock domains we have a potential area for bugs dependent on the possible combinations of clock speeds. It becomes effectively asynchronous because we need to determine when data from one clock domain arrives relative to the edge of the other clock. I can't understand the Haskell stuff…

Ok, yeah sorry the docs other than the tutorial assume some familiarity with Haskell.

2. What do you mean by "verification IP"? It was that phrase that made me mention testbenches.

Basically, while CLaSH is hard coded to understand certain types such as the Signal type, almost all primitive function are just defined with Verilog/VHDL templates which it instantiates. One can write their own templates that work just the same way. So for any piece of CLaSH-compilable Haskell, you get VHDL/Verilog for free, and for any bit of piece of VHDL/Verilog, you can use it in CLaSH by writing some Haskell (with the same ports, and that hopefully does the same thing) and then telling CLaSH the Haskell is to be replaced with your Verilog/VHDL.

This is about as good bidirectional comparability as one can get. Automatic Verilog/VHDL -> CLaSH compilation would be an improvement, but I don't think it is possible: I'm not sure to what degree the semantics of Verilog/VHDL are formalized, and even if they are, there's no way the implementations all respect those semantics.

The testbench functions are just templated like any other primitive function.

1. UnsafeSynchronizer "casts" one signal to another -- it's compiled to a plain net in Verilog/VHDL. At each output cycle, n, it looks at the round(n*fin/fout) input cycle and give it that value.

Obviously this is unsafe because, as you say, in the real world the problem is asynchronous. You don't know the exact frequency ratios and phase differences, nor are they constant, and even if you did you'd get subtle timing errors with an incoming value that doesn't change on the clock edge.

The trick is it is a pretty basic "black box" to augment CLaSH with, so proper synthesizers can be written in pure CLaSH. if that's not enough for some super-asynchronous synchronizer design, one can always fall back on writing their own black-box as described above.

------------------------------------------------------------------------------------------------------------

I don't think anyone imagines that CLaSH will be immediately understandable to someone who has never used Haskell. So no way does anyone expect the benefits will be immediately clear. So are you saying the restrictions I mention sound too onerous, or are you saying "I dunno, it looks weird"?

If the former, that's perfectly acceptable, thank you for reading.

If the latter, I'm sorry but this is a pet peeve of mine--we get this a lot in the function programming community. Understand that we are claiming the benefits are worth the non-trivial learning curve. If it was so damn obvious, it couldn't offer much benefit over the status quo---people would have already switched en mass and it would be the status quo.

While C-esque cuteness looks nice, I agree such things are doomed to failure. The C model is easy enough to stand, but it's linearity, implicit state, and notion of control flow have nothing to do with the hardware---you can understand both models, but the compilation process is necessarily non-trivial and sufficiently "far from subjective" that many designs cannot be expressed at all, and many more must be expressed through very round about means.

Functional HDLs like CLaSH have a dead-simple structural compilation model, so while they may not understand every circuit, they can express it---the compiler is near subjective but not homomorphic counting these like this SR flip-flop:

  \ r s -> let q  = nor r q'
               q' = nor s q
           in (q, q')
This compiles to exactly what it looks like, but diverges (i.e. infinite loops) under Haskell's semantics.

Lastly here is a comparison of writing the same project twice (though the paper is done by the CLaSH designers) http://www.researchgate.net/profile/Jan_Kuper/publication/47...

Re: CλaSH – From Haskell to Hardware

#52
post #31
post #25

Earlier quoted context omitted.

What are your thoughts about Esterel[1]? [1]: http://en.wikipedia.org/wiki/Esterel

I don't have experience with Esterel in particular, but I can make some statements about imperative synchronous languages in general: - They're a step in the right direction (e.g., implicit state machines), but then they're doing too much of a good thing. For example, in my experience, "abort" and especially "suspend" statements are not that important in non-toy examples, but they make the compiler more complex. - In…

P.S.

Note that Esterel isn't mainly meant to design circuits but to write safety-critical hard realtime software.

Re: CλaSH – From Haskell to Hardware

#53

Earlier quoted context omitted.

I ask about clock domains because you stated real world designs are by and large synchronous. The issue is when we have data crossing clock domains we have a potential area for bugs dependent on the possible combinations of clock speeds. It becomes effectively asynchronous because we need to determine when data from one clock domain arrives relative to the edge of the other clock. I can't understand the Haskell stuff…

Ok, yeah sorry the docs other than the tutorial assume some familiarity with Haskell. 2. What do you mean by "verification IP"? It was that phrase that made me mention testbenches. Basically, while CLaSH is hard coded to understand certain types such as the Signal type, almost all primitive function are just defined with Verilog/VHDL templates which it instantiates. One can write their own templates that work just th…

Verification IP is reusable code created by verification engineers. E.g. Say the designers are developing a networking module. The verification engineers would build the verification IP to generate the network packets. They also build the monitors to check the network protocols. For any design under verification, there is a corresponding amount of verification providing stimulus and checking.

Check out: https://verificationacademy.com/verification-methodology-ref...

The reason I bring this up is: verification is the hard part of the HW workflow. The other similarly tough part is synthesis. Every single project I have been in, verification and synthesis are the toughest tasks that consumes the most team effort. Not design. When we plan projects, it all revolves around the verification task.

For every bus, every module and at various stages of SoC integration, we are writing verification code using System Verilog.

If you want to improve our tools, I would look at the verification/simulation or the synthesis side.

Re: CλaSH – From Haskell to Hardware

#54

Earlier quoted context omitted.

Today's beginners don't make the tools. I must be too old. The new guys can come and bring their new tools. I am retired now. Back when I started, we used to care how the older engineers did stuff. The academics who trained us at uni had never worked in industry and had no real clue. Hence we had to learn the real stuff from the older guys. These days we are the old guys but just treated like yesterday's newspaper.

> Today's beginners don't make the tools. Not necessarily, I am a beginner in hardware design, and I am creating a new programming language and IDE for hardware design. > The academics who trained us at uni had never worked in industry and had no real clue. Hence we had to learn the real stuff from the older guys. I can relate, this is by talking to older designers that my co-founder and myself learned that CDC is a…

Verification and synthesis are the pain points. Projects revolve around them not the design. In HW, the design of each module itself is usually pretty conservative. We are a conservative bunch remember! But it's feature creep that crams in more and more modules to handle the variety of ways a single SoC can be applied to multiple markets.

The end result is multiple clock domains and buses going everywhere, multiple RAM modules, lots of different clock gating options to shut down parts of the system not in use. Etc.

When I look at a large design, I don't worry about the design effort. The first thing that comes to mind is the verification effort. You spend about four times or more the amount of effort verifying the design because you cannot afford any mistakes. That effort is building everything around the ports of a design that makes it thoroughly verifiable. The stimulus is constrained randomly generated transactions on every input to the design and checkers of every output. Coverage determines whether the random transactions have covered every case. And it not just every combination of inputs. Every module has state internally: you have to cover every possible state transition.

One of the older guys at my old company joked that: These days the design is done by the verification team.

The behavior of the design is modeled by the verification engineer so they can detect when the design has a bug. Often the verification team is working with an empty stub because they get ahead of the design team. It gets to the extreme case of the verification team telling the design team how to write everything.

Re: CλaSH – From Haskell to Hardware

#55

Earlier quoted context omitted.

I wrote and verified IP and I worked at the SoC integration level. I would say hardware engineers realize the tools suck but this stuff is targeting issues I don't care about. The bugs are not due to language generally. If software guys want to write a new language for HW engineers, they need to ask HW engineers what the issues are rather then go off on a tangent. As it is they don't even know what the workflow is li…

> The bugs are not due to language generally. That's like saying that buffer overflows are not due to how strings are represented in C. Yes a bug is the programmer's fault, but languages can make it harder to have bugs in the first place (for instance you can't have buffer overflows in any other higher level language than C). In the case of the hardware industry, we see a language with a weak type system (Verilog). S…

Latches are caught by the synthesis tools generally. Designers usually run a unconstrained synthesis as a matter of course to determine whether they have written junk.

As for the other bugs, I look forward to this new paradigm of spotting them early without verification effort.

Reasoning about transactions is already how verification works. It is transaction based. UVM is a library of SystemVerilog classes aimed at abstracting the verification to higher levels.

Check out: https://verificationacademy.com/verification-methodology-ref...

We build over these classes to create our test benches.

Re: CλaSH – From Haskell to Hardware

#56
post #33
post #32

Earlier quoted context omitted.

I am a pretty junior ASIC engineer who has relatively more exposure to software world compared to many of my peers. In my last project I did some IP integration work and the lack of decent development tools led to significant chores. I did make use of Emacs verilog-mode like GP mentioned and even wrote some small macros in elisp but overall experience is far from satisfactory. Not to even mention the usability of pro…

> I want to make some difference. But I'm not sure where to start... 1. Take a promising language, improve it where necessary. 2. Add excellent support for translation to VHDL and Verilog. The generated HDL code has to be readable, editable, and it has to reflect the structure of the original code more or less 1:1. You also need to support "inline VHDL/Verilog" (like inline assembly in software). Otherwise, your lang…

Are you referring to a new DSL based on software languages, something like MyHDL? I think this is definitely promising for designs that are started from scratch. However, as soon as there is need to integrate with other legacy code, it falls back to the current painful way of manual integration.

What do you think about an IDE that supplements existing HDL languages? Not as drastic as making a shiny new language, but it avoids many challenges you brought up.

Since you are coming from a CS background, do you have recommendation for good IDE frameworks that can be leveraged?

Post reply on HN