Constructive Computer Architecture: Guards

Slides:



Advertisements
Similar presentations
Elastic Pipelines and Basics of Multi-rule Systems Arvind Computer Science & Artificial Intelligence Lab Massachusetts Institute of Technology February.
Advertisements

An EHR based methodology for Concurrency management Arvind (with Asif Khan) Computer Science & Artificial Intelligence Lab Massachusetts Institute of Technology.
Constructive Computer Architecture: Multirule systems and Concurrent Execution of Rules Arvind Computer Science & Artificial Intelligence Lab. Massachusetts.
March 2007http://csg.csail.mit.edu/arvindSemantics-1 Scheduling Primitives for Bluespec 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.
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.
December 10, 2009 L29-1 The Semantics of Bluespec Arvind Computer Science & Artificial Intelligence Lab Massachusetts Institute.
December 12, 2006http://csg.csail.mit.edu/6.827/L24-1 Scheduling Primitives for Bluespec Arvind Computer Science & Artificial Intelligence Lab Massachusetts.
Pipelining combinational circuits Arvind Computer Science & Artificial Intelligence Lab. Massachusetts Institute of Technology February 20, 2013http://csg.csail.mit.edu/6.375L05-1.
Constructive Computer Architecture: Bluespec execution model and concurrency semantics Arvind Computer Science & Artificial Intelligence Lab. Massachusetts.
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.
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.
Modular Refinement Arvind Computer Science & Artificial Intelligence Lab Massachusetts Institute of Technology March 8,
Introduction to Bluespec: A new methodology for designing Hardware Arvind Computer Science & Artificial Intelligence Lab. Massachusetts Institute of Technology.
Simple Inelastic and Folded Pipelines Arvind Computer Science & Artificial Intelligence Lab Massachusetts Institute of Technology February 14, 2011L04-1.
Computer Architecture: A Constructive Approach Bluespec execution model and concurrent rule scheduling Teacher: Yoav Etsion Taken (with permission) from.
October 20, 2009L14-1http://csg.csail.mit.edu/korea Concurrency and Modularity Issues in Processor pipelines Arvind Computer Science & Artificial Intelligence.
Elastic Pipelines: Concurrency Issues
EHRs: Designing modules with concurrent methods
EHRs: Designing modules with concurrent methods
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
Folded “Combinational” circuits
Scheduling Constraints on Interface methods
Blusepc-5: Dead cycles, bubbles and Forwarding in Pipelines Arvind
Sequential Circuits - 2 Constructive Computer Architecture 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)
Pipelining combinational circuits
Multirule Systems and Concurrent Execution of Rules
Sequential Circuits Constructive Computer Architecture Arvind
Pipelining combinational circuits
EHR: Ephemeral History Register
Constructive Computer Architecture: Well formed BSV programs
Blusepc-5: Dead cycles, bubbles and Forwarding in Pipelines Arvind
Bluespec-7: Scheduling & Rule Composition
Modules with Guarded Interfaces
Pipelining combinational circuits
Sequential Circuits - 2 Constructive Computer Architecture Arvind
Introduction to Bluespec: A new methodology for designing Hardware
Elastic Pipelines: Concurrency Issues
Multirule systems and Concurrent Execution of Rules
Stmt FSM Arvind (with the help of Nirav Dave)
IP Lookup: Some subtle concurrency issues
Elastic Pipelines: Concurrency Issues
Elastic Pipelines and Basics of Multi-rule Systems
Constructive Computer Architecture: Guards
GCD: A simple example to introduce Bluespec
Elastic Pipelines and Basics of Multi-rule Systems
Bluespec-7: Scheduling & Rule Composition
Multirule systems and Concurrent Execution of Rules
Introduction to Bluespec: A new methodology for designing Hardware
IP Lookup: Some subtle concurrency issues
Bluespec-7: Semantics of Bluespec
Bluespec-5: Scheduling & Rule Composition
Modular Refinement Arvind
Constructive Computer Architecture: Well formed BSV programs
Presentation transcript:

Constructive Computer Architecture: Guards Arvind Computer Science & Artificial Intelligence Lab. Massachusetts Institute of Technology September 30, 2015 http://csg.csail.mit.edu/6.175

Elastic pipeline f1 f2 f3 x inQ fifo1 fifo2 outQ rule stage1; if(inQ.notEmpty && fifo1.notFull) begin fifo1.enq(f1(inQ.first)); inQ.deq; end endrule rule stage2; if(fifo1.notEmpty && fifo2.notFull) begin fifo2.enq(f2(fifo1.first)); fifo1.deq; end endrule rule stage3; if(fifo2.notEmpty && outQ.notFull) begin outQ.enq(f3(fifo2.first)); fifo2.deq; end endrule Proper use of FIFOs always involves checking for emptiness or fullness conditions September 30, 2015 http://csg.csail.mit.edu/6.175

Easy mistakes versus What is the difference? rule stage1; if(inQ.notEmpty && fifo1.notFull) begin fifo1.enq(f1(inQ.first); inQ.deq; end endrule versus What is the difference? rule stage1E; if(inQ.notEmpty && fifo1.notFull) fifo1.enq(f1(inQ.first); if(inQ.notEmpty) inQ.deq; endrule Guards is an abstraction to deal with such “atomicity” issues stage1E may dequeue something even though the value read has not been processed (ie enqueued into fifo1) September 30, 2015 http://csg.csail.mit.edu/6.175

FIFO Module: methods with guarded interfaces rdy enab enq deq first FIFO interface Fifo#(numeric type size, type t); method Action enq(t x); method Action deq; method t first; endinterface not full not empty not empty Every method has a guard (rdy wire) The compiler ensures that an action method is invoked (en) only if the guard is true. Similarly the value returned by a value method is meaningful only if its guard is true Guards make it possible to transfer the responsibility of the correct use of a method from the user to the compiler Guards are extraordinarily convenient for programming and also enhance modularity of the code September 30, 2015 http://csg.csail.mit.edu/6.175

One-Element FIFO Implementation with guards module mkCFFifo (Fifo#(1, t)); Reg#(t) d <- mkRegU; Reg#(Bool) v <- mkReg(False); method Action enq(t x) if (!v); v <= True; d <= x; endmethod method Action deq if (v); v <= False; method t first if (v); return d; endmodule n rdy enab enq deq first FIFO not full not empty not empty September 30, 2015 http://csg.csail.mit.edu/6.175

Elastic pipeline with guards f1 f2 f3 x inQ fifo1 fifo2 outQ rule stage1 (True); fifo1.enq(f1(inQ.first); inQ.deq(); endrule rule stage2 (True); fifo2.enq(f2(fifo1.first); fifo1.deq; endrule rule stage3 (True); outQ.enq(f3(fifo2.first); fifo2.deq; endrule guard When can stage1 rule fire? The explicit guard is true but the compiler lifts all the implicit guards of the methods to the top of the rule - inQ has an element - fifo1 has space September 30, 2015 http://csg.csail.mit.edu/6.175

Switch with guards inQ redQ greenQ rule switch (True); if (inQ.first.color == Red) begin redQ.enq (inQ.first.value); inQ.deq; end else begin greenQ.enq(inQ.first.value); inQ.deq; end endrule rule switchRed (inQ.first.color == Red); redQ.enq(inQ.first.value); inQ.deq; endrule; rule switchGreen (inQ.first.color == Green); greenQ.enq(inQ.first.value); inQ.deq; September 30, 2015 http://csg.csail.mit.edu/6.175

GCD module with Guards If x is 0 then the rule cannot fire Reg#(Bit#(32)) x <- mkReg(0); Reg#(Bit#(32)) y <- mkReg(0); rule gcd (x != 0); if (x >= y) begin x <= x – y; end else begin x <= y; y <= x; end endrule method Action start(Bit#(32) a, Bit#(32) b) if (x == 0); x <= a; y <= b; endmethod method Bit#(32) result if (x == 0); return y; endmethod If x is 0 then the rule cannot fire (Andy) Changed code to conform with BSV syntax Start method can be invoked only if x is 0 The result is available only when x is 0 is True. September 30, 2015 http://csg.csail.mit.edu/6.175

All methods have implicit guards Every method call has an implicit guard associated with it m.enq(x), the guard indicated whether one can enqueue into fifo m or not Methods of primitive modules like registers and EHRs have their guards always set to True Guards play an important role in scheduling; a rule is considered for scheduling only if its guard is true (“can fire”) Nevertheless guards are merely syntactic sugar and are lifted to the top of each rule by the compiler Information a guard carries can be encoded in a value method September 30, 2015 http://csg.csail.mit.edu/6.175

Guard Elimination September 30, 2015 http://csg.csail.mit.edu/6.175

Making guards explicit in compilation Make the guards explicit in every method call by naming the guard and separating it from the unguarded body of the method call, i.e., syntactically replace m.g(e) by m.gB(e) when m.gG Notice m.gG has no parameter because the guard value should not depend upon the input September 30, 2015 http://csg.csail.mit.edu/6.175

Lifting implicit guards rule foo if (True); (if (p) fifo.enq(8)); x.w(7) All implicit guards are made explicit, and lifted and conjoined to the rule guard rule foo if (p && fifo.enqG || !p); if (p) fifo.enqB(8); x.w(7) rule foo if (fifo.enqG || !p); if (p) fifo.enqB(8); x.w(7) September 30, 2015 http://csg.csail.mit.edu/6.175

Make implicit guards explicit <a> ::= <a> | <a> | if (<e>) <a> | m.g(<e>) | let t = <e> in <a> The kernel language with abstract syntax m.gB(<e>) when m.gG <a> ::= <a> | <a> | if (<e>) <a> | m.g(<e>) | let t = <e> in <a> | <a> when <e> The new kernel language methods without guards guarded action We use “|” instead of “;” for parallel composition. “|” and “::=” represent meta-syntax. September 30, 2015 http://csg.csail.mit.edu/6.175

Syntax for guards rule x (g); a endrule is the same as rule x (a when g) method foo(x, y) if (g); endmethod is the same as method foo(x, y) (a when g) endmethod If no guard is explicitly supplied, the guard is assumed to be True September 30, 2015 http://csg.csail.mit.edu/6.175

Guards vs If’s The predicate in a Conditional action only affects the actions within the scope of the conditional action (if (p1) a1) | a2 p1 has no effect on a2 ... The guard on one action of a parallel group of actions affects every action within the group (a1 when p1) | a2 ==> (a1 | a2) when p1 Mixing ifs and whens (if (p) (a1 when q)) | a2  ((if (p) a1) | a2) when ((p && q) || !p)  ((if (p) a1) | a2) when (q || !p) September 30, 2015 http://csg.csail.mit.edu/6.175

Guard Lifting Axioms without Let-blocks All the guards can be “lifted” to the top of a rule (a1 when p) | a2  a1 | (a2 when p)  if (p when q) a  if (p) (a when q)  (a when p1) when p2  m.gB(e when p)  similarly for expressions ... Rule r (a when p)  (a1 | a2) when p (if (p) a) when q (if (p) a) when (q || !p) a when (p1 && p2) m.gB(e) when p Rule r (if (p) a) We will call this guard lifting transformation WIF, for when-to-if A complete guard lifting procedure also requires rules for let-blocks September 30, 2015 http://csg.csail.mit.edu/6.175

Scheduling with guards At the top level a guard behaves just like an “if” A rule whose guard is False at a given cycle will result in no state change even if it is scheduled The guards of most rules can be evaluated in parallel, often with small amount of computation (The exceptions are 1. if two guards call the same method and the method has parameters; 2. if guards involve EHRs) The scheduler takes advantage of this fact by considering only those rules for scheduling in a given cycle whose guards are True September 30, 2015 http://csg.csail.mit.edu/6.175

Scheduling and control logic Modules (Current state) “CAN_FIRE” “WILL_FIRE” Modules (Next state) Rules cf1 Scheduler wf1 a1 p1 cfn wfn ns1 Muxing an pn cond After mapping all the rules, we have to combine their logic some how. For a particular state elemetn like the PC register, the latch enable is the or the enable signals from all the rules that updates PC. The actual next state value of PC has to be selected through a multiplexer. Notice, this circuit only works if only one of these pi signal is asserted at a time action nsn Compiler synthesizes a scheduler such that at any given time will-fire for only non-conflicting rules are true September 30, 2015 http://csg.csail.mit.edu/6.175

Hierarchical scheduling interface module According to Bluespec semantics, at most one rule from any module should execute in a given cycle Which module? Modules form a natural hierarchy; Schedule inside out or outside in? September 30, 2015 http://csg.csail.mit.edu/6.175

Hierarchical scheduling Scheduling is done outside-in: First, the rules of the outermost modules are scheduled, which may call (enable) methods of inner modules Then the rules of subsequent inner modules are scheduled, as long as they can be scheduled concurrently with the called methods BSV provides annotation to reverse this priority on a module basis It is because of scheduling complications that current BSV doesn’t allow modular compilation in the presence of interface parameters September 30, 2015 http://csg.csail.mit.edu/6.175