Docsity

lecture note on vector processor , Exams of Advanced Computer Architecture

Toggle sidebar
bg1
1
1
SupercomputerArchitecture:
SupercomputerArchitecture:
VectorProcessing
VectorProcessing
Hiroaki Kobayashi
1/11/2005
1/11/2005 Hiroaki Kobayashi 2
WhatisaSupercomputer?
WhatisaSupercomputer?
A supercomputer is a hardware and software system
that provides close to the maximum performance that
can currently be achieved.
♦Over the last 10 years the range for the Top500
(http://www.top500.org) has increased greater than Moore’s Law
♦1993:
ī˜€#1 = 59.7 GFlop/s
ī˜€#500 = 422 MFlop/s
♦2004:
ī˜€#1 = 70 TFlop/s
ī˜€#500 = 850 GFlop/s
CRAY-1 (1976)
First Supercomputer
160MFlo
p
/s
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15

Partial preview of the text

Download lecture note on vector processor and more Exams Advanced Computer Architecture in PDF only on Docsity!

1

Hiroaki Kobayashi

1/11/2005 Hiroaki Kobayashi 2

A supercomputer is a hardware and software system

that provides close to the maximum performance that

can currently be achieved.

Over the last 10 years the range for the Top

(http://www.top500.org) has increased greater than Moore’s Law

#1 = 59.7 GFlop/s

#500 = 422 MFlop/s

#1 = 70 TFlop/s

#500 = 850 GFlop/s

CRAY-1 (1976)

First Supercomputer 160MFlop/s

Emergence of supercomputers 1/11/2005 Hiroaki Kobayashi 3

Accelerators

1/11/2005 Hiroaki Kobayashi 4

Source: J.Dongarra

1/11/2005 Hiroaki Kobayashi 7

Basic Idea z Extend the instruction set and architecture of the system to support the execution of commonly used vector operations in hardware.

z Vector Operations work on vectors, linear arrays of numbers. Ā„ Typical vector operation might add two 64-element, floating- point vectors to obtain a single 64-element vector results.

Ā„ Example: A[i] = B[i] + C[i], i=1,

are represented by a vector instruction of the type

VOP V3, V1, V

where VOP represents a vector operation , and V1, V2, V3 indicate specific vector registers.

The operation performed is: V3 = V1 VOP V

for all register values within each vector registers.

1/11/2005 Hiroaki Kobayashi 8

z A single vector instruction specifies a great deal of work Ā„ It is equivalent to executing an entire loop. z By using a vector instruction, the compiler or programmer indicates that the computation of each result in the vector is independent of the computation of other results in the same vector and so hardware does not have to check for data hazards within a vector instruction.

z Hardware needs only check for data hazards between two vector instructions once per vector operand, not once for every element within the vectors. z Vector instructions that access memory have a known access pattern. Ā„ If the vector’s elements are all adjacent, then fetching the vector from a set of heavily interleaved memory banks works very well. z Because an entire loop is replaced by a vector instruction whose behavior is predetermined, control hazards that would normally arise from the loop branch are nonexistent

For these reason, vector operations can be made faster than a sequence of scalar operations on the same number of data items.

1/11/2005 Hiroaki Kobayashi 9

z Vector registers

Ā„ Each vector register is a fixed-length bank holding a single vector and must have at least two read ports and one write port.

z Vector functional units

Ā„ Each unit is fully pipelined and can start a new operation on every clock cycle. A control unit is needed to detect hazards, both from conflicts for the functional unit and from conflicts for register accesses.

z Vector load-store unit

Ā„ This is a vector memory unit that loads or stores a vector to or from memory. Vector loads and stores are fully pipelined, so that words can be moved between the vector registers and memory with a bandwidth of 1 word per clock cycle, after an initial latency.

From VR &VR2 (^) To VR

Pre-normalizeFraction addPost-normalizeRound

Pipelined FP ADD Unit

1/11/2005 Hiroaki Kobayashi 10

Remarks:

  1. The clock rates shown are for the vector units.
  2. The lanes show the number of parallel pipelines used to execute operations within each vector instruction.
  3. The Fujitsu machines’ vector registers are configurable.
  4. The NEC machines have eight foreground vector registers connected to the arithmetic units plus 32-64 background vector registers connected between the memory system and the foreground vector registers.
  5. The Cray SV1 can group four CPUs with 2 lanes each to act in unison as a single larger CPU with eight lanes, called a multi-streaming Processor (MSP).

1/11/2005 Hiroaki Kobayashi 13

z SAXPY (Single-precision a X plus Y) and DAXPY (Double-precision a X plus Y)

Y = a X + Y, whereX andY are vectors, initially resident in

memory, anda is a scalar

¾Many scientific applications include this type of problems.

How is SAXPY/DAXPY translated into scalar and vector codes?

(Assume that the number of elements, or length, of a vector register (64) matches the length of the vector operation)

1/11/2005 Hiroaki Kobayashi 14

This reduction occurs both

  1. because the vector operations work on 64 elements and
  2. because the overhead instructions that constitute nearly half the loop on MIPS are not present in the vector code.

MIPS code LD F0,a ;load scalar a DADDIU R4,Rx,#512 ;last address to load Loop LD F2,0(Rx) ;load X(i) MUL.D F2,F2,F0 ;a X(i) LD F4,0(Ry) ;load Y(i) ADD.D F4,F4,F2 ;a X(i) + Y(i) SD 0(Ry),F4 ;store into Y(i) DADDIU Rx,Rx,#8; ;increment index to X DADDIU Ry,Ry,#8 ;increment index to Y DSUBU R20,R4,Rx ;compute bound BNEZ R20, Loop ; check if done

The vector processor greatly reduces the dynamic instruction bandwidth. Executing only 6 instructions versus almost 600 for MIPS.

Vector code LD F0,a ;load scalar a LV V1,Rx ;load vector X MULV.D V2,V1,F0 ;vector-scalar multiply LV V3,Ry ;load vector Y ADDV.D V4,V2,V3 ;add SV Ry,V4 ;store the result

1/11/2005 Hiroaki Kobayashi 15

MIPS code LD F0,a ;load scalar a DADDIU R4,Rx,#512 ;last address to load Loop LD F2,0(Rx) ;load X(i) MUL.D F2,F2,F0 ;a X(i) LD F4,0(Ry) ;load Y(i) ADD.D F4,F4,F2 ;a X(i) + Y(i) SD 0(Ry),F4 ;store into Y(i) DADDIU Rx,Rx,#8; ;increment index to X DADDIU Ry,Ry,#8 ;increment index to Y DSUBU R20,R4,Rx ;compute bound BNEZ R20, Loop ; check if done

Vector code LD F0,a ;load scalar a LV V1,Rx ;load vector X MULV.D V2,V1,F0 ;vector-scalar multiply LV V3,Ry ;load vector Y ADDV.D V4,V2,V3 ;add SV Ry,V4 ;store the result

' In the straightforward MIPS code, every ADD.D must wait for a MUL.D and every S.D must wait for the ADD.D & On the vector processor, each vector instruction will only stall for the first element in each vector, and then subsequent elements will flow smoothly down the pipeline.

Pipeline stalls: only once per vector operation vs. once per vector element!

A large decrease in the frequency of pipeline interlock in vector processing

1/11/2005 Hiroaki Kobayashi 16

z Three factors that affect the

execution time of a sequence of

vector operations

Ā„ Length of the operand vectors Ā„ Structural hazards among the operations Ā„ Data dependency

z The time for a single vector

instruction can be computed

when the vector length and the

initiation rate are given.

Ā„ Initiation rate: the rate at which a vector unit consumes new operands, and produces new results.

z Model for estimating vector execution

time

Ā„ One lane with an initiation rate of one element per clock cycle for individual operations Ā„ Notion of a convoy and a chime Ā‹ A convoy is a set of vector instructions that could potentially begin execution together in one clock period. Ā‹ The instructions in a convoy must not contain any structural hazards or data hazards Ā‹ A timing metric, called chime , can be used for estimating the performance of a vector sequence consisting of convoys. Ā‹ A chime is the unit of time taken to execute one convoy.

1/11/2005 Hiroaki Kobayashi 19

Question: If the startup overhead is assumed as shown in the table, Show the time that each convoy can begin and total number of cycles needed, and how does the time compare to the chime approximation for a vector length of length 64?

Add unit 6

Multiply unit 7

Load and store unit 12

Start-up overhead (cycles)

Unit

Start-up overhead

  1. SV 30 + 3 n 30 + 3 n + 12 41 + 4 n
  2. ADDV.D 24 + 2 n 24 + 2 n + 6 29 + 3 n
  3. MULVS.D LV 12 + n 12 + n + 12 23 + 2 n
  4. LV 0 12 11 + n

Convoy Starting time First-result time Last-result time

Answer

Time per result for a vector of length 64 is 4+(41/64)=4.64 clock cycles

Start-up time add a 16% overhead to the execution time!

1/11/2005 Hiroaki Kobayashi 20

z The start-up time for a load is the time to get the first word from memory into a register Ā„ If the rest of the vector can be supplied without stalling, then the vector initiation rate is equal to the rate at which new words are fetched or stored. Ā„ Unlike simpler functional units, the initiation rate may not necessarily be 1 clock because memory bank stalls can reduce effective throughput.

Vector load 12

Vector divide 20

Vector multiply 7

Vector add 6

Start-up penalty

Operation

Startup-penalties of Cray 1

To maintain an initiation rate of 1 word fetched or stored per clock, the memory system must be capable of producing or accepting this much data

Banked Memory System

1/11/2005 Hiroaki Kobayashi 21

  1. The memory system needs to have multiple banks and able to control the addresses to the banks independently. Ā„ Many vector computer support multiple loads or stores per clock, and the memory bank cycle time is often several times larger than the CPU cycle time.
  2. Many vector processors support the ability to load or store data words that are not sequential. z Independent bank addressing, rather than interleaving, is required.
  3. Many vector computers support multiple processors sharing the same memory system, and so each processor will be generating its own independent stream of address

Three primary reasons for use of memory banks for vector processing, rather than simple interleaving.

BK0 BK1 BKn

Memory System

Vector Processors

Banks

Time

Pipeline Memory latency cycle

Memory transaction

1/11/2005 Hiroaki Kobayashi 22

Cray T z 2.167 ns CPU clock cycle z 32 processors, each capable of four loads and two stores per CPU clock cycle z SRAM memory cycle of 15ns

Calculate the minimum number of memory banks required to allow all CPU to run at full memory bandwidth

  • The maximum number of memory references each cycle is 192 (=32CPUs X 6 references/CPU)
  • Each SRAM bank is busy for 15/2.167 = 6.92 clock cycles, rounding up 7 clock cycles.

192 7 = 1344 memory Banks! But actually, 1024 memory banks are adopted (later model introduce synchronous DRAM for providing sufficient bandwidth).

1/11/2005 Hiroaki Kobayashi 25

Strip mining

z Generation of code such that each vector operation is done for a

size less than or equal to the MVL.

do 10 I = 1,n 10 Y(i) = a * X(i) + Y(i)

Strip mining

low = VL = (nmod MVL) /* find the odd-size piece / do 1 j = 0, (n / MVL) / outer loop / do 10 i = low, low + VL – 1 / runs for length VL / Y(i) = a * X(i) + Y(i) / main operation / 10 continue low = low + VL / start of next vector / VL = MVL / reset the length to max */ 1 continue The inner loop of the code is vectorizable with length VL.

The variablem is used for the expression (n mod MVL)

1/11/2005 Hiroaki Kobayashi 26

z There are two key factors that contribute to the running time of a strip-mined loop consisting of a sequence of convoys:

  1. The number of convoys in the loop, which determines the number of chimes. z Tchime for the execution time in chimes
  2. The overhead for each strip- mined sequence of convoys. z This overhead consists of the cost of executing the scalar code for strip-mining each block, Tloop , plus the vector start-up cost for each convoy, T (^) start

z Total running time for a vector sequence operating on a vector of length n , called T n :

T n = āŽ” n / MVLāŽ¤ (T (^) loop + T (^) start ) + n T (^) chime

T (^) start , T (^) loop and T (^) chime are compiler and processor dependent Ā„ The register allocation and scheduling of the instructions affect both what goes in a convoy and the start-up overhead of each convoy

1/11/2005 Hiroaki Kobayashi 27

z What is the execution time for the vector operation A = B s, where s is a scalar and the length of the vector A and B is 200?

Assume z The addresses of A and B are initially in Ra and Rb , s is in Fs, and R always holds 0. z T (^) loop is a constant value of 15 from Cray-1 data.

Answer

  • Since (200 mod 64)=8, the first iteration of the strip-mind loop will execute for a vector length of 8 element, and the following iterations will execute for a vector length of 64 elements
  • Since the vector length is either 8 or 64, increment the address registers by 8x8=64 after the first segment and 8X64=512 for later segments.
  • Since the total number of bytes in the vector is 8X200=1600, the test for completion is performed by comparing the address of the next vector segment to the initial address plus 1600

1/11/2005 Hiroaki Kobayashi 28

Generated Code:

DADDUI R2,R0,#1600 ;total # of bytes in vector DADDU R2,R2,Ra ;address of the end of A vector DADDUI R1,R0,#8 ;loads length of 1 st^ segment MTC1 VLR,R1 ;load vector length in VLR DADDUI R1,R0,#64 ;length in bytes of 1 st^ segments DADDUI R3,R0,#64 ;vector length of other segments Loop:LV V1,Rb ;load B MULVS.D V2,V1,Fs ;vector * scalar SV Ra,V2 ;store A DADDU Ra,Ra,R1 ;address of next segment of A DADDU Rb,Rb,R1 ;address of next segment of B DADDUI R1,R0,#512 ;load byte offset next segment MTC1 VLR,R3 ;set length to 64 elements DSUBU R4,R2,Ra ;at the end of A? BNEZ R4,Loop ;if not, go back

  • The three vector instructions in the loop are dependent and must go into three convoys, hence Tchime =

The execution time per element with all start-up costs is 784/200=3.9, compared with a chime approximation of 3.

1/11/2005 Hiroaki Kobayashi 31

Suppose z 8 memory banks z A total memory latency of 12 cycles Ā„ The time from when the address arrives at the bank until the bank returns a data value. The latency includes the start-up cost of fetching a vector from memory. z A bank busy time of 6 cycles Ā„ The time the bank is occupied with one request. A processor cannot issue a second request to the same bank until the bank busy time has elapsed

Ā‹ How long will it take to complete a 64-element vector load with a stride of 1? Ā‹ With a stride of 32?

Case of 1-Stride: z Since the number of banks is larger than the bank busy time, for a stride of 1, no conflict on memory banks ¾ The load will take 76 (=12+64) clock cycles, 1.2 clocks per element

Case of 32-Stride: z Every access to memory (after the first one) will collide with the previous access and will have to wait for the 6-clock-cycle bank busy time. ¾ The load will take 391 (=12+1+6*63) cycles, 6.1 clocks per element

1/11/2005 Hiroaki Kobayashi 32

z Memory bank conflicts will not

occur within a single vector

memory instruction if

9 The stride and number of

banks are relatively prime with

respect to each other, and

9 There are enough banks to

avoid conflicts in the unit stride

case

z With 64 banks, a stride of 32 will

stall on every other access,

rather than every access.

z With 256 banks, a stride of 32 will

stall on every 8 access.

Increasing the number of memory banks to a number greater than the minimum to prevent stalls with a stride of length 1 will decrease the stall frequency for some other strides.

Programming for avoiding conflicts whenever possible

Programming for avoiding conflicts whenever possible

And…

1/11/2005 Hiroaki Kobayashi 33

z Chaining

Ā„ The concept of

forwarding extended to

vector registers

Ā„ The results from the first

functional unit in the

chain are forwarded to

the second functional unit.

Example:

MULV.D V1,V2,V ADDV.D V4,V1,V

A sustained rate (ignoring start-up) of two floating-point operation per cycle. Total running time: (Vector length)+(Start-up Time (^) ADD) + (Start-up timeMULV)

1/11/2005 Hiroaki Kobayashi 34

A i B i

D i

C i

lo a d

lo a d lo a d

s t o r e

Example D(i)=A(i) B(i)+C(i)

vld $v4, 8, $s vld $v5, 8, $s vld $v7, 8, $s vfmp $v6, $v4, $v vfad $v3, $v6, $v vst $v3, 8, $s

Assembler Image VLD^ VLD VLD

VFAD

VFMP

VST

Vector Multiplier

Vector Adder

Vector Register Memory

1/11/2005 Hiroaki Kobayashi 37

z Sparse Matrices

Ā„ The elements of a vector are usually stored in some

compacted form and then accessed indirectly.

Example: A sparse vector sum on the arrays A and C, using index vector K and M to designate the nonzero elements of A and C.

do 100 i=1,n 100 A(K(i)) = A(K(i)) + C(M(i))

Scatter-Gather Operations using index vectors ¾ Support moving between a dense representation (i.e., zeros are not included) and normal representation (i.e., the zeros are included) of a sparse matrix

1/11/2005 Hiroaki Kobayashi 38

z A gather operation takes an

index vector and fetches the

vector whose elements are

at the addresses given by

adding a base address to the

offsets given in the index

vector.

Ā„ The result is a non-sparse vector in a vector register.

z After these elements are

operated on in dense form,

the sparse vector can be

stored in expanded form by

a scatter store , using the

same index vector.

Ra, Rc, Rk, and Rm contain the starting addresses of the vectors LVI: load vector indexed SVI: store vector indexed

Scatter-gather

Example

1/11/2005 Hiroaki Kobayashi 39

z Combination of parallel and

pipelined functional units

z Each lane contains one

portion of the vector-

register file and one

execution pipeline from

each vector functional unit

z Each vector functional unit

executes vector

instructions at the rate of

one element group per

cycle using multiple

pipeline, one per lane.

z Inter-lane wiring is only

required to access main

memory

1/11/2005 Hiroaki Kobayashi 40