lecture-3 (performance metrics and isa) cs422-spring 2020

39
Lecture-3 (Performance Metrics and ISA) CS422-Spring 2020 Biswa@CSE-IITK

Upload: others

Post on 17-Apr-2022

2 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Lecture-3 (Performance Metrics and ISA) CS422-Spring 2020

Lecture-3 (Performance Metrics and ISA)CS422-Spring 2020

Biswa@CSE-IITK

Page 2: Lecture-3 (Performance Metrics and ISA) CS422-Spring 2020

What about Multi-core Systems?

CS422 2

Throughput = ∑ IPC (i)

Weighted Speedup = ∑ (IPC-together(i) / IPC-alone (i))

Harmonic Mean of Speedups = N/∑ (IPC-alone(i)/IPC-together (i))

Unfairness = Max-Slowdown/Min-Slowdown = max(Individual slowdowns)/min(individual slowdowns)

Individual Slowdown (i) = CPI-together (i) / CPI-alone (i)

Application i running on an N-core system

Page 3: Lecture-3 (Performance Metrics and ISA) CS422-Spring 2020

Example

CS422 3

Single Program IMTEL AND

App. A IPC=1 IPC=0.5 1

App. B IPC=2 IPC=1 0.5

IMTEL AND

Weighted Speedup 1 1.25

Hmean of Speedups 0.5 0.4

Amean of IPCs 0.75 0.75

Hmean of IPCs 0.66 0.66

Page 4: Lecture-3 (Performance Metrics and ISA) CS422-Spring 2020

ISA

CS422 4

instruction set

software

hardware

I/O systemProcessor

Digital Design

Circuit Design

Datapath & Control

Transistors

Memory

Compiler

Operating

System(Mac OS X)

Application (iTunes)

Assembler

Page 5: Lecture-3 (Performance Metrics and ISA) CS422-Spring 2020

ISA

CS422 5

• ISA: Instruction SetArchitecture

– A well-defined hardware/software interface

• The “contract” between software andhardware

– Functional definition of operations supported byhardware

– Precise description of how toinvoke all features

• No guarantees regarding

– How operations are implemented

– Which operations are fast and which are slow (andwhen)

– Which operations take more energy (and which takeless)

Page 6: Lecture-3 (Performance Metrics and ISA) CS422-Spring 2020

ISA

CS422 6

... the attributes of a [computing] system as seen by the programmer, i.e. the conceptual structure and functional behavior, as distinct from the organization of the data flows and controls the logic design, and the physical implementation.

– Amdahl, Blaaw, and Brooks, 1964

Page 7: Lecture-3 (Performance Metrics and ISA) CS422-Spring 2020

ISA

CS422 7

• Programmer-visible states

– Program counter, general purpose registers, memory, control registers

• Programmer-visible behaviors– What to do, when todo it

ISAs last forever, don’t add stuff you don’t need

Page 8: Lecture-3 (Performance Metrics and ISA) CS422-Spring 2020

An Example of Instruction Encoding

CS422 8

Syntax: ADD $8 $9 $10 Semantics: $8 = $9 + $10

000000 01001 01010 01000 00000 100000Binary:

opcode rs rt rd functshamtBitfield:

Page 9: Lecture-3 (Performance Metrics and ISA) CS422-Spring 2020

Features of the Ideal ISA

CS422 9

• Unambiguous

• Expressive

• Easily describes all the algorithms that will run on this platform

• Instructions are used

• Very complex instructions might not be used often

• (Relatively) easy to compile, easy to implement well

• Implementation provides good performance, cost, etc.

• ISAs often highly reliant on microarchitecture and vice-versa

• Some ISAs easy to implement on some microarchitectures

• Some microarchitectures make some instructions easy to implement

Page 10: Lecture-3 (Performance Metrics and ISA) CS422-Spring 2020

Do not get confused with micro-architecture

CS422 10

◼ ISA

❑ Agreed upon interface between software and hardware

◼ SW/compiler assumes, HW promises

❑ What the software writer needs to know to write and debug system/user programs

◼ Microarchitecture

❑ Specific implementation of an ISA, Not visible to the software

◼ Microprocessor

❑ ISA, uarch, circuits

❑ “Architecture” = ISA + microarchitecture

Page 11: Lecture-3 (Performance Metrics and ISA) CS422-Spring 2020

CS422 11

◼ Instructions

❑ Opcodes, Addressing Modes, Data Types

❑ Instruction Types and Formats

❑ Registers, Condition Codes

◼ Memory

❑ Address space, Addressability, Alignment, Virtual memory management

◼ Call, Interrupt/Exception Handling, Access Control, Priority/Privilege

◼ I/O: memory-mapped vs. instr, Task/thread Management, Power and Thermal Management

◼ Multi-threading support, Multiprocessor support

ISA

Page 12: Lecture-3 (Performance Metrics and ISA) CS422-Spring 2020

Micro-architecture

CS422 12

◼ Implementation of the ISA under specific design constraints and goals

◼ Anything done in hardware without exposure to software

❑ Pipelining

❑ In-order versus out-of-order instruction execution

❑ Memory access scheduling policy

❑ Speculative execution

❑ Superscalar processing (multiple instruction issue?)

❑ Clock gating

❑ Caching? Levels, size, associativity, replacement policy, Prefetching?

❑ Voltage/frequency scaling? Error correction?

Page 13: Lecture-3 (Performance Metrics and ISA) CS422-Spring 2020

What is What?

CS422 13

◼ ADD instruction’s opcode

◼ Number of general purpose registers

◼ Number of ports to the register file

◼ Number of cycles to execute the MUL instruction

◼ Whether or not the machine employs pipelined instruction execution

◼ Remember

❑ Microarchitecture: Implementation of the ISA under specific design constraints and goals

Page 14: Lecture-3 (Performance Metrics and ISA) CS422-Spring 2020

Design Point

CS422 14

◼ A set of design considerations and their importance

❑ leads to tradeoffs in both ISA and uarch

◼ Considerations

❑ Cost

❑ Performance

❑ Maximum power consumption and Energy consumption (battery life)

❑ Availability

❑ Reliability and Correctness

❑ Time to Market

◼ Design point determined by the “Problem” space (application space), the intended users/market

Page 15: Lecture-3 (Performance Metrics and ISA) CS422-Spring 2020

Trade-offs

CS422 15

◼ ISA-level tradeoffs

◼ Microarchitecture-level tradeoffs

◼ System and Task-level tradeoffs

❑ How to divide the labor between hardware and software

◼ Computer architecture is the science and art of making the appropriate trade-offs to meet a design point

❑ Why art?

Page 16: Lecture-3 (Performance Metrics and ISA) CS422-Spring 2020

Mantra

CS422 16

MicroarchitectureISA

PLsAlgorithmProblem

Runtime System(VM, OS, MM)

User

We do not (fully) know the future (applications, users, market) and it changes

LogicCircuitsElectrons

New demands from the top(Look Up)

New issues andcapabilitiesat the bottom(Look Down)

New demands andpersonalities of users(Look Up)

Page 17: Lecture-3 (Performance Metrics and ISA) CS422-Spring 2020

ISA in Details

CS422 17

• Which architecture to use: Stack, Accumulator, R-R, R-M

• #Registers

• Trade-offs in terms of #operands, #registers, ….

• Big vs Little Endian

• Importance of Alignment

• Which instructions are dominant and which addressing modes are dominant ?

• Fixed vs Variable Encoding , RISC vs CISC

• Pseudo - instructions

• ISA vs micro-architecture

Page 18: Lecture-3 (Performance Metrics and ISA) CS422-Spring 2020

Architecture, registers, operands, etc

CS422 18

• Instruction processing style

• Specifies the number of “operands” an instruction “operates” on and how it does so

• 0, 1, 2, 3 address machines: 0-address: stack machine (push A, pop A, op)

• 1-address: accumulator machine (ld A, st A, op A)

• 2-address: 2-operand machine (one is both source and dest)

• 3-address: 3-operand machine (source and dest are separate)

• Tradeoffs? Larger operate instructions vs. more executed operations

• Code size vs. execution time vs. on-chip memory space

Page 19: Lecture-3 (Performance Metrics and ISA) CS422-Spring 2020

Endianness (Byte Ordering within a Word)

CS422 19

• Big Endian: address of most significant byte = word address (xx00 = Big End of word)

– IBM 360/370, Motorola 68k, MIPS, Sparc, HP PA

• Little Endian: address of least significant byte = word address(xx00 = Little End of word)

– Intel 80x86, DEC Vax, DEC Alpha (Windows NT)

msb lsb

3 2 1 0

little endian byte 0

0 1 2 3

big endian byte 0

Page 20: Lecture-3 (Performance Metrics and ISA) CS422-Spring 2020

Example

• int x = ABCD

• Big-endian:

Little-endian:

Big –endian: A B C D, Little-endian: D C B A

But why to have two options? Why not an universal one? What about bi-endianness? Can we check the endianness of our machine? Why not have endianness at the bit level?

CS422 20

msb lsb

0 1 2 3

msb lsb

3 2 1 0

Page 21: Lecture-3 (Performance Metrics and ISA) CS422-Spring 2020

Alignment (A myth may be ☺)

CS422 21

• Object of size s bytes at byte address A is aligned if

A mod s = 0

• Alignment for faster transfer of data ?

• Why fast ??

• Think about memory.

0 1 2 3

Aligned

Not

Aligned

Page 22: Lecture-3 (Performance Metrics and ISA) CS422-Spring 2020

Dominant Instructions

CS422 22

° Rank instruction Integer Average Percent total executed

1 load 22%

2 conditional branch 20%

3 compare 16%

4 store 12%

5 add 8%

6 and 6%

7 sub 5%

8 move register-register 4%

9 call 1%

10 return 1%

Total 96%

° Simple instructions dominate instruction frequency

Page 23: Lecture-3 (Performance Metrics and ISA) CS422-Spring 2020

RISC vs CISC

CS422 23

RISC-I (1982) Contains 44,420 transistors, fabbed in 5 µm NMOS, with a die area of 77 mm2, ran at 1 MHz. This chip is probably the first VLSI RISC.

RISC-II (1983) contains 40,760 transistors, was fabbed in 3 µm NMOS, ran at 3 MHz, and the size is 60 mm2.

Page 24: Lecture-3 (Performance Metrics and ISA) CS422-Spring 2020

RISC vs CISC

CS422 24

• CISC vs. RISC

• Complex instruction set computer → complex instructions

• Initially motivated by “not good enough” code generation

• Reduced instruction set computer → simple instructions

• John Cocke, mid 1970s, IBM 801, Goal: enable better compiler control

• RISC motivated by

• Memory stalls (no work done in a complex instruction when there is a memory stall?)

• Simplifying the hardware → lower cost, higher frequency

• Enabling the compiler to optimize the code better

• Find fine-grained parallelism to reduce stalls

Page 25: Lecture-3 (Performance Metrics and ISA) CS422-Spring 2020

Warm-up on Scribing: Due January 21th

• ISA, RISC-CISC, RISC-V

• https://people.eecs.berkeley.edu/~kubitron/courses/cs252-F00/handouts/papers/patterson80.pdf

• http://www.cs.uccs.edu/~xzhou/teaching/CS4520/Assignment/papers/R1_Comment_Case_RISC_SigArchNews_patterson.pdf

• https://engineering.berkeley.edu/magazine/spring-2015/simplify-risc-story

CS422 25

Page 26: Lecture-3 (Performance Metrics and ISA) CS422-Spring 2020

Instruction Pipelining

CS422 26

Page 27: Lecture-3 (Performance Metrics and ISA) CS422-Spring 2020

Single-Instruction Datapath

CS422 27

• Process one instruction at a time

• Single-cycle control: hardwired• Low CPI (1)• Long clock period (to accommodate slowest instruction)

• Multi-cycle control: typically micro-programmed• Short clock period• High CPI

• Can we have both low CPI and short clock period?• Not if datapath executes only one instruction at a time• No good way to make a single instruction go faster

Single-cycle

Multi-cycle

ins0.(fetch,dec,ex,mem,wb) ins1.(fetch,dec,ex,mem,wb)

ins0.(dec,ex)ins0.fetch ins1.(dec,ex)ins1.fetchins0.(mem,wb) ins1.(mem,wb)

time

Page 28: Lecture-3 (Performance Metrics and ISA) CS422-Spring 2020

Write-Back (WB)

Memory(MEM)

Execute(EX)

Inst. Decode &Register Read

(ID)

5-Stage MIPS Datapath

Inst. Fetch(IF)

I-cache

Reg

FilePC

+1

D-cache

ALU

RS_STEPIF_STEP ID_STEP OF_STEP EX_STEP

Page 29: Lecture-3 (Performance Metrics and ISA) CS422-Spring 2020

Stage 1: Fetch• Fetch instruction from instruction cache

• Use PC to index instruction cache

• Increment PC (assume no branches for now)

• Write state to the pipeline register (IF/ID)• The next stage will read this pipeline register

Page 30: Lecture-3 (Performance Metrics and ISA) CS422-Spring 2020

Stage 1: Fetch Diagram

Inst

ruct

ion

bits

IF / ID

Pipeline register

PC

Instruction

Cache

en

en

1

+

M

U

X

PC

+ 1

Deco

de

target

Page 31: Lecture-3 (Performance Metrics and ISA) CS422-Spring 2020

Stage 2: Decode• Decodes opcode bits

• Set up Control signals for later stages

• Read input operands from register file• Specified by decoded instruction bits

• Write state to the pipeline register (ID/EX)• Opcode

• Register contents, immediate operand

• PC+1 (even though decode didn’t use it)

• Control signals (from insn) for opcode and destReg

Page 32: Lecture-3 (Performance Metrics and ISA) CS422-Spring 2020

Stage 2: Decode Diagram

ID / EX

Pipeline register

regA

conte

nts

regB

conte

ntsRegister File

regA

regB

en

Inst

ruct

ion

bits

IF / ID

Pipeline register

PC

+ 1

PC

+ 1

Contr

ol

Sign

als/

imm

Fetc

h

Execu

te

destReg

data

target

Page 33: Lecture-3 (Performance Metrics and ISA) CS422-Spring 2020

Stage 3: Execute• Perform ALU operations

• Calculate result of instruction• Control signals select operation

• Contents of regA used as one input

• Either regB or constant offset (imm from insn) used as second input

• Calculate PC-relative branch target• PC+1+(constant offset)

• Write state to the pipeline register (EX/Mem)• ALU result, contents of regB, and PC+1+offset

• Control signals (from insn) for opcode and destReg

Page 34: Lecture-3 (Performance Metrics and ISA) CS422-Spring 2020

Stage 3: Execute Diagram

ID / EX

Pipeline register

regA

conte

nts

regB

conte

nts

EX/Mem

Pipeline register

PC

+ 1

Contr

ol

Sign

als/

imm

Contr

ol

Sign

als

PC

+1

+offse

t

+

regB

conte

ntsDeco

de

Mem

ory

destRegdata

target

A

L

UM

U

X

ALU

resu

lt

Page 35: Lecture-3 (Performance Metrics and ISA) CS422-Spring 2020

Stage 4: Memory• Perform data cache access

• ALU result contains address for LD or ST

• Opcode bits control R/W and enable signals

• Write state to the pipeline register (Mem/WB)• ALU result and Loaded data

• Control signals (from insn) for opcode and destReg

Page 36: Lecture-3 (Performance Metrics and ISA) CS422-Spring 2020

Stage 4: Memory Diagram

ALU

resu

lt

Mem/WB

Pipeline register

ALU

resu

lt

EX/Mem

Pipeline register

Contr

ol

sign

als

PC

+1

+offse

t

regB

conte

nts

Load

ed

dat

a

Data Cache

en R/W

in_addr

in_data

Contr

ol

sign

als

Execu

te

Wri

te-b

ack

destRegdata

target

Page 37: Lecture-3 (Performance Metrics and ISA) CS422-Spring 2020

Stage 5: Write-back• Writing result to register file (if required)

• Write Loaded data to destReg for LD

• Write ALU result to destReg for ALU insn

• Opcode bits control register write enable signal

Page 38: Lecture-3 (Performance Metrics and ISA) CS422-Spring 2020

Stage 5: Write-back Diagram

ALU

resu

lt

Mem/WB

Pipeline register

Contr

ol

sign

als

Load

ed

dat

aM

U

X

data

destRegM

U

X

Mem

ory

Page 39: Lecture-3 (Performance Metrics and ISA) CS422-Spring 2020

Putting It All Together

PC Inst

Cache

RegisterFile

M

U

XA

L

U

1

Data

Cache

++

M

U

X

IF/ID ID/EX EX/Mem Mem/WB

M

U

X Co

ntr

ol

sign

als/

imm

valB

valA

PC+1PC+1target

ALU

result

Co

ntr

ol

sign

als

valB

ALU

result

mdata

eq?instru

ction

regAregB

data

dest

M

U

X

data

dest

Co

ntr

ol

sign

als