50
CS 61C: Great Ideas in Computer Architecture (a.k.a. Machine Structures) Lecture 1: Course Introduction Instructors: Krste Asanović, Randy H. Katz http://inst.eecs.berkeley.edu/~cs61c/

CS 61C: Great Ideas in Computer Architecture (a.k.a

  • Upload
    others

  • View
    3

  • Download
    0

Embed Size (px)

Citation preview

CS61C:GreatIdeasinComputerArchitecture(a.k.a.MachineStructures)

Lecture1:CourseIntroduction

Instructors:Krste Asanović,RandyH.Katz

http://inst.eecs.berkeley.edu/~cs61c/

Agenda

• ThinkingaboutMachineStructures• GreatIdeasinComputerArchitecture• WhatYouNeedtoKnowAboutThisClass• EverythingisaNumber

9/6/17 2Fall2017 - Lecture#1

Agenda

• ThinkingaboutMachineStructures• GreatIdeasinComputerArchitecture• WhatYouNeedtoKnowAboutThisClass• EverythingisaNumber

9/6/17 3Fall2017 - Lecture#1

MostPopularProgrammingLanguages2016-7

• Whatdoyouthinkisthemost“popular”programminglanguageinusetoday?

9/6/17 4Fall2017 - Lecture#1

WhyYouNeedtoLearnC!

9/6/17 5Fall2017 - Lecture#1

CS61CisNOTreallyaboutCProgramming

• Itisaboutthehardware-softwareinterface– Whatdoestheprogrammerneedtoknowtoachievethehighestpossibleperformance

• Cisclosetotheunderlyinghardware,unlikelanguageslikePython andJava!– Allowsustotalkaboutkeyhardwarefeaturesinhigherlevelterms– Allowsprogrammertoexplicitlyharnessunderlyinghardwareparallelismforhigherperformance andpower efficiency

9/6/17 6Fall2017 - Lecture#1

OldSchoolCS61C

9/6/17 7Fall2017 - Lecture#1

NewSchoolCS61C(1/2)

9/6/17 8Fall2017 - Lecture#1

PersonalMobileDevices

NetworkEdge

Devices

NewSchoolCS61C(2/2)

9/6/17 9Fall2017 - Lecture#1

New-SchoolMachineStructures

• ParallelRequestsAssignedtocomputere.g.,Search“cats”

• ParallelThreadsAssignedtocoree.g.,Lookup,Ads

• ParallelInstructions>[email protected].,5pipelinedinstructions

• ParallelData>[email protected].,Addof4pairsofwords

• HardwaredescriptionsAllgatesfunctioninginparallelatsametime

9/6/17 Fall2017 - Lecture#1

SmartPhone

Warehouse-Scale

Computer

SoftwareHardware

HarnessParallelism&AchieveHighPerformance

LogicGates

Core Core…

Memory(Cache)

Input/Output

Computer

MainMemory

Core

InstructionUnit(s) FunctionalUnit(s)

A3+B3A2+B2A1+B1A0+B0

10

Agenda

• ThinkingaboutMachineStructures• GreatIdeasinComputerArchitecture• WhatYouNeedtoKnowAboutThisClass• EverythingisaNumber

9/6/17 11Fall2017 - Lecture#1

FiveGreatIdeasinComputerArchitecture

1. Abstraction(LayersofRepresentation/Interpretation)2. Moore’sLaw(Designingthroughtrends)3. PrincipleofLocality(MemoryHierarchy)4. Parallelism5. DependabilityviaRedundancy

9/6/17 12Fall2017 - Lecture#1

Anythingcanberepresentedasanumber,

i.e.,dataorinstructions

GreatIdea#1:Abstraction(LevelsofRepresentation/Interpretation)

9/6/17 13Fall2017 - Lecture#1

lw $t0,0($2)lw $t1,4($2)sw $t1,0($2)sw $t0,4($2)

HighLevelLanguageProgram(e.g.,C)

AssemblyLanguageProgram(e.g.,MIPS)

MachineLanguageProgram(MIPS)

HardwareArchitectureDescription(e.g.,blockdiagrams)

Compiler

Assembler

MachineInterpretation

temp=v[k];v[k]=v[k+1];v[k+1]=temp;

0000 1001 1100 0110 1010 1111 0101 10001010 1111 0101 1000 0000 1001 1100 0110 1100 0110 1010 1111 0101 1000 0000 1001 0101 1000 0000 1001 1100 0110 1010 1111

LogicCircuitDescription(CircuitSchematicDiagrams)

ArchitectureImplementation

GordonMooreIntelCofounderB.S.Cal1950!

9/6/17 14Fall2017 - Lecture#1

Predicts:2XTransistors/chip

every2years

#2:Moore’sLaw

JimGray’sStorageLatencyAnalogy:HowFarAwayistheData?

9/6/17 15Fall2017 - Lecture#1RegistersOn Chip CacheOn Board Cache

Main Memory

Disk

12

10

100

Tape /Optical Robot

109

10 6

Sacramento

This CampusThis Room

My Head

10 min

1.5 hr

2 Years

1 min

Pluto

2,000 Years

Andromeda

(ns)

JimGrayTuringAwardB.S.Cal1966Ph.D.Cal1969!

Fall2017-- Lecture#1

GreatIdea#3:PrincipleofLocality/MemoryHierarchy

9/6/17 169/6/17 Fall2017 - Lecture#1

GreatIdea#4:Parallelism

9/6/17 17Fall2017 - Lecture#1

GreatIdea#5:DependabilityviaRedundancy

• Redundancysothatafailingpiecedoesn’tmakethewholesystemfail

9/6/17 18Fall2017 - Lecture#1

1+1=2 1+1=2 1+1=1

1+1=22of3agree

FAIL!

Increasingtransistordensityreducesthecostofredundancy

GreatIdea#5:DependabilityviaRedundancy

• Appliestoeverythingfromdatacenterstostoragetomemorytoinstructors– Redundantdatacenters sothatcanlose1datacenterbutInternetservicestaysonline

– Redundantdisks sothatcanlose1diskbutnotlosedata(RedundantArraysofIndependentDisks/RAID)

– Redundantmemorybits ofsothatcanlose1bitbutnodata(ErrorCorrectingCode/ECCMemory)

9/6/17 19Fall2017 - Lecture#1

Break!

9/6/17 20Fall2017 - Lecture#1

WhyisArchitectureExcitingToday?

9/6/17 21Fall2017 - Lecture#1

CPUSpeedFlat

OldConventionalWisdom

• Moore’sLaw+DennardScaling=faster,cheaper,lower-powergeneral-purposecomputerseachyear

• Inglorydays,1%/weekperformanceimprovement!

• Dumbtocompetebydesigningparallelorspecializedcomputers

• Bytimeyou’vefinisheddesign,nextgenerationofgeneral-purposewillbeatyou

9/6/17 22Fall2017 - Lecture#1

NewConventionalWisdom

9/6/17 23Fall2017 - Lecture#1

GoogleTPU2SpecializedEngineforNNtrainingDeployedincloud45TFLOPS/chip

Seriousheatsinks!

Agenda

• ThinkingaboutMachineStructures• GreatIdeasinComputerArchitecture• WhatYouNeedtoKnowAboutThisClass• EverythingisaNumber

9/6/17 24Fall2017 - Lecture#1

CourseInformation• CourseWeb:http://inst.eecs.Berkeley.edu/~cs61c/• Instructors:Krste Asanović andRandyH.Katz• TeachingStaff:

– Co-HeadTAs:StevenHo,StevenChen,andPeijei Li– TAs:NikhilAthreya,ConnorBrennan,IreneDea,DylanDreyer,

JulianEarly,DerekFeng,Haoan Jing,Tejas Kannan,DanielHo,LisaLee,Ehimare Okayomon,Srinivasa Pranav,NicholasRiasanovsky,WilliamSheu

– Tutors:,RyanHayes,AnnaLi,SameerSuresh,MorganReschenberg,Keyhan Vakil,NicolasZoghb

• Textbooks:Average15pagesofreading/week(canrent!)– Patterson&Hennessey,ComputerOrganizationandDesign,RISC-Ved.– Kernighan&Ritchie,TheCProgrammingLanguage,2nd Edition– Barroso&Holzle,TheDatacenterasaComputer,2nd Edition,FREE!

• Piazza:– Everyannouncement,discussion,clarificationhappensthere!

9/6/17 25Fall2017 - Lecture#1

CS61cHouseRulesinaNutshell• Webcast?Yes!• LabsanddiscussionafterNEXTTuesday’slecture• Waitlisted?Enrollinanyavailablesection/lab,swaplater• ExcusedAbsences:Letusknowbysecondweek• Midtermsareinclass26Septemberand31October;Finalis14Decemberat7-10PM

• LabsandProjects(4+1ExtraCredit)arepartnered– DiscussionisGood,butCo-Developing/Sharing/BorrowingProjectCodeorCircuitsisBad

– NoPublicReposPlease:Don’tLook,Don’tPublish• JoinPiazzaformoredetails…seehttp://inst.eecs.berkeley.edu/~cs61c/fa17/

9/6/17 26Fall2017 - Lecture#1

EPA!• Effort

– AttendingprofandTAofficehours,completingallassignments,turninginHW,doingreadingquizzes

• Participation– Attendingdiscussionandaskinggreatquestions

• Altruism– HelpingothersinlaboronPiazza

• EPA!pointshavethepotentialtobumpstudentsuptothenextgradelevel!(butactualEPA!scoresareinternal)

9/6/17 27Fall2017 - Lecture#1

PeerInstruction

• Increasereal-timelearninginlecture,testunderstandingofconceptsvs.details

• Ascompletea“segment” askmultiple-choicequestion– 1-2minutestodecideyourself– 2minutesinpairs/triplestoreachconsensus.– Teachothers!– 2minutediscussionofanswers,questions,clarifications

• NoneedforiClickers;wewilldistributecolorcardsforyoutouse!

9/6/17 28Fall2017 - Lecture#1

CollaborationinBlack and• GoodCollaboration

– Highleveldiscussionandbrainstorming,stoppingshortofcodesnippets

– Sittingtogetherandco-writingcode,inspectingeachother’scode,taking(orgiving)codewhetherinexchangeorwholesalecopying

• Thisshouldbeobvious,but…– Don’thiresomeonetodoyourassignments– Don’tasksomeoneoutsideoftheclass(aparent,astudentfromaprevioussemester,sourceforge)tohelpyou

– Don’tusesearchenginestolookforsolutionson-lineorinsomeone’sunprotectedGitHub (anddon’tputyourcourseprojectsolutionsinunprotectedGitHubs please!)

– Itissupposedtobeyourownworkafterall!9/6/17 29Fall2017 - Lecture#1

ArchitectureofatypicalLecture

30

Attention

Time(minutes)10 35 60 78 90

Administrivia “Andinconclusion…”

Full

Fun/News

9/6/17 Fall2017 - Lecture#1

Break!

9/6/17 31Fall2017 - Lecture#1

Agenda

• ThinkingaboutMachineStructures• GreatIdeasinComputerArchitecture• WhatYouNeedtoKnowAboutThisClass• EverythingisaNumber

9/6/17 Fall2017 - Lecture#1 32

ComputerData• Computersrepresentdataasbinaryvalues• Unitelement:bit

– Justtwopossiblevalues,0or1– Canbeefficientlystored/communicated/manipulatedinhardware

• Usemanybitstostoremorecomplexinformation,e.g.– Byte:8bits,canrepresent28 =256differentvalues– Word,e.g.4bytes(32bits)torepresent232 differentvalues– 64-bitfloatingpointnumbers– Textfiles,databases,… (manybytes)– Computerprogram

9/6/17 33Fall2017 - Lecture#1

BinaryNumberConversionBinaryà Decimal

1001010two = ?ten

Decimalà Binary

74ten = ?two

9/6/17 34Fall2017 - Lecture#1

BinaryDigit DecimalValue0 0 x 20 = 0

1 1 x 21 = 2

0 0 x 22 = 0

1 0 x 23 = 8

0 0 x 24 = 0

0 0 x 25 = 0

1 1 x 26 = 64

S = 74ten

Decimal Binary(odd?)74 0

/2 = 37 1

/2 = 18 0

/2 = 9 1

/2 = 4 0

/2 = 2 0

/2 = 1 1

Collect à 1001010two

Hexadecimal

9/6/17 35Fall2017 - Lecture#1

• Problem:manydigits– e.g.7643ten =1110111011011two

• Solutions:– Grouping: 1110111011011two– Hexadecimal: 1DDBhex– Octal: 1110111011011two

16733oct

Binary Hex

0000 0

0001 1

0010 2

0011 3

0100 4

0101 5

0110 6

0111 7

1000 8

1001 9

1010 A

1011 B

1100 C

1101 D

1110 E

1111 F

TheComputerKnowsit,too

9/6/17 36Fall2017 - Lecture#1

Output Decimal: 1234Hex: 4d2Octal: 2322Literals (not supported by all compilers):0x4d2 = 1234 (hex)0b10011010010 = 1234 (binary)02322 = 1234 (octal, prefix 0 - zero)

E.g.1GiBytediskversus1GBytedisk

Marketingexploitsthis:1TBdiskà 100GBlessthan1TiB

LargeNumbers

9/6/17 37Fall2017 - Lecture#1

• DecimalSuffix Multiplier ValueK 103 1000M 106 1000,000G 109 1000,000,000T 1012 1000,000,000,000

• Binary(IEC)Suffix Multiplier ValueKi 210 1024Mi 220 1048,576Gi 230 1073,741,824Ti 240 1099,511,627,776

https://en.wikipedia.org/wiki/Byte

SignedIntegerRepresentation

Sign&magnitude(8-bitexample):

Rulesforaddition,a+b:• If(a>0andb>0):add• If(a>0andb<0):subtract• …• +0,-0à aretheyequal?comparatormusthandlespecialcase!

Cumbersome• ”Complicated”hardware:reducedspeed/increasedpower• Isthereabetterway?

9/6/17 38Fall2017 - Lecture#1

sign 7-bitmagnitude (0…127)

4-bitExample

7+ -3

4

9/6/17 39

7+ -3 +16

4 +16

7+ 13

4 +16

0111+ 1101

10100 0100 +10000

Decimal Binary

• Mapnegativeà positivenumbers§ ExampleforN=4-bit:-3à 24– 3=13§ “Two’scomplement”§ Nospecialrulesforaddingpositiveandnegativenumbers

-8 -7 … -1 0 1 … 70 1 … 7 8 9 … 15

+24 =16

Two’sComplement

9/6/17 40Fall2017 - Lecture#1

SignedDecimal UnsignedDecimal BinaryTwo’sComplement-128 128 1 0 0 0 0 0 0 0-127 129 1 0 0 0 0 0 0 1… … …-2 254 1 1 1 1 1 1 1 0-1 255 1 1 1 1 1 1 1 10 0 0 0 0 0 0 0 0 01 1 0 0 0 0 0 0 0 1… … . . .127 127 0 1 1 1 1 1 1 1

Note:Mostsignificantbit(MSB)equalssign

+256

+0

UnaryNegation(Two’sComplement)4-bitExample(-8ten …+7ten)

BruteForce&Tedious Clever&Elegant

16ten 10000two- 3ten - 0011two13ten 1101two

16ten 10000two- 13ten - 1101two

3ten 0011two

”largest”4-bitnumber+1

9/6/17 Fall2017 - Lecture#1 41

15ten 01111two- 3ten - 0011two12ten 1100two invert

+1ten +0001two13ten 1101two

YourTurn

• Whatisthedecimalvalueofthefollowingbinary8-bit2’scomplementnumber?

11100001two

9/6/17 42Fall2017 - Lecture#1

Answer ValueA 33tenB -31tenC 225tenD -33tenE Noneoftheabove

Addition4-bitExample

Unsigned Signed(Two’sComplement)

9/6/17 43Fall2017 - Lecture#1

3ten 0011two+4ten +0100two

7ten 0111two

3ten 0011two+11ten +1011two

14ten 1110two

3ten 0011two+4ten +0100two

7ten 0111two

3ten 0011two+-5ten +1011two

-2ten 1110two

Nospecialrulesfortwo’scomplementsignedaddition

Overflow4-bitExample

Unsigned Signed(Two’sComplement)

9/6/17 44Fall2017 - Lecture#1

13ten 1101two+14ten +1110two

27ten 1 1011two

7ten 0111two+1ten +0001two

8ten 0 1000two

-3ten 1101two+-2ten +1110two

-5ten 1 1011two

7ten 0111two+1ten +0001two-8ten 01000two

Carry-outà Overflow Carry-outà Overflow

carry-outbutnooverflowcarry-outandoverflow

nocarry-outbutoverflownocarry-outandnooverflow

OverflowDetection4-bitExample

Unsigned• Carry-outindicatesoverflow

Signed(Two’sComplement)• Overflowif

– SignsofoperandsareequalAND

– Signofresultdiffersfromsignofoperands

• Nooverflowwhensignsofoperandsdiffer

9/6/17 45Fall2017 - Lecture#1

Overflowrulesdependonoperands(signedvsunsigned)

SignExtensionDecimal Binary

4-bit 8-bit 32-bit3ten 0011two 00000011two 0000000000000011two-3ten 1101two 11111101two 1111111111111101two

9/6/17 46Fall2017 - Lecture#1

• Whyisthisrelevant?• Assignmentdiffersforsigned(above)andunsignednumbers

• Compilerknows(fromtypedeclaration)• Differentassemblyinstructionsforcopyingsigned/unsigneddata

YourTurn

• Whichrangeofdecimalscanbeexpressedwitha6-bittwo’scomplementnumber?

9/6/17 47Fall2017 - Lecture#1

Answer RangeA -32…32B -64…63C -31…32D -16…15E -32…31

Answer

• Whichrangeofdecimalscanbeexpressedwitha6-bittwo’scomplementnumber?

9/6/17 48Fall2017 - Lecture#1

Answer RangeA -32…32B -64…63C -31…32D -16…15E -32…31

AndInConclusion…(1/2)• CS61C:

– Higherspeedperformance+betterenergyefficiencybyleveragingcomputerarchitecture:

• Strengthandweaknesses(e.g.cache)• Performancefeatures(e.g.parallelinstructions)

– LearnCandassemblyfacilitateaccesstomachinefeatures• Basis:fivegreatideasincomputerarchitecture

1. Abstraction:LayersofRepresentation/Interpretation2. Moore’sLaw3. PrincipleofLocality/MemoryHierarchy4. Parallelism5. DependabilityviaRedundancy

• PerformanceMeasurementandImprovement9/6/17 49Fall2017 - Lecture#1

AndInConclusion…(2/2)

• EverythingisaNumber!– Collectionsofbitscanstoreandcommunicatearbitrarydigitaldata– Evenprogramsarerepresentedbybits

• Two’scomplementrepresentationavoidsspecialrulesforadditionofnegativenumbers

9/6/17 50Fall2017 - Lecture#1