Chisel: Constructing Hardware in a Scala Embedded Language

Chisel: Constructing Hardware in a Scala Embedded Language

Chisel: Constructing Hardware in a Scala Embedded Language Jonathan Bachrach, Huy Vo, Brian Richards, Yunsup Lee, Andrew Waterman, Rimas Avižienis, John Wawrzynek, Krste Asanovic´ EECS Department, UC Berkeley ∗ {jrb|huytbvo|richards|yunsup|waterman|rimas|johnw|krste}@eecs.berkeley.edu ABSTRACT designs must be inferred from a subset of the language, com- In this paper we introduce Chisel, a new hardware construc- plicating tool development and designer education. These tion language that supports advanced hardware design using languages also lack the powerful abstraction facilities that highly parameterized generators and layered domain-specific are common in modern software languages, which leads to hardware languages. By embedding Chisel in the Scala pro- low designer productivity by making it difficult to reuse com- gramming language, we raise the level of hardware design ab- ponents. Constructing efficient hardware designs requires straction by providing concepts including object orientation, extensive design-space exploration of alternative system mi- functional programming, parameterized types, and type in- croarchitectures [9] but these traditional HDLs have limited ference. Chisel can generate a high-speed C++-based cycle- module generation facilities and are ill-suited to producing accurate software simulator, or low-level Verilog designed to and composing the highly parameterized module generators map to either FPGAs or to a standard ASIC flow for syn- required to support thorough design-space exploration. Re- thesis. This paper presents Chisel, its embedding in Scala, cent extensions such as SystemVerilog improve the type sys- hardware examples, and results for C++ simulation, Verilog tem and parameterized generate facilities but still lack many emulation and ASIC synthesis. powerful programming language features. To work around these limitations, one common approach is to use another language as a macro processing language Categories and Subject Descriptors for an underlying HDL. For example, Genesis2 uses Perl to B.6.3 [Logic Design]: [Design Aids { automatic synthesis, provide more flexible parameterization and elaboration of hardware description languages] hardware blocks written in SystemVerilog [9]. The language called Verischemelog [6] provides a Scheme syntax for spec- ifying modules in a similar format to Verilog. JHDL [1] General Terms equates Java classes with modules. HML [7] uses standard Design, Languages, Performance ML functions to wire together a circuit. These approaches allow familiar and powerful languages to be macro languages for hardware netlists, but effectively require leaf components Keywords of the design to be described in the underlying HDL. This CAD combined approach is cumbersome, combining the poor ab- straction facilities of the underlying HDL with a completely different high-level programming model that does not un- 1. INTRODUCTION derstand hardware types and semantics. The dominant traditional hardware-description languages An alternative approach is to begin from a domain-specific (HDLs), Verilog and VHDL, were originally developed as application programming language from which a hardware hardware simulation languages, and were only later adopted block is generated. Esterel [2] uses event-based statements as a basis for hardware synthesis. Because the semantics of to program hardware for reactive systems. DIL [4] is an in- these languages are based around simulation, synthesizable termediate language targeted at stream processing and hard- ware virtualization. Bluespec [3] supports a general concur- ∗Research supported by DoE Award DE-SC0003624, and by Microsoft (Award #024263 ) and Intel (Award #024894) rent computation model, based on guarded atomic actions. funding and by matching funding by U.C. Discovery (Award While these can provide great designer productivity when #DIG07-10227). the task in hand matches the pattern encoded in the appli- cation programming model, they are a poor match for tasks outside their domain. For example, the design of a pro- grammable microprocessor is not well described in a stream Permission to make digital or hard copies of all or part of this work for programming model, and guarded atomic actions are not a personal or classroom use is granted without fee provided that copies are natural way to express a high-level DSP algorithm. Further- not made or distributed for profit or commercial advantage and that copies more, in general it is difficult to derive an efficient microar- bear this notice and the full citation on the first page. To copy otherwise, to chitecture from a higher-level computation model, especially republish, to post on servers or to redistribute to lists, requires prior specific if the goal is a programmable engine to run many applica- permission and/or a fee. DAC 2012, June 3-7, 2012, San Francisco, California, USA. tions, where the human designer would prefer to write a Copyright 2012 ACM 978-1-4503-1199-1/12/06 ...$10.00. generator to explore this design space in detail. Bundles and Vecs can be arbitrarily nested to build com- In this paper, we introduce Chisel (Constructing Hard- plex data structures. The set of primitive classes (Bits, Fix, ware In a Scala Embedded Language), a new hardware de- UFix, Bool) plus the aggregate classes (Bundles and Vecs) sign language we have developed based on the Scala pro- all inherit from a common superclass, Data. Every object gramming language [8]. Chisel is intended to be a simple that ultimately inherits from Data can be represented as a platform that provides modern programming language fea- bit vector in a hardware design. tures for accurately specifying low-level hardware blocks, but which can be readily extended to capture many use- 2.2 Combinational Circuits ful high-level hardware design patterns. By using a flexible A circuit is represented as a graph of nodes in Chisel. Each platform, each module in a project can employ whichever node is a hardware operator that has zero or more inputs design pattern best fits that design, and designers can freely and that drives one output. A literal is a degenerate node combine multiple modules regardless of their programming that has no inputs and drives a constant value on its output. model. Chisel can generate fast cycle-accurate C++ simu- One way to create and wire together nodes is using textual lators for a design, or generate low-level Verilog suitable for expressions: either FPGA emulation or ASIC synthesis with standard (a & b) | (~c & d) tools. We present several design examples and results from where & and | represent bitwise-AND and -OR respectively, emulation and synthesis experiments. and ~ represents bitwise-NOT. The names a through d rep- resent named wires of some (unspecified) width. Any simple 2. CHISEL OVERVIEW expression can be converted directly into a circuit tree, with Instead of building a new hardware design language from named wires at the leaves and operators forming the inter- scratch, we chose to embed hardware construction primi- nal nodes. The final circuit output of the expression is taken tives within the Scala programming language. We chose from the operator at the root of the tree, in this example, Scala for a number of reasons: Scala 1) is a very powerful the bitwise-OR. language with features we feel are important for building Simple expressions can build circuits in the shape of trees, circuit generators, 2) is specifically developed as a base for but to construct circuits in the shape of arbitrary directed domain-specific languages, 3) compiles to the JVM, 4) has a acyclic graphs (DAGs), we must describe fan-out. In Chisel, large set of development tools and IDEs, and 5) has a fairly we can name a wire holding a subexpression by declaring a large and growing user community. Chisel comprises a set variable, then referencing it multiple times in subsequent of Scala libraries that define new hardware datatypes and a expressions: set of routines to convert a hardware data structure into ei- val sel = a | b val out = (sel & in1) | (~sel & in0) ther a fast C++ simulator or low-level Verilog for emulation or synthesis. This section describes the features of the base The named Chisel wire sel holds the output of the first Chisel system, whereas the next two sections describe how bitwise-OR operator so that the output can be used multiple Chisel supports abstraction and powerful generators. times in the second expression. Bit widths are automatically inferred unless set manually 2.1 Chisel Datatypes by the user. The bit-width inference engine starts from the The basic Chisel datatypes are used to specify the type of graph's input ports and calculates node output bit widths values held in state elements or flowing on wires. In Chisel, a from their respective input bit widths, always preserving exact results unless an explicit truncation is requested. raw collection of bits is represented by the Bits type. Signed and unsigned integers are considered subsets of fixed-point 2.3 Functions numbers and are represented by types Fix and UFix respec- We can define functions to factor out a repeated piece of tively. Boolean values are represented as type Bool. Note logic that we later reuse multiple times in a design: that these types are distinct from Scala's builtin types such as . Constant or literal values are expressed using Scala def clb(a: Bits, b: Bits, c: Bits, d: Bits) = (a & b) | (~c & d) Int val out = clb(a,b,c,d) integers or strings passed to constructors for the types. Chisel provides a Bundle class, which the user extends The def keyword is part of Scala and introduces a function to make collections of values with named fields (similar to definition, with each argument followed by a colon then its structs in other languages): type, and the function return type given after the colon fol- lowing the argument list. The equals (=) sign indicates the class MyFloat extends Bundle { start of the function definition. val sign = Bool() val exponent = UFix(width = 8) val significand = UFix(width = 23) 2.4 Ports and Components } Ports are used as interfaces to hardware components.

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    10 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us