ACA Notes
ACA Notes
10CS74
A d v a n c e C o mp u t e r A r c h i t e c t u r e
Subject Code: 10CS74
Hours/Week : 04
Total Hours : 52
I.A. Marks : 25
Exam Hours: 03
Exam Marks: 100
PART - A
UNIT - 1
FUNDAMENTALS OF COMPUTER DESIGN: Introduction; Classes of computers;
Defining computer architecture; Trends in Technology, power in Integrated Circuits and
cost; Dependability; Measuring, reporting and summarizing Performance; Quantitative
Principles of computer design.
6 hours
UNIT - 2
PIPELINING: Introduction; Pipeline hazards; Implementation of pipeline; What makes
pipelining hard to implement?
6 Hours
UNIT - 3
INSTRUCTION LEVEL PARALLELISM 1: ILP: Concepts and challenges; Basic
Compiler Techniques for exposing ILP; Reducing Branch costs with prediction;
Overcoming Data hazards with Dynamic scheduling; Hardware-based speculation.
7 Hours
UNIT - 4
INSTRUCTION LEVEL PARALLELISM 2: Exploiting ILP using multiple issue
and static scheduling; Exploiting ILP using dynamic scheduling, multiple issue and
speculation; Advanced Techniques for instruction delivery and Speculation; The Intel
Pentium 4 as example.
7 Hours
Page 1
10CS74
PART - B
UNIT - 5
MULTIPROCESSORS AND THREAD LEVEL PARALLELISM: Introduction;
Symmetric shared-memory architectures; Performance of symmetric sharedmemory
multiprocessors; Distributed shared memory and directory-based coherence; Basics of
synchronization; Models of Memory Consistency. 7 Hours
UNIT - 6
REVIEW OF MEMORY HIERARCHY: Introduction; Cache performance; Cache
Optimizations, Virtual memory.
6 Hours
UNIT - 7
MEMORY HIERARCHY DESIGN: Introduction; Advanced optimizations of Cache
performance; Memory technology and optimizations; Protection: Virtual memory and
virtual machines.
6 Hours
UNIT - 8
HARDWARE AND SOFTWARE FOR VLIW AND EPIC: Introduction: Exploiting
Instruction-Level Parallelism Statically; Detecting and Enhancing Loop-Level
Parallelism; Scheduling and Structuring Code for Parallelism; Hardware Support for
Exposing Parallelism: Predicated Instructions; Hardware Support for Compiler
Speculation; The Intel IA-64 Architecture and Itanium Processor; Conclusions. 7 Hours
TEXT BOOK:
1.
REFERENCE BOOKS:
1.
2.
Page 2
10CS74
Table of Contents
Sl.NO
1
2
3
4
5
6
7
8
Contents
Unit-I
Unit-II
Unit-III
Unit-IV
Unit-V
Unit-VI
Unit-VII
Unit-VIII
Page No
4-17
18-33
34-49
50-69
70-89
90-101
102-119
120-156
Page 3
10CS74
PART - A
UNIT - 1
FUNDAMENTALS OF COMPUTER DESIGN:
Page 4
10CS74
UNIT I
FUNDAMENTALS OF COMPUTER DESIGN
Introduction
Today s desktop computers (less than $500 cost) ar e having more
performance, larger memory and storage than a computer bought in 1085 for 1
million dollar. Highest performance microprocessors of today outperform
Supercomputers of less than 10 years ago. The rapid improvement has come both
from advances in the technology used to build computers and innovations made in
the computer design or in other words, the improvement made in the computers
can be attributed to innovations of technology and architecture design.
During the first 25 years of electronic computers, both forces made a
major contribution, delivering performance improvement of about 25% per year.
Microprocessors were evolved during late 1970s and their ability along with
improvements made in the Integrated Circuit (IC) technology y contributed to 35%
performance growth per year.
The virtual elimination of assembly language programming reduced the n eed
for object-code compatibility. The creation of standardized vendor-independent
operating system lowered the cost and risk of bringing out a new architecture.
In the yearly 1980s, the Reduced Instruction Set Computer (RISC) based
machines focused the attention of designers on two critical performance techniques,
the exploitation Instruction Level Parallelism (ILP) and the use of caches. The figu
re 1.1 shows the growth in processor performance since the mid 1980s. The graph
plots performance relative to the VAX-11/780 as measured b y the SPECint
benchmarks. From the figure it is clear that architectural and organizational
enhancements led to 16 years of sustained growth in performance at an annual rate of
over 50%. Since 2002, processor performance improvement has dropped to about 20%
per year due to the following hurdles:
Maximum power dissipation of air-cooled chips
Little ILP left to exploit efficiently
Limitations laid by memory latency
The hurdles signals historic switch from relying solely on ILP to Thread Level
Parallelism (TLP) and Data Level Parallelism (DLP).
Page 5
10CS74
Classes of Computers
1960: Large Main frames (Millions of $ )
(Applications: Business Data processing, large Scientific computin g)
1970: Minicomputers (Scientific laboratories, Time sharing concepts)
1980: Desktop Computers (Ps) in the form of Personal computers and workstations.
(Larger Memory, more computing power, Replaced Time sharing g systems)
1990: Emergence of Internet and WWW, PDAs, emergence of high performance digital
consumer electronics
2000: Cell phones
These changes in computer use have led to three different computing classes each
characterized by different applications, requirements and computing technologies.owth in
processor performance since 1980s
Page 6
10CS74
Desktop computing
The first and still the largest market in dollar terms is desktop computing. Desktop
computing system cost range from $ 500 (low end) to $ 5000 (high-end
configuration). Throughout this range in price, the desktop market tends to drive to
optimize price- performance. The perf ormance concerned is compute performance
and graphics performance. The combination of performance and price are the
driving factors to the customers and the computer designer. Hence, the newest,
high performance and cost effective processor often appears first in desktop computers.
Servers:
Servers provide large-scale and reliable computing and file services and are
mainly used in the large-scale en terprise computing and web based services. The three
important
characteristics of servers are:
Dependability: Severs must operate 24x7 hours a week. Failure of server system
is far more catastrophic than a failure of desktop. Enterprise will lose revenue if
the server is unavailable.
Scalability: as the business grows, the server may have to provide more
functionality/ services. Thus ability to scale up the computin g capacity, memory,
storage and I/O bandwidth is crucial.
Throughput: transactions completed per minute or web pages served per second
are crucial for servers.
Embedded Computers
Simple embedded microprocessors are seen in washing machines, printers,
network switches, handheld devices such as cell phones, smart cards video game
devices etc. embedded computers have the widest spread of processing power and
cost. The primary goal is often meeting the performance need at a minimum price
rather than achieving higher performance at a higher price. The other two characteristic
requirements are to minimize the memory and power.
In many embedded applications, the memory can be substantial portion of
the systems cost and it is very important to optimize the memory size in such
cases. The application is expected to fit totally in the memory on the p rocessor
chip or off chip memory. The importance of memory size translates to an emphasis
on code size which is dictated by the application. Larger memory consumes more
power. All these aspects are considered while choosing or designing processor for the
embedded applications.
Page 7
10CS74
Page 8
10CS74
Trends in Technology
The designer must be aware of the following rapid changes in implementation
technology.
Integrated C ircuit (IC) Logic technology
Memory technology (semiconductor DRAM technology)
Storage o r magnetic disk technology
Network technology
IC Logic technology:
Transistor density increases by about 35%per year. Increase in die size
corresponds to about 10 % to 20% per year. The combined effect is a growth rate
in transistor count on a chip of about 40% to 55% per year. Semiconductor DRAM
technology:cap acity increases by about 40% per year.
Storage Technology:
Before 1990: the storage density increased by about 30% per year.
After 1990: the storage density increased by about 60 % per year.
Disks are still 50 to 100 times cheaper per bit than DRAM.
Page 9
10CS74
Network Technology:
Network performance depends both on the per formance of the switches and
on the performance of the transmission system. Although the technology improves
continuously, the impact of these improvements can be in discrete leaps.
Performance trends: Bandwidth or throughput is the total amount of work done in
given time.
Latency or response time is the time between the start and the completion of an
event. (for eg. Millisecond for disk access)
A simple rule of thumb is that bandwidth gro ws by at least the square of the
improvement in latency. Computer designers should make plans accordingly.
IC Processes are characterizes by the f ature sizes.
Feature sizes decreased from 10 microns(1971) to 0.09 microns(2006)
Feature sizes shrink, devices shrink quadr atically.
Shrink in vertical direction makes the operating v oltage of the transistor to
reduce.
Transistor performance improves linearly with decreasing
feature size
Department of CSE, SJBIT
Page 10
10CS74
.
Transistor count improves quadratically with a linear improvement in Transistor
performance.
!!! Wire delay scales poo rly comp ared to Transistor performance.
Feature sizes shrink, wires get shorter.
Signal delay fo r a wire increases in proportion to the product of Resistance and
Capacitance.
Trends in Cost
The underlying principle that drives the cost down is the learning curvemanufacturing
costs decrease over time.
Volume is a second key factor in determining cost. Volume decreases cost since it
increases purchasing manufacturing efficiency. As a rule of thumb, the cost decreases
Department of CSE, SJBIT
Page 11
10CS74
Dependability:
The Infrastructure providers offer Service Level Agreement (SLA) or Service
Level Objectives (SLO) to guarantee that their networking or power services would be
dependable.
Department of CSE, SJBIT
Page 12
10CS74
Performance:
The Execution time or Response time is defined as the time between the start and
completion of an event. The total amount of work done in a given time is defined as the
Throughput.
The Administrator of a data center may be interested in increasing the
Throughput. The computer user may be interested in reducing the Response time.
Computer user says that computer is faster when a program runs in less time.
The routinely executed programs are the best candidates for evaluating the performance
of the new computers. To evaluate new system the user would simply compare the
execution time of their workloads.
Page 13
10CS74
Benchmarks
The real applications are the best choice of benchmarks to evaluate the
performance. However, for many of the cases, the workloads will not be known at the
time of evaluation. Hence, the benchmark program which resemble the real applications
are chosen. The three types of benchmarks are:
KERNELS, which are small, key pieces of real applications;
Toy Programs: which are 100 line programs from beginning programming
assignments, such Quicksort etc.,
Synthetic Benchmarks: Fake programs invented to try to match the profile and
behavior of real applications such as Dhrystone.
To make the process of evaluation a fair justice, the following points are to be followed.
Source code modifications are not allowed.
Source code modifications are allowed, but are essentially impossible.
Source code modifications are allowed, as long as the modified version produces
the same output.
To increase predictability, collections of benchmark applications, called
benchmark suites, are popular
SPECCPU: popular desktop benchmark suite given by Standard Performance
Evaluation committee (SPEC)
CPU only, split between integer and floating point programs
SPECint2000 has 12 integer, SPECfp2000 has 14 integer programs
SPECCPU2006 announced in Spring 2006.
SPECSFS (NFS file server) and SPECWeb (WebServer) added as server
benchmarks
Transaction Processing Council measures server performance and
costperformance for databases
TPC-C Complex query for Online Transaction Processing
TPC-H models ad hoc decision support
TPC-W a transactional web benchmark
TPC-App application server and web services benchmark
SPEC Ratio: Normalize execution times to reference computer, yielding a ratio
proportional to performance = time on reference computer/time on computer being rated
If program SPECRatio on Computer A is 1.25 times bigger than Computer B, then
Page 14
10CS74
Page 15
10CS74
i. The fraction of the computation time in the original computer that can be
converted to take advantage of the enhancement. Fraction enhanced is always less than or
equal to
Example: If 15 seconds of the execution time of a program that takes 50
seconds in total can use an enhancement, the fraction is 15/50 or 0.3
ii. The improvement gained by the enhanced execution mode; ie how much
faster the task would run if the enhanced mode were used for the entire program. Speedup
enhanced is the time of the original mode over the time of the enhanced mode and is always
greater then 1.
Page 16
10CS74
Example:
A System contains Floating point (FP) and Floating Point Square Root (FPSQR) unit.
FPSQR is responsible for 20% of the execution time. One proposal is to enhance the
FPSQR hardware and speedup this operation by a factor of 15 second alternate is just to
try to make all FP instructions run faster by a factor of 1.6 times faster with the same
effort as required for the fast FPSQR, compare the two design alternative
Page 17
10CS74
UNIT - 2
PIPELINING:
Introduction
Pipeline hazards
Implementation of pipeline
What makes pipelining hard to implement?
6 Hours
Page 18
10CS74
UNIT II
Pipelining: Basic and Intermediate concepts
Pipeline is an implementation technique that exploits parallelism among the instructions
in a sequential instruction stream. Pipeline allows to overlapping the execution of
multiple instructions. A Pipeline is like an assembly line each step or pipeline stage
completes a part of an instructions. Each stage of the pipeline will be operating an a
separate instruction. Instructions enter at one end progress through the stage and exit at
the other end. If the stages are perfectly balance.
(assuming ideal conditions), then the time per instruction on the pipeline processor is
given by the ratio:
Time per instruction on unpipelined machine/ Number of Pipeline stages
Under these conditions, the speedup from pipelining is equal to the number of stage
pipeline. In practice, the pipeline stages are not perfectly balanced and pipeline does
involve some overhead. Therefore, the speedup will be always then practically less than
the number of stages of the pipeline. Pipeline yields a reduction in the average execution
time per instruction. If the processor is assumed to take one (long) clock cycle per
instruction, then pipelining decrease the clock cycle time. If the processor is assumed to
take multiple CPI, then pipelining will aid to reduce the CPI.
A Simple implementation of a RISC instruction set
Instruction set of implementation in RISC takes at most 5 cycles without pipelining.
The 5 clock cycles are:
1. Instruction fetch (IF) cycle:
Send the content of program count (PC) to memory and fetch the current
instruction from memory to update the PC.
Page 19
10CS74
* Register- Register ALU instruction: ALU performs the operation specified in the
instruction using the values read from the register file.
* Register- Immediate ALU instruction: ALU performs the operation specified in the
instruction using the first value read from the register file and that sign extended
immediate.
4. Memory access (MEM)
For a load instruction, using effective address the memory is read. For a store
instruction memory writes the data from the 2nd register read using effective address.
5. Write back cycle (WB)
Write the result in to the register file, whether it comes from memory system (for
a LOAD instruction) or from the ALU.
Page 20
10CS74
Each stage of the pipeline must be independent of the other stages. Also, two different
operations cant be performed with the same data path resource on the same clock. For
example, a single ALU cannot be used to compute the effective address and perform a
subtract operation during the same clock cycle. An adder is to be provided in the stage 1
to compute new PC value and an ALU in the stage 3 to perform the arithmetic indicatedin
the instruction (See figure 2.2). Conflict should not arise out of overlap of instructions
using pipeline. In other words, functional unit of each stage need to be independent of
other functional unit. There are three observations due to which the risk of conflict is
reduced.
Separate Instruction and data memories at the level of L1 cache eliminates a
conflict for a single memory that would arise between instruction fetch and data
access.
Register file is accessed during two stages namely ID stage WB. Hardware
should allow to perform maximum two reads one write every clock cycle.
To start a new instruction every cycle, it is necessary to increment and store the
PC every cycle.
Page 21
10CS74
Buffers or registers are introduced between successive stages of the pipeline so that at the
end of a clock cycle the results from one stage are stored into a register (see figure 2.3).
During the next clock cycle, the next stage will use the content of these buffers as input.
Figure 2.4 visualizes the pipeline activity.
Page 22
10CS74
Page 23
10CS74
Pipeline Hazards
Hazards may cause the pipeline to stall. When an instruction is stalled, all the
instructions issued later than the stalled instructions are also stalled. Instructions issued
earlier than the stalled instructions will continue in a normal way. No new instructions
are fetched during the stall. Hazard is situation that prevents the next instruction in the
instruction stream fromk executing during its designated clock cycle. Hazards will reduce
the pipeline performance.
Performance with Pipeline stall
A stall causes the pipeline performance to degrade from ideal performance. Performance
improvement from pipelining is obtained from:
Assume that,
i) cycle time overhead of pipeline is ignored
ii) stages are balanced
With theses assumptions
If all the instructions take the same number of cycles and is equal to the number of
pipeline stages or depth of the pipeline, then,
Page 24
10CS74
Types of hazard
Three types hazards are:
1. Structural hazard
2. Data Hazard
3. Control Hazard
Structural hazard
Structural hazard arise from resource conflicts, when the hardware cannot support all
possible combination of instructions simultaneously in overlapped execution. If some
combination of instructions cannot be accommodated because of resource conflicts, the
processor is said to have structural hazard. Structural hazard will arise when some
functional unit is not fully pipelined or when some resource has not been duplicated
enough to allow all combination of instructions in the pipeline to execute. For example, if
memory is shared for data and instruction as a result, when an instruction contains data
memory reference, it will conflict with the instruction reference for a later instruction (as
shown in figure 2.5a). This will cause hazard and pipeline stalls for 1 clock cycle.
Page 25
10CS74
Page 26
10CS74
DADD instruction produces the value of R1 in WB stage (Clock cycle 5) but the DSUB
instruction reads the value during its ID stage (clock cycle 3). This problem is called Data
Hazard. DSUB may read the wrong value if precautions are not taken. AND instruction
will read the register during clock cycle 4 and will receive the wrong results. The XOR
instruction operates properly, because its register read occurs in clock cycle 6 after
DADD writes in clock cycle 5. The OR instruction also operates without incurring a
hazard because the register file reads are performed in the second half of the cycle
whereas the writes are performed in the first half of the cycle.
Page 27
10CS74
The LD instruction gets the data from the memory at the end of cycle 4. even with
forwarding technique, the data from LD instruction can be made available earliest during
clock cycle 5. DADD instruction requires the result of LD instruction at the beginning of
clock cycle 5. DADD instruction requires the result of LD instruction at the beginning of
clock cycle 4. This demands data forwarding of clock cycle 4. This demands data
forwarding in negative time which is not possible. Hence, the situation calls for a pipeline
stall.Result from the LD instruction can be forwarded from the pipeline register to the
and instruction which begins at 2 clock cycles later after the LD instruction. The load
instruction has a delay or latency that cannot be eliminated by forwarding alone. It is
necessary to stall pipeline by 1 clock cycle. A hardware called Pipeline interlock detects a
hazard and stalls the pipeline until the hazard is cleared. The pipeline interlock helps to
preserve the correct execution pattern by introducing a stall or bubble. The CPI for the
stalled instruction increases by the length of the stall. Figure 2.7 shows the pipeline
before and after the stall. Stall causes the DADD to move 1 clock cycle later in time.
Forwarding to the AND instruction now goes through the register file or forwarding is
not required for the OR instruction. No instruction is started during the clock cycle 4.
Control Hazard
When a branch is executed, it may or may not change the content of PC. If a branch is
taken, the content of PC is changed to target address. If a branch is taken, the content of
PC is not changed
The simple way of dealing with the branches is to redo the fetch of the instruction
following a branch. The first IF cycle is essentially a stall, because, it never performs
useful work. One stall cycle for every branch will yield a performance loss 10% to 30%
depending on the branch frequency
Department of CSE, SJBIT
Page 28
10CS74
3. Treat every branch as taken: As soon as the branch is decoded and target
Address is computed, begin fetching and executing at the target if the branch target is
known before branch outcome, then this scheme gets advantage.
For both predicated taken or predicated not taken scheme, the compiler can
improve performance by organizing the code so that the most frequent path
matches the hardware choice.
4. Delayed branch technique is commonly used in early RISC processors.
In a delayed branch, the execution cycle with a branch delay of one is
Branch instruction
Sequential successor-1
Branch target if taken
The sequential successor is in the branch delay slot and it is executed irrespective of
whether or not the branch is taken. The pipeline behavior with a branch delay is shown in
Figure 2.9. Processor with delayed branch, normally have a single instruction delay.
Compiler has to make the successor instructions valid and useful there are three ways in
Department of CSE, SJBIT
Page 29
10CS74
Page 30
10CS74
Types of exceptions:
The term exception is used to cover the terms interrupt, fault and exception.
I/O device request, page fault, Invoking an OS service from a user program, Integer
arithmetic overflow, memory protection overflow, Hardware malfunctions, Power failure
etc. are the different classes of exception. Individual events have important characteristics
that determine what action is needed corresponding to that exception.
i)
If the event occurs at the same place every time the program is executed with the
same data and memory allocation, the event is asynchronous. Asynchronous events are
caused by devices external to the CPU and memory such events are handled after the
completion of the current instruction.
ii)
User requested versus coerced:
User requested exceptions are predictable and can always be handled after the
current instruction has completed. Coerced exceptions are caused by some
hardware event that is not under the control of the user program. Coerced
exceptions are harder to implement because they are not predictable
iii)
Page 31
10CS74
Operation: send out the [PC] and fetch the instruction from memory in to the Instruction
Register (IR). Increment PC by 4 to address the next sequential instruction.
2. Instruction decode / Register fetch cycle (ID)
Operation: decode the instruction and access that register file to read the registers
( rs and rt). File to read the register (rs and rt). A & B are the temporary registers.
Operands are kept ready for use in the next cycle.
Department of CSE, SJBIT
Page 32
10CS74
Decoding is done in concurrent with reading register. MIPS ISA has fixed length
Instructions. Hence, these fields are at fixed locations.
3. Execution/ Effective address cycle (EX)
One of the following operations are performed depending on the instruction
type.
* Memory reference:
:
Operation: ALU adds the operands to compute the effective address and places
the result in to the register ALU output.
Register Register ALU instruction:
Operation: The ALU performs the operation specified by the function code on the value
taken from content of register A and register B.
*. Register- Immediate ALU instruction:
Operation: the content of register A and register Imm are operated (function Op) and
result is placed in temporary register ALU output.
*. Branch:
Page 33
10CS74
UNIT - 3
INSTRUCTION LEVEL PARALLELISM 1: ILP
Concepts and challenges
Basic Compiler Techniques for exposing ILP
Reducing Branch costs with prediction
Overcoming Data hazards with Dynamic scheduling
Hardware-based speculation.
7 Hours
Page 34
10CS74
UNIT III
Instruction Level Parallelism
The potential overlap among instruction execution is called Instruction Level Parallelism
(ILP) since instructions can be executed in parallel. There are mainly two approaches to
exploit ILP.
i)
ii)
Factors of both programs and processors limit the amount of parallelism that can be
exploited among instructions and these limit the performance achievable. The
performance of the pipelined processors is given by:
Pipeline CPI= Ideal Pipeline CPI + Structural stalls + Data hazard stalls + Control stalls
By reducing each of the terms on the right hand side, it is possible to minimize the overall
pipeline CPI.
To exploit the ILP, the primary focus is on Basic Block (BB). The BB is a straight line
code sequence with no branches in except the entry and no branches out except at the
exit. The average size of the BB is very small i.e., about 4 to 6 instructions. The flow
diagram segment of a program is shown below (Figure 3.1). BB1 , BB2 and BB3 are the
Basic Blocks.
Page 35
10CS74
The amount of overlap that can be exploited within a Basic Block is likely to be less than
the average size of BB. To further enhance ILP, it is possible to look at ILP across
multiple BB. The simplest and most common way to increase the ILP is to exploit the
parallelism among iterations of a loop (Loop level parallelism). Each iteration of a loop
can overlap with any other iteration.
Page 36
10CS74
Name Dependences
A Name Dependence occurs when two instructions use the same Register or Memory
location, but there is no flow of data between the instructions associated with that name.
Two types of Name dependences:
i) Antidependence: between instruction i and instruction j occurs when instruction j
writes a register or memory location that instruction i reads. he original ordering must be
preserved to ensure that i reads the correct value.
Eg: L.D F0, 0(R1)
DADDUI R1, R1, R3
ii) Output dependence: Output Dependence occurs when instructions i and j write to the
same register or memory location.
Ex: ADD.D F4, F0, F2
SUB.D F4, F3, F5
The ordering between the instructions must be preserved to ensure that the value finally
written corresponds to instruction j.The above instruction can be reordered or can be
executed simultaneously if the name of the register is changed. The renaming can be
easily done either statically by a compiler or dynamically by the hardware.
Data hazard: Hazards are named by the ordering in the program that must be preserved
by the pipeline
RAW (Read After Write): j tries to read a source before i writes it, so j in correctly gets
old value, this hazard is due to true data dependence.
WAW (Write After Write): j tries to write an operand before it is written by i. WAW
hazard arises from output dependence.
WAR (Write After Read): j tries to write a destination before it is read by i, so that I
incorrectly gets the new value. WAR hazard arises from an antidependence and normally
cannot occur in static issue pipeline.
CONTROL DEPENDENCE:
A control dependence determines the ordering of an instruction i with respect to a branch
instruction,
Ex: if P1 {
S1;
}
if P2 {
S2;
}
S1 is Control dependent on P1 and
Department of CSE, SJBIT
Page 37
10CS74
Page 38
10CS74
7 L.D F6,-8(R1)
9 ADD.D F8,F6,F2
12 S.D -8(R1),F8
13 L.D F10,-16(R1)
15 ADD.D F12,F10,F2
18 S.D -16(R1),F12
19 L.D F14,-24(R1)
21 ADD.D F16,F14,F2
24 S.D -24(R1),F16
25 DADDUI R1,R1,#-32
:alter to 4*8
26 BNEZ R1,LOOP
Unrolled loop that minimizes the stalls to 14 clock cycles for four iterations is given
below:
1 Loop: L.D F0, 0(R1)
Page 39
10CS74
Page 40
10CS74
To reduce the Branch cost, prediction of the outcome of the branch may be done.
The prediction may be done statically at compile time using compiler support or
dynamically using hardware support. Schemes to reduce the impact of control hazard are
discussed below:
Static Branch Prediction
Assume that the branch will not be taken and continue execution down the
sequential instruction stream. If the branch is taken, the instruction that are being fetched
and decoded must be discarded. Execution continues at the branch target. Discarding
instructions means we must be able to flush instructions in the IF, ID and EXE stages.
Alternately, it is possible that the branch can be predicted as taken. As soon as the
instruction decoded is found as branch, at the earliest, start fetching the instruction from
the target address.
Average misprediction = untaken branch frequency = 34% for SPEC
pgms.
The graph shows the misprediction rate for set of SPEC benchmark
programs
Page 41
10CS74
Page 42
10CS74
Idea: record m most recently executed branches as taken or not taken, and use that
pattern to select the proper n-bit branch history table (BHT)
In general, (m,n) predictor means record last m branches to select between 2m history
tables, each with n-bit counters
Thus, old 2-bit BHT is a (0,2) predictor
Global Branch History: m-bit shift register keeping T/NT status of last m
branches.
Each entry in table has m n-bit predictors. In case of (2,2) predictor, behavior of recent
branches selects between four predictions of next branch, updating just that prediction.
The scheme of the table is shown:
Comparisons of different schemes are shown in the graph.
Tournament predictor is a multi level branch predictor and uses n bit saturating counter
to chose between predictors. The predictors used are global predictor and local predictor.
Advantage of tournament predictor is ability to select the right predictor for a
particular branch which is particularly crucial for integer benchmarks.
A typical tournament predictor will select the global predictor almost 40% of the
time for the SPEC integer benchmarks and less than 15% of the time for the SPEC
FP benchmarks
Existing tournament predictors use a 2-bit saturating counter per branch to choose
among two different predictors based on which predictor was most effective oin
recent prediction.
Department of CSE, SJBIT
Page 43
10CS74
Page 44
10CS74
Page 45
10CS74
Page 46
10CS74
At the time MUL.D is ready to commit only the two L.D instructions have already
committed,though others have completed execution
Actually, the MUL.D is at the head of the ROB the L.D instructions are shown only for
understanding purposes #X represents value field of ROB entry number X
Page 47
10CS74
Reorder Buffer
Example
Loop: LD
F0
R1
MULTD
F4
F0
F2
SD
F4
R1
SUBI
R1
R1
#8
BNEZ
R1
Loop
Page 48
10CS74
Reorder Buffer
Notes
If a branch is mispredicted, recovery is done by flushing the ROB of all entries that
appear after the mispredicted branch
entries before the branch are allowed to continue
restart the fetch at the correct branch successor
When an instruction commits or is flushed from the ROB then the corresponding slots
become available for subsequent instructions
Advantages of hardware-based speculation:
Page 49
10CS74
UNIT - IV
INSTRUCTION LEVEL PARALLELISM 2:
Exploiting ILP using multiple issue and static scheduling
Exploiting ILP using dynamic scheduling
Multiple issue and speculation
Advanced Techniques for instruction delivery and Speculation
The Intel Pentium 4 as example.
7 Hours
Page 50
10CS74
UNIT IV
INSTRUCTION LEVEL PARALLELISM 2
What is ILP?
Instruction Level Parallelism
Number of operations (instructions) that can be performed in parallel
Formally, two instructions are parallel if they can execute simultaneously in a pipeline
of arbitrary depth without causing any stalls assuming that the pipeline has sufficient
resources
Primary techniques used to exploit ILP
Deep pipelines
Multiple issue machines
Basic program blocks tend to have 4-8 instructions between branches
Little ILP within these blocks
Must find ILP between groups of blocks
Example Instruction Sequences
Independent instruction sequence:
lw $10, 12($1)
sub $11, $2, $3
and $12, $4, $5
or $13, $6, $7
add $14, $8, $9
Dependent instruction sequence:
lw $10, 12($1)
sub $11, $2, $10
and $12, $11, $10
or $13, $6, $7
add $14, $8, $13
Finding ILP:
Must deal with groups of basic code blocks
Common approach: loop-level parallelism
Department of CSE, SJBIT
Page 51
10CS74
Example:
In MIPS (assume $s0 initialized properly):
for (i=1000; i > 0; i--)
x[i] = x[i] + s;
Loop: lw $t0, 0($s1) # t0 = array element
addu $t0, $t0, $s2 # add scalar in $s2
sw $t0, 0($s1) # store result
addi $s1, $s1, -4 # decrement pointer
bne $s1, $0, Loop # branch $s1 != 0
Loop Unrolling:
Technique used to help scheduling (and performance)
Copy the loop body and schedule instructions from different iterations of the
loop gether
MIPS example (from prev. slide):
Loop: lw $t0, 0($s1) # t0 = array element
addu $t0, $t0, $s2 # add scalar in $s2
sw $t0, 0($s1) # store result
lw $t1, -4($s1)
addu $t1, $t1, $s2
sw $t1, -4($s1)
addi $s1, $s1, -8 # decrement pointer
bne $s1, $0, Loop # branch $s1 != 0
Note the new register & counter adjustment!
Previous example, we unrolled the loop once
This gave us a second copy
Why introduce a new register ($t1)?
Antidependence (name dependence)
Loop iterations would reuse register $t0
No data overlap between loop iterations!
Compiler RENAMED the register to prevent a dependence
Allows for better instruction scheduling and identification of true dependencies
In general, you can unroll the loop as much as you want
A factor of the loop counter is generally used
Limited advantages to unrolling more than a few times
Page 52
10CS74
Page 53
10CS74
Page 54
10CS74
Page 55
10CS74
Page 56
10CS74
Page 57
10CS74
Register Renaming
Use more registers than are defined by the architecture
Architectural registers: defined by ISA
Physical registers: total registers
Help with name dependencies
Antidependence
Write after Read hazard
Output dependence
Write after Write hazard
Page 58
10CS74
Reservation Stations
Require 7 fields
Operation to perform on operands (2 operands)
Tags showing which RS/Func. Unit will be producing operand (or zero if operand
available/unnecessary)
Two source operand values
A field for holding memory address calculation data
Initially, immediate field of instruction
Later, effective address
Busy
Indicates that RS and its functional unit are busy
Register file support
Each entry contains a field that identifies which RS/func. unit will be writing into this
entry (or blank/zero if noone will be writing to it) Limitation of Current Machine
Instruction execution requires branches to be resolved
Department of CSE, SJBIT
Page 59
10CS74
For wide-issue machines, may issue one branch per clock cycle!
Desire:
Predict branch direction to get more ILP
Eliminate control dependencies
Approach:
Predict branches, utilize speculative instruction execution
Requires mechanisms for fixing machine when speculation is incorrect
Tomasulos w/Hardware Speculation
Page 60
10CS74
Page 61
10CS74
Page 62
10CS74
Overview of P4
Page 63
10CS74
Pentium 4 Pipeline
See handout for overview of major steps
Prescott (90nm version of P4) had 31 pipeline stages
Not sure how pipeline is divided up
Page 64
10CS74
Page 65
10CS74
Store-to-Load Forwarding
Stores must wait to write until non-speculative
Loads occasionally want data from store location
Check both cache and Store Forwarding Buffer
SFB is where stores are waiting to be written
If hit when comparing load address to SFB address, use SFB data, not cache data
Done on a partial address
Memory Ordering Buffer
Ensures that store-to-load forwarding was correct
If not, must re-execute load
Force forwarding
Mechanism for forwarding in case addresses are misaligned
MOB can tell SFB to forward or not
False forwarding
Fixes partial address match between load and SFB
Page 66
10CS74
Page 67
10CS74
P4: CPI
Page 68
10CS74
Page 69
10CS74
PART - B
UNIT - 5
MULTIPROCESSORS AND THREAD LEVEL PARALLELISM:
Introduction
Symmetric shared-memory architectures
Performance of symmetric sharedmemory multiprocessors
Distributed shared memory and directory-based coherence
Basics of synchronization
Models of Memory Consistency.
7 Hours
Page 70
10CS74
UNIT V
Multiprocessors and Thread-Level Parallelism
We have seen the renewed interest in developing multiprocessors in early 2000:
- The slowdown in uniprocessor performance due to the diminishing returns in exploring
instruction-level parallelism.
- Difficulty to dissipate the heat generated by uniprocessors with high clock rates.
- Demand for high-performance servers where thread-level parallelism is natural.
For all these reasons multiprocessor architectures has become increasingly attractive.
Page 71
10CS74
Page 72
10CS74
1. MIMDs offer flexibility. With the correct hardware and software support, MIMDs
can function as single-user multiprocessors focusing on high performance for one
application, as multiprogrammed multiprocessors running many tasks simultaneously, or
as some combination of these functions.
2. MIMDs can build on the cost/performance advantages of off-the-shelf
microprocessors. In fact, nearly all multiprocessors built today use the same
microprocessors found in workstations and single-processor servers.
With an MIMD, each processor is executing its own instruction stream. In many cases,
each processor executes a different process. Recall from the last chapter, that a process is
an segment of code that may be run independently, and that the state of the process
contains all the information necessary to execute that program on a processor. In a
multiprogrammed environment, where the processors may be running independent tasks,
each process is typically independent of the processes on other processors. It is also
useful to be able to have multiple processors executing a single program and sharing the
code and most of their address space. When multiple processes share code and data in
this way, they are often called threads
. Today, the term thread is often used in a casual way to refer to multiple loci of
execution that may run on different processors, even when they do not share an address
space. To take advantage of an MIMD multiprocessor with n processors, we must usually
have at least n threads or processes to execute. The independent threads are typically
identified by the programmer or created by the compiler. Since the parallelism in this
situation is contained in the threads, it is called thread-level parallelism.
Threads may vary from large-scale, independent processesfor example,
independent programs running in a multiprogrammed fashion on different processors to
parallel iterations of a loop, automatically generated by a compiler and each executing for
perhaps less than a thousand instructions. Although the size of a thread is important in
considering how to exploit thread-level parallelism efficiently, the important qualitative
Department of CSE, SJBIT
Page 73
10CS74
distinction is that such parallelism is identified at a high-level by the software system and
that the threads consist of hundreds to millions of instructions that may be executed in
parallel. In contrast, instruction level parallelism is identified by primarily by the
hardware, though with software help in some cases, and is found and exploited one
instruction at a time.
Existing MIMD multiprocessors fall into two classes, depending on the number of
processors involved, which in turn dictate a memory organization and interconnect
strategy. We refer to the multiprocessors by their memory organization, because what
constitutes a small or large number of processors is likely to change over time.
The first group, which we call
Page 74
10CS74
Distributing the memory among the nodes has two major benefits. First, it is a
costeffective way to scale the memory bandwidth, if most of the accesses are to the local
memory in the node. Second, it reduces the latency for accesses to the local memory.
These two advantages make distributed memory attractive at smaller processor counts as
processors get ever faster and require more memory bandwidth and lower memory
latency. The key disadvantage for a distributed memory architecture is that
communicating data between processors becomes somewhat more complex and has
higher latency, at least when there is no contention, because the processors no longer
share a single centralized memory. As we will see shortly, the use of distributed memory
leads to two different paradigms for interprocessor communication. Typically, I/O as well
as memory is distributed among the nodes of the multiprocessor, and the nodes may be
small SMPs (28 processors). Although the use of multiple processors in a node together
with a memory and a network interface is quite useful from the cost-efficiency viewpoint.
Page 75
10CS74
Suppose you want to achieve a speedup of 80 with 100 processors. What fraction
of the original computation can be sequential?
Page 76
10CS74
Cache Coherence
Unfortunately, caching shared data introduces a new problem because the view of
memory held by two different processors is through their individual caches, which,
without any additional precautions, could end up seeing two different values. I.e, If two
different processors have two different values for the same location, this difficulty is
generally referred to as cache coherence problem
Page 77
10CS74
Informally:
Any read must return the most recent write
Too strict and too difficult to implement
Better:
Any write must eventually be seen by a read
All writes are seen in proper order (serialization)
Page 78
10CS74
Directory based
Sharing status of a block of physical memory is kept in one location called the
directory.
Directory-based coherence has slightly higher implementation overhead than
snooping.
It can scale to larger processor count.
Snooping
Every cache that has a copy of data also has a copy of the sharing status of the
block.
No centralized state is kept.
Caches are also accessible via some broadcast medium (bus or switch)
Cache controller monitor or snoop on the medium to determine whether or not
they have a copy of a block that is represented on a bus or switch access.
Snooping protocols are popular with multiprocessor and caches attached to single
shared memory as they can use the existing physical connection- bus to memory, to
interrogate the status of the caches. Snoop based cache coherence scheme is implemented
on a shared bus. Any communication medium that broadcasts cache misses to all the
processors.
Basic Snoopy Protocols
Write strategies
Write-through: memory is always up-to-date
Write-back: snoop in caches to find most recent copy
Write Invalidate Protocol
Multiple readers, single writer
Write to shared data: an invalidate is sent to all caches which snoop and
invalidate any copies
Read miss: further read will miss in the cache and fetch a new
copy of the data.
Write Broadcast/Update Protocol (typically write through)
Write to shared data: broadcast on bus, processors snoop, and update
any copies
Read miss: memory/cache is always up-to-date.
Write serialization: bus serializes requests!
Bus is single point of arbitration
Examples of Basic Snooping Protocols
Write Invalidate
Page 79
10CS74
Write Update
Example Protocol
Snooping coherence protocol is usually implemented by incorporating a
finitestate controller in each node
Logically, think of a separate controller associated with each cache block
That is, snooping operations or cache requests for different blocks can
proceed independently
In implementations, a single controller allows multiple operations to distinct
blocks to proceed in interleaved fashion
that is, one operation may be initiated before another is completed, even
through only one cache access or one bus access is allowed at time
Page 80
10CS74
Page 81
10CS74
Conclusion
End of uniprocessors speedup => Multiprocessors
Parallelism challenges: % parallalizable, long latency to remote memory
Centralized vs. distributed memory
Small MP vs. lower latency, larger BW for Larger MP
Message Passing vs. Shared Address
Uniform access time vs. Non-uniform access time
Snooping cache over shared medium for smaller MP by invalidating other
cached copies on write
Sharing cached data _ Coherence (values returned by a read), Consistency
(when a written value will be returned by a read)
Shared medium serializes writes _ Write consistency
Implementation Complications
Write Races:
Cannot update cache until bus is obtained
Otherwise, another processor may get bus first,
and then write the same cache block!
Two step process:
Arbitrate for bus
Place miss on bus and complete operation
If miss occurs to block while waiting for bus, handle miss (invalidate
may be needed) and then restart.
Split transaction bus:
Bus transaction is not atomic:
Department of CSE, SJBIT
Page 82
10CS74
Example Result
Department of CSE, SJBIT
Page 83
10CS74
Page 84
10CS74
Page 85
10CS74
Page 86
10CS74
Why Synchronize?
Need to know when it is safe for different processes to use shared data
Issues for Synchronization:
Uninterruptable instruction to fetch and update memory (atomic
operation);
User level synchronization operation using this primitive;
For large scale MPs, synchronization can be a bottleneck; techniques to
reduce contention and latency of synchronization
Uninterruptable Instruction to Fetch and Update Memory
Atomic exchange: interchange a value in a register for a value in memory
0 _ synchronization variable is free
1 _ synchronization variable is locked and unavailable
Set register to 1 & swap
New value in register determines success in getting lock
0 if you succeeded in setting the lock (you were first)
1 if other processor had already claimed access
Key is that exchange operation is indivisible
Test-and-set: tests a value and sets it if the value passes the test
Fetch-and-increment: it returns the value of a memory location and atomically
increments it
0 _ synchronization variable is free
Hard to have read & write in 1 instruction: use 2 instead
Load linked (or load locked) + store conditional
Load linked returns the initial value
Store conditional returns 1 if it succeeds (no other store to same memory
location since preceding load) and 0 otherwise
Example doing atomic swap with LL & SC:
try:
mov R3,R4 ;
mov exchange value
ll
sc
beqz
mov
Page 87
10CS74
Page 88
10CS74
Page 89
10CS74
UNIT - VI
REVIEW OF MEMORY HIERARCHY:
Introduction
Cache performance
Cache Optimizations
Virtual memory.
6 Hours
Page 90
10CS74
UNIT VI
REVIEW OF MEMORY HIERARCHY
Unlimited amount of fast memory
- Economical solution is memory hierarchy
- Locality
- Cost performance
Principle of locality
- most programs do not access all code or data uniformly.
Locality occurs
- Time (Temporal locality)
- Space (spatial locality)
Guidelines
Smaller hardware can be made faster
Different speed and sizes
Goal is provide a memory system with cost per byte than the next lower level
Each level maps addresses from a slower, larger memory to a smaller but faster
memory higher in the hierarchy.
Address mapping
Address checking.
Hence protection scheme for address for scrutinizing addresses are also part of
the memory hierarchy.
Why More on Memory Hierarchy?
Page 91
10CS74
Page 92
10CS74
Page 93
10CS74
Cache Optimizations
Six basic cache optimizations
1. Larger block size to reduce miss rate:
- To reduce miss rate through spatial locality.
- Increase block size.
- Larger block size reduce compulsory misses.
- But they increase the miss penalty.
2. Bigger caches to reduce miss rate:
- capacity misses can be reduced by increasing the cache capacity.
- Increases larger hit time for larger cache memory and higher cost and power.
3. Higher associativity to reduce miss rate:
- Increase in associativity reduces conflict misses.
4. Multilevel caches to reduce penalty:
- Introduces additional level cache
- Between original cache and memory.
- L1- original cache
L2- added cache.
L1 cache: - small enough
- speed matches with clock cycle time.
L2 cache: - large enough
- capture many access that would go to main memory.
Average access time can be redefined as
Hit timeL1+ Miss rate L1 X ( Hit time L2 + Miss rate L2 X Miss penalty L2)
5. Giving priority to read misses over writes to reduce miss penalty:
- write buffer is a good place to implement this optimization.
- write buffer creates hazards: read after write hazard.
6. Avoiding address translation during indexing of the cache to reduce hit time:
- Caches must cope with the translation of a virtual address from the processor to
a physical address to access memory.
- common optimization is to use the page offset.
- part that is identical in both virtual and physical addresses- to index the cache.
Page 94
10CS74
Page 95
10CS74
Way prediction: keep extra bits in cache to predict the way, or block within
the set, of next cache access.
Multiplexer is set early to select desired block, only 1 tag comparison performed that
clock cycle in parallel with reading the cache data
Miss _ 1st check other blocks for matches in next clock cycle
Accuracy 85%
Drawback: CPU pipeline is hard if hit takes 1 or 2 cycles
- Used for instruction caches vs. data caches
Third optimization: Trace Cache
Find more instruction level parallelism?
How to avoid translation from x86 to microops?
Trace cache in Pentium 4
1. Dynamic traces of the executed instructions vs. static sequences of instructions
as determined by layout in memory
Built-in branch predictor
2. Cache the micro-ops vs. x86 instructions
Decode/translate from x86 to micro-ops on trace cache miss
+ 1. _ better utilize long blocks (dont exit in middle of block, dont enter
at label in middle of block)
- 1. _ complicated address mapping since addresses no longer aligned to
powerof2 multiples of word size
- 1. _ instructions may appear multiple times in multiple dynamic traces
due to different branch outcomes
Fourth optimization: pipelined cache access to increase bandwidth
Pipeline cache access to maintain bandwidth, but higher latency
Instruction cache access pipeline stages:
1: Pentium
2: Pentium Pro through Pentium III
4: Pentium 4
- _ greater penalty on mispredicted branches
- _ more clock cycles between the issue of the load and the use of the data
Fifth optimization: Increasing Cache Bandwidth Non-Blocking Caches
Department of CSE, SJBIT
Page 96
10CS74
FP programs on average: AMAT= 0.68 -> 0.52 -> 0.34 -> 0.26
Int programs on average: AMAT= 0.24 -> 0.20 -> 0.19 -> 0.19
8 KB Data Cache, Direct Mapped, 32B block, 16 cycle miss, SPEC 92
Page 97
10CS74
Page 98
10CS74
Critical Word FirstRequest the missed word first from memory and
send it to the CPU as soon as it arrives; let the CPU continue execution while
filling the rest of the words in the block
Long blocks more popular today _ Critical Word 1st Widely used
Eight optimization: Merging Write Buffer to Reduce Miss Penalty Write buffer to allow processor to continue while waiting to write to memory
If buffer contains modified blocks, the addresses can be checked to see if
address of new data matches the address of a valid write buffer entry
If so, new data are combined with that entry
Increases block size of write for write-through cache of writes to sequential
words, bytes since multiword writes more efficient to memory
The Sun T1 (Niagara) processor, among many others, uses write merging
Page 99
10CS74
Page 100
10CS74
Page 101
10CS74
UNIT - VII
MEMORY HIERARCHY DESIGN:
Introduction
Advanced optimizations of Cache performance
Memory technology and optimizations
Protection
Virtual memory and virtual machines.
6 Hours
Page 102
10CS74
UNIT VII
MEMORY HIERARCHY DESIGN
AMAT and Processor Performance
AMAT = Average Memory Access Time
Miss-oriented Approach to Memory Access
CPIExec includes ALU and Memory instructions
Separating out Memory component entirely
CPIALUOps does not include memory instructions
Summary: Caches
The Principle of Locality:
Program access a relatively small portion of the address space at any instant of
time.
Temporal Locality OR Spatial Locality:
Three Major Categories of Cache Misses:
Compulsory Misses: sad facts of life. Example: cold start misses.
Capacity Misses: increase cache size
Conflict Misses: increase cache size and/or associativity
Where Misses Come From?
Classifying Misses: 3 Cs
Compulsory The first access to a block is not in the cache,
Also called cold start misses or first reference misses.
(Misses in even an Infinite Cache)
Capacity If the cache cannot contain all the blocks needed during execution
of a program,
Conflict If block-placement strategy is set associative or direct mapped,
conflict misses (in addition to compulsory & capacity misses) will occur because
a block can be discarded and later retrieved if too many blocks map to its set.
(Misses in N-way Associative, Size X Cache)
More recent, 4th C:
Coherence Misses caused by cache coherence
Page 103
10CS74
Write Policy:
Write Through: needs a write buffer.
Write Back: control can be complex
Summary:
The Cache Design Space
Several interacting dimensions
cache size
block size
associativity
replacement policy
write-through vs write-back
The optimal choice is a compromise
Simplicity often wins
Page 104
10CS74
Cache Organization?
Assume total cache size not changed
What happens if: Which of 3Cs is obviously affected?
Change Block Size
Change Cache Size
Change Cache Internal Organization
Change Associativity
Change Compiler
Page 105
10CS74
Page 106
10CS74
Miss - 1st check other blocks for matches in next clock cycle
3. Fast Hit times via Trace Cache
Find more instruction level parallelism?
How avoid translation from x86 to microops?- Trace cache in Pentium 4
1. Dynamic traces of the executed instructions vs. static sequence of instructions
as determined by layout in memory
Built-in branch predictor
2. Cache the micro-ops vs. x86 instructions - Decode/translate from x86 to
micro-ops on trace cache miss
+ 1. better utilize long blocks (dont exit in middle of block, dont enter at label in
middle of block)
- 1. complicated address mapping since addresses no longer aligned to power-of-2
multiples of word size
- 1. instructions may appear multiple times in multiple dynamic traces due to different
branch outcomes
4: Increasing Cache Bandwidth by Pipelining
Pipeline cache access to maintain bandwidth, but higher latency
Instruction cache access pipeline stages:
1: Pentium
2: Pentium Pro through Pentium III
4: Pentium 4
- greater penalty on mispredicted branches
- more clock cycles between the issue of the load and the use of the data
Page 107
10CS74
Banking works best when accesses naturally spread themselves across banks
mapping of addresses to banks affects behavior of memory system
Page 108
10CS74
Page 109
10CS74
Page 110
10CS74
White:
Merging Arrays
Motivation: some programs reference multiple arrays in the same dimension with the
same indices at the same time =>
these accesses can interfere with each other,leading to conflict misses
Solution: combine these independent matrices into a single compound array, so that a
single cache block can contain the desired elements
Merging Arrays Example
Page 111
10CS74
Loop Fusion
Some programs have separate sections of code that access with the same
loops, performing different computations on the common data
Solution:
Fuse the code into a single loop =>
the data that are fetched into the cache can be used repeatedly before being
swapped out => reducing misses via improved temporal locality
Loop Fusion Example
Summary of Compiler Optimizations- to Reduce Cache Misses (by hand)
10. Reducing Misses by Hardware Prefetching of Instructions & Data
Prefetching relies on having extra memory bandwidth that can be used without
penalty
Instruction Prefetching
Typically, CPU fetches 2 blocks on a miss: the requested block and the next
consecutive block.
Requested block is placed in instruction cache when it returns, and prefetched
block is placed into instruction stream buffer
Data Prefetching
Pentium 4 can prefetch data into L2 cache from up to 8 streams from 8 different
4 KB pages
Prefetching invoked if 2 successive L2 cache misses to a page,if distance
between those cache blocks is < 256 bytes
11. Reducing Misses by Software Prefetching Data
Data Prefetch
Load data into register (HP PA-RISC loads)
Cache Prefetch: load into cache
(MIPS IV, PowerPC, SPARC v. 9)
Special prefetching instructions cannot cause faults;
a form of speculative execution
Issuing Prefetch Instructions takes time
Is cost of prefetch issues < savings in reduced misses?
Higher superscalar reduces difficulty of issue bandwi
Compiler Optimization vs. Memory Hierarchy Search
Compiler tries to figure out memory hierarchy optimizations
New approach: Auto-tuners 1st run variations of program on computer to find
best combinations of optimizations (blocking, padding, ) and algorithms, then produce
C code to be compiled for that computer
Auto-tuner targeted to numerical method
Page 112
10CS74
Page 113
10CS74
Non-volatile, magnetic
Lost to 4 Kbit DRAM (today using 512Mbit DRAM)
Access time 750 ns, cycle time 1500-3000 ns
DRAM logical organization (4 Mbit)
Quest for DRAM Performance
1. Fast Page mode
Add timing signals that allow repeated accesses to row buffer without
nother row access time
Such a buffer comes naturally, as each array will buffer 1024 to 2048
bits for each access
2. Synchronous DRAM (SDRAM)
Add a clock signal to DRAM interface, so that the repeated transfers
would not bear overhead to synchronize with DRAM controller
3. Double Data Rate (DDR SDRAM)
Transfer data on both the rising edge and falling edge of the DRAM
clock signal I doubling the peak data rate
DDR2 lowers power by dropping the voltage from 2.5 to 1.8 volts +
offers higher clock rates: up to 400 MHz
DDR3 drops to 1.5 volts + higher clock rates: up to 800 MHz
4.Improved Bandwidth, not Latency
DRAM name based on Peak Chip Transfers / Sec
DIMM name based on Peak DIMM MBytes / Sec
Need for Error Correction!
Motivation:
Failures/time proportional to number of bits!
As DRAM cells shrink, more vulnerable
Went through period in which failure rate was low enough without error
correction that people didnt do correction
DRAM banks too large now
Servers always corrected memory systems
Basic idea: add redundancy through parity bits
Common configuration: Random error correction
SEC-DED (single error correct, double error detect)
One example: 64 data bits + 8 parity bits (11% overhead)
Really want to handle failures of physical components as well
Organization is multiple DRAMs/DIMM, multiple DIMMs
Want to recover from failed DRAM and failed DIMM!
Chip kill handle failures width of single DRAM chip
DRAM Technology
Semiconductor Dynamic Random Access Memory
Emphasize on cost per bit and capacity
Multiplex address lines cutting # of address pins in half
Row access strobe (RAS) first, then column access strobe (CAS)
Memory as a 2D matrix rows go to a buffer
Subsequent CAS selects subrow
Department of CSE, SJBIT
Page 114
10CS74
RAS improvement
SRAM Technology
Cache uses SRAM: Static Random Access Memory
SRAM uses six transistors per bit to prevent the information from being disturbed when
read
_no need to refresh
SRAM needs only minimal power to retain the charge in
the standby mode _ good for embedded applications
No difference between access time and cycle time for
SRAM
Emphasize on speed and capacity
SRAM address lines are not multiplexed
SRAM speed is 8 to 16x that of DRAM
Improving Memory Performance
in a Standard DRAM Chip
Fast page mode: time signals that allow repeated accesses to buffer without another row
access time
Synchronous RAM (SDRAM): add a clock signal to DRAM interface, so that the
repeated transfer would not bear overhead to synchronize with the controller
Asynchronous DRAM involves overhead to sync with controller
Peak speed per memory module 8001200MB/sec in 2001
Double data rate (DDR): transfer data on both the rising edge and falling edge of
DRAM clock signal
Peak speed per memory module 16002400MB/sec in 2001
Page 115
10CS74
Protection:
Virtual Memory and Virtual Machines
Slide Sources: Based on Computer Architecture by Hennessy/Patterson.
Supplemented from various freely downloadable sources
Security and Privacy
Innovations in Computer Architecture and System software
Protection through Virtual Memory
Protection from Virtual Machines
Architectural requirements
Performance
Protection via Virtual Memory
Processes
Running program
Environment (state) needed to continue running it
Protect Processes from each other
Page based virtual memory including TLB which caches page table
entries Example: Segmentation and paging in 80x86
Processes share hardware without interfering with each other
Provide User Process and Kernel Process
Readable portion of Processor state:
User supervisor mode bit
Exception enable/disable bit
Memory protection information
Department of CSE, SJBIT
Page 116
10CS74
Page 117
10CS74
Page 118
10CS74
Page 119
10CS74
UNIT - 8
HARDWARE AND SOFTWARE FOR VLIW AND EPIC:
Introduction
Exploiting Instruction-Level Parallelism Statically
Detecting and Enhancing Loop-Level Parallelism
Scheduling and Structuring Code for Parallelism
Hardware Support for Exposing Parallelism
Predicated Instructions; Hardware Support for Compiler Speculation
The Intel IA-64 Architecture and Itanium Processor; Conclusions.
7 Hours
Page 120
10CS74
UNIT VIII
HARDWARE AND SOFTWARE FOR VLIW AND EPIC
Loop Level Parallelism- Detection and Enhancement
Static Exploitation of ILP
Use compiler support for increasing parallelism
Supported by hardware
Techniques for eliminating some types of dependences
Applied at compile time (no run time support)
Finding parallelism
Reducing control and data dependencies
Using speculation
Unrolling Loops High-level
for (i=1000; i>0; i=i-1) x[i] = x[i] + s;
C equivalent of unrolling to block four iterations into one:
for (i=250; i>0; i=i-1)
{
x[4*i] = x[4*i] + s;
x[4*i-1] = x[4*i-1] + s;
x[4*i-2] = x[4*i-2] + s;
x[4*i-3] = x[4*i-3] + s;
}
Enhancing Loop-Level Parallelism
Consider the previous running example:
for (i=1000; i>0; i=i-1) x[i] = x[i] + s;
there is no loop-carried dependence where data used in a later iteration depends on
data produced in an earlier one
in other words, all iterations could (conceptually) be executed in parallel
Contrast with the following loop:
for (i=1; i<=100; i=i+1) { A[i+1] = A[i] + C[i]; /* S1 */
B[i+1] = B[i] + A[i+1]; /* S2 */ }
what are the dependences?
A Loop with Dependences
For the loop:
for (i=1; i<=100; i=i+1) { A[i+1] = A[i] + C[i]; /* S1 */
B[i+1] = B[i] + A[i+1]; /* S2 */ }
what are the dependences?
There are two different dependences:
loop-carried: (prevents parallel operation of iterations)
S1 computes A[i+1] using value of A[i] computed in previous iteration
S2 computes B[i+1] using value of B[i] computed in previous iteration
not loop-carried: (parallel operation of iterations is ok)
Department of CSE, SJBIT
Page 121
10CS74
Page 122
10CS74
Thus:
axj+b=cxk+d
The Greatest Common Divisor (GCD) Test
If a loop carried dependence exists, then :
GCD(c, a) must divide (d-b)
The GCD test is sufficient to guarantee no loop carried dependence
However there are cases where GCD test succeeds but no dependence exits because GCD
test does not take loop bounds into account
Example:
for (i=1; i<=100; i=i+1) {
x[2*i+3] = x[2*i] * 5.0;
}
a=2b=3c=2d=0
GCD(a, c) = 2
d - b = -3
2 does not divide -3 _ No loop carried dependence possible.
Example- Loop Iterations to be Independent
Finding multiple types of dependences
for (i=1; i<=100; i=i+1) {
Y[i] = X[i] / c; /* S1 */
X[i] = X[i] + c; /* S2 */
Z[i] = Y[i] + c; /* S3 */
Y[i] = c - Y[i]; /* S4 */ }
Answer The following dependences exist among the four statements:
1. There are true dependences from S1 to S3 and from S1 to S4 because of Y[i]. These
are not loop carried, so they do not prevent the loop from being considered parallel.
These dependences will force S3 and S4 to wait for S1 to complete.
2. There is an antidependence from S1 to S2, based on X[i].
3. There is an antidependence from S3 to S4 for Y[i].
4. There is an output dependence from S1 to S4, based on Y[i].
Eliminating false dependencies
The following version of the loop eliminates these false (or pseudo) dependences.
for (i=1; i<=100; i=i+1 {
/* Y renamed to T to remove output dependence */
T[i] = X[i] / c;
/* X renamed to X1 to remove antidependence */
X1[i] = X[i] + c;
/* Y renamed to T to remove antidependence */
Z[i] = T[i] + c;
Y[i] = c - T[i];
}
Drawback of dependence analysis
When objects are referenced via pointers rather than array indices (but see discussion
Department of CSE, SJBIT
Page 123
10CS74
below)
When array indexing is indirect through another array, which happens with many
representations of sparse arrays
When a dependence may exist for some value of the inputs, but does not exist in
actuality when the code is run since the inputs never take on those values
When an optimization depends on knowing more than just the possibility of a
dependence, but needs to know on which write of a variable does a read of that variable
depend
Points-to analysis
Relies on information from three major sources:
1. Type information, which restricts what a pointer can point to.
2. Information derived when an object is allocated or when the address of an object is
taken, which can be used to restrict what a pointer can point to. For example, if p always
points to an object allocated in a given source line and q never points to that object, then
p and q can never point to the same object.
3. Information derived from pointer assignments. For example, if p may be assigned the
value of q, then p may point to anything q points to.
Eliminating dependent
computations
copy propagation, used to simplify sequences like the following:
DADDUI R1,R2,#4
DADDUI R1,R1,#4
to
DADDUI R1,R2,#8
Tree height reduction
they reduce the height of the tree structure representing a computation, making it wider
but shorter.
Recurrence
Recurrences are expressions whose value on one iteration is given by a function that
depends onthe previous iterations.
sum = sum + x;
sum = sum + x1 + x2 + x3 + x4 + x5;
If unoptimized requires five dependent operations, but it can be rewritten as
sum = ((sum + x1) + (x2 + x3)) + (x4 + x5);
evaluated in only three dependent operations.
Scheduling and Structuring Code for Parallelism
Static Exploitation of ILP
Use compiler support for increasing parallelism
Supported by hardware
Techniques for eliminating some types of dependences
Applied at compile time (no run time support)
Department of CSE, SJBIT
Page 124
10CS74
Finding parallelism
Reducing control and data dependencies
Using speculation
Techniques to increase the amount of ILP
For processor issuing more than one instruction on every clock cycle.
Loop unrolling,
software pipelining,
trace scheduling, and
superblock scheduling
Software pipelining
Symbolic loop unrolling
Benefits of loop unrolling with reduced code size
Instructions in loop body selected from different loop iterations
Increase distance between dependent instructions in
Software pipelined loop
Loop: SD F4,16(R1) #store to v[i]
ADDD F4,F0,F2 #add to v[i-1]
LD F0,0(R1) #load v[i-2]
ADDI R1,R1,-8
BNE R1,R2,Loop
5 cycles/iteration (with dynamic scheduling and renaming)
Need startup/cleanup code
SW pipelining example
Iteration i:
L.D
Department of CSE, SJBIT
F0,0(R1)
Page 125
ADD.D
S.D
Iteration i+1: L.D
ADD.D
S.D
Iteration i+2: L.D
ADD.D
S.D
10CS74
F4,F0,F2
F4,0(R1)
F0,0(R1)
F4,F0,F2
F4,0(R1)
F0,0(R1)
F4,F0,F2
F4,0(R1)
#point to v[n-2]
#load v[n]
#add v[n]
#load v[n-1]
#store to v[i]
#add to v[i-1]
#load v[i-2]
#store v[1]
#add v[0]
#store v[0]
Page 126
10CS74
Advantages
Less code space than conventional unrolling
Loop runs at peak speed during steady state
Overhead only at loop initiation and termination
Complements unrolling
Disadvantages
Hard to overlap long latencies
Unrolling combined with SW pipelining
Requires advanced compiler transformations
Global Code Scheduling
Global code scheduling aims to compact a code fragment with internal control structure
into the shortest possible sequence that preserves the data and control dependences.
Page 127
10CS74
Page 128
10CS74
Trace Scheduling:
Focusing on the Critical Path
Page 129
10CS74
Trace Scheduling,
Superblocks and Predicated Instructions
For processor issuing more than one instruction on every clock cycle.
Loop unrolling,
software pipelining,
Department of CSE, SJBIT
Page 130
10CS74
Trace Selection
Likely sequence of basic blocks that can be put together
Sequence is called a trace
What can you select?
Loop unrolling generates long traces
Static branch prediction forces some straight-line code behavior
Trace Selection
Page 131
10CS74
(cont.)
Trace Example
If the shaded portion in previous code was frequent path and it was unrolled 4 times : _
Trace exits are jumps off the frequent path
Trace entrances are returns to the trace
Trace Compaction
Squeeze these into smaller number of wide instructions
Move operations as early as it can be in a trace
Pack the instructions into as few wide instructions as possible
Simplifies the decisions concerning global code motion
All branches are viewed as jumps into or out of the trace
Bookkeeping
Cost is assumed to be little
Best used in scientific code with extensive loops
Page 132
10CS74
Superblock Construction
Page 133
10CS74
Tail duplication
Creates a separate block that corresponds to the portion of trace after the entry
When proceeding as per prediction Take the path of superblock code
When exit from
superblock
Residual loop that handles rest of the iterations
Analysis on Superblocks
Reduces the complexity of bookkeeping and scheduling
Unlike the trace approach
Can have larger code size though
Assessing the cost of duplication
Compilation process is not simple any more
H/W Support : Conditional Execution
Also known as Predicated Execution
Enhancement to instruction set
Can be used to eliminate branches
All control dependences are converted to data dependences
Instruction refers to a condition
Evaluated as part of the execution
True?
Executed normally
False?
Execution continues as if the instruction were a no-op
Example :
Conditional move between registers
Example
if (A==0)
S = T;
Straightforward Code
BNEZ R1,
L;
ADDU R2, R3, R0
L:
Conditional Code
CMOVZ R2, R3, R1
Annulled if R1 is not 0
Conditional Instruction
Can convert control to data dependence
In vector computing, its called if conversion.
Traditionally, in a pipelined system
Dependence has to be resolved closer to front of pipeline
For conditional execution
Dependence is resolved at end of pipeline, closer to the register write
Page 134
10CS74
Another example
A = abs(B)
if (B < 0)
A = -B;
else
A = B;
Two conditional moves
One unconditional and one conditional move
The branch condition has moved into the
instruction
Control dependence becomes data dependence
Assume : Two issues, one to ALU and one to memory; or branch by itself
Wastes a memory operation slot in second cycle
Can incur a data dependence stall if branch is not taken
R9 depends on R8
Predicated Execution
Assume : LWC is predicated load and loads if third operand is not 0
Page 135
10CS74
Page 136
10CS74
Page 137
10CS74
Page 138
10CS74
Page 139
10CS74
Page 140
10CS74
Page 141
10CS74
EPIC
EPIC Overview
Builds on VLIW
Redefines instruction format
Instruction coding tells CPU how to process data
Very compiler dependent
Predicated execution
EPIC pros and cons
EPIC Pros:
Compiler has more time to spend with code
Time spent by compiler is a one-time cost
Reduces circuit complexity
Chip Layout
Itanium Architecture Diagram
Page 142
10CS74
Itanium Specs
4 Integer ALU's
4 multimedia ALU's
2 Extended Precision FP Units
2 Single Precision FP units
2 Load or Store Units
3 Branch Units
10 Stage 6 Wide Pipeline
32k L1 Cache
96K L2 Cache
4MB L3 Cache(extern)
800Mhz Clock
Intel Itanium
800 MHz
10 stage pipeline
Can issue 6 instructions (2 bundles) per cycle
4 Integer, 4 Floating Point, 4 Multimedia, 2 Memory, 3 Branch Units
32 KB L1, 96 KB L2, 4 MB L3 caches
2.1 GB/s memory bandwidth
Page 143
10CS74
Itanium2 Specs
6 Integer ALU's
6 multimedia ALU's
2 Extended Precision FP Units
2 Single Precision FP units
2 Load and Store Units
3 Branch Units
8 Stage 6 Wide Pipeline
32k L1 Cache
256K L2 Cache
3MB L3 Cache(on die)
1Ghz Clock initially
Up to 1.66Ghz on Montvale
Itanium2 Improvements
Initially a 180nm process
Increased to 130nm in 2003
Further increased to 90nm in 2007
Improved Thermal Management
Clock Speed increased to 1.0Ghz
Bus Speed Increase from 266Mhz to 400Mhz
Page 144
10CS74
Page 145
10CS74
On function call, machine shifts register window such that previous output registers
become new locals starting at r32
Page 146
10CS74
Page 147
10CS74
Page 148
10CS74
Page 149
10CS74
Instruction Encoding
Each instruction includes the opcode and three operands
Each instructions holds the identifier for a corresponding Predicate Register
Each bundle contains 3 independent instructions
Each instruction is 41 bits wide
Each bundle also holds a 5 bit template field
Distributing Responsibility
_ILP Instruction Groups
_Control flow parallelism
Parallel comparison
Multiway branches
_Influencing dynamic events
Provides an extensive set of hints that the compiler uses to tell the hardware about likely
branch behavior (taken or not taken, amount to fetch at branch target) and memory
operations (in what level of the memory hierarchy to cache data).
Page 150
10CS74
Page 151
10CS74
Control speculation
_ Not all the branches can be removed using predication.
_ Loads have longer latency than most instructions and tend to start timecritical
chains of instructions
_ Constraints on code motion on loads limit parallelism
_ Non-EPIC architectures constrain motion of load instruction
_ IA-64: Speculative loads, can safely schedule load instruction before one or
more prior branches
Control Speculation
_Exceptions are handled by setting NaT (Not a Thing) in target register
_Check instruction-branch to fix-up code if NaT flag set
_Fix-up code: generated by compiler, handles exceptions
_NaT bit propagates in execution (almost all IA-64 instructions)
_NaT propagation reduces required check points
Speculative Load
_ Load instruction (ld.s) can be moved outside of a basic block even if branch target
is not known
_ Speculative loads does not produce exception - it sets the NaT
_ Check instruction (chk.s) will jump to fix-up code if NaT is set
Data Speculation
Department of CSE, SJBIT
Page 152
10CS74
_ The compiler may not be able to determine the location in memory being
referenced (pointers)
_ Want to move calculations ahead of a possible memory dependency
_ Traditionally, given a store followed by a load, if the compiler cannot
determine if the addresses will be equal, the load cannot be moved ahead of the
store.
_ IA-64: allows compiler to schedule a load before one or more stores
_ Use advance load (ld.a) and check (chk.a) to implement
_ ALAT (Advanced Load Address Table) records target register, memory
address accessed, and access size
Data Speculation
1. Allows for loads to be moved ahead of stores even if the compiler is unsure if
addresses are the same
2. A speculative load generates an entry in the ALAT
3. A store removes every entry in the ALAT that have the same address
4. Check instruction will branch to fix-up if the given address is not in the ALAT
Page 153
10CS74
Register Model
_128 General and Floating Point Registers
_32 always available, 96 on stack
_As functions are called, compiler allocates a specific number of local and output
registers to use in the function by using register allocation instruction Alloc.
Department of CSE, SJBIT
Page 154
10CS74
On function call, machine shifts register window such that previous output registers
become new locals starting at r32
Software Pipelining
_loops generally encompass a large portion of a programs execution time, so its
important to expose as much loop-level parallelism as possible.
_Overlapping one loop iteration with the next can often increase the parallelism.
Software Pipelining
Page 155
10CS74
Page 156