cs 110 computer architecture (a.k.a. machine structures

46
CS 110 Computer Architecture (a.k.a. Machine Structures) Lecture 1: Course Introduction Instructor: Sören Schwertfeger http://shtech.org/courses/ca/ School of Information Science and Technology SIST ShanghaiTech University 1 Slides based on UC Berkley's CS61C

Upload: others

Post on 03-Jun-2022

2 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: CS 110 Computer Architecture (a.k.a. Machine Structures

CS110ComputerArchitecture

(a.k.a.MachineStructures)Lecture1:CourseIntroduction

Instructor:SörenSchwertfeger

http://shtech.org/courses/ca/

School of Information Science and Technology SIST

ShanghaiTech University

1Slides based on UC Berkley's CS61C

Page 2: CS 110 Computer Architecture (a.k.a. Machine Structures

Agenda

• ThinkingaboutMachineStructures• GreatIdeasinComputerArchitecture• Whatyouneedtoknowaboutthisclass• EverythingisaNumber

2

Page 3: CS 110 Computer Architecture (a.k.a. Machine Structures

Agenda

• ThinkingaboutMachineStructures• GreatIdeasinComputerArchitecture• Whatyouneedtoknowaboutthisclass• EverythingisaNumber

3

Page 4: CS 110 Computer Architecture (a.k.a. Machine Structures

CS110isNOTreallyaboutCProgramming

• Itisaboutthehardware-software interface– Whatdoestheprogrammerneedtoknowtoachievethehighestpossibleperformance

• Cisclosetotheunderlyinghardware,unlikelanguageslikeScheme,Python,Java!– Allowsustotalkaboutkeyhardwarefeaturesinhigherlevelterms

– Allowsprogrammertoexplicitlyharnessunderlyinghardwareparallelismforhighperformance

4

Page 5: CS 110 Computer Architecture (a.k.a. Machine Structures

OldSchoolComputerArchitecture

5

Page 6: CS 110 Computer Architecture (a.k.a. Machine Structures

NewSchoolComputerArchitecture(1/3)

6

PersonalMobileDevices

Page 7: CS 110 Computer Architecture (a.k.a. Machine Structures

NewSchoolComputerArchitecture(2/3)

7

Page 8: CS 110 Computer Architecture (a.k.a. Machine Structures

NewSchoolComputerArchitecture(3/3)

8

Page 9: CS 110 Computer Architecture (a.k.a. Machine Structures

OldSchoolMachineStructures

9

I/OsystemProcessor

CompilerOperatingSystem(MacOSX)

Application(ex:browser)

DigitalDesignCircuitDesign

InstructionSetArchitecture

Datapath&Control

transistors

MemoryHardware

Software Assembler

Page 10: CS 110 Computer Architecture (a.k.a. Machine Structures

New-SchoolMachineStructures(It’sabitmorecomplicated!)

• ParallelRequestsAssigned tocomputere.g.,Search“cats”

• ParallelThreadsAssigned tocoree.g.,Lookup,Ads

• ParallelInstructions>[email protected].,5pipelined instructions

• ParallelData>1dataitem@one timee.g.,Addof4pairsofwords

• HardwaredescriptionsAllgatesfunctioning in

parallelatsametime10

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

Project1

Project3

Project2

Page 11: CS 110 Computer Architecture (a.k.a. Machine Structures

Agenda

• ThinkingaboutMachineStructures• GreatIdeasinComputerArchitecture• Whatyouneedtoknowaboutthisclass• EverythingisaNumber

11

Page 12: CS 110 Computer Architecture (a.k.a. Machine Structures

6GreatIdeasinComputerArchitecture

1. Abstraction(LayersofRepresentation/Interpretation)

2. Moore’sLaw(Designingthroughtrends)3. PrincipleofLocality(MemoryHierarchy)4. Parallelism5. PerformanceMeasurement&Improvement6. DependabilityviaRedundancy

12

Page 13: CS 110 Computer Architecture (a.k.a. Machine Structures

GreatIdea#1:Abstraction(LevelsofRepresentation/Interpretation)

13

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

Anythingcanberepresentedasanumber,

i.e.,dataorinstructions

Page 14: CS 110 Computer Architecture (a.k.a. Machine Structures

#2:Moore’sLaw

14

GordonMooreIntelCofounder

Predicts:2XTransistors/chip

every2years

Page 15: CS 110 Computer Architecture (a.k.a. Machine Structures

InterestingTimes

15

Moore’sLawreliedonthecostoftransistorsscalingdownastechnologyscaledtosmallerandsmallerfeaturesizes.

BUTnewest,smallestfabricationprocesses<14nm,mighthavegreatercost/transistor!!!!So,whyshrink????

Page 16: CS 110 Computer Architecture (a.k.a. Machine Structures

JimGray’sStorageLatencyAnalogy:HowFarAwayistheData?

RegistersOn Chip CacheOn Board Cache

Main Memory

Disk

12

10

100

Tape /Optical Robot

109

106

This CampusThis Room

My Head

10 min

1.5 hr

2 Years

1 min

Pluto

2,000 Years

Andromeda

(ns)

JimGrayTuringAward

Suzhou

Page 17: CS 110 Computer Architecture (a.k.a. Machine Structures

GreatIdea#3:PrincipleofLocality/MemoryHierarchy

2/23/16 17

Page 18: CS 110 Computer Architecture (a.k.a. Machine Structures

GreatIdea#4:Parallelism

18

Page 19: CS 110 Computer Architecture (a.k.a. Machine Structures

2/23/16 19

Caveat:Amdahl’sLaw

GeneAmdahlComputerPioneer

Page 20: CS 110 Computer Architecture (a.k.a. Machine Structures

GreatIdea#5:PerformanceMeasurementandImprovement

• Tuningapplicationtounderlyinghardwaretoexploit:– Locality– Parallelism– Specialhardwarefeatures,likespecializedinstructions(e.g.,matrixmanipulation)

• Latency– Howlongtosettheproblemup– Howmuchfasterdoesitexecuteonceitgetsgoing– Itisallabouttimetofinish

20

Page 21: CS 110 Computer Architecture (a.k.a. Machine Structures

CopingwithFailures

• 4disks/server,50,000servers• Failurerateofdisks:2%to10%/year

– Assume4%annualfailurerate• Onaverage,howoftendoesadiskfail?

a) 1/monthb) 1/weekc) 1/dayd) 1/hour

21

Page 22: CS 110 Computer Architecture (a.k.a. Machine Structures

CopingwithFailures

• 4disks/server,50,000servers• Failurerateofdisks:2%to10%/year

– Assume4%annualfailurerate• Onaverage,howoftendoesadiskfail?

a) 1/monthb) 1/weekc) 1/dayd) 1/hour

22

50,000x 4=200,000disks200,000x 4%=8000disksfail

365daysx 24hours=8760hours

Page 23: CS 110 Computer Architecture (a.k.a. Machine Structures

NASAFixingRover’sFlashMemory

• OpportunitystillactiveonMarsafter>10years

• Butflashmemorywornout

• Newsoftwareupdatetoavoidusingwornoutmemorybanks

23http://www.engadget.com/2014/12/30/nasa-opportunity-rover-flash-fix/

Page 24: CS 110 Computer Architecture (a.k.a. Machine Structures

GreatIdea#6:DependabilityviaRedundancy

• Redundancysothatafailingpiecedoesn’tmakethewholesystemfail

24

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

1+1=22of3agree

FAIL!

Increasingtransistordensity reducesthecostofredundancy

Page 25: CS 110 Computer Architecture (a.k.a. Machine Structures

GreatIdea#5:DependabilityviaRedundancy

• Appliestoeverythingfromdatacenterstostoragetomemorytoinstructors– Redundantdatacenters sothatcanlose1datacenterbutInternetservicestaysonline

– Redundantdisks sothatcanlose1diskbutnotlosedata(RedundantArraysofIndependentDisks/RAID)

– Redundantmemorybits ofsothatcanlose1bitbutnodata(ErrorCorrectingCode/ECCMemory)

25

Page 26: CS 110 Computer Architecture (a.k.a. Machine Structures

Agenda

• ThinkingaboutMachineStructures• GreatIdeasinComputerArchitecture• Whatyouneedtoknowaboutthisclass• EverythingisaNumber

26

Page 27: CS 110 Computer Architecture (a.k.a. Machine Structures

WeeklySchedule

Lecture Tuesday,08:15-09:55.room:H2109Lecture Friday,10:15-11:55. room:H2109Discussions Tuesday,18:40-20:20.教学楼309.Lab1 Monday,15:00-16:40.教学楼308Lab2 Tuesday,15:00-16:40.教学楼309Lab3 Thursday,15:00-16:40.行政楼405

27

Page 28: CS 110 Computer Architecture (a.k.a. Machine Structures

CourseInformation• CourseWeb:http://shtech.org/course/ca/• Acknowledgement:InstructorsofUCBerkeley’sCS61C:

http://www-inst.eecs.berkeley.edu/~cs61c/• Instructor:

– SörenSchwertfeger• TeachingAssistants:(seewebpage)• Textbooks:Average15pagesofreading/week

– Patterson&Hennessey,ComputerOrganizationandDesign,5th Edition(Chineseversionis4th edition– significantdifferences!)

– Kernighan&Ritchie,TheCProgrammingLanguage,2nd Edition– Barroso&Holzle,TheDatacenterasaComputer,2nd Edition

• Piazza:– Everyannouncement,discussion,clarificationhappensthere

28

Page 29: CS 110 Computer Architecture (a.k.a. Machine Structures

CourseGrading• Projects:33%• Homework:17%• Lab:10%• Exams:35%

– Midterm1:7.5%– Midterm2:7.5%– Final:20%

• Participation:5%

29

Page 30: CS 110 Computer Architecture (a.k.a. Machine Structures

LatePolicy…SlipDays!• Assignmentsdueat11:59:59PM• Youhave3 slipdaytokens(NOThourormin)• Everydayyourprojectorhomeworkislate(evenbyaminute)wedeductatoken

• Afteryou’veusedupalltokens,it’s25%deductedperday.– Nocreditifmorethan3dayslate– Saveyourtokensforprojects,worthmore!!

• Noneedforsobstories,justuseaslipday!• Gradebot isopentill3daysafterduedate!• Ifyouneedmoretime(slipdaysplusdeduction)sendtheTAandProf.anemail!

30

Page 31: CS 110 Computer Architecture (a.k.a. Machine Structures

PolicyonAssignmentsandIndependentWork

• ALLPROJECTSWILLBEDONEWITHAPARTNER• Withtheexceptionoflaboratoriesandassignmentsthatexplicitlypermityouto

workingroups, allhomeworkandprojectsaretobeYOURworkandyourworkALONE.

• PARTNERTEAMSMAYNOTWORKWITHOTHERPARTNERTEAMS• Youareencouraged todiscussyourassignmentswithotherstudents,andcreditwill

beassignedtostudentswhohelpothers,particularlybyansweringquestionsonPiazza,butweexpectthatwhatyouhandinisyours.

• ItisNOTacceptabletocopysolutions fromother students.• ItisNOTacceptabletocopy(or startyour) solutions fromtheWeb.• ItisNOTacceptabletousePUBLICgithub archives(giving youranswersaway)• Wehavetoolsandmethods, developedovermanyyears,fordetectingthis.You

WILLbecaught,andthepenaltiesWILLbesevere.• AttheminimumFinthecourse,andalettertoyouruniversityrecorddocumenting

theincidenceofcheating.• BothGiverandReceiverareequallyculpableandsufferequalpenalties

31

Page 32: CS 110 Computer Architecture (a.k.a. Machine Structures

Discussion&Labs&HW1

• Firstdiscussiontoday!Tuesday,18:40-20:20教学楼309– Topic:Numberrepresentation– Letusknowwhattopicsyou’dliketohavecovered!– Topicnextdiscussion:C

• Labs:Findapartnerforyourlab-workandtheprojects– fromyoulabclass!– SendanemailtoXuQingwen (xuqw)– Labsstartnextweek

• HW1willbepostedonFriday.

32

Page 33: CS 110 Computer Architecture (a.k.a. Machine Structures

ArchitectureofatypicalLecture

33

Attention

Time(minutes)10 35 60 78 90

Administrivia “Andinconclusion…”

Full

Fun/News

Page 34: CS 110 Computer Architecture (a.k.a. Machine Structures

Agenda

• ThinkingaboutMachineStructures• GreatIdeasinComputerArchitecture• Whatyouneedtoknowaboutthisclass• EverythingisaNumber

34

Page 35: CS 110 Computer Architecture (a.k.a. Machine Structures

KeyConcepts• Insidecomputers,everythingisanumber• Butnumbersusuallystoredwithafixedsize

– 8-bitbytes,16-bithalfwords,32-bitwords,64-bitdoublewords,…

• Integerandfloating-pointoperationscanleadtoresultstoobig/smalltostorewithintheirrepresentations:overflow/underflow

35

Page 36: CS 110 Computer Architecture (a.k.a. Machine Structures

NumberRepresentation

• Valueofi-th digitisd × Baseiwherei startsat0andincreasesfromrighttoleft:

• 12310=110 x 10102 +210 x 10101 +310 x 10100

=1x10010 +2x1010 +3x110=10010 +2010 +310=12310

• Binary(Base2),Hexadecimal(Base16),Decimal(Base10)differentwaystorepresentaninteger– Weuse1two,5ten,10hex tobeclearer

(vs.12,48,510,1016)

36

Page 37: CS 110 Computer Architecture (a.k.a. Machine Structures

NumberRepresentation

• Hexadecimaldigits:0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F

• FFFhex =15tenx16ten2 +15tenx16ten1 +15tenx16ten0=3840ten +240ten +15ten=4095ten

• 111111111111two =FFFhex =4095ten• Mayputblankseverygroupofbinary,octal,orhexadecimaldigitstomakeiteasiertoparse,likecommasindecimal

37

Page 38: CS 110 Computer Architecture (a.k.a. Machine Structures

SignedandUnsignedIntegers

• C,C++,andJavahavesignedintegers,e.g.,7,-255:int x, y, z;

• C,C++alsohaveunsigned integers,e.g.foraddresses

• 32-bitwordcanrepresent232 binarynumbers• Unsignedintegersin32bitwordrepresent0to232-1(4,294,967,295)(4Gig)

38

Page 39: CS 110 Computer Architecture (a.k.a. Machine Structures

UnsignedIntegers00000000000000000000000000000000two =0ten00000000000000000000000000000001two =1ten00000000000000000000000000000010two =2ten

... ...01111111111111111111111111111101two =2,147,483,645ten01111111111111111111111111111110two =2,147,483,646ten01111111111111111111111111111111two =2,147,483,647ten10000000000000000000000000000000two =2,147,483,648ten10000000000000000000000000000001two =2,147,483,649ten10000000000000000000000000000010two =2,147,483,650ten

... ...11111111111111111111111111111101two =4,294,967,293ten11111111111111111111111111111110two =4,294,967,294ten11111111111111111111111111111111two =4,294,967,295ten

39

Page 40: CS 110 Computer Architecture (a.k.a. Machine Structures

SignedIntegersandTwo’s-ComplementRepresentation

• SignedintegersinC;want½numbers<0,want½numbers>0,andwantone0

• Two’scomplementtreats0aspositive,so32-bitwordrepresents232integersfrom-231(–2,147,483,648) to231-1(2,147,483,647)– Note:onenegativenumberwithnopositiveversion– Booklistssomeotheroptions,allofwhichareworse– Everycomputerusestwo’scomplementtoday

• Most-significantbit(leftmost)isthesignbit,since0meanspositive(including0),1meansnegative– Bit31ismostsignificant,bit0isleastsignificant

40

Page 41: CS 110 Computer Architecture (a.k.a. Machine Structures

Two’s-ComplementIntegers00000000000000000000000000000000two =0ten00000000000000000000000000000001two =1ten00000000000000000000000000000010two =2ten

... ...01111111111111111111111111111101two =2,147,483,645ten01111111111111111111111111111110two =2,147,483,646ten01111111111111111111111111111111two =2,147,483,647ten10000000000000000000000000000000two =–2,147,483,648ten10000000000000000000000000000001two =–2,147,483,647ten10000000000000000000000000000010two =–2,147,483,646ten

... ...11111111111111111111111111111101two =–3ten11111111111111111111111111111110two =–2ten11111111111111111111111111111111two =–1ten

41

SignBit

Page 42: CS 110 Computer Architecture (a.k.a. Machine Structures

WaystoMakeTwo’sComplement• ForN-bitword,complementto2tenN

– For4bitnumber3ten=0011two,two’scomplement

(i.e.-3ten)wouldbe

16ten-3ten=13ten or10000two – 0011two =1101two

42

• Hereisaneasierway:– Invertallbitsandadd1

– Computersactuallydoitlikethis,too

0011two

1100two+1two

3ten

1101two

Bitwisecomplement

-3ten

Page 43: CS 110 Computer Architecture (a.k.a. Machine Structures

Two’s-ComplementExamples

• Assumeforsimplicity4bitwidth,-8to+7represented

43

00110010

3+25 0101

00111110

3+(-2)

1 10001

01110001

7+1-8 1000Overflow!

11011110

-3+(-2)

-5 11011

10001111

-8+(-1)+7 10111

CarryintoMSB=CarryOutMSB

CarryintoMSB=CarryOutMSB

Underflow!

Overflow/Underflowwhenmagnitudeofresulttoobig/toosmalltofitintoresultrepresentation

Carryin=carryfromlesssignificantbitsCarryout=carrytomoresignificantbits

Page 44: CS 110 Computer Architecture (a.k.a. Machine Structures

0to+31

-16to+15

-32to+31☐

44

Supposewehada5-bitword.Whatintegerscanberepresentedintwo’scomplement?

Page 45: CS 110 Computer Architecture (a.k.a. Machine Structures

0to+31

-16to+15

-32to+31☐

45

Supposewehada5bitword.Whatintegerscanberepresentedintwo’scomplement?

Page 46: CS 110 Computer Architecture (a.k.a. Machine Structures

Summary• ComputerArchitecture:Learn6greatideasincomputerarchitecturetoenablehighperformanceprogrammingviaparallelism,notjustlearnC1. Abstraction

(LayersofRepresentation/Interpretation)2. Moore’sLaw3. PrincipleofLocality/MemoryHierarchy4. Parallelism5. PerformanceMeasurementandImprovement6. DependabilityviaRedundancy

• EverythingisaNumber!46