Docsity

Parallelisation - Compiler Optimisation - Lecture Slides, Slides of Computer Science

Partial preview of the text

Download Parallelisation - Compiler Optimisation - Lecture Slides and more Slides Computer Science in PDF only on Docsity!

Parallelisation

Michael O’BoyleFebruary, 2011

M. O’Boyle

Parallelisation

1

Lecture Overview

•^

Parallelisation for fork/join

-^

Mapping parallelism to shared memory multi-processors

-^

Loop distribution and fusion

-^

Data Partitioning and SPMD parallelism

-^

Communication, synchronisation and load imbalance. M. O’Boyle

Parallelisation

3

Loop Parallelisation

•^

Assume a single address space machine. Each processor sees the same set ofaddresses. Do not need to know physical location of memory reference.

-^

Control- orientated approach.

Concerned with finding independent iterations

of a loop. Then map or schedule these to the processor.

-^

Aim: find maximum amount of parallelism and minimise synchronisation.

-^

Secondary aim: improve load imbalance.

Inter-processor communication not

considered.

-^

Main memory just part of hierarchy - so use uni-processor approaches. M. O’Boyle

Parallelisation

4

Loop Parallelisation: Fork/join

•^

Fork/join assumes that there is a forking of parallel threads at the beginningof a parallel loop

-^

Each thread executes one or more iterations. Depend on later scheduling policy

-^

There is a corresponding join or synchronisation at the end

-^

For this reason loop parallel approaches favour outer loop parallelism

-^

Can use loop interchange to improve the fork/join overhead. M. O’Boyle

Parallelisation

6

Parallelisation approach

•^

Loop distribution eliminates carried dependences and creates opportunity forouter-loop parallelism.

-^

However increases number of synchronisations needed after each distributedloop.

-^

Maximal

distribution

often

finds

components

too

small

for

efficient

parallelisation

-^

Solution: fuse together parallelisable lops. M. O’Boyle

Parallelisation

February, 2011

7

Loop Fusion

•^

Fusion is illegal if fusing two loops causes the dependence direction to bechanged Do i = 1,N

a(i) = b(i) +c

EnddoDo i = 1,N

d(i) = a(i+1) +e

Enddo

Do i = 1,N

a(i) = b(i) +cd(i) = a(i+1) +e

Enddo

•^

Profitability:

Parallel loops should not generally be merged with sequential

loops: Tapered fusion M. O’Boyle

Parallelisation

9

Data Parallelism: Mapping

•^

Placement of work and data on processors.

Assume parallelism found in a

previous stage

-^

Typically program parallelism

O

(n

)^

is much greater than machine parallelism

O

(p

n >> p

•^

We have many options as to how to map a parallel program

-^

Key issue:

What is the best mapping that achieves

O

(p

)^

parallelism but

minimises cost

-^

Costs include communication, load imbalance and synchronisation M. O’Boyle

Parallelisation

10

Simple Fortran example

Dimension Integer a(4,8)Do i = 1, 4

Do j = 1,

a(i,j) = i + j Enddo Enddo

1

2

3

4

5

6

7

8

1 2 3 4

2

3

4

5

6

7

8

9

3

4

5

6

7

8

9

10

4

5

6

7

8

9

10

11

5

6

7

8

9

10

11

12

loop j

loop i

Iteration Space Data Space

1 4

1

8

index 1

index 2

M. O’Boyle

Parallelisation

12

Partitioning by rows of a and hence iterator i: Local writes^1

2

3

4

5

6

7

8

1 2 3 4

2

3

4

5

6

7

8

9

3

4

5

6

7

8

9

10

4

5

6

7

8

9

10

11

5

6

7

8

9

10

11

12

loop j

loop i

Iteration Space Data Space

1 4

1

8

index 1

index 2

P1 P2 P3 P4 P1 P2 P3 P

Dimension Integer a(1..1,1..8)Do i = 1, 1

Processor 1

Do j = 1,

a(i,j) = i + j Enddo Enddo...Dimension Integer a(3..3,1..8)Do i = 3, 3

Processor 3

Do j = 1,

a(i,j) = i + j Enddo Enddo

etc..

M. O’Boyle

Parallelisation

13

Linear Program representation

Do i = 1, Do j = 1, Do k = i,16c(i,j) = c(i,j)

+a(i,k)*b(j,k)

i j k

Polytope

AJ

b

. Access matrices

U

c^

U

a^

U

b

[

]

c

i j k

[

]

a

i j k

[

]

a

i j k

Can we automatically generate code for each processor given that writes must belocal? M. O’Boyle

Parallelisation

February, 2011

15

Load Balance : 4 procs

Do i = 1,

Do j = 1,

Do k = i,

c(i,j) = c(i,j) +a(i,k)*b(j,k)

Assuming c, a,b are to be partitioned in a similar mannerHow should we partition to minimise load imbalance?^ •

Row: 928,672,416,160 per processor, load imbalance: 384 • Column: 544 iterations per processor Why this variation? M. O’Boyle

Parallelisation

16

Load Balance :

k

j i

Partition by ””invariant” iterator j.Can be expressed as a polytope condition M. O’Boyle

Parallelisation

18

Reducing Communication :Column Partitioning

Each processor has columns of

a

and

b

allocated to it

Look at access pattern of second processor

P

P

P

P

P

The columns of

a

scheduled to P2 access all of b

n

2

n (^2) p^

remote access

M. O’Boyle

Parallelisation

19

Reducing Communication :Row Partitioning

Each processor has rows of

a

and

b

allocated to it

Look at access pattern of second processor

a^

b

P1 P2 P3 P

The rows of

a

scheduled to P2 access corresponding rows of

b

0 remote accesses. M. O’Boyle

Parallelisation