February 28, 2005http://csg.csail.mit.edu/6.884/L09-1 Bluespec-3: Modules & Interfaces Arvind Computer Science & Artificial Intelligence Lab Massachusetts.

Slides:



Advertisements
Similar presentations
An EHR based methodology for Concurrency management Arvind (with Asif Khan) Computer Science & Artificial Intelligence Lab Massachusetts Institute of Technology.
Advertisements

February 25, 2005http://csg.csail.mit.edu/6.884/L08-1 Bluespec-2: Designing with Rules Arvind Computer Science & Artificial Intelligence Lab Massachusetts.
Stmt FSM Richard S. Uhler Computer Science & Artificial Intelligence Lab Massachusetts Institute of Technology (based on a lecture prepared by Arvind)
Asynchronous Pipelines: Concurrency Issues Arvind Computer Science & Artificial Intelligence Lab Massachusetts Institute of Technology October 13, 2009http://csg.csail.mit.edu/koreaL12-1.
Modeling Processors Arvind Computer Science & Artificial Intelligence Lab Massachusetts Institute of Technology February 22, 2011L07-1
March, 2007http://csg.csail.mit.edu/arvindIPlookup-1 IP Lookup Arvind Computer Science & Artificial Intelligence Lab Massachusetts Institute of Technology.
September 24, L08-1 IP Lookup: Some subtle concurrency issues Arvind Computer Science & Artificial Intelligence Lab.
IP Lookup: Some subtle concurrency issues Arvind Computer Science & Artificial Intelligence Lab Massachusetts Institute of Technology February 22, 2011L06-1.
December 10, 2009 L29-1 The Semantics of Bluespec Arvind Computer Science & Artificial Intelligence Lab Massachusetts Institute.
February 22, 2005http://csg.csail.mit.edu/6.884/L07-1 Bluespec-1: Design Affects Everything Arvind Computer Science & Artificial Intelligence Lab Massachusetts.
December 12, 2006http://csg.csail.mit.edu/6.827/L24-1 Scheduling Primitives for Bluespec Arvind Computer Science & Artificial Intelligence Lab Massachusetts.
February 14, 2007L04-1http://csg.csail.mit.edu/6.375/ Bluespec-1: Design methods to facilitate rapid growth of SoCs Arvind Computer Science & Artificial.
September 3, 2009L02-1http://csg.csail.mit.edu/korea Introduction to Bluespec: A new methodology for designing Hardware Arvind Computer Science & Artificial.
Introduction to Bluespec: A new methodology for designing Hardware Arvind Computer Science & Artificial Intelligence Lab. Massachusetts Institute of Technology.
Multiple Clock Domains (MCD) Continued … Arvind with Nirav Dave Computer Science & Artificial Intelligence Lab Massachusetts Institute of Technology November.
March 6, 2006http://csg.csail.mit.edu/6.375/L10-1 Bluespec-4: Rule Scheduling and Synthesis Arvind Computer Science & Artificial Intelligence Lab Massachusetts.
Constructive Computer Architecture: Guards Arvind Computer Science & Artificial Intelligence Lab. Massachusetts Institute of Technology September 24, 2014.
September 22, 2009http://csg.csail.mit.edu/koreaL07-1 Asynchronous Pipelines: Concurrency Issues Arvind Computer Science & Artificial Intelligence Lab.
Constructive Computer Architecture Sequential Circuits Arvind Computer Science & Artificial Intelligence Lab. Massachusetts Institute of Technology
Elastic Pipelines: Concurrency Issues Arvind Computer Science & Artificial Intelligence Lab Massachusetts Institute of Technology February 28, 2011L08-1http://csg.csail.mit.edu/6.375.
Introduction to Bluespec: A new methodology for designing Hardware Arvind Computer Science & Artificial Intelligence Lab. Massachusetts Institute of Technology.
Constructive Computer Architecture Sequential Circuits - 2 Arvind Computer Science & Artificial Intelligence Lab. Massachusetts Institute of Technology.
February 20, 2009http://csg.csail.mit.edu/6.375L08-1 Asynchronous Pipelines: Concurrency Issues Arvind Computer Science & Artificial Intelligence Lab Massachusetts.
1 Tutorial: Lab 4 Again Nirav Dave Computer Science & Artificial Intelligence Lab Massachusetts Institute of Technology.
Modular Refinement Arvind Computer Science & Artificial Intelligence Lab Massachusetts Institute of Technology March 8,
October 22, 2009http://csg.csail.mit.edu/korea Modular Refinement Arvind Computer Science & Artificial Intelligence Lab Massachusetts Institute of Technology.
Introduction to Bluespec: A new methodology for designing Hardware Arvind Computer Science & Artificial Intelligence Lab. Massachusetts Institute of Technology.
Multiple Clock Domains (MCD) Arvind with Nirav Dave Computer Science & Artificial Intelligence Lab Massachusetts Institute of Technology.
October 20, 2009L14-1http://csg.csail.mit.edu/korea Concurrency and Modularity Issues in Processor pipelines Arvind Computer Science & Artificial Intelligence.
Modeling Processors Arvind Computer Science & Artificial Intelligence Lab Massachusetts Institute of Technology March 1, 2010
Elastic Pipelines: Concurrency Issues
Introduction to Bluespec: A new methodology for designing Hardware
Introduction to Bluespec: A new methodology for designing Hardware
Concurrency properties of BSV methods and rules
Bluespec-6: Modeling Processors
Bluespec-6: Modules and Interfaces
Scheduling Constraints on Interface methods
Blusepc-5: Dead cycles, bubbles and Forwarding in Pipelines Arvind
Sequential Circuits Constructive Computer Architecture Arvind
Sequential Circuits: Constructive Computer Architecture
Introduction to Bluespec: A new methodology for designing Hardware
Stmt FSM Arvind (with the help of Nirav Dave)
Performance Specifications
Multirule Systems and Concurrent Execution of Rules
Constructive Computer Architecture: Guards
Sequential Circuits Constructive Computer Architecture Arvind
Modular Refinement Arvind
Modular Refinement Arvind
Blusepc-5: Dead cycles, bubbles and Forwarding in Pipelines Arvind
Bluespec-7: Scheduling & Rule Composition
Modeling Processors: Concurrency Issues
Modules with Guarded Interfaces
Sequential Circuits - 2 Constructive Computer Architecture Arvind
Introduction to Bluespec: A new methodology for designing Hardware
Elastic Pipelines: Concurrency Issues
Stmt FSM Arvind (with the help of Nirav Dave)
Modular Refinement - 2 Arvind
Elastic Pipelines: Concurrency Issues
Bluespec-5: Modeling Processors
Constructive Computer Architecture: Guards
GCD: A simple example to introduce Bluespec
Control Hazards Constructive Computer Architecture: Arvind
Design methods to facilitate rapid growth of SoCs
Introduction to Bluespec: A new methodology for designing Hardware
Tutorial 4: RISCV modules Constructive Computer Architecture
Modeling Processors Arvind
Modeling Processors Arvind
Modular Refinement Arvind
Implementing for Correct Concurrency
Bluespec-8: Modules and Interfaces
Presentation transcript:

February 28, 2005http://csg.csail.mit.edu/6.884/L09-1 Bluespec-3: Modules & Interfaces Arvind Computer Science & Artificial Intelligence Lab Massachusetts Institute of Technology Based on material prepared by Bluespec Inc, January 2005

February 22, 2005L07-2http://csg.csail.mit.edu/6.884/ Bluespec: State and Rules organized into modules All state (e.g., Registers, FIFOs, RAMs,...) is explicit. Behavior is expressed in terms of atomic actions on the state: Rule: condition  action Rules can manipulate state in other modules only via their interfaces. interface module

February 22, 2005L07-3http://csg.csail.mit.edu/6.884/ typedef bit[15:0] Tin; typedef bit[31:0] Tout; module mkMult0 (Empty); Tin d_init = 9, r_init = 5; // compile-time constants Reg#(Tout) product <- mkReg (0); Reg#(Tout) d <- mkReg ({16’h0000, d_init}); Reg#(Tin) r <- mkReg (r_init); rule cycle (r != 0); if (r[0] == 1) product <= product + d; d <= d << 1; r > 1; endrule: cycle rule done (r == 0); $display (“Product = %d”, product); endrule: done endmodule: mkMult0 State Example 1: simple binary multiplication Behavior This module has no interface methods; it only multiplies 9 by 5! Replace it by a “start” method Replace it by a “result” method

February 22, 2005L07-4http://csg.csail.mit.edu/6.884/ interface Mult_ifc; method Action start (Tin, x, Tin y); method Tout result (); endinterface module mkMult1 (Mult_ifc); Reg#(Tout) product <- mkReg (0); Reg#(Tout) d <- mkReg (0); Reg#(Tin) r <- mkReg (0); rule cycle (r != 0); if (r[0] == 1) product <= product + d; d <= d << 1; r > 1; endrule: cycle method Action start (d_init, r_init) if (r == 0); d <= d_init; r <= r_init; endmethod  method result () if (r == 0);  return product;  endmethod endmodule: mkMult1 Example 1: Modularized Behavior State Interface

February 22, 2005L07-5http://csg.csail.mit.edu/6.884/ Interfaces An interface declaration defines an interface type Corresponds, roughly, to the port list of an RTL module Contains prototypes of methods, which are “transactions” that can be invoked on the module A module declaration specifies the interface that it implements (a.k.a. provides) interface Mult_ifc; method Action start (Tin x, Tin y); method Tout result(); endinterface module mkMult1 (Mult_ifc); … endmodule

February 22, 2005L07-6http://csg.csail.mit.edu/6.884/ A Test bench for Example 1 module mkTest (Empty); Reg#(int) state <- mkReg(0); Mult_ifc m <- mkMult1(); rule go (state == 0); m.start (9, 5); state <= 1; endrule rule finish (state == 1); $display (“Product = %d”, m.result()); state <= 2; endrule endmodule: mkTest Instantiating the mkMult module Invoking mkMult’s methods

February 22, 2005L07-7http://csg.csail.mit.edu/6.884/ module mkTest (Empty) ; Reg#(int) state <- mkReg(0); Mult_ifc m <- mkMult1(); … endmodule Module and interface instantiation Modules instantiate other modules Just like instantiating primitive state elements like registers Standard module-instantiation shorthand: This: is shorthand for: module mkMult1 (Mult_ifc); … endmodule Mult_ifc m <- mkMult1(); Mult_ifc m(); mkMult1 mult_inst(m); (interface instantiation) (module instantiation)

February 22, 2005L07-8http://csg.csail.mit.edu/6.884/ module mkTest (Empty) ; … Mult_ifc m <- mkMult1(); rule go (state==0); m.start(9,5); state <= 1; endrule … endmodule Methods are invoked from rules Rule condition: state==0 && r==0 Conjunction of explicit (state==0) and implicit (r==0) conditions Rule actions: state<=1, d<=9 and r<=5 Thus, a part of the rule’s action is in a different module, behind a method invocation module mkMult1 (Mult_ifc); … method Action start (x, y) if (r == 0); d <= x; r <= y; endmethod … endmodule

February 22, 2005L07-9http://csg.csail.mit.edu/6.884/ Three Method Forms BSV method calls look like function and procedure calls: Value methods: Functions which take 0 or more arguments and return a value x = m.result() Action methods: Procedures which take 0 or more arguments and perform an action m.start(x) Actionvalue methods: Procedures which take 0 or more arguments, perform an action, and return a result. x <- m.pop() Value methods can be called from any expression but action or actionvalue methods can be called only from a rule or a method body (not from a rule or method predicate)

February 22, 2005L07-10http://csg.csail.mit.edu/6.884/ Methods as ports Interface method types can be interpreted directly as I/O wires of a module: Arguments are input signals Return values are output signals An implicit condition is an output “ready” signal An Action type (side-effect) indicates an incoming “enable” signal

February 22, 2005L07-11http://csg.csail.mit.edu/6.884/ Methods as ports: Mult_ifc rdy enab rdy start result j == 0 Mult_ifc module start: 16-bit arguments has side effect (action) result: no argument 32-bit result no side effect interface Mult_ifc; method Action start (Tin x, Tin y); method Tout result (); endinterface 16

February 22, 2005L07-12http://csg.csail.mit.edu/6.884/ interface FIFO #(type t); method Action enq(t);// enqueue an item method Action deq();// remove oldest entry method t first();// inspect oldest item method Action clear();// make FIFO empty endinterface: FIFO Methods as ports: FIFO interface n = # of bits needed to represent the values of type “t“ not full not empty rdy enab n n rdy enab rdy enq deq first FIFO module clear enab

February 22, 2005L07-13http://csg.csail.mit.edu/6.884/ Methods as ports: summary Methods can be viewed as a higher-level description of ports: A method groups related ports together  e.g., data_in, RDY and ENABLE Enforces the “micro-protocol”  Called only when ready  Strobes data at the right time  … and more … It is easy to relate the generated Verilog to the BSV source: Transparent translation from methods to ports

February 22, 2005L07-14http://csg.csail.mit.edu/6.884/ Syntax note: “<-” “ <- ” is used in two ways: Module instantiation shorthand Invoking an ActionValue method These two uses are distinguished by context Queue#(int) q <- mkQueue; … rule r1 (…); x <- q.pop(); … endrule

February 22, 2005L07-15http://csg.csail.mit.edu/6.884/ Two uses of “<-” In both uses, the operator Has a side-effect  “instantiate a module”  “discard an element from the FIFO” And returns a value  “return the interface”  “return the discarded FIFO element” In one case these happen during static elaboration In the other case these happen dynamically (during HW execution)

February 22, 2005L07-16http://csg.csail.mit.edu/6.884/ Sharing methods

February 22, 2005L07-17http://csg.csail.mit.edu/6.884/ A method can be invoked from more than one rule interface FIFO#(type t); Action enq (t n); … endinterface module mkFIFO (…); … method enq (x) if (… notFull …); … endmethod … endmodule: mkFIFO module mkTest (…); … FIFO#(int) f <- mkFIFO(); … rule r1 (… cond1 …); … f.enq (… expr1 …); … endrule rule r2 (… cond2 …); … f.enq (… expr2 …); … endrule endmodule: mkTest (In general the two invoking rules could be in different modules)

February 22, 2005L07-18http://csg.csail.mit.edu/6.884/ Sharing methods In software, to call a function/procedure from two processes just means: Create two instances (usually on two stacks) A BSV method represents real hardware There is only one instance (per instantiated module) It is a shared resource Parallel accesses must be scheduled (controlled) Data inputs and outputs must be muxed/ distributed The BSV compiler inserts logic to accomplish this sharing This logic is not an artifact of using BSV—it is logic that the designer would otherwse have to design manually

February 22, 2005L07-19http://csg.csail.mit.edu/6.884/ Sharing a method The compiler inserts logic for sharing a method not full not empty n n RDY ENAB RDY ENAB RDY enq deq first FIFO DATA_IN DATA_OUT r1 r2 control

February 22, 2005L07-20http://csg.csail.mit.edu/6.884/ Important special cases Value methods without arguments need no muxing or control, since they have no inputs into the module Examples:  r._read for a register  f.first for a FIFO Note: these methods are combinational functions, but they depend on the module’s internal state (Advanced topic) BSV primitives can specify a replication factor for certain methods, so two calls to the “same” method actually get connected (automatically) to different replicas of the method E.g., a read method of a multi-ported register file

February 22, 2005L07-21http://csg.csail.mit.edu/6.884/ Interface variations It is the designer’s choice how to expose the functionality of a module using interface methods E.g., a FIFO can have several interfaces

February 22, 2005L07-22http://csg.csail.mit.edu/6.884/ interface FIFO #(type t); method Action enq(t);// enqueue an item method Action deq();// remove oldest entry method t first();// inspect oldest item method Action clear();// make FIFO empty endinterface: FIFO A FIFO interface n = # of bits needed to represent the values of type “t“ not full not empty rdy enab n n rdy enab rdy enq deq first FIFO module clear enab

February 22, 2005L07-23http://csg.csail.mit.edu/6.884/ interface FIFO #(type t); method Action push(t); // enqueue an item method ActionValue#(t) pop(); // remove oldest entry method t first(); // inspect oldest item method Action clear(); // make FIFO empty endinterface: FIFO Another FIFO interface: Combine first & deq not full not empty rdy enab n n rdy enab rdy push pop first FIFO module clear enab n may or may not provide “first” method

February 22, 2005L07-24http://csg.csail.mit.edu/6.884/ FIFOF: Explicit ready signals The designer might want to expose the implicit ready signals–the notFull and notEmpty signals: The original enq/deq/first methods may or may not be protected by implicit conditions, depending on the module implementation interface FIFOF#(type aType); … enq … first … deq … clear method Bool notFull(); method Bool notEmpty(); endinterface

February 22, 2005L07-25http://csg.csail.mit.edu/6.884/ Modularizing your design Consider a speculative, out-of-order microachitecture Branch Register File ALU Unit Re- Order Buffer (ROB) MEM Unit Data Memory Instruction Memory Fetch Decode FIFO Re- Order Buffer (ROB) Branch Register File ALU Unit MEM Unit Data Memory Instruction Memory Fetch Decode Suppose we want to focus on the ROB module

February 22, 2005L07-26http://csg.csail.mit.edu/6.884/ ROB actions Empty Waiting Dispatched Killed Done E W Di K Do Head Tail V --Instr -V - -Instr -V - -Instr -V - -Instr -V - -Instr -V - -Instr -V - -Instr -V - -Instr -V - -Instr -V - -Instr -V - V 0-Instr BV 0W -Instr CV 0W -Instr DV 0W -Instr AV 0W V --Instr -V - -Instr -V - E E E E E E E E E E E E V 0 Re-Order Buffer Insert an instr into ROB Decode Unit Register File Get operands for instr Writeback results Get a ready ALU instr Get a ready MEM instr Put ALU instr results in ROB Put MEM instr results in ROB ALU Unit(s) MEM Unit(s) Resolve branches Operand 1ResultInstructionOperand 2 State

February 22, 2005L07-27http://csg.csail.mit.edu/6.884/ Modularizing your design A natural organization for two modules may be “recursive”. Module AModule B but unfortunately BSV does not handle recursive module calls...

February 22, 2005L07-28http://csg.csail.mit.edu/6.884/ A rule that calls a method can be turned into a method module moduleA (InterfaceA); rule foo(True);  MsgTypeB msg <- modB.getMessage();   endrule endmodule: moduleA module ModuleA (InterfaceA); method foo(MsgTypeB msg);  endmethod endmodule: moduleA Module A rule

February 22, 2005L07-29http://csg.csail.mit.edu/6.884/ Alternative Modularization Put one module inside the other Module A Module B rules Create a new module and put both modules inside it. Provide rules to pass values inbetween Module C Module B rule Module A rules

February 22, 2005L07-30http://csg.csail.mit.edu/6.884/ Glue module code... module mkTest (Empty); InterfaceA modA <- mkModuleA(); InterfaceB modB <- mkModuleB(); rule messagefromAtoB (True); MsgTypeA msg <- modA.getMessageToB(); modB.handleMessageFromA(msg); endrule  rule messagefromBtoA (True);  MsgTypeB msg <- modB.getMessageToA();  modA.handleMessageFromB(msg);  endrule endmodule: mkTest

February 22, 2005L07-31http://csg.csail.mit.edu/6.884/ Modular organization: Two Stage Pipeline  Read method call  Action method call iMem RFile rf FIFO bu dMem fetch & decode pc execute  set pc

February 22, 2005L07-32http://csg.csail.mit.edu/6.884/ Summary An interface type (e.g., Mult_ifc) specifies the prototypes of the methods in such an interface The same interface can be provided by many modules Module definition: A module header specifies the interface type provided (or implemented) by the module Inside a module, each method is defined  Can contain implicit conditions, actions and returned values Many module definitions can provide the same interface Module use: An interface and a module are instantiated Interface methods can be invoked from rules and other methods  Method implicit conditions contribute to rule conditions  Method actions contribute to rule actions  rule semantics extends smoothly across module boundaries