pattern matching and recognition 689 - special topics on advanced compiler technologies
DESCRIPTION
Pattern Matching and Recognition 689 - Special Topics on Advanced Compiler Technologies. Alin Jula March,19 th 2003. Motivation - Why do we care ?. Abstract concepts are simpler to deal with and closer to the human language Enables implementation substitution - PowerPoint PPT PresentationTRANSCRIPT
![Page 1: Pattern Matching and Recognition 689 - Special Topics on Advanced Compiler Technologies](https://reader036.vdocument.in/reader036/viewer/2022062323/5681593c550346895dc67aba/html5/thumbnails/1.jpg)
1
Pattern Matching and Recognition689 - Special Topics on Advanced Compiler Technologies
Alin JulaMarch,19th 2003
![Page 2: Pattern Matching and Recognition 689 - Special Topics on Advanced Compiler Technologies](https://reader036.vdocument.in/reader036/viewer/2022062323/5681593c550346895dc67aba/html5/thumbnails/2.jpg)
2
Motivation - Why do we care ?
Abstract concepts are simpler to deal with and closer to the human language
Enables implementation substitution e.g. recurrences can be replaced
Eases maintenance process e.g. Polaris - 600,000 lines of code
![Page 3: Pattern Matching and Recognition 689 - Special Topics on Advanced Compiler Technologies](https://reader036.vdocument.in/reader036/viewer/2022062323/5681593c550346895dc67aba/html5/thumbnails/3.jpg)
3
General Issues Pattern matching and recognition = Semantic
compiler
Low - Level codes
assembly
C++, Java
Fortran,C
CASE Instruments
Higher - Level codes STAPL
Human languages : English, Romanian, Spanish, etcHighest Level
compilers
Semantic compilers
![Page 4: Pattern Matching and Recognition 689 - Special Topics on Advanced Compiler Technologies](https://reader036.vdocument.in/reader036/viewer/2022062323/5681593c550346895dc67aba/html5/thumbnails/4.jpg)
4
Example “Given a set of uranium isotopes
with random energies and velocities, calculate their coordinates (energy, velocities, space coordinates,etc) after 3 seconds of interaction”
Equivalent with thousands or maybe hundred of thousands of lines of code
![Page 5: Pattern Matching and Recognition 689 - Special Topics on Advanced Compiler Technologies](https://reader036.vdocument.in/reader036/viewer/2022062323/5681593c550346895dc67aba/html5/thumbnails/5.jpg)
5
Program code Parser Intermediate Representation
Pattern Matcher
Library of
Patterns
Matched PatternsConcept Interpreter
Parallel CodeProgram Understanding
Code Generation and Replacement
Pattern Matching and Recognition
![Page 6: Pattern Matching and Recognition 689 - Special Topics on Advanced Compiler Technologies](https://reader036.vdocument.in/reader036/viewer/2022062323/5681593c550346895dc67aba/html5/thumbnails/6.jpg)
6
Program Understanding (Low to High Level)
Code Generation and Replacement (High to Low Level)
Pattern Matching and Recognition
![Page 7: Pattern Matching and Recognition 689 - Special Topics on Advanced Compiler Technologies](https://reader036.vdocument.in/reader036/viewer/2022062323/5681593c550346895dc67aba/html5/thumbnails/7.jpg)
7
Quilici - Overview Translates C into C++
Input : C code in Abstract Syntax Tree form
Output : Programming plans ( then C++ )
Analysis Bottom-Up on the Code Top-Down on the Programming Plans
![Page 8: Pattern Matching and Recognition 689 - Special Topics on Advanced Compiler Technologies](https://reader036.vdocument.in/reader036/viewer/2022062323/5681593c550346895dc67aba/html5/thumbnails/8.jpg)
8
Quilici - Example
C code
Equivalent C++ code
![Page 9: Pattern Matching and Recognition 689 - Special Topics on Advanced Compiler Technologies](https://reader036.vdocument.in/reader036/viewer/2022062323/5681593c550346895dc67aba/html5/thumbnails/9.jpg)
9
Quilici - Plan Library A Library of patterns
(programming plans) Extends an existing Library (from
Andersen Consulting for understanding Cobol).
![Page 10: Pattern Matching and Recognition 689 - Special Topics on Advanced Compiler Technologies](https://reader036.vdocument.in/reader036/viewer/2022062323/5681593c550346895dc67aba/html5/thumbnails/10.jpg)
10
Quilici - Programming Plan Programming Plan
definition :list of attributes recognition rule(s)
components of the plan constraints on the components
![Page 11: Pattern Matching and Recognition 689 - Special Topics on Advanced Compiler Technologies](https://reader036.vdocument.in/reader036/viewer/2022062323/5681593c550346895dc67aba/html5/thumbnails/11.jpg)
11
Quilici -Programming Plan
Read Values within a while loop
![Page 12: Pattern Matching and Recognition 689 - Special Topics on Advanced Compiler Technologies](https://reader036.vdocument.in/reader036/viewer/2022062323/5681593c550346895dc67aba/html5/thumbnails/12.jpg)
12
Quilici - Library Organization
Plan indices Connects plans hierarchically Objective : narrows the search
Specialization Constraints Stores only the constraints Objective: eliminates commonalties
Implied Plans Objects recognized form a particular plan Objective : avoids matching them with the
code, their existence is implied from the recognized plans
![Page 13: Pattern Matching and Recognition 689 - Special Topics on Advanced Compiler Technologies](https://reader036.vdocument.in/reader036/viewer/2022062323/5681593c550346895dc67aba/html5/thumbnails/13.jpg)
13
Quilici - The Algorithm
![Page 14: Pattern Matching and Recognition 689 - Special Topics on Advanced Compiler Technologies](https://reader036.vdocument.in/reader036/viewer/2022062323/5681593c550346895dc67aba/html5/thumbnails/14.jpg)
14
Quilici Example
![Page 15: Pattern Matching and Recognition 689 - Special Topics on Advanced Compiler Technologies](https://reader036.vdocument.in/reader036/viewer/2022062323/5681593c550346895dc67aba/html5/thumbnails/15.jpg)
15
Program code Parser Intermediate Representation
Pattern Matcher
Library of
Patterns
Matched PatternsConcept Interpreter
Parallel Code
Program code Parser Intermediate Representation
Pattern Matcher
Library of
Patterns
Matched PatternsConcept Interpreter
![Page 16: Pattern Matching and Recognition 689 - Special Topics on Advanced Compiler Technologies](https://reader036.vdocument.in/reader036/viewer/2022062323/5681593c550346895dc67aba/html5/thumbnails/16.jpg)
16
BH - Overview Parallelizes FORTRAN code using
pattern matching Input : (FORTRAN code - abstract syntax
tree) Output ( parallel FORTRAN code )
Analysis Patterns are found in the code User replaces these patterns with an
already parallelized implementation
![Page 17: Pattern Matching and Recognition 689 - Special Topics on Advanced Compiler Technologies](https://reader036.vdocument.in/reader036/viewer/2022062323/5681593c550346895dc67aba/html5/thumbnails/17.jpg)
17
BH - Overview
![Page 18: Pattern Matching and Recognition 689 - Special Topics on Advanced Compiler Technologies](https://reader036.vdocument.in/reader036/viewer/2022062323/5681593c550346895dc67aba/html5/thumbnails/18.jpg)
18
BH- Pattern Language Describes
programming concepts domain concepts
The patterns are written in the pattern language before pattern recognition process
![Page 19: Pattern Matching and Recognition 689 - Special Topics on Advanced Compiler Technologies](https://reader036.vdocument.in/reader036/viewer/2022062323/5681593c550346895dc67aba/html5/thumbnails/19.jpg)
19
BH - Pattern Language Syntax
![Page 20: Pattern Matching and Recognition 689 - Special Topics on Advanced Compiler Technologies](https://reader036.vdocument.in/reader036/viewer/2022062323/5681593c550346895dc67aba/html5/thumbnails/20.jpg)
20
BH - Patterns Examples
![Page 21: Pattern Matching and Recognition 689 - Special Topics on Advanced Compiler Technologies](https://reader036.vdocument.in/reader036/viewer/2022062323/5681593c550346895dc67aba/html5/thumbnails/21.jpg)
21
BH - Pattern Classification Hierarchical approach Classification of patterns
base-concept (atomic) - e.g. swap intermediate-concept - e.g. pivoting domain-concept - e.g. Gaussian
elimination Dependencies between the
patterns are stored in the library
![Page 22: Pattern Matching and Recognition 689 - Special Topics on Advanced Compiler Technologies](https://reader036.vdocument.in/reader036/viewer/2022062323/5681593c550346895dc67aba/html5/thumbnails/22.jpg)
22
BH - Pattern Classification
![Page 23: Pattern Matching and Recognition 689 - Special Topics on Advanced Compiler Technologies](https://reader036.vdocument.in/reader036/viewer/2022062323/5681593c550346895dc67aba/html5/thumbnails/23.jpg)
23
BH - Pattern Recognition The user is asked to specify the
domain concepts as narrow as possible
The AST is then compared against the Pattern Library
![Page 24: Pattern Matching and Recognition 689 - Special Topics on Advanced Compiler Technologies](https://reader036.vdocument.in/reader036/viewer/2022062323/5681593c550346895dc67aba/html5/thumbnails/24.jpg)
24
BH - Domain Patterns
![Page 25: Pattern Matching and Recognition 689 - Special Topics on Advanced Compiler Technologies](https://reader036.vdocument.in/reader036/viewer/2022062323/5681593c550346895dc67aba/html5/thumbnails/25.jpg)
25
BH - Algorithm Prune the space of patterns to
search Base concepts are identified Intermediate patterns are built up
from the base ones Domain concepts are built up from
intermediate ones One Pass Search !
Fastnot Effective
![Page 26: Pattern Matching and Recognition 689 - Special Topics on Advanced Compiler Technologies](https://reader036.vdocument.in/reader036/viewer/2022062323/5681593c550346895dc67aba/html5/thumbnails/26.jpg)
26
BH - Algorithm
![Page 27: Pattern Matching and Recognition 689 - Special Topics on Advanced Compiler Technologies](https://reader036.vdocument.in/reader036/viewer/2022062323/5681593c550346895dc67aba/html5/thumbnails/27.jpg)
27
BH - Algorithm (cont.)
![Page 28: Pattern Matching and Recognition 689 - Special Topics on Advanced Compiler Technologies](https://reader036.vdocument.in/reader036/viewer/2022062323/5681593c550346895dc67aba/html5/thumbnails/28.jpg)
28
Program code Parser Intermediate Representation
Pattern Matcher
Library of
Patterns
Matched PatternsConcept Interpreter
Parallel Code
Program code Parser Intermediate Representation
Pattern Matcher
Library of
Patterns
Matched PatternsConcept Interpreter
Parallel Code
![Page 29: Pattern Matching and Recognition 689 - Special Topics on Advanced Compiler Technologies](https://reader036.vdocument.in/reader036/viewer/2022062323/5681593c550346895dc67aba/html5/thumbnails/29.jpg)
29
K - Overview Parallelizes FORTRAN 77 and C
code using pattern matching Input : (FORTRAN 77 and C code -
abstract syntax tree) Output ( parallel C code )
Analysis Graph based Hierarchical approach
![Page 30: Pattern Matching and Recognition 689 - Special Topics on Advanced Compiler Technologies](https://reader036.vdocument.in/reader036/viewer/2022062323/5681593c550346895dc67aba/html5/thumbnails/30.jpg)
30
K-Library Collected around of 150 patterns
for scientific numeric codes Hierarchical approach
e.g. matrix-multiplication = loop over a dot product
Patterns characterized based on the depth of the loop nest e.g. scalar =0. Dot product=1,matrix
multiplication=2, etc
![Page 31: Pattern Matching and Recognition 689 - Special Topics on Advanced Compiler Technologies](https://reader036.vdocument.in/reader036/viewer/2022062323/5681593c550346895dc67aba/html5/thumbnails/31.jpg)
31
K - library
![Page 32: Pattern Matching and Recognition 689 - Special Topics on Advanced Compiler Technologies](https://reader036.vdocument.in/reader036/viewer/2022062323/5681593c550346895dc67aba/html5/thumbnails/32.jpg)
32
K- Library Organization Organized as a Pattern Hierarchy
Graph(PHG) G(V,E) - V is a set of patterns, E set of
dependencies between patterns m dependent of the trigger patterns mi,
there is an edge between (m,mi)
Pattern recognition becomes a path finding program in PHG
![Page 33: Pattern Matching and Recognition 689 - Special Topics on Advanced Compiler Technologies](https://reader036.vdocument.in/reader036/viewer/2022062323/5681593c550346895dc67aba/html5/thumbnails/33.jpg)
33
K - Library Organization
![Page 34: Pattern Matching and Recognition 689 - Special Topics on Advanced Compiler Technologies](https://reader036.vdocument.in/reader036/viewer/2022062323/5681593c550346895dc67aba/html5/thumbnails/34.jpg)
34
K - Algorithm
![Page 35: Pattern Matching and Recognition 689 - Special Topics on Advanced Compiler Technologies](https://reader036.vdocument.in/reader036/viewer/2022062323/5681593c550346895dc67aba/html5/thumbnails/35.jpg)
35
K - Paramat Paramat=PARallelize Automatically
by pattern MATching Tool for pattern recognition and
algorithm substitution Automatic Parallelization Tool
![Page 36: Pattern Matching and Recognition 689 - Special Topics on Advanced Compiler Technologies](https://reader036.vdocument.in/reader036/viewer/2022062323/5681593c550346895dc67aba/html5/thumbnails/36.jpg)
36
K - Paramat
![Page 37: Pattern Matching and Recognition 689 - Special Topics on Advanced Compiler Technologies](https://reader036.vdocument.in/reader036/viewer/2022062323/5681593c550346895dc67aba/html5/thumbnails/37.jpg)
37
K -Paramat Algorithm replacement
(recurrences) Data distribution Run time prediction
![Page 38: Pattern Matching and Recognition 689 - Special Topics on Advanced Compiler Technologies](https://reader036.vdocument.in/reader036/viewer/2022062323/5681593c550346895dc67aba/html5/thumbnails/38.jpg)
38
Program code Parser Intermediate Representation
Pattern Matcher
Library of
Patterns
Matched PatternsConcept Interpreter
Parallel Code
Program code Parser Intermediate Representation
Pattern Matcher
Library of
Patterns
Matched PatternsConcept Interpreter
Parallel Code
![Page 39: Pattern Matching and Recognition 689 - Special Topics on Advanced Compiler Technologies](https://reader036.vdocument.in/reader036/viewer/2022062323/5681593c550346895dc67aba/html5/thumbnails/39.jpg)
39
W & Y - Overview Program Understanding as
Constraint Satisfaction Problem a set of variables Xi
a set of values for each Xi, Dom (Xi) set of constraints - permissible
subsets to variable Constraints implemented in Prolog Searching algorithm - backtracking
![Page 40: Pattern Matching and Recognition 689 - Special Topics on Advanced Compiler Technologies](https://reader036.vdocument.in/reader036/viewer/2022062323/5681593c550346895dc67aba/html5/thumbnails/40.jpg)
40
W & Y - Overview
![Page 41: Pattern Matching and Recognition 689 - Special Topics on Advanced Compiler Technologies](https://reader036.vdocument.in/reader036/viewer/2022062323/5681593c550346895dc67aba/html5/thumbnails/41.jpg)
41
W & Y - Algorithm
![Page 42: Pattern Matching and Recognition 689 - Special Topics on Advanced Compiler Technologies](https://reader036.vdocument.in/reader036/viewer/2022062323/5681593c550346895dc67aba/html5/thumbnails/42.jpg)
42
W& Y - Results
![Page 43: Pattern Matching and Recognition 689 - Special Topics on Advanced Compiler Technologies](https://reader036.vdocument.in/reader036/viewer/2022062323/5681593c550346895dc67aba/html5/thumbnails/43.jpg)
43
Program code Parser Intermediate Representation
Pattern Matcher
Library of
Patterns
Matched PatternsConcept Interpreter
Parallel Code
Program code Parser Intermediate Representation
Pattern Matcher
Library of
Patterns
Matched PatternsConcept Interpreter
![Page 44: Pattern Matching and Recognition 689 - Special Topics on Advanced Compiler Technologies](https://reader036.vdocument.in/reader036/viewer/2022062323/5681593c550346895dc67aba/html5/thumbnails/44.jpg)
44
PAP -Overview Parallelizable Algorithmic Patterns Graphical tool - permits
vizualization of the recognized concepts, together with the implementation within the program
Integrated into Vienna Fortran Compilation System
![Page 45: Pattern Matching and Recognition 689 - Special Topics on Advanced Compiler Technologies](https://reader036.vdocument.in/reader036/viewer/2022062323/5681593c550346895dc67aba/html5/thumbnails/45.jpg)
45
PAP - Recognizer
Performs a hierarchical parsing driven by concept recognition rules (implemented in Prolog)
Concept its compositional hierarchy (set of
composing subcomponents) Relationships and constraints among
composing components
![Page 46: Pattern Matching and Recognition 689 - Special Topics on Advanced Compiler Technologies](https://reader036.vdocument.in/reader036/viewer/2022062323/5681593c550346895dc67aba/html5/thumbnails/46.jpg)
46
PAP - Recognizer
PAP builds an Abstract Program Representation(APR) from a Basic Program Representation (BPR) (initial code )
Base level of representation - Program Dependence Graph (PDG) nodes - statements edges
control flow ( labeled with T/F) data dependence (labeled with variable identifier)
The APR is a hierarchical PDG
![Page 47: Pattern Matching and Recognition 689 - Special Topics on Advanced Compiler Technologies](https://reader036.vdocument.in/reader036/viewer/2022062323/5681593c550346895dc67aba/html5/thumbnails/47.jpg)
47
PAP - APR
![Page 48: Pattern Matching and Recognition 689 - Special Topics on Advanced Compiler Technologies](https://reader036.vdocument.in/reader036/viewer/2022062323/5681593c550346895dc67aba/html5/thumbnails/48.jpg)
48
PAP - Traits PAP deals with
Program variation - various implementations for the same algorithm
Delocalization - implementation of a concept throughout the code
Overlapping implementations - implementations of two or more concepts are merged
![Page 49: Pattern Matching and Recognition 689 - Special Topics on Advanced Compiler Technologies](https://reader036.vdocument.in/reader036/viewer/2022062323/5681593c550346895dc67aba/html5/thumbnails/49.jpg)
49
PAP - Output example
![Page 50: Pattern Matching and Recognition 689 - Special Topics on Advanced Compiler Technologies](https://reader036.vdocument.in/reader036/viewer/2022062323/5681593c550346895dc67aba/html5/thumbnails/50.jpg)
50
Program code Parser Intermediate Representation
Pattern Matcher
Library of
Patterns
Matched PatternsConcept Interpreter
Parallel Code
Program code Intermediate RepresentationParser
Pattern Matcher
Library of
Patterns
Matched Patterns
![Page 51: Pattern Matching and Recognition 689 - Special Topics on Advanced Compiler Technologies](https://reader036.vdocument.in/reader036/viewer/2022062323/5681593c550346895dc67aba/html5/thumbnails/51.jpg)
51
BFV - Overview Code Generator Graphical Tool Input
Design Patterns Output
C++ code.
![Page 52: Pattern Matching and Recognition 689 - Special Topics on Advanced Compiler Technologies](https://reader036.vdocument.in/reader036/viewer/2022062323/5681593c550346895dc67aba/html5/thumbnails/52.jpg)
52
BFV
![Page 53: Pattern Matching and Recognition 689 - Special Topics on Advanced Compiler Technologies](https://reader036.vdocument.in/reader036/viewer/2022062323/5681593c550346895dc67aba/html5/thumbnails/53.jpg)
53
BFV
![Page 54: Pattern Matching and Recognition 689 - Special Topics on Advanced Compiler Technologies](https://reader036.vdocument.in/reader036/viewer/2022062323/5681593c550346895dc67aba/html5/thumbnails/54.jpg)
54
BFV
![Page 55: Pattern Matching and Recognition 689 - Special Topics on Advanced Compiler Technologies](https://reader036.vdocument.in/reader036/viewer/2022062323/5681593c550346895dc67aba/html5/thumbnails/55.jpg)
55
Parser Intermediate Representation
Pattern Matcher
Library of
Patterns
Matched Patterns
Program code
Concept Interpreter
Parallel Code
Program code
Concept Interpreter
![Page 56: Pattern Matching and Recognition 689 - Special Topics on Advanced Compiler Technologies](https://reader036.vdocument.in/reader036/viewer/2022062323/5681593c550346895dc67aba/html5/thumbnails/56.jpg)
57
References [Quilici] "An Opportunistic, Memory-Based Approach to
Recognizing Programmings Plans" , Alex Quilici [BH] "A Pattern Matching Approach for reusing Software Libraries
in Parallel Systems" ,S. Bhansali, J.R. Hagemeister [K] "Pattern-Driven Automatic Parallelization" , Christoph Kessler [W&Y] "Program Understanding as Constraint Satisfaction
Representation and Reasoning Techniques" , S. Woods, Q. Yang [PAP]"PAP Recognizer : a Tool for Automatic Recognition of
Parallelizable Patterns" , B. Di Martino, G. Iannello [BFV] "Automatic Code Generation from Design Patterns“, IBM
Systems Journal, Vol. 35, No. 2, Frank Budinsky, Marilyn Finnie, Patsy Yu,John Vlissides
[M&Y] "Automatic Algorithm Recognition and Replacement” , Robert Metzger and Zhaofang Wen