Constructive Computer Architecture Tutorial 2 Advanced BSV Sizhuo Zhang 6.175 TA Oct 9, 2015T02-1http://csg.csail.mit.edu/6.175.

Slides:



Advertisements
Similar presentations
Spring 2009W. Rhett DavisNC State UniversityECE 406Slide 1 ECE 406 – Design of Complex Digital Systems Lecture 8: Sequential Design Spring 2009 W. Rhett.
Advertisements

Chapter 12 Qualified Types. Motivation  What should the principal type of (+) be? Int -> Int -> Int-- too specific a -> a -> a-- too general  It seems.
Programming Concepts MIT - AITI. Variables l A variable is a name associated with a piece of data l Variables allow you to store and manipulate data in.
Modeling Processors Arvind Computer Science & Artificial Intelligence Lab Massachusetts Institute of Technology February 22, 2011L07-1
Computer Architecture: A Constructive Approach Branch Direction Prediction – Six Stage Pipeline Joel Emer Computer Science & Artificial Intelligence Lab.
Computer Architecture: A Constructive Approach Sequential Circuits Arvind Computer Science & Artificial Intelligence Lab. Massachusetts Institute of Technology.
Copyright © Bluespec Inc Bluespec SystemVerilog™ Design Example A DMA Controller with a Socket Interface.
Constructive Computer Architecture Combinational circuits-2 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 March 15, 2010.
Multiple Clock Domains (MCD) Continued … Arvind with Nirav Dave Computer Science & Artificial Intelligence Lab Massachusetts Institute of Technology November.
Oct 2, 2014T01-1http://csg.csail.mit.edu/6.175 Constructive Computer Architecture Tutorial 1 BSV Sizhuo Zhang TA.
Constructive Computer Architecture: Guards Arvind Computer Science & Artificial Intelligence Lab. Massachusetts Institute of Technology September 24, 2014.
Constructive Computer Architecture Tutorial 8 Final Project Part 2: Coherence Sizhuo Zhang TA Nov 25, 2015T08-1http://csg.csail.mit.edu/6.175.
Constructive Computer Architecture Tutorial 4 Debugging Sizhuo Zhang TA Oct 23, 2015T04-1http://csg.csail.mit.edu/6.175.
Constructive Computer Architecture Tutorial 2 Advanced BSV Andy Wright TA September 26, 2014http://csg.csail.mit.edu/6.175T02-1.
Constructive Computer Architecture Sequential Circuits Arvind Computer Science & Artificial Intelligence Lab. Massachusetts Institute of Technology
Copyright 2004 Scott/Jones Publishing Alternate Version of STARTING OUT WITH C++ 4 th Edition Chapter 6 Functions.
Computer Architecture: A Constructive Approach Next Address Prediction – Six Stage Pipeline Joel Emer Computer Science & Artificial Intelligence Lab. Massachusetts.
Constructive Computer Architecture Combinational circuits Arvind Computer Science & Artificial Intelligence Lab. Massachusetts Institute of Technology.
Constructive Computer Architecture Sequential Circuits Arvind Computer Science & Artificial Intelligence Lab. Massachusetts Institute of Technology September.
Constructive Computer Architecture Sequential Circuits - 2 Arvind Computer Science & Artificial Intelligence Lab. Massachusetts Institute of Technology.
Verification Presentation to SystemVerilog Basic Committee Peter Flake Nov 15, 2002.
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.
6.375 Tutorial 3 Scheduling, Sce-Mi & FPGA Tools Ming Liu
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
Functions and Types in Bluespec
Bluespec-6: Modeling Processors
Folded “Combinational” circuits
Scheduling Constraints on Interface methods
Sequential Circuits - 2 Constructive Computer Architecture Arvind
Sequential Circuits Constructive Computer Architecture Arvind
Sequential Circuits: Constructive Computer Architecture
BSV Tutorial 1 Ming Liu Feb 12, 2016
Pipelining combinational circuits
Constructive Computer Architecture: Lab Comments & RISCV
Constructive Computer Architecture: Guards
BSV Types Constructive Computer Architecture Tutorial 1 Andy Wright
Sequential Circuits Constructive Computer Architecture Arvind
Constructive Computer Architecture Tutorial 7 Final Project Overview
Pipelining combinational circuits
Modular Refinement Arvind
Modular Refinement Arvind
BSV objects and a tour of known BSV problems
EHR: Ephemeral History Register
6.375 Tutorial 2 Guards and Scheduling Ming Liu
Debugging BSV and Typeclasses. Constructive Computer Architecture
Constructive Computer Architecture: Well formed BSV programs
Constructive Computer Architecture Tutorial 3 RISC-V Processor
Modules with Guarded Interfaces
Pipelining combinational circuits
Sequential Circuits - 2 Constructive Computer Architecture Arvind
6.375 Tutorial 5 RISC-V 6-Stage with Caches Ming Liu
Bypassing Computer Architecture: A Constructive Approach Joel Emer
Type & Typeclass Syntax in function
Bluespec-5: Modeling Processors
Constructive Computer Architecture: Guards
2. Second Step for Learning C++ Programming • Data Type • Char • Float
Modeling Processors Arvind
Modular Refinement Arvind
Constructive Computer Architecture: Well formed BSV programs
Tutorial 7: SMIPS Labs and Epochs Constructive Computer Architecture
PROGRAMMING IN HASKELL
Caches-2 Constructive Computer Architecture Arvind
CS295: Modern Systems Bluespec Introduction – More Topics
CS295: Modern Systems Introduction To Bluespec – Types
Bluespec-8: Modules and Interfaces
Constructive Computer Architecture Tutorial 1 Andy Wright 6.S195 TA
Presentation transcript:

Constructive Computer Architecture Tutorial 2 Advanced BSV Sizhuo Zhang TA Oct 9, 2015T02-1http://csg.csail.mit.edu/6.175

EHR and Scheduling Design example Up/down counter Oct 9, 2015T01-2http://csg.csail.mit.edu/6.175 interface Counter; Bit#(8) read; Action increment(Bit#(8) x); Action decrement; endinterface

Up/Down Counter Conflict Design Oct 9, 2015T01-3http://csg.csail.mit.edu/6.175 module mkCounter( Counter ); Reg#(Bit#(8)) count <- mkReg(0); method Bit#(8) read; return count; endmethod method Action increment(Bit#(8) x); count <= count + x; endmethod method Action decrement; count <= count – 1; endmethod endmodule increment conflicts with decrement

Concurrent Design A general technique Replace conflicting registers with EHRs Choose an order for the methods Assign ports of the EHR sequentially to the methods depending on the desired schedule Method described in paper that introduces EHRs: “The Ephemeral History Register: Flexible Scheduling for Rule-Based Designs” by Daniel Rosenband Oct 9, 2015T01-4http://csg.csail.mit.edu/6.175

Up/Down Counter Concurrent design: read < inc < dec Oct 9, 2015T01-5http://csg.csail.mit.edu/6.175 module mkCounter( Counter ); Ehr#(3, Bit#(8)) count <- mkEhr(0); method Bit#(8) read; // use port 0 return count[0]; endmethod method Action increment(Bit#(8) x);; // use port 1 count[1] <= count[1] + x; endmethod method Action decrement; // use port 2 count[2] <= count[2] – 1; endmethod endmodule We could use Ehr#(2, Bit#(8)), but not necessary.

Conflict-Free Design A general technique Replace conflicting Action and ActionValue methods with writes to EHRs representing method call requests If there are no arguments for the method call, the EHR should hold a value of Bool If there are arguments for the method call, the EHR should hold a value of Maybe#(Tuple2#(TypeArg1,TypeArg2)) or something similar Create a canonicalize rule to handle all of the method call requests at the same time Reset all the method call request EHRs to False or tagged invalid at the end of the canonicalize rule Guard method calls with method call requests If there is an outstanding request, don’t allow a second one to happen Oct 9, 2015T01-6http://csg.csail.mit.edu/6.175

Up/Down Counter Conflict-Free design – methods Oct 9, 2015T01-7http://csg.csail.mit.edu/6.175 module mkCounter( Counter ); Reg#(Bit#(8)) count <- mkReg(0); Ehr#(2, Maybe#(Bit#(8))) inc_req <- mkEhr(Invalid); Ehr#(2, Bool) dec_req <- mkEhr(False); // canonicalize rule on next slide method Bit#(8) read = count; method Action increment(Bit#(8) x) if(!isValid(inc_req[0])); inc_req[0] <= Valid (x); endmethod method Action decrement if(!dec_req[0]); dec_req[0] <= True; endmethod endmodule

Up/Down Counter Conflict-Free design – canonicalize rule Oct 9, 2015T01-8http://csg.csail.mit.edu/6.175 module mkCounter( Counter ); // Reg and EHR definitions on previous slide rule canonicalize; let count_nxt = count; if(isValid(inc_req[1])) count_nxt = count_nxt + fromMaybe(?, inc_req[1]); if(dec_req[1]) count_nxt = count_nxt - 1; count <= count_nxt inc_req[1] <= Invalid; dec_req[1] <= False; endrule // methods on previous slide endmodule This is basically the solution to Lab 4.

Synthesis Boundary Module without synthesis boundary Methods are inlined Pros: Aggressive guard lifting (if … else …) Cons: long compile time if instantiated many times Module with synthesis boundary The module will be compiled separately The module becomes a black box Pros: shorter compile time, no inlining Cons: conservative guards Oct 9, 2015T01-9http://csg.csail.mit.edu/6.175 (* synthesize *) Module mkMyModule( MyModuleIFC );

Synthesis Boundary Guard Logic (Example) Synthesis boundaries simplifies guard logic Lifted guard without synthesis boundary:  (!x || g(p)) && (x || g(q)) Lifted guard with synthesis boundary: p && q Synthesis boundaries do not allow inputs to be in guards. There are other restriction… Oct 9, 2015T01-10http://csg.csail.mit.edu/6.175 method Action doAction( Bool x ); if( x ) begin when p; end else begin when q; end endmethod

Synthsis Boundary A synthesis boundary can only be placed over a module with: No type parameters in its interface No parameters in the module’s constructor that can’t be converted to bits (no interfaces can be passed in) Takeaway Synthesis boundary may affect guard & scheduling Faster compilation Oct 9, 2015T01-11http://csg.csail.mit.edu/6.175

Typeclass Motivating example: parametrized add Some type t can be added: Bit#(n), Int#(n) Some cannot: enum, struct, tagged union Typeclass If a type blongs to a typeclass, then certain operations can be performed on this type Arith: +, -, *, /, %, negate Bits: pack, unpack Oct 9, 2015T01-12http://csg.csail.mit.edu/6.175 function t adder(t a, t b); return a + b; endfunction

Typeclass Define a typeclass If types a and n are in typeclass Bits, then we can do pack & unpack with them Oct 9, 2015T01-13http://csg.csail.mit.edu/6.175 typeclass Bits#(type a, numeric type n); function Bit#(n) pack(a x); function a unpack(Bit#(n) x); endtypeclass

Instance Types are added to typeclasses by creating instances of that typeclass deriving: do above process in a default way Oct 9, 2015T01-14http://csg.csail.mit.edu/6.175 typedef enum { Red, Green, Blue } Color deriving (Eq); // no deriving(Bits) instance Bits#(Color, 2); function Bit#(2) pack(Color x); return x==Red ? 3 : x==Green ? 2 : 1; endfunction function Color unpack(Bit#(2) x); return x==3 ? Red : x==2 ? Green : Blue; endfunction endinstance

Provisos Tell compiler that type t can do “+” Add provisos (compile error without provisos) Provisos Tell compiler additional information about the parametrized types Compiler can type check based on the info Oct 9, 2015T01-15http://csg.csail.mit.edu/6.175 function t adder(t a, t b) provisos(Arith#(t)); return a + b; endfunction

Typeclass Takeaway Typeclasses allow polymorphism across types Provisos restrict modules type parameters to specified type classes Typeclass Examples ( BSV Reference guide Section B.1) Eq: ==, != Ord:, =, min, max, compare Bits: pack, unpack Arith: +, -, *, /, %, negate Literal: fromInteger, inLiteralRange FShow: fshow (format values nicely as strings) Oct 9, 2015T01-16http://csg.csail.mit.edu/6.175

RISC-V Processor Code Oct 9, 2015T01-17http://csg.csail.mit.edu/6.175