Polly as an analysis pass in LLVM Utpal Bora * , Johannes Doerfert + - - PowerPoint PPT Presentation

polly as an analysis pass in llvm
SMART_READER_LITE
LIVE PREVIEW

Polly as an analysis pass in LLVM Utpal Bora * , Johannes Doerfert + - - PowerPoint PPT Presentation

Polly as an analysis pass in LLVM Utpal Bora * , Johannes Doerfert + , Tobias Grosser $ , Venugopal Raghavan and Ramakrishna Upadrasta * IIT Hyderabad * , Saarland University + , ETH Zurich $ , AMD India Pvt. Ltd. Goal Use precise dependence


slide-1
SLIDE 1

Polly as an analysis pass in LLVM

Utpal Bora*, Johannes Doerfert+, Tobias Grosser$, Venugopal Raghavan£ and Ramakrishna Upadrasta* IIT Hyderabad*, Saarland University+, ETH Zurich$, AMD India Pvt. Ltd.£

slide-2
SLIDE 2

❖ Use precise dependence analysis of Polly in LLVM transformations

Goal

2

slide-3
SLIDE 3

Example for vectorization

MultiSource/Benchmarks/TSVC/LinearDependence-flt for (int i = 0; i < LEN2; i++) { for (int j = 0; j < i; j++) { aa[i][j] = aa[j][i] + bb[i][j]; } }

3

Loop Vectorizer falsely states memory dependence

slide-4
SLIDE 4

Example for vectorization

MultiSource/Benchmarks/TSVC/LinearDependence-flt for (int i = 0; i < LEN2; i++) { for (int j = 0; j < i; j++) { aa[i][j] = aa[j][i] + bb[i][j]; } }

4

No memory dependence because of j < i

slide-5
SLIDE 5

Example for vectorization

MultiSource/Benchmarks/TSVC/LinearDependence-flt for (int i = 0; i < LEN2; i++) { for (int j = 0; j < i; j++) { aa[i][j] = aa[j][i] + bb[i][j]; } }

5

No memory dependence because of j < i Polly correctly determines no dependence

slide-6
SLIDE 6

Example for vectorization

MultiSource/Benchmarks/TSVC/LinearDependence-flt for (int i = 0; i < LEN2; i++) { for (int j = 0; j < i; j++) { aa[i][j] = aa[j][i] + bb[i][j]; } }

6

No memory dependence because of j < i Polly correctly determines no dependence Loop is parallel and vectorizable This loop can be vectorized using PolyhedralInfo.

slide-7
SLIDE 7

Implementation Detail

❖ PolyhedralInfo- a new interface to Polly ❖ APIs exposed for LLVM transformations

➢ check loop is parallel: isParallel(Loop *L) ➢ check vectorization legality: isVectorizable(Loop *L, unsigned int *VF) VF - Vectorization Factor We compute the maximum VF for the given loop if it is vectorizable. It is set to UINT_MAX for parallel loops

7

slide-8
SLIDE 8

8

slide-9
SLIDE 9

Checking loop parallelism

9

for (i = 0; i < n; i++) for (j = 0; j < n; j++) A[i] = 1; $ opt -polly-process-unprofitable \

  • polyhedral-info \
  • polly-check-parallel \
  • analyze 1.ll

loop.i: Loop is parallel. loop.j: Loop is not parallel.

slide-10
SLIDE 10

Checking loop parallelism

10

for (i = 0; i < n; i++) for (j = 0; j < n; j++) A[j] = 1; $ opt -polly-process-unprofitable \

  • polyhedral-info \
  • polly-check-parallel \
  • analyze 2.ll

loop.i: Loop is not parallel. loop.j: Loop is parallel.

slide-11
SLIDE 11

Checking loop vectorization legality

11

void f ( int *A, int N ) { for ( int j = 0; j < N; j++ ) for ( int i = 0; i < N; i++ ) A[i + 8] = A[i] + 1; }

$ opt -polly-process-unprofitable \

  • polyhedral-info \
  • polly-check-vectorizable \
  • analyze 3.ll

loop.j: Loop is not vectorizable loop.i: Loop is vectorizable with max VF = 8

slide-12
SLIDE 12

Using PolyhedralInfo in LLVM

Include the header PolyhedralInfo #include "polly/PolyhedralInfo.h" void getAnalysisUsage(AnalysisUsage &AU) const override { AU.addRequired<PolyhedralInfo>(); … } bool runOnFunction(Function &F) override { auto *PHInfo = &getAnalysis<PolyhedralInfo>(); auto IsParallel = PHInfo->isParallel(TheLoop); … unsigned int VF = 0; auto IsVectorizable = PHInfo->isVectorizable(TheLoop, &VF); … }

12

slide-13
SLIDE 13

Future Work

❖ Derive runtime checks in LLVM for assumptions in Polly ❖ Modeling dependences at instruction granularity ❖ Parametric dependence distances ❖ Demand driven computation of dependences

13

slide-14
SLIDE 14

Thank You!

14