Cse Viii Advanced Computer Architectures 06CS81 Notes PDF
Cse Viii Advanced Computer Architectures 06CS81 Notes PDF
Cse Viii Advanced Computer Architectures 06CS81 Notes PDF
m
Marks
PART - A
o
UNIT - 1
s.c
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
c
vtu
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
w.
Compiler Techniques for exposing ILP; Reducing Branch costs with prediction;
Overcoming Data hazards with Dynamic scheduling; Hardware-based speculation.
7 Hours
UNIT - 4
ww
PART - B
UNIT - 5
Dept of CSE,SJBIT,Bangalore 1
Advanced Computer Architecture 06CS81
7 Hours
m
UNIT - 6
REVIEW OF MEMORY HIERARCHY: Introduction; Cache performance; Cache
Optimizations, Virtual memory.
o
6 Hours
s.c
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
c
HARDWARE AND SOFTWARE FOR VLIW AND EPIC: Introduction: Exploiting
vtu
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
w.
TEXT BOOK:
REFERENCE BOOKS:
Dept of CSE,SJBIT,Bangalore 2
Advanced Computer Architecture 06CS81
Table of Contents
1 Syllabus 1-2
m
2 Unit-I 4-17
o
3 Unit-II 18-32
s.c
4 Unit-III 33-48
5 Unit-IV 49-67
6
c Unit-V 68-87
vtu
7 Unit-VI 88-99
8 Unit-VII 100-116
w.
9 Unit-VIII 117-154
ww
Dept of CSE,SJBIT,Bangalore 3
Advanced Computer Architecture 06CS81
PART - A
UNIT - 1
m
Introduction; Classes of computers
o
Trends in Technology, power in Integrated Circuits and cost
s.c
Dependability
Dept of CSE,SJBIT,Bangalore 4
Advanced Computer Architecture 06CS81
UNIT I
m
Introduction
o
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
s.c
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.
In the yearly 1980s, the Reduced Instruction Set Computer (RISC) based
machines focused the attention of designers on two critical performance techniques,
w.
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
ww
over 50%. Since 2002, processor performance improvement has dropped to about 20%
per year due to the following hurdles:
The hurdles signals historic switch from relying solely on ILP to Thread Level
Parallelism (TLP) and Data Level Parallelism (DLP).
Dept of CSE,SJBIT,Bangalore 5
Advanced Computer Architecture 06CS81
o m
c s.c
vtu
Classes of Computers
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
Dept of CSE,SJBIT,Bangalore 6
Advanced Computer Architecture 06CS81
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
m
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:
o
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
s.c
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.
c
•Scalability: as the business grows, the server may have to provide more
vtu
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
w.
Dept of CSE,SJBIT,Bangalore 7
Advanced Computer Architecture 06CS81
m
ISA refers to the actual programmer visible Instruction set. The ISA serves as
boundary between the software and hardware. Th e seven dimensions of the ISA are:
o
Register architectures. The operands are either Registers or Memory locations.
The two popular versions of this class are:
s.c
Register-Memory ISAs : ISA of 80x86, can access memory as part of many
instructions.
Load -Store ISA Eg. ISA of MIPS, can access memory only with Load or
Store instructions.
iii) Addressing modes:Specify the address of a M object apart from register and constant
operands.
MIPS Addressing modes:
•Register mode addressing
•Immediate mode addressing
w.
Dept of CSE,SJBIT,Bangalore 8
Advanced Computer Architecture 06CS81
m
vi) Control flow instructions:All ISAs support:
Conditional & Unconditional Branches
Procedure C alls & Returns MIPS 80x86
• Conditional Branches tests content of Register Condition code bits
o
• Procedure C all JAL CALLF
• Return Address in a R Stack in M
s.c
vii) Encoding an ISA
Fixed Length ISA Variable Length ISA
MIPS 32 Bit long 80x86 (1-18 bytes)
Simplifies decoding Takes less space
c
Number of Registers and number of Addressing modes hav e significant
impact on the length of instruction as the register field and addressing mode field
can appear many times in a single instruction.
vtu
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
w.
IC Logic technology:
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.
Dept of CSE,SJBIT,Bangalore 9
Advanced Computer Architecture 06CS81
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.
m
given time.
Latency or response time is the time between the start and the completion of an
event. (for eg. Millisecond for disk access)
o
c s.c
vtu
w.
ww
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
Dept of CSE,SJBIT,Bangalore 10
Advanced Computer Architecture 06CS81
.
•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.
m
Trends in Power in Integrated Circuits
For CMOS chips, the dominant source of energy consumption is due to switching
o
transistor, also called as Dynamic power and is given b y the following equation.
s.c
* Frequency switched dynamic
•For mobile devices, energy is the better metric
c
•For a fix ed task, slowing clock rate (frequency switched) reduces power, but not energy
•Capacitive load a function of number of transistors connected to output and technology,
which determines capacitance of wires and transistors
vtu
•Dropping voltage helps both, so went from 5V down to 1V
•To save energy & dynamic power, most CPUs now turn off clock of inactive modules
•Distributing the power, removing the heat and preventing hot spots have become
increasingly difficult challenges.
• The leakage current flows even when a transistor is off. Therefore static power is
equally important.
w.
•In 2006, goal for leakage is 25% of total power consumption; high performance designs
at 40%
•Very low power systems even gate voltage to inactive modules to control loss due to
leakage
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
Dept of CSE,SJBIT,Bangalore 11
Advanced Computer Architecture 06CS81
Cost of IC = Cost of [die+ testing die+ Packaging and final test] / (Final test yoeld)
m
Cost of die = Cost of wafer/ (Die per wafer x Die yield)
The number of dies per wafer is approximately the area of the wafer divided by the area
of the die.
o
Die per wafer = [_ * (Wafer Dia/2)2/Die area]-[_* wafer dia/_(2*Die area)]
s.c
The first term is the ratio of wafer area to die area and the second term compensates for
the rectangular dies near the periphery of round wafers(as shown in figure).
c
vtu
w.
ww
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.
Dept of CSE,SJBIT,Bangalore 12
Advanced Computer Architecture 06CS81
The two main measures of Dependability are Module Reliability and Module
m
Availability. Module reliability is a measure of continuous service accomplishment (or
time to failure) from a reference initial instant.
1. Mean Time To Failure (MTTF) measures Reliability
2. Failures In Time (FIT) = 1/MTTF, the rate of failures
• Traditionally reported as failures per billion hours of operation
o
• Mean Time To Repair (MTTR) measures Service Interruption
– Mean Time Between Failures (MTBF) = MTTF+MTTR
s.c
• Module availability measures service as alternate between the 2 states of
accomplishment and interruption (number between 0 and 1, e.g. 0.9)
• Module availability = MTTF / ( MTTF + MTTR)
Performance: c
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
vtu
Throughput.
Computer user says that computer is faster when a program runs in less time.
w.
ww
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.
Benchmarks
Dept of CSE,SJBIT,Bangalore 13
Advanced Computer Architecture 06CS81
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.,
m
• 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.
o
• Source code modifications are allowed, as long as the modified version produces
the same output.
s.c
• 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
c
– SPECCPU2006 announced in Spring 2006.
SPECSFS (NFS file server) and SPECWeb (WebServer) added as server
benchmarks
vtu
• 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
w.
Dept of CSE,SJBIT,Bangalore 14
Advanced Computer Architecture 06CS81
o m
• Note : when comparing 2 computers as a ratio, execution times on the reference
computer drop out, so choice of reference computer is irrelevant.
s.c
Quantitative Principles of Computer Design
While designing the computer, the advantage of the following points can be
exploited to enhance the performance.
* Parallelism: is one of most important methods for improving performance.
c
- One of the simplest ways to do this is through pipelining ie, to over lap the
instruction Execution to reduce the total time to complete an instruction
sequence.
vtu
- Parallelism can also be exploited at the level of detailed digital design.
- Set- associative caches use multiple banks of memory that are typically searched
n parallel. Carry look ahead which uses parallelism to speed the process of
computing.
* Principle of locality: program tends to reuse data and instructions they have used
recently. The rule of thumb is that program spends 90 % of its execution time in only
w.
10% of the code. With reasonable good accuracy, prediction can be made to find what
instruction and data the program will use in the near future based on its accesses in the
recent past.
* Focus on the common case while making a design trade off, favor the frequent case
ww
over the infrequent case. This principle applies when determining how to spend
resources, since the impact of the improvement is higher if the occurrence is frequent.
Amdahl’s Law: Amdahl’s law is used to find the performance gain that can be obtained
by improving some portion or a functional unit of a computer Amdahl’s law defines the
speedup that can be gained by using a particular feature.
Speedup is the ratio of performance for entire task without using the enhancement
when possible to the performance for entire task without using the enhancement.
Execution time is the reciprocal of performance. Alternatively, speedup is defined as thee
ratio of execution time for entire task without using the enhancement to the execution
time for entair task using the enhancement when possible.
Speedup from some enhancement depends an two factors:
Dept of CSE,SJBIT,Bangalore 15
Advanced Computer Architecture 06CS81
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
m
enhanced is the time of the original mode over the time of the enhanced mode and is always
greater then 1.
o
s.c
The Processor performance Equation:
Processor is connected with a clock running at constant rate. These discrete time events
are called clock ticks or clock cycle.
CPU time for a program can be evaluated:
c
vtu
w.
ww
Dept of CSE,SJBIT,Bangalore 16
Advanced Computer Architecture 06CS81
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
o m
c s.c
vtu
w.
ww
Dept of CSE,SJBIT,Bangalore 17
Advanced Computer Architecture 06CS81
UNIT - 2
m
PIPELINING:
Introduction
o
Pipeline hazards
Implementation of pipeline
s.c
What makes pipelining hard to implement?
6 Hours
c
vtu
w.
ww
Dept of CSE,SJBIT,Bangalore 18
Advanced Computer Architecture 06CS81
UNIT II
m
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
o
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:
s.c
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
c
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
vtu
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.
Send the content of program count (PC) to memory and fetch the current
instruction from memory to update the PC.
ww
Decode the instruction and access the register file. Decoding is done in parallel
with reading registers, which is possible because the register specifies are at a fixed
location in a RISC architecture. This corresponds to fixed field decoding. In addition it
involves:
- Perform equality test on the register as they are read for a possible branch.
- Sign-extend the offset field of the instruction in case it is needed.
- Compute the possible branch target address.
Dept of CSE,SJBIT,Bangalore 19
Advanced Computer Architecture 06CS81
The ALU operates on the operands prepared in the previous cycle and performs
one of the following function defending on the instruction type.
m
* 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
o
immediate.
s.c
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.
The execution of the instruction comprising of the above subtask can be pipelined. Each
of the clock cycles from the previous section becomes a pipe stage – a cycle in the
pipeline. A new instruction can be started on each clock cycle which results in the
execution pattern shown figure 2.1. Though each instruction takes 5 clock cycles to
ww
complete, during each clock cycle the hardware will initiate a new instruction and will be
executing some part of the five different instructions as illustrated in figure 2.1.
Dept of CSE,SJBIT,Bangalore 20
Advanced Computer Architecture 06CS81
m
Each stage of the pipeline must be independent of the other stages. Also, two different
o
operations can’t 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
s.c
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.
c
• 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.
vtu
• 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.
w.
ww
Dept of CSE,SJBIT,Bangalore 21
Advanced Computer Architecture 06CS81
o m
s.c
Buffers or registers are introduced between successive stages of the pipeline so that at the
c
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.
vtu
w.
ww
Dept of CSE,SJBIT,Bangalore 22
Advanced Computer Architecture 06CS81
o m
s.c
Basic Performance issues in Pipelining
c
Pipelining increases the CPU instruction throughput but, it does not reduce the
executiontime of an individual instruction. In fact, the pipelining increases the execution
time of each instruction due to overhead in the control of the pipeline. Pipeline overhead
vtu
arises from the combination of register delays and clock skew. Imbalance among the pipe
stages reduces the performance since the clock can run no faster than the time needed for
the slowest pipeline stage.
w.
ww
Dept of CSE,SJBIT,Bangalore 23
Advanced Computer Architecture 06CS81
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
m
instruction stream fromk executing during its designated clock cycle. Hazards will reduce
the pipeline performance.
o
A stall causes the pipeline performance to degrade from ideal performance. Performance
improvement from pipelining is obtained from:
c s.c
vtu
Assume that,
i) cycle time overhead of pipeline is ignored
ii) stages are balanced
w.
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,
Dept of CSE,SJBIT,Bangalore 24
Advanced Computer Architecture 06CS81
m
Therefore,
Speedup = Depth of the pipeline.
Types of hazard
o
Three types hazards are:
1. Structural hazard
s.c
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
c
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
vtu
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.
w.
ww
Dept of CSE,SJBIT,Bangalore 25
Advanced Computer Architecture 06CS81
o m
c s.c
vtu
Pipeline stall is commonly called Pipeline bubble or just simply bubble
w.
Data Hazard
Consider the pipelined execution of the following instruction sequence (Timing diagram
shown in figure 2.6)
ww
Dept of CSE,SJBIT,Bangalore 26
Advanced Computer Architecture 06CS81
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
m
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.
o
The DADD instruction will produce the value of R! at the end of clock cycle 3. DSUB
instruction requires this value only during the clock cycle 4. If the result can be moved
s.c
from the pipeline register where the DADD store it to the point (input of LAU) where
DSUB needs it, then the need for a stall can be avoided. Using a simple hardware
technique called Data Forwarding or Bypassing or short circuiting, data can be made
available from the output of the ALU to the point where it is required (input of LAU) at
the beginning of immediate next clock cycle.
Forwarding works as follows:
c
i) The output of ALU from EX/MEM and MEM/WB pipeline register is always
feedback to the ALU inputs.
vtu
ii) If the Forwarding hardware detects that the previous ALU output serves as the
source for the current ALU operations, control logic selects the forwarded result
as the input rather than the value read from the register file. Forwarded results are
required not only from the immediate previous instruction, but also from an instruction
that started 2 cycles earlier. The result of ith instruction Is required to be forwarded to
(i+2)th instruction also. Forwarding can be generalized to include passing a result directly
to the functional unit that requires it.
w.
LD R1, 0(R2)
DADD R3, R1, R4
AND R5, R1, R6
ww
OR R7, R1, R8
The pipelined data path for these instructions is shown in the timing diagram (figure 2.7)
Dept of CSE,SJBIT,Bangalore 27
Advanced Computer Architecture 06CS81
o m
c s.c
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
vtu
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
w.
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.
ww
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
Dept of CSE,SJBIT,Bangalore 28
Advanced Computer Architecture 06CS81
There are many methods for dealing with the pipeline stalls caused by branch
delay
1. Freeze or Flush the pipeline, holding or deleting any instructions after the
ranch until the branch destination is known. It is a simple scheme and branch penalty is
m
fixed and cannot be reduced by software
2. Treat every branch as not taken, simply allowing the hardware to continue as if
the branch were not to executed. Care must be taken not to change the processor
state until the branch outcome is known.
Instructions were fetched as if the branch were a normal instruction. If the branch
o
is taken, it is necessary to turn the fetched instruction in to a no-of instruction and restart
the fetch at the target address. Figure 2.8 shows the timing diagram of both the situations.
c s.c
vtu
w.
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
ww
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
Dept of CSE,SJBIT,Bangalore 29
Advanced Computer Architecture 06CS81
o m
s.c
The limitations on delayed branch arise from
i) Restrictions on the instructions that are scheduled in to delay slots.
not taken.
c
ii) Ability to predict at compiler time whether a branch is likely to be taken or
Dept of CSE,SJBIT,Bangalore 30
Advanced Computer Architecture 06CS81
m
Types of exceptions:
The term exception is used to cover the terms interrupt, fault and exception.
o
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
s.c
that determine what action is needed corresponding to that exception.
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
c
caused by devices external to the CPU and memory such events are handled after the
completion of the current instruction.
vtu
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
w.
Exception that occur within instruction are usually synchronous, since the
instruction triggers the exception. It is harder to implement exceptions that occur
withininstructions than those between instructions, since the instruction must be
stopped and restarted. Asynchronous exceptions that occurs within instructions arise from
catastrophic situations and always causes program termination.
Dept of CSE,SJBIT,Bangalore 31
Advanced Computer Architecture 06CS81
m
sequential successors and begin their execution in the normal fashion. 11) Restarting is
usually implemented by saving the PC of the instruction at which to restart. Pipeline
control can take the following steps to save the pipeline state safely.
i) Force a trap instruction in to the pipeline on the next IF
ii) Until the trap is taken, turn off all writes for the faulting instruction and for all
o
instructions that follow in pipeline. This prevents any state changes for instructions that
will not be completed before the exception is handled.
s.c
iii) After the exception – handling routine receives control, it immediately saves
the PC of the faulting instruction. This value will be used to return from the exception
later.
NOTE:
1. with pipelining multiple exceptions may occur in the same clock cycle because
c
there are multiple instructions in execution.
2 Handling the exception becomes still more complicated when the instructions are
allowed to execute in out of order fashion.
vtu
w.
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.
ww
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.
Dept of CSE,SJBIT,Bangalore 32
Advanced Computer Architecture 06CS81
Decoding is done in concurrent with reading register. MIPS ISA has fixed length
Instructions. Hence, these fields are at fixed locations.
m
* Memory reference:
o
Operation: ALU adds the operands to compute the effective address and places
the result in to the register ALU output.
Register – Register ALU instruction:
s.c
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:
c
vtu
Operation: the content of register A and register Imm are operated (function Op) and
result is placed in temporary register ALU output.
*. Branch:
w.
ww
Dept of CSE,SJBIT,Bangalore 33
Advanced Computer Architecture 06CS81
UNIT - 3
m
Basic Compiler Techniques for exposing ILP
o
Overcoming Data hazards with Dynamic scheduling
s.c
Hardware-based speculation.
7 Hours
c
vtu
w.
ww
Dept of CSE,SJBIT,Bangalore 34
Advanced Computer Architecture 06CS81
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.
m
i) Hardware based approach: An approach that relies on hardware to help
discover and exploit the parallelism dynamically. Intel Pentium series which
has dominated in the market) uses this approach.
o
ii) Software based approach: An approach that relies on software technology to
find parallelism statically at compile time. This approach has limited use in
s.c
scientific or application specific environment. Static approach of exploiting
ILP is found in Intel Itanium.
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:
c
Pipeline CPI= Ideal Pipeline CPI + Structural stalls + Data hazard stalls + Control stalls
vtu
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
w.
Basic Blocks.
Dept of CSE,SJBIT,Bangalore 35
Advanced Computer Architecture 06CS81
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.
m
Data Dependency and Hazard
o
order.
There are three different types dependences.
s.c
• Data Dependences (True Data Dependency)
• Name Dependences
• Control Dependences
Data Dependences
c
An instruction j is data dependant on instruction i if either of the following holds:
i) Instruction i produces a result that may be used by instruction j
Eg1: i: L.D F0, 0(R1)
vtu
j: ADD.D F4, F0, F2
ith instruction is loading the data into the F0 and jth instruction use F0 as one the
operand. Hence, jth instruction is data dependant on ith instruction.
Eg2: DADD R1, R2, R3
DSUB R4, R1, R5
instruction i
Eg: L.D F4, 0(R1)
MUL.D F0, F4, F6
ADD.D F5, F0, F7
ww
Dependences are the property of the programs. A Data value may flow between
instructions either through registers or through memory locations. Detecting the data flow
and dependence that occurs through registers is quite straight forward. Dependences that
flow through the memory locations are more difficult to detect. A data dependence
convey three things.
Dept of CSE,SJBIT,Bangalore 36
Advanced Computer Architecture 06CS81
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.
m
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
o
ii) Output dependence: Output Dependence occurs when instructions i and j write to the
s.c
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
c
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.
vtu
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
w.
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.
ww
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
Dept of CSE,SJBIT,Bangalore 37
Advanced Computer Architecture 06CS81
m
To keep a pipe line full, parallelism among instructions must be exploited by
finding sequence of unrelated instructions that can be overlapped in the pipeline. To
avoid a pipeline stall,a dependent instruction must be separated from the source
instruction by the distance in clock cycles equal to the pipeline latency of that source
o
instruction. A compiler’s ability to perform this scheduling depends both on the amount
of ILP available in the program and on the latencies of the functional units in the
s.c
pipeline.
The compiler can increase the amount of available ILP by transferring loops.
for(i=1000; i>0 ;i=i-1)
X[i] = X[i] + s;
We see that this loop is parallel by the noticing that body of the each iteration is
independent. c
The first step is to translate the above segment to MIPS assembly language
vtu
Loop: L.D F0, 0(R1) : F0=array element
ADD.D F4, F0, F2 : add scalar in F2
S.D F4, 0(R1) : store result
DADDUI R1, R1, #-8 : decrement pointer
: 8 Bytes (per DW)
BNE R1, R2, Loop : branch R1! = R2
w.
Without any Scheduling the loop will execute as follows and takes 9 cycles for each
iteration.
1 Loop: L.D F0, 0(R1) ;F0=vector element
2 stall
3 ADD.D F4, F0, F2 ;add scalar in F2
ww
4 stall
5 stall
6 S.D F4, 0(R1) ;store result
7 DADDUI R1, R1,# -8 ;decrement pointer 8B (DW)
8 stall ;assumes can’t forward to branch
9 BNEZ R1, Loop ;branch R1!=zero
We can schedule the loop to obtain only two stalls and reduce the time to 7 cycles:
L.D F0, 0(R1)
Dept of CSE,SJBIT,Bangalore 38
Advanced Computer Architecture 06CS81
Stall
Stall
m
BNE R1, R2, Loop
Loop Unrolling can be used to minimize the number of stalls. Unrolling the body of the
loop by our times, the execution of four iteration can be done in 27 clock cycles or 6.75
o
clock cycles per iteration.
s.c
1 Loop: L.D F0,0(R1)
3 ADD.D F4,F0,F2
7 L.D F6,-8(R1)
9 ADD.D F8,F6,F2
c
vtu
12 S.D -8(R1),F8 ;drop DSUBUI & BNEZ
13 L.D F10,-16(R1)
15 ADD.D F12,F10,F2
w.
19 L.D F14,-24(R1)
21 ADD.D F16,F14,F2
ww
24 S.D -24(R1),F16
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)
Dept of CSE,SJBIT,Bangalore 39
Advanced Computer Architecture 06CS81
m
6 ADD.D F8, F6, F2
o
9 S.D 0(R1), F4
s.c
10 S.D -8(R1), F8
The loop unrolling requires understanding how one instruction depends on another and
how the instructions can be changed or reordered given the dependences:
w.
1. Determine loop unrolling useful by finding that loop iterations were independent
(except for maintenance code)
2. Use different registers to avoid unnecessary constraints forced by using same registers
for different computations
ww
3. Eliminate the extra test and branch instructions and adjust the loop termination and
iteration code
4. Determine that loads and stores in unrolled loop can be interchanged by observing that
loads and stores from different iterations are independent
5. Schedule the code, preserving any dependences needed to yield the same result as the
original code
Dept of CSE,SJBIT,Bangalore 40
Advanced Computer Architecture 06CS81
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:
m
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.
o
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
s.c
the target address.
c
vtu
w.
The graph shows the misprediction rate for set of SPEC benchmark
ww
programs
With deeper pipelines the branch penalty increases when measured in clock
cycles. Similarly, with multiple issue, the branch penalty increases in terms of
instructions lost. Hence, a simple static prediction scheme is inefficient or may not be
efficient in most of the situations. One approach is to look up the address of the
instruction to see if a branch was taken the last time this instruction was executed, and if
so, to begin fetching new instruction from the target address.
Dept of CSE,SJBIT,Bangalore 41
Advanced Computer Architecture 06CS81
m
– There are a small number of important branches in programs which have
dynamic behavior for which dynamic branch prediction performance will be definitely
better compared to static branch prediction.
o
• Branch History Table (BHT) is used to dynamically predict the outcome of the
current branch instruction. Lower bits of PC address index table of 1-bit values
s.c
– Says whether or not branch taken last time
o - No address check
• Problem: in a loop, 1-bit BHT will cause two mispredictions (average is 9 iterations
before exit):
– End of loop case, when it exits instead of looping as before
c
– First time through loop on next time through code, when it predicts exit instead of
looping
vtu
• Simple two bit history table will give better performance. The four different states of 2
bit predictor is shown in the state transition diagram.
w.
ww
Dept of CSE,SJBIT,Bangalore 42
Advanced Computer Architecture 06CS81
• 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
m
– 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.
o
• 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.
s.c
The scheme of the table is shown:
c
vtu
w.
Tournament predictor is a multi level branch predictor and uses n bit saturating counter
ww
to chose between predictors. The predictors used are global predictor and local predictor.
– 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.
Dept of CSE,SJBIT,Bangalore 43
Advanced Computer Architecture 06CS81
o m
s.c
Dynamic Branch Prediction Summary
and Pentium 4
Tomasulu idea:
ww
ROB:
1.The instructions are stored sequentially but we have indicators to say if it is speculative
or completed execution.
2. If completed execution and not speculative and reached head of the queue then we
commit it.
Dept of CSE,SJBIT,Bangalore 44
Advanced Computer Architecture 06CS81
o m
c s.c
vtu
Speculating on Branch Outcomes
Dept of CSE,SJBIT,Bangalore 45
Advanced Computer Architecture 06CS81
3. allow instructions to execute and complete out of order but force them to commit in
m
order
4. Add hardware called the reorder buffer (ROB), with registers to hold the result of
an instruction between completion and commit
o
Tomasulo’s Algorithm with Speculation: Four Stages
s.c
1. Issue: get instruction from Instruction Queue
_ if reservation station and ROB slot free (no structural hazard),
control issues instruction to reservation station and ROB, and sends to reservation
station operand values (or reservation station source for values) as well as
allocated ROB slot number
_
c
2. Execution: operate on operands (EX)
when both operands ready then execute;if not ready, watch CDB for result
vtu
3. Write result: finish execution (WB)
_ write on CDB to all awaiting units and ROB; mark reservation station available
Dept of CSE,SJBIT,Bangalore 46
Advanced Computer Architecture 06CS81
m
6. ADD.D F6, F8, F2
The position of Reservation stations, ROB and FP registers are indicated below:
o
Assume latencies load 1 clock, add 2 clocks, multiply 10 clocks, divide 40 clocks
Show data structures just before MUL.D goes to commit…
s.c
Reservation Stations
c
vtu
At the time MUL.D is ready to commit only the two L.D instructions have already
committed,though others have completed execution
w.
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
Reorder Buffer
Dept of CSE,SJBIT,Bangalore 47
Advanced Computer Architecture 06CS81
o m
Example
Loop: LD F0 0 R1
s.c
MULTD F4 F0 F2
SD F4 0 R1
SUBI R1 R1 #8
BNEZ R1
c Loop
vtu
Assume instructions in the loop have been issued twice
Assume L.D and MUL.D from the first iteration have committed and all other
instructions have completed
Assume effective address for store is computed prior to its issue
Show data structures
Reorder Buffer
w.
ww
Dept of CSE,SJBIT,Bangalore 48
Advanced Computer Architecture 06CS81
o m
Notes
c s.c
• If a branch is mispredicted, recovery is done by flushing the ROB of all entries that
appear after the mispredicted branch
vtu
• 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
main disadvantage:
complex and requires substantial hardware resources;
Dept of CSE,SJBIT,Bangalore 49
Advanced Computer Architecture 06CS81
UNIT - IV
m
Exploiting ILP using multiple issue and static scheduling
o
Multiple issue and speculation
s.c
Advanced Techniques for instruction delivery and Speculation
c
vtu
w.
ww
Dept of CSE,SJBIT,Bangalore 50
Advanced Computer Architecture 06CS81
UNIT IV
What is ILP?
m
• 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
o
resources
– Primary techniques used to exploit ILP
s.c
• 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
c
Example Instruction Sequences
lw $10, 12($1)
ww
Finding ILP:
• Must deal with groups of basic code blocks
• Common approach: loop-level parallelism
– Example:
Dept of CSE,SJBIT,Bangalore 51
Advanced Computer Architecture 06CS81
m
addi $s1, $s1, -4 # decrement pointer
bne $s1, $0, Loop # branch $s1 != 0
Loop Unrolling:
o
• Technique used to help scheduling (and performance)
• Copy the loop body and schedule instructions from different iterations of the
loop gether
s.c
• MIPS example (from prev. slide):
Dept of CSE,SJBIT,Bangalore 52
Advanced Computer Architecture 06CS81
m
Loop Unrolling: Limitations
• Overhead amortization decreases as loop is unrolled more
• Increase in code size
– Could be bad if ICache miss rate increases
o
• Register pressure
– Run out of registers that can be used in renaming process
–
s.c
Exploiting ILP: Deep Pipelines
Deep Pipelines
• Increase pipeline depth beyond 5 stages
– Generally allows for higher clock rates
– UltraSparc III -- 14 stages
– Pentium III -- 12 stages
c
– Pentium IV -- 22 stages
• Some versions have almost 30 stages
vtu
– Core 2 Duo -- 14 stages
– AMD Athlon -- 9 stages
– AMD Opteron -- 12 stages
– Motorola G4e -- 7 stages
– IBM PowerPC 970 (G5) -- 14 stages
• Increases the number of instructions executing at the same time
• Most of the CPUs listed above also issue multiple instructions per cycle
w.
Dept of CSE,SJBIT,Bangalore 53
Advanced Computer Architecture 06CS81
• Benefit
m
– CPIs go below one, use IPC instead (instructions/cycle)
– Example: Issue width = 3 instructions, Clock = 3GHz
• Peak rate: 9 billion instructions/second, IPC = 3
• For our 5 stage pipeline, 15 instructions “in flight” at any given time
o
• Multiple Issue types
– Static
• Most instruction scheduling is done by the compiler
s.c
– Dynamic (superscalar)
• CPU makes most of the scheduling decisions
• Challenge: overcoming instruction dependencies
– Increased latency for loads
– Control hazards become worse
• Requires a more ambitious design
c
– Compiler techniques for scheduling
– Complex instruction decoding logic
vtu
Exploiting ILP:Multiple Issue Computers Static Scheduling
Instruction Issuing
• Have to decide which instruction types can issue in a cycle
– Issue packet: instructions issued in a single clock cycle
– Issue slot: portion of an issue packet
w.
Dept of CSE,SJBIT,Bangalore 54
Advanced Computer Architecture 06CS81
m o
c s.c
vtu
Static Multiple Issue Scheduling
w.
ww
Dept of CSE,SJBIT,Bangalore 55
Advanced Computer Architecture 06CS81
o m
c s.c
vtu
Static Mult. Issue w/Loop Unrolling
w.
ww
Dept of CSE,SJBIT,Bangalore 56
Advanced Computer Architecture 06CS81
m
– Instructions can execute out-of-order
• Execute once all operands are ready
– Instructions commit in-order
• Commit refers to when the architectural register file is updated (current completed state
o
of program
Aside: Data Hazard Refresher
• Two instructions (i and j), j follows i in program order
s.c
• Read after Read (RAR)
• Read after Write (RAW)
– Type:
– Problem:
• Write after Read (WAR)
– Type:
– Problem:
• Write after Write (WAW)
c
vtu
– Type: Problem:
Superscalar Processors
• Register Renaming
– Use more registers than are defined by the architecture
• Architectural registers: defined by ISA
• Physical registers: total registers
– Help with name dependencies
w.
• Antidependence
– Write after Read hazard
• Output dependence
– Write after Write hazard
Dept of CSE,SJBIT,Bangalore 57
Advanced Computer Architecture 06CS81
o m
c s.c
vtu
Instruction Execution Process
• Three parts, arbitrary number of cycles/part
• Above does not allow for speculative execution
• Issue (aka Dispatch)
– If empty reservation station (RS) that matches instruction, send to RS with operands
rom register file and/or know which functional unit will send operand
w.
Write Back
Dept of CSE,SJBIT,Bangalore 58
Advanced Computer Architecture 06CS81
Reservation Stations
m
• Require 7 fields
– Operation to perform on operands (2 operands)
– Tags showing which RS/Func. Unit will be producing operand (or zero if operand
o
available/unnecessary)
– Two source operand values
– A field for holding memory address calculation data
s.c
• 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
c
entry (or blank/zero if noone will be writing to it) Limitation of Current Machine
vtu
Instruction execution requires branches to be resolved
• 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
w.
Dept of CSE,SJBIT,Bangalore 59
Advanced Computer Architecture 06CS81
o m
c s.c
vtu
Tomasulo’s w/HW Speculation
Dept of CSE,SJBIT,Bangalore 60
Advanced Computer Architecture 06CS81
m
• Write Result
– Similar to before, but put result into ROB
• Commit (next slide)
o
Committing Instructions
Look at head of ROB
• Three types of instructions
s.c
– Incorrectly predicted branch
• Indicates speculation was wrong
• Flush ROB
• Execution restarts at proper location – Store
• Update memory
• Remove store from ROB
– Everything else
• Update registers
c
• Remove instruction from ROB
vtu
RUU Superscalar Computers
w.
ww
Dept of CSE,SJBIT,Bangalore 61
Advanced Computer Architecture 06CS81
o m
c s.c
Modeling tool Simple Scalar implements an RUU style processor
– You will be using this tool after Spring Break
vtu
• Architecture similar to speculative Tomasulo’s
• Register Update Unit (RUU)
– Controls instructions scheduling and dispatching to functional units
– Stores intermediate source values for instructions
– Ensures instruction commit occurs in order!
– Needs to be of appropriate size
• Minimum of issue width * number of pipeline stages
w.
Dept of CSE,SJBIT,Bangalore 62
Advanced Computer Architecture 06CS81
m o
c s.c
vtu
w.
Overview of P4
ww
Dept of CSE,SJBIT,Bangalore 63
Advanced Computer Architecture 06CS81
o m
Pentium 4 Pipeline
c s.c
vtu
• See handout for overview of major steps
• Prescott (90nm version of P4) had 31 pipeline stages
– Not sure how pipeline is divided up
–
w.
ww
Dept of CSE,SJBIT,Bangalore 64
Advanced Computer Architecture 06CS81
m
P4: Branch Handling
o
BTBs (Branch Target Buffers)
– Keep both branch history and branch target addresses
• Target address is instruction immediately after branch
s.c
– Predict if no entry in BTB for branch
• Static prediction
• If a backwards branch, see how far target is from current; if within a threshold, predict
taken, else predict not taken
• If a forward branch, predict not taken
• Also some other rules
c
• Front-end BTB is L2 (like) for the trace cache BTB (L1 like)
– Port 1: Shared between second fast ALU and Complex integer and FP/Media scheduler
– Port 2: Load
Port 3: Store
Execute 6 micro-ops/cycle
– Simple ALUs run at 2x machine clock rate
– Can generate 4 simple ALU results/cycle
– Do one load and one store per cycle
• Loads involve data speculation
– Assume that most loads hit L1 and Data Translation Look-aside Buffer (DTLB)
– Get data into execution, while doing address check
• Fix if L1 miss occurred
Dept of CSE,SJBIT,Bangalore 65
Advanced Computer Architecture 06CS81
• 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
m
• Done on a partial address
• Memory Ordering Buffer
– Ensures that store-to-load forwarding was correct
• If not, must re-execute load
o
– Force forwarding
• Mechanism for forwarding in case addresses are misaligned
• MOB can tell SFB to forward or not
s.c
– False forwarding
• Fixes partial address match between load and SFB
Dept of CSE,SJBIT,Bangalore 66
Advanced Computer Architecture 06CS81
m o
P4: Misspeculation Percentages
c s.c
vtu
w.
ww
Dept of CSE,SJBIT,Bangalore 67
Advanced Computer Architecture 06CS81
m o
s.c
P4: CPI
c
vtu
w.
ww
Dept of CSE,SJBIT,Bangalore 68
Advanced Computer Architecture 06CS81
m o
c s.c
vtu
P4 vs. Opteron: Real Performance
w.
ww
Dept of CSE,SJBIT,Bangalore 69
Advanced Computer Architecture 06CS81
PART - B
UNIT - 5
m
Symmetric shared-memory architectures
o
Distributed shared memory and directory-based coherence
s.c
Basics of synchronization
c
vtu
w.
ww
Dept of CSE,SJBIT,Bangalore 70
Advanced Computer Architecture 06CS81
UNIT V
m
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.
o
A Taxonomy of Parallel Architectures
s.c
The idea of using multiple processors both to increase performance and to
improve availability dates back to the earliest electronic computers. About 30 years ago,
Flynn proposed a simple model of categorizing all computers that is still useful today. He
looked at the parallelism in the instruction and data streams called for by the instructions
at the most constrained component of the multiprocessor, and placed all computers in one
of four categories: c
1.Single instruction stream, single data stream
vtu
(SISD)—This category is the uniprocessor.
w.
ww
Dept of CSE,SJBIT,Bangalore 71
Advanced Computer Architecture 06CS81
o m
s.c
3.Multiple instruction streams, single data stream (MISD)—No commercial
multiprocessor of this type has been built to date, but may be in the future. Some special
c
purpose stream processors approximate a limited form of this (there is only a single data
stream that is operated on by successive functional units).
vtu
w.
ww
Dept of CSE,SJBIT,Bangalore 72
Advanced Computer Architecture 06CS81
o m
s.c
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.
c
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.
vtu
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
w.
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
ww
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.
Dept of CSE,SJBIT,Bangalore 73
Advanced Computer Architecture 06CS81
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
m
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
o
c s.c
vtu
w.
satisfy the memory demands of a small number of processors. By replacing a single bus
with multiple buses, or even a switch, a centralized shared memory design can be scaled
to a few dozen processors. Although scaling beyond that is technically conceivable,
sharing a centralized memory, even organized as multiple banks, becomes less attractive
as the number of processors sharing it increases.
Because there is a single main memory that has a symmetric relationship to all
processos and a uniform access time from any processor, these multiprocessors are often
called symmetric (shared-memory) multiprocessors ( SMPs), and this style of architecture
is sometimes called UMA for uniform memory access. This type of centralized
sharedmemory architecture is currently by far the most popular organization.
Dept of CSE,SJBIT,Bangalore 74
Advanced Computer Architecture 06CS81
m
decrease in number (which is another reason not to use small and large scale). Of course,
the larger number of processors raises the need for a high bandwidth interconnect.
o
c s.c
vtu
w.
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
ww
Dept of CSE,SJBIT,Bangalore 75
Advanced Computer Architecture 06CS81
• Suppose you want to achieve a speedup of 80 with 100 processors. What fraction
m
of the original computation can be sequential?
o
c
Data Communication Models for Multiprocessors s.c
vtu
– shared memory: access shared address space implicitly via load and store
operations.
– message-passing: done by explicitly passing messages among the
processors
• can invoke software with Remote Procedure Call (RPC)
• often via library, such as MPI: Message Passing Interface
• also called "Synchronous communication" since communication
w.
Message-Passing Multiprocessor
- The address space can consist of multiple private address spaces that are
ww
Multicomputer (cluster):
Dept of CSE,SJBIT,Bangalore 76
Advanced Computer Architecture 06CS81
m
system on a board into the bus backplane.
Developed by
• IBM – One chip multiprocessor
• AMD and INTEL- Two –Processor
o
• SUN – 8 processor multi core
Symmetric shared – memory support caching of
• Shared Data
s.c
• Private Data
caches
c
Shared data: used by multiple processor
When shared data are cached, the shared value may be replicated in multiple
vtu
advantages: reduce access latency and memory contention induces a new problem: cache
coherence.
Cache Coherence
Unfortunately, caching shared data introduces a new problem because the view of
w.
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
ww
Dept of CSE,SJBIT,Bangalore 77
Advanced Computer Architecture 06CS81
• Informally:
m
– All writes are seen in proper order (“serialization”)
–
• Two rules to ensure this:
– “If P writes x and then P1 reads it, P’s write will be seen by P1 if the read
o
and write are sufficiently far apart”
– Writes to a single location are serialized: seen in one order
s.c
• Latest write will be seen
• Otherwise could see writes in illogical order (could see older
value after a newer value)
The above three properties are sufficient to ensure coherence,When a written value will
be seen is also important. This issue is defined by memory consistency model. Coherence
and consistency are complementary.
w.
• migration: a data item can be moved to a local cache and used there in a
transparent fashion.
• replication for shared data that are being simultaneously read.
• both are critical to performance in accessing shared data.
To over come these problems, adopt a hardware solution by introducing a
protocol tomaintain coherent caches named as Cache Coherence Protocols
These protocols are implemented for tracking the state of any sharing of a data block.
Two classes of Protocols
• Directory based
• Snooping based
Dept of CSE,SJBIT,Bangalore 78
Advanced Computer Architecture 06CS81
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.
m
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)
o
• 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.
s.c
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.
Write Invalidate
Dept of CSE,SJBIT,Bangalore 79
Advanced Computer Architecture 06CS81
o m
Write Update
c s.c
vtu
w.
Example Protocol
Dept of CSE,SJBIT,Bangalore 80
Advanced Computer Architecture 06CS81
m
– Clean in all caches and up-to-date in memory (Shared)
– OR Dirty in exactly one cache (Exclusive)
– OR Not in any caches
• Each cache block is in one state (track these):
– Shared : block can be read
o
– OR Exclusive : cache has only copy, its writeable, and dirty
– OR Invalid : block contains no data (in uniprocessor cache too)
s.c
• Read misses: cause all caches to snoop bus
• Writes to clean blocks are treated as misses
c
State Transitions for Each Cache Block is as shown below
vtu
w.
ww
Dept of CSE,SJBIT,Bangalore 81
Advanced Computer Architecture 06CS81
o m
Conclusion
c s.c
vtu
• “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
w.
Implementation Complications
ww
• 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:
Dept of CSE,SJBIT,Bangalore 82
Advanced Computer Architecture 06CS81
Performance Measurement
m
• Overall cache performance is a combination of
– Uniprocessor cache miss traffic
– Traffic caused by communication – invalidation and subsequent cache
misses
• Changing the processor count, cache size, and block size can affect these two
o
components of miss rate
• Uniprocessor miss rate: compulsory, capacity, conflict
s.c
• Communication miss rate: coherence misses
– True sharing misses + false sharing misses
• Assume that words x1 and x2 are in the same cache block, which is in the shared
state in the caches of P1 and P2. Assuming the following sequence of events,
identify each miss as a true sharing miss or a false sharing miss.
ww
Example Result
Dept of CSE,SJBIT,Bangalore 83
Advanced Computer Architecture 06CS81
m
• 4: False sharing miss
• 5: True sharing miss
o
Distributed Shared-Memory Architectures
s.c
Distributed shared-memory architectures
• Separate memory per processor
– Local or remote access via memory controller
– The physical address space is statically distributed Coherence
Problems
• Simple approach: uncacheable
c
– shared data are marked as uncacheable and only private data are
kept in caches
– very long latency to access memory for shared data
vtu
• Alternative: directory for memory blocks
The directory per memory tracks state of every block in every
cache
• which caches have a copies of the memory block, dirty vs. clean,
...
Two additional complications
• The interconnect cannot be used as a single point of arbitration like the
w.
bus
• Because the interconnect is message oriented, many messages must have
explicit responses
memory, each keeping track of which processors have copies of their memory blocks
Directory Protocols
Dept of CSE,SJBIT,Bangalore 84
Advanced Computer Architecture 06CS81
m
– Assume messages received and acted upon in order sent
o
c s.c
vtu
• local node: the node where a request originates
• home node: the node where the memory location and directory entry of an address
reside
• remote node: the node that has a copy of a cache block (exclusive or shared)
w.
ww
Dept of CSE,SJBIT,Bangalore 85
Advanced Computer Architecture 06CS81
m
Directory Operations: Requests and Actions
• Message sent to directory causes two actions:
– Update the directory
– More messages to satisfy request
o
• Block is in Uncached state: the copy in memory is the current value; only
possible requests for that block are:
s.c
– Read miss: requesting processor sent data from memory &requestor
made only sharing node; state of block made Shared.
– Write miss: requesting processor is sent the value & becomes the
Sharing node. The block is made Exclusive to indicate that the only valid copy is
cached. Sharers indicates the identity of the owner.
• Block is Shared => the memory value is up-to-date:
c
– Read miss: requesting processor is sent back the data from memory &
requesting processor is added to the sharing set.
– Write miss: requesting processor is sent the value. All processors in the
vtu
set Sharers are sent invalidate messages, & Sharers is set to identity of
requesting processor. The state of the block is made Exclusive.
• Block is Exclusive: current value of the block is held in the cache of the
processor identified by the set Sharers (the owner) => three possible directory requests:
– Read miss: owner processor sent data fetch message, causing state of
block in owner’s cache to transition to Shared and causes owner to send data to directory,
where it is written to memory & sent back to requesting processor.
w.
Identity of requesting processor is added to set Sharers, which still contains the
identity of the processor that was the owner (since it still has a readable copy). State is
shared.
– Data write-back: owner processor is replacing the block and hence must
write it back, making memory copy up-to-date (the home directory
ww
essentially becomes the owner), the block is now Uncached, and the Sharer set is
empty.
– Write miss: block has a new owner. A message is sent to old owner
causing the cache to send the value of the block to the directory from which it is sent to
the requesting processor, which becomes the new owner. Sharers is set to identity of new
owner, and state of block is made Exclusive.
Dept of CSE,SJBIT,Bangalore 86
Advanced Computer Architecture 06CS81
• 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
m
reduce contention and latency of synchronization
o
1 _ synchronization variable is locked and unavailable
– Set register to 1 & swap
s.c
– 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 c
– 0 _ synchronization variable is free
• Hard to have read & write in 1 instruction: use 2 instead
vtu
• 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
w.
Dept of CSE,SJBIT,Bangalore 87
Advanced Computer Architecture 06CS81
m
– Likely to get cache hits for such variables
• Problem: exchange includes a write, which invalidates all other copies; this
generates considerable bus traffic
• Solution: start by simply repeatedly reading the variable; when it changes, then
try exchange (“test and test&set”):
o
try: li R2,#1
lockit: lw R3,0(R1) ;load var
s.c
bnez R3,lockit ; _ 0 _ not free _ spin
exch R2,0(R1) ; atomic exchange
bnez R2,try ; already locked?
..... .....
c
seems that P1: A = 0; P2: B = 0;
A = 1; B = 1;
vtu
L1: if (B == 0) ... L2: if (A == 0) ...
• Impossible for both if statements L1 & L2 to be true?
– What if write invalidate is delayed & processor continues?
• Memory consistency models:
what are the rules for such cases?
• Sequential consistency: result of any execution is the same as if the accesses of
each processor were kept in order and the accesses among different
w.
synchronization operations
write (x)
...
release (s) {unlock}
...
acquire (s) {lock}
...
read(x)
• Only those programs willing to be nondeterministic are not synchronized: “data
race”: outcome f(proc. speed)
• Several Relaxed Models for Memory Consistency since most programs are
Dept of CSE,SJBIT,Bangalore 88
Advanced Computer Architecture 06CS81
• Key idea: allow reads and writes to complete out of order, but to use
synchronization operations to enforce ordering, so that a synchronized program behaves
m
as if the processor were sequentially consistent
– By relaxing orderings, may obtain performance advantages
– Also specifies range of legal compiler optimizations on shared data
– Unless synchronization points are clearly defined and programs are
synchronized, compiler could not interchange read and write of 2 shared data items
o
because might affect the semantics of the program
• 3 major sets of relaxed orderings:
s.c
1. W_R ordering (all writes completed before next read)
• Because retains ordering among writes, many programs that operate under
sequential consistency operate under this model, without additional
synchronization. Called processor consistency
2. W _ W ordering (all writes completed before next write)
3. R _ W and R _ R orderings, a variety of models depending on ordering
c
restrictions and how synchronization operations enforce ordering
• Many complexities in relaxed consistency models; defining precisely what it means for
a write to complete; deciding when processors can see values that it has written
vtu
w.
ww
Dept of CSE,SJBIT,Bangalore 89
Advanced Computer Architecture 06CS81
UNIT - VI
Introduction
m
Cache performance
Cache Optimizations
o
Virtual memory.
s.c
6 Hours
c
vtu
w.
ww
Dept of CSE,SJBIT,Bangalore 90
Advanced Computer Architecture 06CS81
UNIT VI
REVIEW OF MEMORY HIERARCHY
m
- Economical solution is memory hierarchy
- Locality
- Cost performance
Principle of locality
o
- most programs do not access all code or data uniformly.
• Locality occurs
- Time (Temporal locality)
s.c
- Space (spatial locality)
• Guidelines
– Smaller hardware can be made faster
– Different speed and sizes
c
vtu
w.
ww
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.
Dept of CSE,SJBIT,Bangalore 91
Advanced Computer Architecture 06CS81
o m
s.c
• The importance of memory hierarchy has increased with advances in performance
of processors.
• Prototype
`– When a word is not found in cache
c
• Fetched from memory and placed in cache with the address tag.
• Multiple words( block) is fetched for moved for efficiency reasons.
– key design
vtu
• Set associative
– Set is a group of block in the cache.
– Block is first mapped on to set.
» Find mapping
» Searching the set
Chosen by the address of the data:
(Block address) MOD(Number of sets in cache)
w.
• n-block in a set
– Cache replacement is called n-way set associative.
Cache data
- Cache read.
- Cache write.
ww
Dept of CSE,SJBIT,Bangalore 92
Advanced Computer Architecture 06CS81
m
– Block miss if blocks map to its set.
o
c s.c
vtu
w.
ww
Dept of CSE,SJBIT,Bangalore 93
Advanced Computer Architecture 06CS81
o m
Cache Optimizations
s.c
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.
c
2. Bigger caches to reduce miss rate:
- capacity misses can be reduced by increasing the cache capacity.
vtu
- 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
w.
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.
Dept of CSE,SJBIT,Bangalore 94
Advanced Computer Architecture 06CS81
m
– Multibanked caches
– Nonblocking caches
• Reducing Miss Penalty
– Critical word first
– Merging write buffers
o
• Reducing Miss Rate
– Compiler optimizations
s.c
• Reducing miss penalty or miss rate via parallelism
– Hardware prefetching
– Compiler prefetching
–
First Optimization : Small and Simple Caches
• Index tag memory and then compare takes time
c
• _ Small cache can help hit time since smaller memory takes less time to index
– E.g., L1 caches same size for 3 generations of AMD microprocessors:
K6, Athlon, and Opteron
vtu
– Also L2 cache small enough to fit on chip with the processor avoids time
penalty of going off chip
• Simple _ direct mapping
– Can overlap tag check with data transmission since no choice
• Access time estimate for 90 nm using CACTI model 4.0
– Median ratios of access time relative to the direct-mapped caches are 1.32,
1.39, and 1.43 for 2-way, 4-way, and 8-way caches
w.
ww
• How to combine fast hit time of Direct Mapped and have the lower conflict
misses of 2-way SA cache?
Dept of CSE,SJBIT,Bangalore 95
Advanced Computer Architecture 06CS81
• Way prediction: keep extra bits in cache to predict the “way,” or block within
the set, of next cache access.
m
– Multiplexer is set early to select desired block, only 1 tag comparison performed that
clock cycle in parallel with reading the cache data
o
– Miss _ 1st check other blocks for matches in next clock cycle
• Accuracy » 85%
s.c
• Drawback: CPU pipeline is hard if hit takes 1 or 2 cycles
- Used for instruction caches vs. data caches
Dept of CSE,SJBIT,Bangalore 96
Advanced Computer Architecture 06CS81
m
• “hit under multiple miss” or “miss under miss” may further lower the effective
miss penalty by overlapping multiple misses
– Significantly increases the complexity of the cache controller as there
can be multiple outstanding memory accesses
o
– Requires multiple memory banks (otherwise cannot support)
– Pentium Pro allows 4 outstanding memory misses
s.c
Value of Hit Under Miss for SPEC
c
vtu
w.
ww
• 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
Dept of CSE,SJBIT,Bangalore 97
Advanced Computer Architecture 06CS81
o m
s.c
Sixth optimization: Increasing Cache Bandwidth via Multiple Banks
• Rather than treat the cache as a single monolithic block, divide into independent
c
banks that can support simultaneous accesses
– E.g.,T1 (“Niagara”) L2 has 4 banks
• Banking works best when accesses naturally spread themselves across banks _
vtu
mapping of addresses to banks affects behavior of memory system
• Simple mapping that works well is “sequential interleaving”
– Spread block addresses sequentially across banks
– E,g, if there 4 banks, Bank 0 has all blocks whose address modulo 4 is 0;
bank 1 has all blocks whose address modulo 4 is 1; …
w.
ww
Dept of CSE,SJBIT,Bangalore 98
Advanced Computer Architecture 06CS81
• Critical Word First—Request 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
o m
Eight optimization: Merging Write Buffer to Reduce Miss Penalty-
s.c
• 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
c
words, bytes since multiword writes more efficient to memory
• The Sun T1 (Niagara) processor, among many others, uses write merging
vtu
w.
ww
Dept of CSE,SJBIT,Bangalore 99
Advanced Computer Architecture 06CS81
m
– Merging Arrays: improve spatial locality by single array of compound
elements vs. 2 arrays
– Loop Interchange: change nesting of loops to access data in order stored
in memory
o
– Loop Fusion: Combine 2 independent loops that have same looping and
some variables overlap
– Blocking: Improve temporal locality by accessing “blocks” of data
s.c
repeatedly vs. going down whole columns or rows
struct merge {
int val;
c
/* After: 1 array of stuctures */
vtu
int key;
};
struct merge merged_array[SIZE];
Reducing conflicts between val & key; improve spatial locality
w.
ww
m
• 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
o
next consecutive block.
– Requested block is placed in instruction cache when it returns, and
prefetched block is placed into instruction stream buffer
s.c
• 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
c
vtu
w.
UNIT - VII
m
Introduction
o
Memory technology and optimizations
s.c
Protection
UNIT VII
MEMORY HIERARCHY DESIGN
m
–CPIExec includes ALU and Memory instructions
•Separating out Memory component entirely
–CPIALUOps does not include memory instructions
o
Summary: Caches
•The Principle of Locality:
–Program access a relatively small portion of the address space at any instant of
s.c
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
c
Where Misses Come From?
vtu
•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,
w.
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
ww
o m
c s.c
vtu
•Write Policy:
–Write Through: needs a write buffer.
–Write Back: control can be complex
w.
Summary:
–associativity
–replacement policy
–write-through vs write-back
–The optimal choice is a compromise
–Simplicity often wins
Cache Organization?
•Assume total cache size not changed
m
–Change Associativity
–Change Compiler
o
How to Improve Cache Performance?
s.c
•Cache optimizations
–1. Reduce the miss rate
–2. Reduce the miss penalty
–3. Reduce the time to hit in the cache
Cache Optimisation
c
Why improve Cache performance:
vtu
w.
ww
m
4. Larger Block size (Compulsory misses)
5. Larger Cache size (Capacity misses)
6. Higher Associativity (Conflict misses)
o
• Reducing hit time
1. Small and simple caches
s.c
2. Way prediction
3. Trace caches
• Increasing cache bandwidth
4. Pipelined caches
5. Multibanked caches
6. Nonblocking caches
c
• Reducing Miss Penalty
7. Critical word first
8. Merging write buffers
vtu
• Reducing Miss Rate
9.Compiler optimizations
• Reducing miss penalty or miss rate via parallelism
10.Hardware prefetching
11.Compiler prefetching
w.
– Also L2 cache small enough to fit on chip with the processor avoids
time penalty of going off chip
• Simple direct mapping
Can overlap tag check with data transmission since no choice
2. Fast Hit times via Way Prediction
• How to combine fast hit time of Direct Mapped and have the lower conflict
misses of 2-way SA cache?
• Way prediction: keep extra bits in cache to predict the “way,” or block within
the set, ofnext 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
m
– 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 (don’t exit in middle of block, don’t enter at label in
middle of block)
o
- 1. ı complicated address mapping since addresses no longer aligned to power-of-2
multiples of word size
s.c
- 1. ı instructions may appear multiple times in multiple dynamic traces due to different
branch outcomes
• “hit under multiple miss” or “miss under miss” may further lower the effective
miss penalty by overlapping multiple misses
– Significantly increases the complexity of the cache controller as there
can be multiple outstanding memory accesses
– Requires muliple memory banks (otherwise cannot support)
– Penium Pro allows 4 outstanding memory misses
• Banking works best when accesses naturally spread themselves across banks ı
mapping of addresses to banks affects behavior of memory system
o m
Simple mapping that works well is “sequential interleaving”
s.c
– Spread block addresses sequentially across banks
– E,g, if there 4 banks, Bank 0 has all blocks whose address modulo 4 is
0; bank 1 has all blocks whose address modulo 4 is 1; ….
o m
8. Merging Write Buffer to Reduce Miss Penalty
•Write buffer to allow processor to continue while waiting to write to memory
s.c
•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
c
vtu
w.
ww
• Instructions
– Reorder procedures in memory so as to reduce conflict misses
– Profiling to look at conflicts (using tools they developed)
• Data
– Merging Arrays: improve spatial locality by single array of compound elements vs. 2
arrays
– Loop Interchange: change nesting of loops to access data in order
m
stored in memory
– Loop Fusion: Combine 2 independent loops that have same looping and some variables
overlap
– Blocking: Improve temporal locality by accessing “blocks” of data repeatedly vs.
going down whole columns or rows
o
Compiler Optimizations- Reduction comes from software (no Hw ch.)
Loop Interchange
s.c
•Motivation: some programs have nested loops that access data in nonsequential order
•Solution: Simply exchanging the nesting of the loops can make the code access the data
in the order it is stored =>
reduce misses by improving spatial locality; reordering maximizes use of data in a cache
block before it is discarded
Loop Interchange Example
/* Before */ c
for (j = 0; j < 100; j = j+1)
for (i = 0; i < 5000; i = i+1)
vtu
x[i][j] = 2 * x[i][j];
/* After */
for (i = 0; i < 5000; i = i+1)
for (j = 0; j < 100; j = j+1)
x[i][j] = 2 * x[i][j];
Blocking
•Motivation: multiple arrays, some accessed by rows and some by columns
w.
•Storing the arrays row by row (row major order) or column by column (column major
order) does not help: both rows and columns are used in every iteration of the loop
(Loop Interchange cannot help)
•Solution: instead of operating on entire rows and columns of an array, blocked
algorithms operate on submatrices or blocks => maximize accesses to the data loaded
ww
Blocking Example
/* Before */
for (i = 0; i < N; i = i+1)
for (j = 0; j < N; j = j+1)
{r = 0;
for (k = 0; k < N; k = k+1){
r = r + y[i][k]*z[k][j];};
x[i][j] = r;
};
/* After */
for (jj = 0; jj < N; jj = jj+B)
for (kk = 0; kk < N; kk = kk+B)
for (i = 0; i < N; i = i+1)
for (j = jj; j < min(jj+B,N); j = j+1)
{r = 0;
for (k = kk; k < min(kk+B,N); k = k + 1)
m
r = r + y[i][k]*z[k][j];
x[i][j] = x[i][j] + r;
};
Snapshot of x, y, z when
i=1
o
White:
c s.c
vtu
White: not yet touched
Light: older access
Dark: newer access Before….
w.
o m
s.c
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
c
•Solution: combine these independent matrices into a single compound array, so that a
single cache block can contain the desired elements
vtu
Merging Arrays Example
Loop Fusion
• Some programs have separate sections of code that access with the same
loops, performing different computations on the common data
w.
• 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
ww
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
m
•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;
o
•a form of speculative execution
•• Issuing Prefetch Instructions takes time
s.c
•– Is cost of prefetch issues < savings in reduced misses?
•– Higher superscalar reduces difficulty of issue bandwi
m
Bandwidth: I/O & Large Block Miss Penalty (L2)
o
Addresses divided into 2 halves (Memory as a 2D matrix):
• RAS or Row Access Strobe
• CAS or Column Access Strobe
s.c
Cache uses SRAM: Static Random Access Memory
No refresh (6 transistors/bit vs. 1 transistor
• Size: DRAM/SRAM - 4-8,
• Cost/Cycle time: SRAM/DRAM - 8-16
c
Main Memory Deep Background
•“Out-of-Core”, “In-Core,” “Core Dump”?
vtu
• “Core memory”?
• 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
w.
– 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
ww
• 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 didn’t do correction
– DRAM banks too large now
– Servers always corrected memory systems
m
• 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
o
• Organization is multiple DRAMs/DIMM, multiple DIMMs
• Want to recover from failed DRAM and failed DIMM!
s.c
• “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
c
– Row access strobe (RAS) first, then column access strobe (CAS)
– Memory as a 2D matrix – rows go to a buffer
– Subsequent CAS selects subrow
vtu
• Use only a single transistor to store a bit
– Reading that bit can destroy the information
– Refresh each bit periodically (ex. 8 milliseconds) by writing back
• Keep refreshing time less than 5% of the total time
• DRAM capacity is 4 to 8 times that of SRAM
• DIMM: Dual inline memory module
– DRAM chips are commonly sold on small boards called DIMMs
w.
m
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
o
– Asynchronous DRAM involves overhead to sync with controller
– Peak speed per memory module 800—1200MB/sec in 2001
s.c
• Double data rate (DDR): transfer data on both the rising edge and falling edge of
DRAM clock signal
– Peak speed per memory module 1600—2400MB/sec in 2001
c
vtu
w.
Protection:
Virtual Memory and Virtual Machines
Slide Sources: Based on “Computer Architecture” by Hennessy/Patterson.
Supplemented from various freely downloadable sources
ww
–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
m
–Memory protection information
•System call to transfer to supervisor mode
–Return like normal subroutine to user mode
•Mechanism to limit memory access
Memory protection
o
•Virtual Memory
–Restriction on each page entry in page table
s.c
–Read, write, execute privileges
–Only OS can update page table
–TLB entries also have protection field
•Bugs in OS
–Lead to compromising security
–Bugs likely due to huge size of OS code
Virtualization
• Goal:
c
Protection via Virtual Machines
vtu
– Run multiple instances of different OS on the same hardware
– Present a transparent view of one or more environments (M-to-N mapping of M “real”
resources, N “virtual” resources)
Protection via Virtual Machines
Virtualization- cont.
• Challenges:
– Have to split all resources (processor, memory, hard drive, graphics card, networking
w.
m
Managing Virtual Memory
• Virtual memory offers many of the features required for hardware virtualization
– Separates the physical memory onto multiple processes
– Each process ‘thinks’ it has a linear address space of full size
o
– Processor holds a page table translating virtual addresses used by a process and the
according physical memory
s.c
– Additional information restricts processes from
• Reading a page of on another process or
• Allow reading but not modifying a memory page or
• Do not allow to interpret data in the memory page as instructions and do not try to
execute them
• Virtual Memory management thus requires
c
– Mechanisms to limit memory access to protected memory
– At least two modes of execution for instructions
• Privileged mode: an instruction is allowed to do what it whatever it wants -> kernel
vtu
mode for OS
• Non-privileged mode: user-level processes
• Intel x86 Architecture: processor supports four levels
– Level 0 used by OS
– Level 3 used by regular applications
•Provide mechanisms to go from non-privileged mode to privileged mode -> system call
•Provide a portion of processor state that a user process can read but not modify
w.
• When the ISAs match the hardware we call it (operating) system virtual
machines
• Multiple OSes all share the native hardware
m
•Processor bound programs have very little virtualisation overhead
•I/O bound jobs have more overhead
•ISA emulation is costly
o
Other benefits of VMs
• Managing software
s.c
–Complete software stack
–Old Oses like DOS
–Current stable OS
–Next OS release
• Managing Hardware
–Multiple servers avoided
c
–VMs enable hardware sharing
–Migration of a running VM to another m/c
•For balancing load or evacuate from failing HW
vtu
Requirements of a VMM
•Guest sw should behave exactly on VM as if on native hw
•Guest sw should not be able to change allocation of RT resources directly
•Timer interrupts should be virtualised
•Two processor modes- system and user
•Priveleged subset of instruction available only in system mode
w.
UNIT - VIII
m
HARDWARE AND SOFTWARE FOR VLIW AND EPIC:
Introduction
o
Exploiting Instruction-Level Parallelism Statically
s.c
Detecting and Enhancing Loop-Level Parallelism
7 Hours
w.
ww
UNIT VIII
m
Static Exploitation of ILP
•Use compiler support for increasing parallelism
–Supported by hardware
•Techniques for eliminating some types of dependences
o
–Applied at compile time (no run time support)
•Finding parallelism
•Reducing control and data dependencies
s.c
•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;
c
vtu
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
w.
m
–even if there are loop-carried dependences it may be possible to parallelize the loop – an
analysis of the dependences is required…
o
B[i+1] = C[i] + D[i]; /* S2 */ }
s.c
–what are the dependences?
•There is one loop-carried dependence:
–S1 uses the value of B[i] computed in a previous iteration by S2
–but this does not force iterations to execute in series. Why…?
–…because S1 of iteration i depends on S2 of iteration i-1…, and the chain of
dependences stops here!
c
Parallelizing Loops with Short Chains of Dependences
•Parallelize the loop:
vtu
–for (i=1; i<=100; i=i+1) { A[i] = A[i] + B[i]; /* S1 */
B[i+1] = C[i] + D[i]; /* S2 */ }
•Parallelized code:
–A[1] = A[1] + B[1];
for (i=1; i<=99; i=i+1)
{ B[i+1] = C[i] + D[i];
A[i+1] = A[i+1] + B[i+1];
w.
}
B[101] = C[100] + D[100];
–the dependence between the two statements in the loop is no longer loop-carried and
iterations of the loop may be executed in parallel
–
ww
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
m
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;
}
o
a=2b=3c=2d=0
GCD(a, c) = 2
s.c
d - b = -3
2 does not divide -3 _ No loop carried dependence possible.
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
m
depend
Points-to analysis
Relies on information from three major sources:
o
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
s.c
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
c
copy propagation, used to simplify sequences like the following:
vtu
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.
w.
Recurrence
Recurrences are expressions whose value on one iteration is given by a function that
depends onthe previous iterations.
sum = sum + x;
ww
•Finding parallelism
•Reducing control and data dependencies
•Using speculation
m
–software pipelining,
–trace scheduling, and
–superblock scheduling
Software pipelining
o
•Symbolic loop unrolling
•Benefits of loop unrolling with reduced code size
s.c
•Instructions in loop body selected from different loop iterations
•Increase distance between dependent instructions in
SW pipelining example
Iteration i: L.D F0,0(R1)
ADD.D F4,F0,F2
S.D F4,0(R1)
Iteration i+1: L.D F0,0(R1)
ADD.D F4,F0,F2
S.D F4,0(R1)
Iteration i+2: L.D F0,0(R1)
ADD.D F4,F0,F2
m
S.D F4,0(R1)
o
ADDI R1,R1-16 #point to v[n-2]
LD F0,16(R1) #load v[n]
s.c
ADDD F4,F0,F2 #add v[n]
LD F0,8(R1) #load v[n-1]
#body for (i=2;i<=n-2;i++)
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
BNE
#cleanup
c
R1,R1,-8
R1,R2,Loop
vtu
SD F4,8(R1) #store v[1]
ADDD F4,F0,F2 #add v[0]
SD F4,0(R1) #store v[0]
Software pipelining versus unrolling
o m
Advantages
c s.c
vtu
•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
w.
into the shortest possible sequence that preserves the data and control dependences.
o m
c s.c
vtu
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
•Data dependences are overcome by unrolling
•In the case of memory operations, using dependence analysis to determine if two
references refer to the same address.
w.
different paths.
•if the frequency information is accurate, is likely to lead to faster code.
Global code scheduling- cont.
•Global code motion is important since many inner loops contain conditional statements.
•Effectively scheduling this code could require that we move the assignments to B and C
to earlier in the execution sequence, before the test of A.
o m
c s.c
vtu
Trace Scheduling:
•Focusing on the Critical Path
w.
ww
o m
Code generation sequence c s.c
vtu
w.
ww
Trace Scheduling,
Superblocks and Predicated Instructions
•For processor issuing more than one instruction on every clock cycle.
–Loop unrolling,
–software pipelining,
Trace Scheduling
•Used when
– Predicated execution is not supported
– Unrolling is insufficient
m
• Best used
– If profile information clearly favors one path over the other
• Significant overheads are added to the infrequent path
• Two steps :
– Trace Selection
o
– Trace Compaction
–
s.c
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 c
vtu
w.
ww
(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
m
•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
o
• Bookkeeping
– Cost is assumed to be little
s.c
• Best used in scientific code with extensive loops
c
vtu
w.
ww
m
• Unlike traces
– Different exit points
– Common in for loops
• Single entry and exit points
• Code motion across exit only need be considered
o
s.c
Superblock Construction
c
vtu
w.
ww
• 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
–
m
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
o
• Compilation process is not simple any more
s.c
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
• True?
– Executed normally
c
– Evaluated as part of the execution
vtu
• False?
– Execution continues as if the instruction were a no-op
• Example :
– Conditional move between registers
–
Example
if (A==0)
w.
S = T;
Straightforward Code
BNEZ R1, L;
ADDU R2, R3, R0
L:
ww
Conditional Code
CMOVZ R2, R3, R1
Annulled if R1 is not 0
Conditional Instruction …
• Can convert control to data dependence
• In vector computing, it’s 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
Another example
• A = abs(B)
if (B < 0)
A = -B;
else
A = B;
• Two conditional moves
m
• One unconditional and one conditional move
• The branch condition has moved into the
instruction
– Control dependence becomes data dependence
–
o
Limitations of Conditional Moves
• Conditional moves are the simplest form of predicated instructions
s.c
• Useful for short sequences
• For large code, this can be inefficient
– Introduces many conditional moves
• Some architectures support full predication
– All instructions, not just moves
• Very useful in global scheduling
c
– Can handle nonloop branches nicely
– Eg : The whole if portion can be predicated if the frequent path is not taken
vtu
w.
ww
• 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
o m
• One instruction issue slot is eliminated
• On mispredicted branch, predicated instruction will not have any effect
s.c
• If sequence following the branch is short, the entire block of the code can be predicated
Some Complications
• Exception Behavior
– Must not generate exception if the predicate is false
• If R10 is zero in the previous example
c
– LW R8, 0(R10) can cause a protection fault
• If condition is satisfied
vtu
– A page fault can still occur
• Biggest Issue – Decide when to annul an instruction
– Can be done during issue
• Early in pipeline
• Value of condition must be known early, can induce stalls
– Can be done before commit
• Modern processors do this
w.
m
– Evaluated as part of the execution
• True?
– Executed normally
• False?
– Execution continues as if the instruction were a no-op
o
• Example :
– Conditional move between registers
s.c
Example
if (A==0)
S = T;
Straightforward Code
BNEZ R1, L;
ADDU R2, R3, R0
L:
Conditional Code
CMOVZ R2, R3, R1
c
vtu
Annulled if R1 is not 0
Conditional Instruction …
• Can convert control to data dependence
• In vector computing, it’s called if conversion.
• Traditionally, in a pipelined system
– Dependence has to be resolved closer to front of pipeline
• For conditional execution
w.
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
m
Example
• 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
o
Predicated Execution
s.c
Assume : LWC is predicated load and loads if third operand is not 0
• One instruction issue slot is eliminated
• On mispredicted branch, predicated instruction will not have any effect
• If sequence following the branch is short, the entire block of the code can be predicated
Predication
Some Complications
• Exception Behavior
c
– Must not generate exception if the predicate is false
vtu
• If R10 is zero in the previous example
– LW R8, 0(R10) can cause a protection fault
• If condition is satisfied
– A page fault can still occur
• Biggest Issue – Decide when to annul an instruction
– Can be done during issue
-- Early in pipeline
w.
m
–Early condition detection may not be possible due to data dependence
–Late condition detection incurs stalls and consumes pipeline resources needlessly
•Instructions may be dependent on multiple branches
•Compiler able to find instruction slots and reorder
o
Hardware support for speculation
Alternatives for handling speculative exceptions
s.c
•Hardware and OS ignore exceptions from speculative instructions
•Mark speculative instructions and check for exceptions
–Additional instructions to check for exceptions and recover
•Registers marked with poison bits to catch exceptions upon read
•Hardware buffers instruction results until instruction is no longer speculative
Exception classes c
•Recoverable: exception from speculative instruction may harm performance, but not
preciseness
vtu
•Unrecoverable: exception from speculative instruction compromises preciseness
o m
s.c
Solution II: mark speculative instructions
c
vtu
w.
ww
m
Solution IV HW mechanism like a ROB
•Instructions are marked as speculative
•How many branches speculatively moved
•Action (T/NT) assumed by compiler
•Usually only one branch
o
•Other functions like a ROB
s.c
HW support for Memory Reference Speculation
•Moving stores across loads
–To avoid address conflict
–Special instruction checks for address conflict
•Left at original location of load instruction
•Acts like a guardian
c
•On speculative load HW saves address
–Speculation failed if a stores changes this address before check
nstruction
vtu
•Fix-up code re-executes all speculated instructions
EPIC
•EPIC – Overview
– Builds on VLIW
– Redefines instruction format
– Instruction coding tells CPU how to process data
– Very compiler dependent
m
– 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
o
– Reduces circuit complexity
c s.c
vtu
w.
ww
Chip Layout
•Itanium Architecture Diagram
o m
s.c
Itanium Specs
•4 Integer ALU's
•4 multimedia ALU's
•2 Extended Precision FP Units
•2 Single Precision FP units
c
•2 Load or Store Units
•3 Branch Units
vtu
•10 Stage 6 Wide Pipeline
•32k L1 Cache
•96K L2 Cache
•4MB L3 Cache(extern)þ
•800Mhz Clock
w.
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
ww
o m
c s.c
vtu
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
w.
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
m
•Register Rotation
–Allows faster loop execution in parallel
•Predication Controls Pipeline Stages
Cache Features
•L1 Cache
o
–4 way associative
–16Kb Instruction
s.c
–16Kb Data
•L2 Cache
–Itanium
•6 way associative
•96 Kb
–Itanium2
•8 way associative
•256 Kb Initially
c
–256Kb Data and 1Mb Instruction on Montvale!
vtu
Cache Features
•L3 Cache
–Itanium
•4 way associative
•Accessible through FSB
•2-4Mb
–Itanium2
w.
•2 – 4 way associative
•On Die
•3Mb
–Up to 24Mb on Montvale chips(12Mb/core)!
Register
ww
Specification
_128, 65-bit General Purpose Registers
_128, 82-bit Floating Point Registers
_128, 64-bit Application Registers
_8, 64-bit Branch Registers
_64, 1-bit Predicate Registers
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
o m
c s.c
vtu
On function call, machine shifts register window such that previous output registers
w.
m o
c s.c
vtu
w.
ww
m o
c s.c
vtu
w.
ww
m o
c s.c
vtu
w.
ww
o m
s.c
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
c
_ILP Instruction Groups
vtu
_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).
w.
ww
o m
c s.c
_Use predicates to eliminate branches, move instructions across branches
_Conditional execution of an instruction based on predicate register (64 1-bit
predicate registers)
vtu
_Predicates are set by compare instructions
_Most instructions can be predicated – each instruction code contains predicate
field
_If predicate is true, the instruction updates the computation state; otherwise, it
behaves like a nop
Scheduling and Speculation
w.
• Basic block: code with single entry and exit, exit point can be multiway branch
• Control Improve ILP by statically move ahead long latency code blocks.
• path is a frequent execution path
• Schedule for control paths
• Because of branches and loops, only small percentage of code is executed regularly
ww
o m
c s.c
vtu
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
w.
_ 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
ww
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
_ 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
m
_ 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
o
1. Allows for loads to be moved ahead of stores even if the compiler is unsure if
addresses are the same
s.c
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
c
vtu
w.
ww
o m
c s.c
vtu
w.
ww
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”.
o m
c s.c
On function call, machine shifts register window such that previous output registers
become new locals starting at r32
vtu
Software Pipelining
_loops generally encompass a large portion of a program’s execution time, so it’s
important to expose as much loop-level parallelism as possible.
_Overlapping one loop iteration with the next can often increase the parallelism.
Software Pipelining
w.
ww
m
“The combination of these loop features and predication enables the compiler to
generate compact code, which performs the essential work of the loop in a highly parallel
form.”
o
c s.c
vtu
w.
ww