scieee AI-readable full text Open interactive document viewer

Processor Design

Espasa Sans, Roger,Canal Corretger, Ramon

Full text

Roger Espasa, Ramon Canal Q1 2017/2018 2 Professor • Roger Espasa • Office: C6-101 • Email: [email protected] • Office hours: – Agreed through email • Ramon Canal • Office: C6-107 • Email: [email protected] • Office hours: – Mon. 16-18, Tue. 10-12 3 Course materials http://docencia.ac.upc.edu/master/MIRI/PD/ – Course Information – Slides – Lab documentation 4 High-Performance Computing 5 Agenda • Course structure • Evaluation • What will I be able to do after the course? • Topics covered • Lab sessions • Course Schedule • Bibliography 6 Course structure • Lectures (once a week) – Friday 12-14 • Lab sessions (once a week) – Tuesday 12-14 • Assignments – 4 Lab sessions – 2 Reviews – 1 Final project (last 4 weeks) 7 Evaluation • Final mark will be based on the performance of: – The lab sessions (Lab) – Presentation of a research topic (T) – The final mark will be computed as: 0,8 x Lab + 0,2 T 8 What will I be able to do after the course? (1) This course offers a more advanced treatment of digital design in the context of microprocessors. With a special emphasis on: 1.Design methodology and practice. 2.Pipeline microprocessor architecture implementation and evaluation 9 Contents 1. Historical Perspective 2. Technology-Aware Processor Design 3. Processor Design Cycle and Fabrication 4. Memory Hierarchy 5. Modern Processor Architectures 2 Agenda •Back in the old days • Back to the future 3 The First Computer The Babba g e Difference Engine (1832) 25,000 parts cost: £17,470 4 ENIAC - The first electronic computer (1946) 5 The Transistor Revolution First transistor Bell Labs, 1948 6 The First Integrated Circuits Bipolar logic 1960’s ECL 3-input Gate Motorola 1966 7 Intel 4004 Micro-Processor 1971 1000 NMOS transistors 1 MHz operation 8 Intel Skylake microprocessor (4C) 2015 1’75B CMOS transistors ~4 GHz operation 14nm 9 Intel Broadwell microprocessor (8C) 2016 3200M CMOS transistors ~4 GHz operation 14nm 10 AMD “Ryzen” microprocessor (8C) 2017 4800M CMOS transistors ~4 GHz operation 14nm 11 Agenda • Back in the old days •Back to the future 18 Productivity Trends 1 10 100 1,000 10,000 100,000 1,000,000 10,000,000 2003 1981 1983 1985 1987 1989 1991 1993 1995 1997 1999 2001 2005 2007 2009 10 100 1,000 10,000 100,000 1,000,000 10,000,000 100,000,000 Tr. Logic/Chip Tr./Eng. Mes x x x x x x x 21%/Any Creixement Productivitat x 58%/Any Creixement Complexitat 10,000 1,000 100 10 1 0.1 0.01 0.001 Transistors Logic per Chip (M) 0.01 0.1 1 10 100 1,000 10,000 100,000 Productivitat (K) Trans./Eng - Mes Source: Sematech Complexity grows faster than design productivity Complexitat Courtesy, ITRS Roadmap 19 CTD – Master CANS 20 21 Technology Scaling • Technology shrinks 0.7x per generation • Each new generation can integrate 2x more functions per chip; the cost per chip is not affected significantly • Thus... The cost per function decreases two fold • But... – How can we design a chip with more functions? – Engineering population doesn‘t double every 2 years • So: we need better and efficient design techniques: – Take advantage of abstraction levels 22 Design Abstraction Levels n+n+ S GD + DEVICE CIRCUIT GATE MODULE SYSTEM 23 Design tools • VLSI system design is a complex process which requires automatization of the synthesis cycle. That’s why we need design tools. • There are three families of tools: – Synthesis tools • They allow a physical representation of circuits expressde in HDL (Hardware Definition Languages). – Analysis and Verification • They guarantee the specifications and the correctness of the design – Testing tools • They verify that there have been no errors on the fabrication process. Historical Perspective Ramon Canal Processor Design– MIRI 24 1 Design Methodology: A walkthrough Ramon Canal 2013 2 Design domains (Gajski i Kuhn) Structural Behavioral Physical / Geometric Processor, memory ALU, registers Cell Device, gate Transistor Program Algorithm Module Boolean equation Transfer function IC Macro Functional unit Gate Masks System level Algorithmic Logic RT level Circuit System Description Design Methodology: Big Picture System Specification Design Partition Design Entry Behavioral Modeling Simulation/Functional Verification Pre-Synthesis Sign-Off Synthesize and Map Gate-level Net List Postsynthesis Design Validation Postsynthesis Timing Verification Test Generation and Fault Simulation Cell Placement/Scan Insertation/Routing Verify Physical and Electrical Rules Synthesize and Map Gate-level Net List Design Integration And Verification Design Sign-Off Gate-Level Synthesis and Technology Mapping • Once all syntax and functional errors have been eliminated, synthesize the design from the behavior description – Optimized Boolean description – Map onto target technology • Optimizations include – Minimize logic – Reduce area – Reduce power – Balance speed vs. other resources consumed • Produces netlist according to target technology (standard cells, FPGA, …) Design Methodology: Big Picture System Specification Design Partition Design Entry Behavioral Modeling Simulation/Functional Verification Pre-Synthesis Sign-Off Synthesize and Map Gate-level Net List Postsynthesis Design Validation Postsynthesis Timing Verification Test Generation and Fault Simulation Cell Placement/Scan Insertation/Routing Verify Physical and Electrical Rules Synthesize and Map Gate-level Net List Design Integration And Verification Design Sign-Off Postsynthesis Design Validation • Does gate-level synthesized logic implement the same input-output function as the HDL behavioral description? HDL Behavioral Desc Gate-Level Desc Logic Synthesis Stimulus Generator Testbench for Postsynthesis Design Validation Response Comparator Postsynthesis Timing Verification • Are the timing specifications met? • Are the speeds adequate on the critical paths? – Can’t accurately be determined until actual physical layout is understood and analyzed—length of wires, relative placement of sources and sinks, number of switch matrix crosspoints traversed, etc. • Resynthesis may be required to achieve timing goals – Resize transistors – Modify architecture – Choose a different target device or technology Test Generation and Fault Simulation • This is NOT about debugging the design! – Design should be correct at this stage, so … • Determine set of test vectors to test for inherent fabrication flaws – Need a quick method to sort out the bad from the good chips – More exhaustive testing may be necessary for chips that pass the first level – More relevant for ASIC design than FPGAs • Avoiding this step is one of the advantages of using the FPGA approach • Fault simulation is used to determine how complete are the test vectors Placement and Routing • ASIC Standard Cells – Select the cells and placement them on the mask – Interconnect the placed cells – Choose implementation scheme for critical signals • E.g., Clock distribution trees to minimize skew – Insert scan paths • FPGAs – Placing functions into particular CLBs/Slices and committing interconnections to particular wires in the switch matrix Physical and Electrical Design Rule Check • Applies to ASICs primarily – Are mask geometries correct to insure high probability of successful fabrication? – Fan-outs correct? Crosstalk signals within specification? Current drops within specification? Noise levels ok? Power dissipation acceptable? • Many of these issues are not significant at a chip level for an FPGA but may be an issue for the system that incorporates the FPGA Parasitic Extraction • Extract geometric information from design to determine capacitance • Yields a much more realistic model of signal performance and delay • Are the speed (timing) and power goals of the design still met? • Could trigger another redesign/resythesize cycle if not met Design Sign-off • All design constraints have been met • Timing specifications have been met • Mask set ready for fabrication Design Methodology: Big Picture System Specification Design Partition Design Entry Behavioral Modeling Simulation/Functional Verification Pre-Synthesis Sign-Off Synthesize and Map Gate-level Net List Postsynthesis Design Validation Postsynthesis Timing Verification Test Generation and Fault Simulation Cell Placement/Scan Insertation/Routing Verify Physical and Electrical Rules Synthesize and Map Gate-level Net List Design Integration And Verification Design Sign-Off 26 Channel definitions • Blocks are placed so empty rectangular spaces are left between them. These spaces will be later used to make the interconnection. 27 Physical Design Cycle Routing –Complete the interconnections between the modules. Factors like critical path, wire spacing, …are considered. Include global routing and detailed routing. Feedthrough Standard cell type 1 Standard cell type 2 28 Global Routing • Each connection will go from each origin block, through the channels until the end block. 29 Global Routing • The length of the connections will depend on the situation of the blocks rather than the way the routing is done. 30 Detailed Routing • The space required for each channel will depend on the complexity and density of the connections. 31 Detailed Routing • Aligned connections require a smaller channel (similar to that of a bus). 32 Detailed Routing • Non-aligned connections increment the complexity of the routing and it increases the amount of space required. 33 Detailed Routing • The number of crossings determines the space required. The size of the channel may have to be increased. 34 Detailed Routing • Aligned connections reduce dramaticaly the area required of the channel for completing the routing. 35 Bus area • The area of each bus is proportional to the number of bits of the bus. 42 Physical Design Cycle Compaction –Compress the layout from all directions to minimize the chip area. Verification –Check correctness of the layout. Include DRC (Design Rule Checking), circuit extraction (generate a circuit from the layout to compare with the original netlist), performance verification (extract geometric information to compute resistance, capacitance, delay, ...) 43 Summing up Physical Design • The area of the blocks is predictable: – Depends of the number of transistors and the spacing. – It does not depend on the connections. • The area of the connections is not much predictable. • If the blocks are larger than the routing: the connections are determined by the separation among the blocks. • If the routing dominates the blocks (in the same way as buses): The buses behave now like blocks. • In any other case it is needed to simulate the connections to estimate their area (very sensible to the floorplanning). 44 Implementation alternatives 45 Implementation Alternatives • Alternatives – integrated circuits • programmable arrays - e.g. ROM, FPGA • full custom fabrication – hybrid integrated circuits • silicon-on-silicon – 3D modules – circuit boards • discrete wiring - wire-wrap • printed circuits • Design rules – topology and geometry constraints – imposed by physics and manufacturing – example: wires must be > 2 microns wide 46 IC implementation alternatives • Full custom design – no constraints - output is geometry • highest-volume, highest performance designs – requires some handcrafted design • 5-10 transistors/day for custom layout – use to design cells for other methods – primary CAD tools • layout editor, plotter • Cell-based design – compose design using a library of cells – at board-level, cells are chips – cell = single gate up to microprocessor – primary CAD tools • partitioning • placement and routing 47 IC implementation alternatives • Gate array design – FPGAs are a form of gate array • Standard cell design • General cell design • Full custom design – still used for analog circuits Design Styles Custom Cell Symbolic Procedural General Cell Design Methods Standard Cell Gate Array Implementation Methods Programmable Arrays Custom 48 Gate Array Design • Array of prefabricated gates/transistors • Map cell-based design onto gates • Wire up gates – in routing channels between gates – over top of gates (sea of gates) – predefined wiring patterns to convert transistors to gates • CAD problems – placement of gates/transistors onto fixed sites – global and local wire routing in fixed space 49 Standard Cell Design • Design circuit using standard cells – cells are small numbers of gates, latches, etc. • Technology mapping selects cells • Place and wire them – cells placed in rows • all cells same height, different widths – wiring between rows - channels • CAD problems – cell placement - row and location within row – wiring in channels – minimize area, delay 50 General Cell Design • Generalization of standard cells • Cells can be large, irregularly shaped – standard cells, RAMs, ROMs, datapaths, etc. • Used in large designs – e.g. Pentium has datapaths, RAM, ROM, standard cells, etc. • CAD problems – placement and routing of arbitrary shapes is difficult Datapath Cache RAM Std. Cells Decode PLA uCode ROM 51 Case study Standard Cell implementation 58 High performance devices • Mixture of full custom, standard cells and macro’s • Full custom for special blocks: Adder (data path), etc. • Macro’s for standard blocks: RAM, ROM, etc. • Standard cells for non critical digital blocks Pentium Power PC 59 Case study FPGA just for prototyping? 60 Why FPGAs? • Custom ICs where sometimes designed to replace the large amount of glue logic: – reduced system complexity and manufacturing cost, improved performance. – However, custom ICs are relatively very expensive to develop, and delay introduction of product to market (time to market) because of increased design time. • Note: need to worry about two kinds of costs: 1. cost of development, sometimes called non-recurring engineering (NRE) 2. cost of manufacture – A tradeoff usually exists between NRE cost and manufacturing costs total costs number of units manufactured (volume) NRE A B FPGA ASIC 61 Why FPGAs? • Therefore the custom IC approach was only viable for products with very high volume (where NRE could be amortized), and which were not time to market (TTM) sensitive. • FPGAs were introduced as an alternative to custom ICs for implementing glue logic: – improved density relative to discrete SSI/MSI components (within around 10x of custom ICs) – with the aid of computer aided design (CAD) tools circuits could be implemented in a short amount of time (no physical layout process, no mask making, no IC manufacturing), relative to ASICs. • lowers NREs • shortens TTM • Because of Moore’s law, the density (gates/area) of FPGAs continued to grow through 00’s to the point where major data processing functions can be implemented on a single FPGA. 62 Why FPGAs? • FPGAs continue to compete with custom ICs for special processing functions (and glue logic) but now also compete with microprocessors in dedicated and embedded applications. – Performance advantage over microprocessors because circuits can be customized for the task at hand. Microprocessors must provide special functions in software (many cycles). • Summary: ASIC = custom IC, MICRO = microprocessor • Newer FPGAs even combine microprocessor cores, special multiplier circuits, memory blocks, and configurable logic on a single chip. performance NREs Unit cost TTM ASIC ASIC ASIC FPGA MICRO FPGA MICRO FPGA MICRO FPGA ASIC MICRO 63 Summary • Logic design process influenced by available technology AND economic drivers – Volume, Time to Market, Costs, Power • FPGA offer a valuable new sweet spot – Low TTM, medium cost, tremendous flexibility (during and after design is done - field upgrades are possible). • Fundamentally tied to powerful CAD tools • Build everything (simple or complex) from one set of building blocks – LUTs + FF + routing + storage + IOs 1 Design Steps Ramon Canal PD Fall 2013 2 Design domains (Gajski) Structural Behavioral Physical / Geometric Processor, memory ALU, registers Cell Device, gate Transistor Program State machine Module Boolean equation Transfer function IC Macro Functional unit Gate Masks 3 Abstraction levels and synthesis Architectural level Logic level Circuit level Behavioral levelStructural level For I=0 to I=15 Sum = Sum + array[I] 0 0 0 0 State Memory + Control Clk Architecture synthesis Logic synthesis Circuit synthesis Layout level Layout synthesis Silicon compilation (not a big success) (Library) (register level) 4 Design domains (Gajski) System level Algorithmic Logic RT level Circuit Hardware Description Language (HDL) • Basic idea is a programming language to describe hardware • Initial purpose was to allow abstract design and simulation – Design could be verified then implemented in hardware • Now Synthesis tools allow direct implementation from HDL code. – Large improvement in designer productivity HDL • HDL allows write-run-debug cycle for hardware development. – Similar to programming software – Much, much faster than design-implement- debug • Combined with modern Field Programmable Gate Array chips large complex circuits (100000s of gates) can be implemented. HDLs • There are many different HDLs – Verilog HDL – ABEL – VHDL • VHDL is the most common – Large standard developed by US DoD – VHDL = VHSIC HDL – VHSIC = Very High Speed Integrated Circuit Verilog HDL • Verilog HDL is second most common – Easier to use in many ways = better for teaching – C - like syntax •History – Developed as proprietry language in 1985 – Opened as public domain spec in 1990 • Due to losing market share to VHDL – Became IEEE standard in 1995 Summary • Why use an HDL? – Describe complex designs (millions of gates) – Input to synthesis tools (synthesizable subset) – Design exploration with simulation • Why not use a general purpose language – Support for structure and instantiation – Support for describing bit-level behavior – Support for timing – Support for concurrency • Verilog vs. VHDL – Verilog is relatively simple and close to C – VHDL is close to Ada – Verilog has 60% of the world digital design market (larger share in US) 16 Design Steps Ramon Canal PD Fall 2013 1 High-Performance Processors’ Design Choices Ramon Canal PD Fall 2013 2 High-Performance Processors’ Design Choices 1 Motivation 2 Multiprocessors 3 Multithreading 4 VLIW 3 Outline • Motivation • Multiprocessors – SISD, SIMD, MIMD, and MISD – Memory organization – Communication mechanisms • Multithreading •VLIW 4 Motivation Instruction-Level Parallelism (ILP): What all we have covered so far: – simple pipelining – dynamic scheduling: scoreboarding and Tomasulo’s alg. – dynamic branch prediction – multiple-issue architectures: superscalar, VLIW – compiler techniques and software approaches Bottom line: There just aren’t enough instructions that can actually be executed in parallel! – instruction issue: limit on maximum issue count – branch prediction: imperfect – # registers: finite – functional units: limited in number – data dependencies: hard to detect dependencies via memory 11 Multiprocessor: Hybrid Organization • Use distributed-memory organization at top level • Each node itself may be a shared-memory multiprocessor (2-8 processors) • What about Big Data? Is it a “game changer”? –Next slides based on the following works: •M. Ferdman et al. “Clearing the clouds” ASPLOS’12 •P.Lotfi-Kamran et al.‘‘Scale-OutProcessors” ISCA’12 •B. Grot et al. “Optimizing Datacenter TCO with Scale-Out Processors”, IEEE MICRO 2012 –Next couple of slides © of Prof. Babak Falsafi (EPFL) Multiprocessors and Big Data PD, 2013 12 PD, 2013 13 PD, 2013 14 PD, 2013 15 PD, 2013 16 Scale-out Processors • Small LLC. Just to capture instructions. • More cores for higher throughput • “Pods” for small distance to memory PD, 2013 17 Performance • Iso server power (20MW) PD, 2013 18 Summary Multiprocessors • Need to tailor chip design to applications – Big Data applications are too big for data caches. Best solution is too eliminate them. – Big Data applications in need of coarse grain parallelism (i.e. At the request level) – Still single-thread performance is STILL important for other applications (i.e. Computation intensive) PD, 2013 19 20 Multithreading Threads: multiple processes that share code and data (and much of their address space) • recently, the term has come to include processes that may run on different processors and even have disjoint address spaces, as long as they share the code Multithreading: exploit thread-level parallelism within a processor – fine-grain multithreading • switch between threads on each instruction! – coarse-grain multithreading • switch to a different thread only if current thread has a costly stall – E.g., switch only on a level-2 cache miss 27 • Each processor supports 128 active hardware threads – 128 SSWs, 1024 target registers, 4096 general-purpose registers • Every cycle, one instruction from one active thread is launched into pipeline • Instruction pipeline is 21 cycles long • At best, a single thread can issue one instruction every 21 cycles – Clock rate is 260MHz, effective single thread issue rate is 260/21 = 12.4MHz Tera MTA (Cray) 28 Multithreading Coarse-grain multithreading – switch only if current thread has a costly stall • E.g., level-2 cache miss – can accommodate slightly costlier switches – less likely to slow down an individual thread • a thread is switched “off” only when it has a costly stall – main disadvantage: • limited in ability to overcome throughput losses – shorter stalls are ignored, and there may be plenty of those • issues instructions from a single thread – every switch involves emptying and restarting the instruction pipeline 29 IBM PowerPC RS64-III (Pulsar) • Commercial coarse-grain multithreading CPU • Based on PowerPC with quad-issue in-order five stage pipeline • Each physical CPU supports two virtual CPUs • On L2 cache miss, pipeline is flushed and execution switches to second thread – short pipeline minimizes flush penalty (4 cycles), small compared to memory access latency – flush pipeline to simplify exception handling 30 Simultaneous Multithreading (SMT) Key Idea: Exploit ILP across multiple threads! – Share CPU to multiple threads – i.e., convert thread-level parallelism into more ILP – exploit following features of modern processors: • multiple functional units – modern processors typically have more functional units available than a single thread can utilize • register renaming and dynamic scheduling – multiple instructions from independent threads can co-exist and co-execute! 31 Multithreading: Illustration (a) A superscalar processor with no multithreading (b) A superscalar processor with coarse-grain multithreading (c) A superscalar processor with fine-grain multithreading (d) A superscalar processor with simultaneous multithreading (SMT) (a) (b) (c) (d) 32 From Superscalar to SMT •SMT is an out-of-order superscalar extended with hardware to support multiple executing threads 33 Simultaneous Multithreaded Processor 34 • Add multiple contexts and fetch engines to wide out-of- order superscalar processor – [Tullsen, Eggers, Levy, University of Washington, 1995] • OOO instruction window already has most of the circuitry required to schedule from multiple threads • Any single thread can utilize whole machine • First examples: – Alpha 21464 (DEC/Compaq) – Pentium IV (Intel) – Power 5 (IBM) – Ultrasparc IV (Sun) Simultaneous Multithreaded Processor 35 SMT: Design Challenges • Dealing with a large register file – needed to hold multiple contexts • Maintaining low overhead on clock cycle – fast instruction issue: choosing what to issue – instruction commit: choosing what to commit – keeping cache conflicts within acceptable bounds • Power hungry! 36 Intel Pentium-4 Processor • Hyperthreading = SMT • Dual physical processors, each 2-way SMT • Logical processors share nearly all resources of the physical processor – Caches, execution units, branch predictors • Die area overhead of hyperthreading ~5 % • When one logical processor is stalled, the other can make progress – No logical processor can use all entries in queues when two threads are active • A processor running only one active software thread to run at the same speed with or without hyperthreading Issue Logic •Intel Pentium IV Glem Hilton et al., “The Microarchitecture of the Pentium 4 processor”, Intel Technology Journal Q1, 2001 Issue Logic •Intel Pentium IV Glem Hilton et al., “The Microarchitecture of the Pentium 4 processor”, Intel Technology Journal Q1, 2001 Issue Logic •Intel Pentium IV Glem Hilton et al., “The Microarchitecture of the Pentium 4 processor”, Intel Technology Journal Q1, 2001 Issue Logic •Intel Core 2 Lynnfield (2009) Sandy Bridge (2011) Issue Logic 1 1Cache size and associativity, ROB size and RS number vary across generations Issue Logic •AMD Athlon Issue Logic •AMD Athlon Issue Logic •AMD Opteron Issue Logic •AMD Opteron Level 2 Cache L2 ECC L2 Tags L2 Tag ECC System Request Queue (SRQ) Cross Bar (XBAR) Memory Controller & HyperTransport™ 2k Branch Targets 16k History Counter RAS & Target Address Data TLB Level 1 Data Cache ECC Instr’n TLB Level 1 Instr’n Cache AGU ALU AGU ALU AGU ALU FADD FMUL FMISC 8-entry Scheduler 8-entry Scheduler 8-entry Scheduler 36-entry Scheduler Fetch 2 - transit Pick DecodeDecodeDecode Pack Pack Pack Decode 1 Decode 2 Decode 1 Decode 2 Decode 1 Decode 2 “Northbridge” Issue Logic •AMD Phenom II (bulldozer core) 4 Processor (+) It knows the state on real-time (+) Precise and adaptable branch prediction (+) Can manage data dependencies not known at compiletime (i.e. Memory dependences) (-) Restricted program scope (-) Small (if any) knowledge of program structure (-) Limited scope for instruction scheduling. (-) Hardware complexity (-) Complex: hits the cycle time (-) Expensive: in area, verification and power cost. 5 Compiler (+) Global view of the program (+) Better information on program structure and high-level parallelism (loops, functions, etc) (+) Potentially larger perspective on instruction scheduling. (+) More sophisticate analysis possible (+) No limits on chip area or cycle time (-) Restrictions on the total compile time and memory usage 6 Programming Translate an idea to a program A good place to optimize: Most effective/efficient algorithm Sequential Search / Binary Search Efficient memory management Memory usage for programs and data Is it worth considering the memory hierarchy? 7 Compiler Translates a HLL program into an assembly code (of a specific processor ISA) Compiler steps: Intermediate language translation Similar to the assembly language but more extensive Translation to assembly code (code generation) What instruction does the ISA support? What if the ISA does not have a divide instruction? How many registers does the ISA have? Usually, each variable is assigned a register. How many variables/registers can we hold at a time? Does the processor support static branch prediction? 8 Cross-Level optimizations What can we optimize that is CPU dependent? Branches Branch Prediction, Critical Branch Detection, Inlining, etc Loops Unrolling, software pipelining , loop fussion/fission, … Memory/Caches  Referencing, blocking/padding, prefetching ,… SIMD and multimedia extensions Vectorization 56 Memory and Processor Performance Gap is Increasing CPU performance doubles every 18 months Memory capacity doubles every 18 months But, speed of memory increases at a much lower rate Speed gap increases by about 50% per year A large portion of program execution time is spent waiting for memory accesses to complete and this % is ever increasing Can the compiler do things to reduce this time? 57 Locality: The Why of Memory Hierarchies Real programs typically access data that is close in time and space to data that has been recently accessed, this is called locality of reference. Spatial Locality: there is a small difference in the addresses of different data. Temporal Locality: there is a small difference in time between accesses to the same data. These characteristics have lead to the structure of the typical modern memory hierarchy. DO I = 1, N DO I = 1, N A(I) = … SUM = SUM + … ENDDO ENDDO spatial locality temporal locality 58 The Memory Hierarchy Number of Levels (Why?) Line Size (Why?) Associativity (Why?) Types of Misses… Processor Level 1 Cache Level 2 Cache Level N Cache . . . Memory Disk Block address Tag Index Block offset 59 What a compiler can do A compiler can restructure applications to uncover and enhance locality A compiler has two dimensions to work with: can change the order of memory access (control flow) can change the layout of memory (declarations) Changing the order of memory accesses the most common method loop transformations: loop interchange, loop tiling, loop fission/fusion, … unimodular transformations Changing the layout of memory data transformations: array transpose, array padding 60 Data Storage in Memory Data storage order is language dependent: Fortran stores multi-dimensional arrays “column-wise” C stores multi-dimensional arrays “row-wise” Accessing array elements in storage order greatly improves performance. A(I,J) J I iiii jj+1 j+2 In memory jjjj ii+1 i+2 In memory a[i][j] j i right most index changes fastest... left most index changes fastest... 67 Software Prefetch Example: int a; int d[100000][16]; int main() {unsigned i,j,k; for (i=0;i<1000;i++) { for (j=0;j<100000;j++) { for (k=0;k<16;k++) { a = a + d[j][k]; } } } } int a; int d[100000][16]; int main() {unsigned i,j,k; for (i=0;i<1000;i++) { for (j=0;j<100000;j++) { prefetch_read(&d[j+5][0]); for (k=0;k<16;k++) { a = a + d[j][k]; } } } } .inline prefetch_read,1 prefetch [%o0+0],0 .end Original 41.4 s Prefetch 27.5 s 68 5 Multimedia Instruction Sets: SIMD and Vector 69 What is Multimedia Processing? Desktop: 3D graphics (games) Speech recognition (voice input) Video/audio decoding (mpeg-mp3 playback) Servers: Video/audio encoding (video servers, IP telephony) Digital libraries and media mining (video servers) Computer animation, 3D modeling & rendering (movies) Embedded: 3D graphics (game consoles) Video/audio decoding & encoding (set top boxes) Image processing (digital cameras) Signal processing (cellular phones) 70 The Need for Multimedia ISAs Why aren’t general-purpose processors and ISAs sufficient for multimedia (despite Moore’s law)? Performance A 1.2GHz Athlon can do MPEG-4 encoding at 6.4fps One 384Kbps W-CDMA channel requires 6.9 GOPS Power consumption A 1.2GHz Athlon consumes ~60W Power consumption increases with clock frequency and complexity Cost A 1.2GHz Athlon costs ~$62 to manufacture and has a list price of ~$600 (module) Cost increases with complexity, area, transistor count, power, etc 71 Example: MPEG Decoding Parsing Dequantization IDCT Block Reconstruction RGB->YUV Input Stream Output to Screen 10% 20% 25% 30% 15% Load Breakdown 72 Example: 3D Graphics Transform Lighting Display Lists Output to Screen Geometry Pipe Setup Rasterization Anti-aliasing Shading, fogging Texture mapping Alpha blending Z-buffer Clipping Frame-buffer ops Rendering Pipe 10% 10% 35% 55% Load Breakdown 73 Characteristics of Multimedia Apps (1) Requirement for real-time response “Incorrect” result often preferred to slow result Unpredictability can be bad (e.g. dynamic execution) Narrow data-types Typical width of data in memory: 8 to 16 bits Typical width of data during computation: 16 to 32 bits 64-bit data types rarely needed Fixed-point arithmetic often replaces floating-point Fine-grain (data) parallelism Identical operation applied on streams of input data Branches have high predictability High instruction locality in small loops or kernels 74 Characteristics of Multimedia Apps (2) Coarse-grain parallelism Most apps organized as a pipeline of functions Multiple threads of execution can be used Memory requirements High bandwidth requirements but can tolerate high latency High spatial locality (predictable pattern) but low temporal locality Cache bypassing and prefetching can be crucial 75 Examples of Media Functions Matrix transpose/multiply DCT/FFT Motion estimation Gamma correction Haar transform Median filter Separable convolution Viterbi decode Bit packing Galois-fields arithmetic … (3D graphics) (Video, audio, communications) (Video) (3D graphics) (Media mining) (Image processing) (Image processing) (Communications, speech) (Communications, cryptography) (Communications, cryptography) 76 Approaches to Mediaprocessing Multimedia Processing General-purpose processors with SIMD extensions Vector Processors VLIW with SIMD extensions (aka mediaprocessors) DSPs ASICs/FPGAs 83 Programming with SIMD Extensions Optimized shared libraries Written in assembly, distributed by vendor Need well defined API for data format and use Language macros for variables and operations C/C++ wrappers for short vector variables and function calls Allows instruction scheduling and register allocation optimizations for specific processors Lack of portability, non standard Compilers for SIMD extensions No commercially available compiler so far Problems Language support for expressing fixed-point arithmetic and SIMD parallelism Complicated model for loading/storing vectors Frequent updates Assembly coding 84 SIMD Performance 0 2 4 6 8 Athlon Alpha 21264 Pentium III PowerPC G4 UltraSparc IIi Speedup over Base Architecture for Berkeley Media Benchmarks Arithmetic Mean Geometic Mean Limitations •Memory bandwidth • Overhead of handling alignment and data width adjustments 85 A Closer Look at MMX/SSE Higher speedup for kernels with narrow data where 128b SSE instructions can be used Lower speedup for those with irregular or strided accesses PentiumIII (500MHz) with MMX/SSE 6.4 4.9 1.3 5.6 1.7 2.8 3.8 22.5 1.5 7.6 1.3 2.2 1.8 4.7 31.1 0 2 4 6 8 10 Speedup over Base Architecture 86 Vector Processors 88 Playstation 2 – Emotion Engine 89 Playstation 2 – Emotion Engine (Vector Units) 90 Playstation 2 – Emotion Engine 91 Playstation 2 – Emotion Engine (Mips III) 92 Playstation 2 – Emotion Engine (Vector unit) 93 Vector Processors Initially developed for super-computing applications, but we will focus only on multimedia today Vector processors have high-level operations that work on linear arrays of numbers: "vectors" + r1 r2 r3 add r3, r1, r2 SCALAR (1 operation) v1 v2 v3 + vector length vadd.vv v3, v1, v2 VECTOR (N operations) 100 Setting the Vector Length A vector register can hold some maximum number of elements for each data width (maximum vector length or MVL) What to do when the application vector length is not exactly MVL? Vector-length (VL) register controls the length of any vector operation, including a vector load or store E.g. vadd.vv with VL=10 is for (I=0; I<10; I++) V1[I]=V2[I]+V3[I] VL can be anything from 0 to MVL How do you code an application where the vector length is not known until run-time? 101 Strip Mining Suppose application vector length > MVL Strip mining Generation of a loop that handles MVL elements per iteration A set operations on MVL elements is translated to a single vector instruction Example: vector saxpy of N elements First loop handles (N mod MVL) elements, the rest handle MVL VL = (N mod MVL); // set VL = N mod MVL for (I=0; I<VL; I++) // 1st loop is a single set of Y[I]=A*X[I]+Y[I]; // vector instructions low = (N mod MVL); VL = MVL; // set VL to MVL for (I=low; I<N; I++) // 2nd loop requires N/MVL Y[I]=A*X[I]+Y[I]; // sets of vector instructions 102 Choosing the Data Type Width Alternatives for selecting the width of elements in a vector register (64b, 32b, 16b, 8b) Separate instructions for each width E.g. vadd64, vadd32, vadd16, vadd8 Popular with SIMD extensions for GPPs Uses too many opcodes Specify it in a control register Virtual-processor width (VPW) Updated only on width changes NOTE MVL increases when width (VPW) gets narrower E.g. with 2Kbits for register, MVL is 32,64,128,256 for 64- ,32-,16-,8-bit data respectively Always pick the narrowest VPW needed by the application 103 Other Features for Multimedia Support for fixed-point arithmetic Saturation, rounding-modes etc Permutation instructions of vector registers For reductions and FFTs Not general permutations (too expensive) Example: permutation for reductions Move 2nd half a a vector register into another one Repeatedly use with vadd to execute reduction Vector length halved after each step 0 15 16 63 V0 0 15 16 63 V1 104 Optimization 1: Chaining Suppose: vmul.vv V1,V2,V3 vadd.vv V4,V1,V5 # RAW hazard Chaining Vector register (V1) is not as a single entity but as a group of individual registers Pipeline forwarding can work on individual vector elements Flexible chaining: allow vector to chain to any other active vector operation => more read/write ports vmul vadd vmul vadd Unchained Chained 105 Optimization 2: Multi-lane Implementation Elements for vector registers interleaved across the lanes Each lane receives identical control Multiple element operations executed per cycle Modular, scalable design No need for inter-lane communication for most vector instructions To/From Memory System Pipelined Datapath Functional Unit Lane Vector Reg. Partition 106 Chaining & Multi-lane Example VL=16, 4 lanes, 2 FUs, 1 LSU, chaining -> 12 ops/cycle Just one new instruction issued per cycle !!!! vld vmul.vv vadd.vv addu vld vmul.vv vadd.vv addu LSU FU0 FU1Scalar Time Element Operations: Instr. Issue: 107 Optimization 3: Conditional Execution Suppose you want to vectorize this: for (I=0; I<N; I++) if (A[I]!= B[I]) A[I] -= B[I]; Solution: vector conditional execution Add vector flag registers with single-bit elements Use a vector compare to set the a flag register Use flag register as mask control for the vector sub Addition executed only for vector elements with corresponding flag element set Vector code vld V1, Ra vld V2, Rb vcmp.neq.vv F0, V1, V2 # vector compare vsub.vv V3, V2, V1, F0 # conditional vsub vst V3, Ra 108 Vector Architecture State General Purpose Registers Flag Registers (32) VP0VP1VP$mvl-1 vr0 vr1 vr31 vf0 vf1 vf31 $vpw bits 1 bit Virtual Processors ($mvl) r0 r1 r31 Scalar Registers 64 bits 109 Two Ways to Vectorization Inner loop vectorization Think of machine as, say, 32 vector registers each with 16 elements 1 instruction updates 32 elements of 1 vector register Good for vectorizing single-dimension arrays or regular kernels (e.g. saxpy) Outer loop vectorization Think of machine as 16 “virtual processors” (VPs) each with 32 scalar registers! ( multithreaded processor) 1 instruction updates 1 scalar register in 16 VPs Good for irregular kernels or kernels with loop-carried dependences in the inner loop These are just two compiler perspectives The hardware is the same for both 116 How to Pick # of Vector Registers? More vector registers: Reduces vector register “spills” (save/restore) Aggressive scheduling of vector instructions: better compiling to take advantage of ILP Fewer Fewer bits in instruction format (usually 3 fields) 32 vector registers are usually enough 117 Context Switch Overhead? The vector register file holds a huge amount of architectural state To expensive to save and restore all on each context switch Extra dirty bit per processor If vector registers not written, don’t need to save on context switch Extra valid bit per vector register, cleared on process start Don’t need to restore on context switch until needed Extra tip: Save/restore vector state only if the new context needs to issue vector instructions 118 Exception Handling: Arithmetic Arithmetic traps are hard Precise interrupts => large performance loss Multimedia applications don’t care much about arithmetic traps anyway Alternative model Store exception information in vector flag registers A set flag bit indicates that the corresponding element operation caused an exception Software inserts trap barrier instructions from SW to check the flag bits as needed IEEE floating point requires 5 flag registers (5 types of traps) 119 Exception Handling: Page Faults Page faults must be precise Instruction page faults not a problem Data page faults harder Option 1: Save/restore internal vector unit state Freeze pipeline, (dump all vector state), fix fault, (restore state and) continue vector pipeline Option 2: expand memory pipeline to check all addresses before send to memory Requires address and instruction buffers to avoid stalls during address checks On a page-fault on only needs to save state in those buffers Instructions that have cleared the buffer can be allowed to complete 120 Exception Handling: Interrupts Interrupts due to external sources I/O, timers etc Handled by the scalar core Should the vector unit be interrupted? Not immediately (no context switch) Only if it causes an exception or the interrupt handler needs to execute a vector instruction 121 Vector Power Consumption Can trade-off parallelism for power Power = C *Vdd2*f If we double the lanes, peak performance doubles Halving f restores peak performance but also allows halving of the Vdd Powernew = (2C)*(Vdd/2)2*(f/2) = Power/4 Simpler logic Replicated control for all lanes No multiple issue or dynamic execution logic Simpler to gate clocks Each vector instruction explicitly describes all the resources it needs for a number of cycles Conditional execution leads to further savings 122 Why Vectors for Multimedia? Natural match to parallelism in multimedia Vector operations with VL the image or frame width Easy to efficiently support vectors of narrow data types High performance at low cost Multiple ops/cycle while issuing 1 instr/cycle Multiple ops/cycle at low power consumption Structured access pattern for registers and memory Scalable Get higher performance by adding lanes without architecture modifications Compact code size Describe N operations with 1 short instruction (v. VLIW) Predictable performance No need for caches, no dynamic execution Mature, developed compiler technology 123 Comparison with SIMD More scalable Can use double the amount of HW (datapaths/registers) without modifying the architecture or increasing instruction issue bandwidth Simpler hardware A simple scalar core is enough Multiple operations per instruction Full support for vector loads and stores No overhead for alignment or data width mismatch Mature compiler technology Although language problems are similar… Disadvantages Complexity of exception model Out of fashion… 124 A Vector Media-Processor: VIRAM Technology: IBM SA-27E 0.18mm CMOS, 6 copper layers 280 mm2 die area 158 mm2DRAM, 50 mm2logic Transistor count: ~115M 14 Mbytes DRAM Power supply & consumption 1.2V for logic, 1.8V for DRAM 2W at 1.2V Peak performance 1.6/3.2 /6.4 Gops (64/32/16b ops) 3.2/6.4/12.8 Gops (with madd) 1.6 Gflops (single-precision) Designed by 5 graduate students 125 Performance Comparison QCIF and CIF numbers are in clock cycles per frame All other numbers are in clock cycles per pixel MMX results assume no first level cache misses VIRAM MMX iDCT 0.75 3.75 (5.0x) Color Conversion 0.78 8.00 (10.2x) Image Convolution 1.23 5.49 (4.5x) QCIF (176x144) 7.1M 33M (4.6x) CIF (352x288) 28M 140M (5.0x) Accelerated systems Use additional computational unit dedicated to some functions? Hardwired logic. Extra CPU. Hardware/software co-design: joint design of hardware and software architectures. Accelerator vs. co-processor A co-processor executes instructions. Instructions are dispatched by the CPU. An accelerator appears as a device on the bus. The accelerator is controlled by registers. Why accelerators? Better cost/performance. Custom logic may be able to perform operation faster than a CPU of equivalent cost. CPU cost is a non-linear function of performance. cost performance Why accelerators? cont’d. Better real-time performance. Put time-critical functions on less-loaded processing elements. Better Energy-Delay tradeoffs Why accelerators? cont’d. Good for : I/O processing in real-time. Data streaming (audio, video, network traffic, real-time monitoring, etc.) Specific “complex” operations: FFT, DCT, EXP, LOG, … Specific “complex” algorithms: Neuronal networks, … Accelerated system architecture CPU accelerator memory I/O request data result data Accelerator implementations Application-specific Integrated Circuit (ASIC). Field-programmable gate array (FPGA). Standard component. Example: graphics processor. System design tasks Design a heterogeneous multiprocessor architecture. Processing element (PE): CPU, accelerator, etc. Program the system. Accelerated system design First, determine that the system really needs to be accelerated. How much faster is the accelerator on the core function? How much data transfer overhead? Design the accelerator itself. Design CPU interface to accelerator. Performance analysis Critical parameter is speedup: how much faster is the system with the accelerator? Must take into account: Accelerator execution time. Data transfer time. Synchronization with the master CPU. Accelerator “usual” problems Memory consistency and coherency (specially if the CPU has caches) Partitioning the source code into accelerated chunks. Scheduling of the code chunks. Allocation to accelerators (if many) Accelerated systems Several off-the-shelf boards are available for acceleration in PCs: FPGA-based core; PCIe bus interface. Natural Markets Embedded Systems FPGAs appearing in set-top boxes, routers, audio equipment, etc. Advantages Performance close to ASIC, sometimes at much lower cost Many other embedded systems still use ASIC due to high volume Cell phones, iPod, game consoles, etc. Reconfigurable! If standards change, architecture is not fixed Can add new features after production Natural Markets High-performance embedded computing (HPEC) High-performance/super computing with special needs (low power, low size/weight, etc.) Satellite image processing Target recognition in a UAV Advantages Much smaller/lower power than a supercomputer Fault tolerance Natural Markets High-performance computing (HPC) Cray, SGI, DRC, GiDEL, Nallatech, XtremeData Combine high-performance microprocessors with FPGA accelerators Novo-G 192 Altera Stratix III FPGAs integrated with 24 quad-core microprocessors Advantages HPC used for many scientific apps Low volume, ASIC rarely feasible, microprocessor too slow Lower power consumption Increasingly important Cooling and energy costs are dominant factor in total cost of ownership Natural Markets General-purpose computing??? Ideal situation: desktop machine/OS uses a programmable accelerator to speedup up all applications (similar to GPU trend) Problems The accelerator can be very fast, but not for all applications Generally requires parallel algorithms Coding constructs used in many applications not appropriate for hardware Subject of tremendous amount of past and likely future research How to use extra transistors on general purpose CPUs? More cache More microprocessor cores GPU FPGA? Something else? Limitations of FPGA acceleration 1) Not all applications can be improved 2) Tools need serious improvement! 3) Design strategies are often ad hoc 4) Floating point? Requires a lot of area, but performance is becoming competitive with other devices Already superior in terms of energy 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 Speedup 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 Speedup Embedded Applications – Large Speedups Desktop Applications – No Speedup Natural Markets General-purpose computing??? Ideal situation: desktop machine/OS uses a programmable accelerator to speedup up all applications (similar to GPU trend) Problems The accelerator can be very fast, but not for all applications Generally requires parallel algorithms Coding constructs used in many applications not appropriate for hardware Subject of tremendous amount of past and likely future research How to use extra transistors on general purpose CPUs? More cache More microprocessor cores GPU FPGA? Something else? Something else… Brain-inspired accelerators Neurmorphic Architectures Modern Architectures: Custom Circuits FPGA Model Torres-Huitzil et. al (INRIA, 2005) designed an hardware architecture for a bio-inspired neural model for motion estimation. Architecture has 3 basic components which perform spatial, temporal, and excitatoryinhibitory connectionist processing. Observed approximately 100 x speedup over Pentium 4 processor implementation for 128x128 images CMOL based design CMOL = Cmos + MOLecular (2003) Konstantin Likharev (State University of New York at Stony Brook) Dan Hammerstrom (Porland State University / DARPA) Similar approach as HP with Memristors HTM on FPGAs Implemented on a Cray XD1 Hierarchical temporal memory (HTM) is a machine learning model developed by Jeff Hawkins and Dileep George of Numenta, Inc. that models some of the structural and algorithmic properties of the neocortex. Level 2 AMD Processor Level 1 AMD Processor FPGA PEPE FPGA PEPE AMD Processor Off-Chip Memory Off-Chip Memory Level 2 AMD Processor Level 1 Level 3 AMD Processor FPGA PEPE FPGA PEPE AMD Processor Off-Chip Memory Off-Chip Memory PEs on FPGA To Host Processor Interface and Reconfiguration Logic Level 2 Node P xu λ/π Addr Addr (A) Memory Access Unit A D Data (D) Data To External Memory Interface Processing Element (PE) λ/π P xu λ A D A D λ P xu λ/π Level 1 Node A D A D A D P xu λ λ/π Level 1 Node A D P xu λ λ/π Level 1 Node A D A D Level 1 Node To Host Processor Interface and Reconfiguration Logic Level 2 Node P xu λ/π Addr Addr (A) Memory Access Unit A D Data (D) Data To External Memory Interface Processing Element (PE) λ/π P xu λ A DA D A D A D λ P xu λ/π Level 1 Node A D A D A D P xu λ λ/π Level 1 Node A D P xu λ λ/π Level 1 Node A DA D A D A D Level 1 Node To Host Processor Interface and Reconfiguration Logic Level 2 Node P xu λ/π Addr Addr (A) Memory Access Unit A D Data (D) Data To External Memory Interface Processing Element (PE) λ/π P xu λ A D A D λ P xu λ/π Level 1 Node A D A D A D P xu λ λ/π Level 1 Node A D P xu λ λ/π Level 1 Node A D A D Level 1 Node To Host Processor Interface and Reconfiguration Logic Level 2 Node P xu λ/π Addr Addr (A) Memory Access Unit A D Data (D) Data To External Memory Interface Processing Element (PE) λ/π P xu λ A DA D A D A D λ P xu λ/π Level 1 Node A D A D A D P xu λ λ/π Level 1 Node A D P xu λ λ/π Level 1 Node A DA D A D A D Level 1 Node In an artificial neural network, neurons can take many forms and are typically referred to as Processing Elements (PE) to differentiate them from the biological equivalents Other examples 18 ARM9 cores simulating the brain Accelerating specific applications Typically machine learning problems -> Hardware neuronal networks Pattern recognition Filtering, etc. Check the works of Olivier Temam (INRIA) Another approach: Simulation (i.e. software) Large Scale Simulations Human Brain Project, EU 2013 BRAIN Initiative, USA 2012 Previously: IBM: Blue Brain Project: IBM & EPFL (Switzerland) IBM Almaden Research Center Los Alamos National Lab Air Force Research Laboratory Academia: Portland State University Royal Institute of Technology (KTM, Sweden) Going anywhere? 43