b - Software Generators

advertisement
June, 2013
(New Slides Added to Support Unaided Reading)
Ted J. Biggerstaff
Software Generators, LLC
Von Neumann
with
Partitioning
Von Neumann
Architecture
Multicore
Threaded
Parallelism
Instruction
Level
Parallelism
(ILP)
Multicore
Threaded
And ILP
//Sobel Edge Detection
b=[(a s)2 +(a sp)2]1/2
Implementation
Neutral
Computation
Spec
GPU
Parallelism
(e.g., C and
CUDA)
DSLGen
((PL C) (partition t))
Execution
Platform
Spec
API or
Layered
Library
(e.g, DirectX)
Speciality
Platform or
Framework
(e.g, MDE
Docs)
Digital Signal
Processing
Chip
API
Future
Architectures
Von Neumann
Architecture
Multicore
Threaded
Parallel
Multicore
Threaded
Parallelism
Instruction
Level
Parallelism
(ILP)
Multicore
Threaded
And ILP
//Sobel Edge Detection
b=[(a s)2 +(a sp)2]1/2
Implementation
Neutral
Computation
Spec
GPU
Parallelism
(e.g., C and
CUDA)
DSLGen
((PL C) (partition t) Mcore
Execution
Platform
(Threads MS)
Spec
(LoadLevel (SliceSize 5)))
API or
Layered
Library
(e.g, DirectX)
Speciality
Platform or
Framework
(e.g, MDE
Docs)
Digital Signal
Processing
Chip
API
Future
Architectures
Von Neumann
Architecture
Multicore
Threaded
Parallelism
Instruction
Level
Parallelism
with SSE
Instruction
Level
Parallelism
(ILP)
Multicore
Threaded
And ILP
//Sobel Edge Detection
b=[(a s)2 +(a sp)2]1/2
Implementation
Neutral
Computation
Spec
GPU
Parallelism
(e.g., C and
CUDA)
DSLGen
((PL C) (partition t) (ILPExecution
SSE))
API or
Layered
Library
(e.g, DirectX)
Platform
Spec
Speciality
Platform or
Framework
(e.g, MDE
Docs)
Digital Signal
Processing
Chip
API
Future
Architectures
Von Neumann
Architecture
Multicore
Threaded
Parallelism
Instruction
Level
Parallelism
(ILP)
Multicore
Threaded
And ILP
//Sobel Edge Detection
b=[(a s)2 +(a sp)2]1/2
Implementation
Neutral
Computation
Spec
GPU
Parallelism
(e.g., C and
CUDA)
DSLGen
((PL MDE) (partition t) Execution
(ILP
Platform
SSE))
Spec
MDE DOCs
for
Parallelism
with SSE
API or
Layered
Library
(e.g, DirectX)
Speciality
Platform or
Framework
(e.g, MDE
Docs)
Digital Signal
Processing
Chip
API
Future
Architectures
PROBLEM DOMAIN (PD)

DSLGen™ Design in PD
PL
PROGRAM LANGUAGE
DOMAIN (PLD)

MDE (Model Driven
Engineering) in PLD
PL
PROBLEM DOMAIN (PD)

DSLGen™ Design in PD
INITIALLY, NO:
OO Classes
OO Methods
PL Scopes
PL Routines
Routine Signatures
PL Loops
Control Flow
Data Flow
Aliasing
…
PROGRAM LANGUAGE
DOMAIN (PLD)

MDE (Model Driven
Engineering) in PLD
Abstractions
PL
PROBLEM DOMAIN (PD)

DSLGen™ Design in PD
Associative
Programming
CONSTRAINTS
(APCs)
PROGRAM LANGUAGE
DOMAIN (PLD)

MDE (Model Driven
Engineering) in PLD
PL
Initial DSLGen™ Architecture
Representation
PROBLEM DOMAIN (PD)

DSLGen™ Design in PD
Iterative APC (e.g.,PD Loop)
PD Partion APC (e.g., edge or center)
PD Design Entity (e.g., Pixel
neighborhood specialized to
partition)
PD Component Definition (MethodTransform specialized to partition)
PROGRAM LANGUAGE
DOMAIN (PLD)

MDE (Model Driven
Engineering) in PLD
PL
Initial DSLGen™ Architectural
Layers
a
b
//Sobel Edge Detection
b=[(a s)2 +(a sp)2]1/2
S
a
a
 i 1, j 1
 ai , j 1

ai 1, j 1
a
a
a
a
a
a
i 1, j
i, j
i 1, j


i 1, j 1

i 1, j 1
i 1, j 1

 1  2  1
0
0
0 

 1
2
1 
=
1*a
i 1, j 1

 0*ai , j 1

 1*ai 1, j 1
 2*a
0*a
2*a
i 1, j
1*a
0*a
1*a
i 1, j 1
i, j
i 1, j





i 1, j 1
i 1, j 1

+

SP
a
 i 1, j 1
 ai , j 1

ai 1, j 1
a
a
a
i 1, j
i, j
i 1, j
a
a
a


i 1, j 1

i 1, j 1
i 1, j 1
  1 0 1
0 2

  1 0 1 
  2
=
1*a
i 1, j 1

  2*ai , j 1

1*ai 1, j 1
0*a
0*a
0*a
i 1, j
i, j
i 1, j
1*a
2*a
1*a


i 1, j 1 

i 1, j 1 
i 1, j 1
where ai,j is NOT an edge pixel
b
S
a
a
 i 1, j 1
 ai , j 1

ai 1, j 1
a
a
a
a
a
a
i 1, j
i, j
i 1, j


i 1, j 1

i 1, j 1
i 1, j 1

0 0 0 
0 0 0 


0 0 0
=
0*a
i 1, j 1

 0*ai , j 1

0*ai 1, j 1
0*a
0*a
0*a
i 1, j
i, j
i 1, j
0*a
0*a
0*a


i 1, j 1

i 1, j 1
i 1, j 1

+

SP
a
 i 1, j 1
 ai , j 1

ai 1, j 1
a
a
a
i 1, j
i, j
i 1, j
a
a
a


i 1, j 1

i 1, j 1
i 1, j 1

0 0 0 
0 0 0 


0 0 0
=
0*a
i 1, j 1

 0*ai , j 1

0*ai 1, j 1
0*a
0*a
0*a
i 1, j
i, j
i 1, j
where ai,j IS an edge pixel
0*a
0*a
0*a


i 1, j 1

i 1, j 1
i 1, j 1
b
//Sobel Edge Detection
b=[(a s)2 +(a sp)2]1/2
a
DSLGen™
Von Neumann
Machine
Multicore with
Threads
Vector Machine
b
Process
Edges
Sequentially
a
b
Process
Center
Edge Processing
Loops
1 Dimensional Loops
Center Processing
Loops
Neighborhood of
c[idx13,idx14]
Processing Loops
(c[idx13,idx14]
s[p15,q16])
(c[idx13,idx14]
sp[p15,q16])
Essence of
Sobel
Edges
Thread
a
Thread Mgr
b
Center Slice
Threads
Start Edge Thread
Routine
Slice Up Center
Start Center Slice
Routine for each Slice
Synchronize Thread
Routines
Edge Processing
Thread
One Dimensional
Loops
Synchronize
Thread
Center Processing
Thread
Loops Over
Center Slice
Loops Over
c[i,j] Pixel
Neighborhood
(c[i,j] 
s[p,q])
(c[i,j] 
sp[p,q])
Essence of
Sobel Edge
Detection
Synchronize
Thread
a
b
Process
Center
(RGB)
An RGB
Edge Loop
Generated
Weight
Vectors
RGB Center
Loops
(c[idx3,idx4]
dsarray9)
(c[idx3,idx4]
dsarray10)
Neighborhood Loops
As SSE
Instruction
Macros

Changing Platforms in Programming
Language (PL) Domain Requires Difficult
Reprogramming
Von Neumann to Multicore to Vector Processor
 Inter-related structures change across the program



PL-Based Abstractions Too Restrictive
Conclusion: Non-PL Abstractions Needed

Associative Programming Constraints (APC)
Isolated design feature of an implementation form
 Partial and provisional specification
 Retains domain knowledge
 Can be composed
 Can be manipulated (algebra of APCs)


Design Frameworks (formal “Design Patterns”)


Large scale architectural framework
Logical Architecture (LA) when combined

Iteration Constraints



Partitioning Constraints (Natural)



Loop Constraints
Recursion Constraints
Matrix edges, corners, non-corner edges, centers
Upper triangular, diagonal, and more
Partitioning Constraints (Synthetic)

Add design features to solution
a
Programmer’s
Specification of
The Platform
Programmer’s
Specification of
Computation
b
a
Programmer’s
Specification of
The Platform
Programmer’s
Specification of
Computation
b
Go To Platform Spec
a
(DSDeclare Neighborhood s :form (array (-1 1) (-1 1))
:of DSNumber)
(DSDeclare Neighborhood sp :form (array (-1 1) (-1 1))
:of DSNumber)
(DSDeclare DSNumber m :facts ((> m 1)))
(DSDeclare DSNumber n :facts ((> n 1)))
(DSDeclare BWImage a :form (array m n) :of BWPixel)
(DSDeclare BWImage b :form (array m n) :of BWPixel)
b
(Defcomponent w (sp #. ArrayReference ?p ?q)
(if (or (== ?i ?ilow) (== ?j ?jlow)
(== ?i ?ihigh) (== ?j ?jhigh)
(tags (constraints partitionmatrixtest edge)))
(then 0) (else (if (and (!= ?p 0) (!= ?q 0))
(then ?q) (else (if (and (== ?p 0) (!= ?q 0))
(then (* 2 ?q)) (else 0)))))))
(Defcomponent w (s #. ArrayReference ?p ?q) ….)
Specializations
b = [(a
s)2
+(a
sp)2]1/2
Built-In Def:
Center
Edge
(ai.j  s) =
(Σp, q (w(s)p , q * a i+p , j+q )
S
a
a
 i 1, j 1
 ai , j 1

ai 1, j 1
a
a
a
a
a
a
i 1, j
i, j
i 1, j


i 1, j 1

i 1, j 1
i 1, j 1

 1  2  1
0
0
0 

 1
2
1 
=
1*a
i 1, j 1

 0*ai , j 1

 1*ai 1, j 1
 2*a
0*a
2*a
i 1, j
1*a
0*a
1*a
i 1, j 1
i, j
i 1, j





i 1, j 1
i 1, j 1

+

SP
a
 i 1, j 1
 ai , j 1

ai 1, j 1
a
a
a
i 1, j
i, j
i 1, j
a
a
a


i 1, j 1

i 1, j 1
i 1, j 1
  1 0 1
0 2

  1 0 1 
  2
=
1*a
i 1, j 1

  2*ai , j 1

1*ai 1, j 1
0*a
0*a
0*a
i 1, j
i, j
i 1, j
1*a
2*a
1*a


i 1, j 1 

i 1, j 1 
i 1, j 1
where ai,j is NOT an edge pixel
b
S
a
a
 i 1, j 1
 ai , j 1

ai 1, j 1
a
a
a
a
a
a
i 1, j
i, j
i 1, j


i 1, j 1

i 1, j 1
i 1, j 1

0 0 0 
0 0 0 


0 0 0
=
0*a
i 1, j 1

 0*ai , j 1

0*ai 1, j 1
0*a
0*a
0*a
i 1, j
i, j
i 1, j
0*a
0*a
0*a


i 1, j 1

i 1, j 1
i 1, j 1
b

+

SP
a
 i 1, j 1
 ai , j 1

ai 1, j 1
a
a
a
i 1, j
i, j
i 1, j
a
a
a


i 1, j 1

i 1, j 1
i 1, j 1

0 0 0 
0 0 0 


0 0 0
=
0*a
i 1, j 1

 0*ai , j 1

0*ai 1, j 1
0*a
0*a
0*a
i 1, j
i, j
i 1, j
where ai,j IS an edge pixel
0*a
0*a
0*a


i 1, j 1

i 1, j 1
i 1, j 1
Return

Specialize IL
(Defcomponent w (sp #.
ArrayReference ?p ?q)
(if (or (== ?i ?ilow) (== ?j ?jlow)
(== ?i ?ihigh) (== ?j ?jhigh)
(tags (constraints
partitionmatrixtest edge)))
(then 0)
(else (if (and (!= ?p 0) (!= ?q 0))
(then ?q)
(else (if (and (== ?p 0)
(!= ?q 0))
(then (* 2 ?q))
(else 0)))))))

SP-Edge1 (== ?i ?ilow)
(Defcomponent w (sp-Edge1
#. ArrayReference ?p ?q) 0)

SP-Center5 (ELSE)
(Defcomponent w (sp-Center5
#. ArrayReference ?p ?q)
(if (and (!= ?p 0) (!= ?q 0))
(then ?q)
(else (if (and (== ?p 0)
(!= ?q 0))
(then (* 2 ?q))
(else 0)))))
Return
a
Programmer’s
Specification of
The Platform
Programmer’s
Specification of
Computation
b
a
((PL C) (partition t) Mcore
(Threads MS)
(LoadLevel (SliceSize 5)))
Programmer’s
Specification of
Computation
b
((PL C) (partition t)
Mcore (Threads MS)
(LoadLevel
(SliceSize 5)))
….
b = [(a s)2 +
(a sp)2]1/2
Partially Translated INS Expression:
b [i,j]= [(a[i,j] s[p,q])2 + (a[i,j]sp[p,q])2]1/2
Loop Constraint:
(forall (i j) { 0<= i<=(m-1), 0<=j<=(n-1), Partestx(S)}
Convolution
Neighborhoods
Set of Partitions
Specializations
Of
Neighbothoods
S and SP:
Edge4
Edge3
Edge1
Edge2
Center5
Transforms
S-Edge1
Sp-Edge1
S-Edge2
Sp-Edge2
S-Edge3
Sp-Edge3
S-Edge4
Sp-Edge4
S-Center5
Sp-Center5
W
Partestx
Row
Col
...
Loop APC
Partition APC
modifying loop APC
Neighborhoods spart &
sppart specialized to
Edge11 partition
NB: Concrete Example
where Spart & sppart
are analogous to s & sp
in abstract example.
Component definitions for
selected neighborhood
spart-0-edge11
W method-transform component
definition specialized to
neighborhood spart-0-edge11
Component definitions for
selected neighborhood
spart-0-center15
W method-transform component
definition specialized to
neighborhood spart-0-center15
Recall body of
definition of W of sp
Return
NB: Concrete Example
where Spart & sppart
are analogous to s & sp
in abstract example.
NB: Concrete Example
where Spart & sppart
are analogous to s & sp
in abstract example.
w.Spart body
specialized to edge
Return
((PL C) (partition t)
Mcore
(Threads MS)
(LoadLevel
(SliceSize 5)))
….
b = [(a s)2 +
(a sp)2]1/2
Partially Translated INS Expression:
b [i,j]= [(a[i,j] s[p,q])2 + (a[i,j]sp[p,q])2]1/2
Slicer: (forall (h) { 0<= h<=(m-1),
eq(mod(h, Rstep(S-Center5-KSegs)), 0),
Partestx(S-Center5-KSegs))
ASlice: (forall (i j)
{h<= i<min((h +RStep(S-Center5-KSegs),m),
0<=j<=(n-1), Partestx(S-Center5-ASeg)}
Center5-KSegs
Center5-ASeg
Edge2
Center5-0
…..
…..
…..
…..
…..
…..
…..
…..
Center5-K
Edge4
Edge3
Edge1
…..
Specializations
Of Neighbothoods
S and SP:
S-Edge1
Sp-Edge1
S-Edge2
Sp-Edge2
S-Edge3
Sp-Edge3
S-Edge4
Sp-Edge4
S-Center5
Sp-Center5
S-Center5-ASeg
Sp-Center5-ASeg
S-Center5-KSegs
SP-Center5-KSegs
((PL C) (partition t)
Mcore
(Threads MS)
(LoadLevel
(SliceSize 5)))
….
b = [(a s)2 +
(a sp)2]1/2
((PL C) (partition t)
Mcore
(Threads MS)
(LoadLevel
(SliceSize 5)))
….
b = [(a s)2 +
(a sp)2]1/2
((PL C) (partition t)
Mcore
(Threads MS)
(LoadLevel
(SliceSize 5)))
….
b = [(a s)2 +
(a sp)2]1/2
Demo
Computation
Specification
Target
Machine
Specification
Data Abstractions
Phase List
Definitions
Generator Execution Unit
v
v
v
v
Read Computation Specification
Read Target Machine Specification
Read List of Phases
For each Phase
o Enable Transforms of that Phase
o Traverse Specification Applying Rewriting
Transforms
v Write Out Generated Program
Generated
GPL Program
Partial
Evaluation
Engine
Inference
Engines
Pattern
Engine
Transformation
Engine
Associative
Programming
Constraint
Definitions
Transformation and
Type Inference Rule
Definitions
Demo



8,060,857 – Automated partitioning of a
computation for parallel or other high
capability architecture
8,225,277 – Non-localized constraints for
automated program generation
8,327,321 - Synthetic partitioning for imposing
implementation design patterns onto logical
architectures of computations
June, 2013
Ted J. Biggerstaff
Software Generators, LLC








Building Logical Architecture
History Debugger
Partial Evaluation Engine
Synchronizing Design Decisions
Pattern Matching Engine
Transformation Engine
Type Inference Engine
Inference Engine
Loop2d5 ((e11-c15)
=(e1-c5, e6-c10))
=
bi,j
sqrt
Loop2d1
+
square

Loop2d2
ak,l
Loop2d4 ((e11-c15)
= (e1-c5, e6-c10))
Loop2d2 (e1-c5)
square

Loop2d3 (e6-c10)
sp,q
Loop2d3
a t,u
spv,w








Building Logical Architecture
History Debugger
Partial Evaluation Engine
Synchronizing Design Decisions
Pattern Matching Engine
Transformation Engine
Type Inference Engine
Inference Engine


Domain Engineer’s Job is DSLGen Extensions
Problem: Analyzing Creation of Logical
Architecture
How are loop constraints and index names created?
 How are partitions created, combined & specialized?
 How do design decisions (e.g., Idx1 -> Idx3 ) happen?



Tools for Analyzing a Generation History?
History Debugger
AST before
rewriting
Bindings of
selected history
node used to
rewrite AST
AST after
rewriting
History
Tree at Top
Level (total
tree typically
~3K nodes)
Bindings
created by
operation of
selected node
Dialog to
search
history tree
Bookmarked
locations (for
debugging or
presentations).
Selected history
node (e.g.,
transform, routine
or trace info)

Dialogs available from History Debugger
Architecture browser (as used earlier to display LA)
 Examine transforms (as used earlier to show w.part)
 Inspect any object (e.g., examine slots of idx3)
 Open source file of a DSLGen™ routine in an editor
(e.g., Gnuemacs)









Building Logical Architecture
History Debugger
Partial Evaluation Engine
Synchronizing Design Decisions
Pattern Matching Engine
Transformation Engine
Type Inference Engine
Inference Engine
void Sobel Edges9( )
{ /* Edge1 partitioning condition is (i=0) */
{for (int j=0; j<=(n-1);++j) b [0,j]=0;}
_endthread( ); }
W.Spart specialized to
center
W.Spart body
specialized to
edge

Inline the Intermediate Language (IL)
(forall (i j) { 0<= i<=(m-1), 0<=j<=(n-1), Partestx(S-Edge1)} b [i,j]=[(a[i,j] s-edge1[i,j])2 + (a[i,j]sp-edge1[i,j])2]1/2
Partestx


Inline the Intermediate Language (IL)
(forall (i j) { 0<= i<=(m-1), 0<=j<=(n-1), Partestx(S-Edge1)} b [i,j]=[(a[i,j] s-Edge1[i,j])2 + (a[i,j]sp-edge1[i,j])2]1/2

Partestx
(forall (i j) { 0<= i<=(m-1), 0<=j<=(n-1), (i==0) )} b [0,j]= [ ((sum(p q) {0<= p<=2, 0<=q<=2}
(* (aref a (row s-Edge1 a[i,j] p q)
(col s-Edge1 a[i,j] p q) )
(w s-Edge1 a[i,j] p q))))2
+ (convolution using sp-Edge1)2]1/2
w
row
col

Inline the Intermediate Language (IL)
(forall (i j) { 0<= i<=(m-1), 0<=j<=(n-1), Partestx(S-Edge1)} b [i,j]=[(a[i,j] s-Edge1[i,j])2 + (a[i,j]sp-Edge1[i,j])2]1/2

Partestx
(forall (i j) { 0<= i<=(m-1), 0<=j<=(n-1), (i==0) )} b [0,j]= [ ((sum (p q) {0<= p<=2, 0<=q<=2}
(* (aref a (row s-Edge1 a[i,j] p q)
(col s-Edge1 a[i,j] p q) )
(w s-Edge1 a[i,j] p q))))2
+ (convolution using sp-Edge1)2]1/2
w
row
col
(forall (i j) { 0<= i<=(m-1), 0<=j<=(n-1), (i==0) )} b [0,j]= [ ((sum (p q) {0<= p<=2, 0<=q<=2}
(* (aref a (+ 0 (+ p -1))
(+ j (+ q -1)))
2
0))) + (“convolution using sp-Edge1” )2]1/2

Inline the Intermediate Language (IL)
(forall (i j) { 0<= i<=(m-1), 0<=j<=(n-1), Partestx(S-Edge1)} b [i,j]=[(a[i,j] s-Edge1[i,j])2 + (a[i,j]sp-Edge1[i,j])2]1/2

Partestx
(forall (i j) { 0<= i<=(m-1), 0<=j<=(n-1), (i==0) )} b [0,j]= [ ((sum (p q) {0<= p<=2, 0<=q<=2}
(* (aref a (row s-Edge1 a[i,j] p q)
(col s-Edge1 a[i,j] p q) )
(w s-Edge1 a[i,j] p q))))2
+ (convolution using sp-Edge1)2]1/2
w
row
col
(forall (i j) { 0<= i<=(m-1), 0<=j<=(n-1), (i==0) )} b [0,j]= [ ((sum(p q) {0<= p<=2, 0<=q<=2}
(* (aref a (+ 0 (+ p -1))
(+ j (+ q -1)))
2
0))) + (“convolution using sp-Edge1” )2]1/2
(…* 0)
(forall (i j) { 0<= i<=(m-1), 0<=j<=(n-1), (i==0) } b [0,j]=[ 0
(…* 0)
+
0]1/2
(forall (i j) { 0<= i<=(m-1), 0<=j<=(n-1), Partestx(S-Edge1)} b [i,j]=[(a[i,j] s-Edge1[i,j])2 + (a[i,j]sp-Edge1[i,j])2]1/2

Partestx
(forall (i j) { 0<= i<=(m-1), 0<=j<=(n-1), (i==0) )} b [0,j]= [ ((forall (p q) {0<= p<=2, 0<=q<=2}
(* (aref a (row s-Edge1 a[i,j] p q)
(col s-Edge1 a[i,j] p q) )
(w s-Edge1 a[i,j] p q))))2
+ (convolution using sp-Edge1)2]1/2
w
row
col
(forall (i j) { 0<= i<=(m-1), 0<=j<=(n-1), (i==0) )} b [0,j]= [ ((forall (p q) {0<= p<=2, 0<=q<=2}
(* (aref a (+ 0 (+ p -1))
(+ j (+ q -1)))
2
0))) + (“convolution using sp-Edge1” )2]1/2
(…* 0)
(forall (i j) { 0<= i<=(m-1), 0<=j<=(n-1), (i==0) } b [0,j]=[ 0
PE
(forall (j) { 0<= i<=(m-1), 0<=j<=(n-1), (i==0) } b [0,j]= 0
(…* 0)
+
0]1/2
void Sobel Edges9( )
{ /* Edge1 partitioning condition is (i=0) */
{for (int j=0; j<=(n-1);++j) b [0,j]=0;}
_endthread( ); }








Building Logical Architecture
History Debugger
Partial Evaluation Engine
Synchronizing Design Decisions
Pattern Matching Engine
Transformation Engine
Type Inference Engine
Inference Engine

How did index variables get synchronized?


di,j and ck,l and ct,u
Answer: Loop constraint combining transforms
generated fix up transforms to be executed later

Loop2d4 combo transform generated
 K -> I, T-> I, L-> J, U->J transforms

NB: Loop constraints for neighborhoods s and sp
elided from example for simplicity








Building Logical Architecture
History Debugger
Partial Evaluation Engine
Synchronizing Design Decisions
Pattern Matching Engine
Transformation Engine
Type Inference Engine
Inference Engine


Left-Hand-Side (LHS) of transformations
Reverse quoting language
Non-syntactically enhanced items are literals (e.g., “a”)
 Syntactically enhanced are operators
 E.G., ?x is variable, $(op …) is a pattern operator






Full backtracking on failure (via “continuations”)
Extensible – User can define new operators
Internal – Lambda tree + fail stack of
continuations
De-compiler for internal to external
Turing complete











$(Por pat1 pat2….patn)
$(Pand pat1 pat2 …patn)
$(pnot pat)
$(none pat1 pat2 … patn)
$(remain ?x)
$(spanto ?x <pattern>)
$(bindvar ?x <pattern>)
$(bindconst ?x <constant>)
$(pcut)
$(pfail)
$(pmatch <pattern> <data>)









$(within <pattern>)
$(ptest <lisp function of one
argument>)
$(papply function ?arg1 ?arg2
... ?argn)
$(pat <variable>)
$(plisp <Lisp Code>)
$(psuch slotname ?vbl
<pattern>)
$(ptrace <lisp expression>
label)
$(plet <let list> <pattern>)
…others …








Building Logical Architecture
History Debugger
Partial Evaluation Engine
Synchronizing Design Decisions
Pattern Matching Engine
Transformation Engine
Type Inference Engine
Inference Engine


Pattern Language used to specify LHS
Transformations



Format
Preroutines and postroutines (like before and after
methods)
Inheritance
Transform
(defconstant LeafOperator
`$(por (,leaf ?op)
$(pand $(ptest atom) ?op)))
(=> PartitioningCompositeLeaf LocalizeAndPartition image
`$(pand #.LeafOperator
$(psuch dimensions ?op ((,_Member ?iiter (,_Range ?ilow ?ihigh)) (,_Member ?jiter (,_Range ?jlow ?jhigh))))
$(por ($(spanto ?taglessremain (tags)) ?thetags) $(psucceed)))
`(,leaf ?newleaf (tags (commasplice ?newtaglist)))
enablePartitioningCompositeLeaf nil all)
Method-Transform (Defines IL)
(Defcomponent w (sp #. ArrayReference ?p ?q)
(if (or (== ?i ?ilow) (== ?j ?jlow)
(== ?i ?ihigh) (== ?j ?jhigh) (tags (constraints partitionmatrixtest edge)))
(then 0)
(else (if (and (!= ?p 0) (!= ?q 0))
(then ?q)
(else (if (and (== ?p 0) (!= ?q 0))
(then (* 2 ?q))
(else 0)))))))
Phase where
it is enabled
to execute
Type object
where
transform lives
LHS pattern
RHS
Preroutine
handles
bookkeeping
operations
after LHS
match
Transformation Definition
(=> PartitioningCompositeLeaf LocalizeAndPartition
image
`$(pand #.LeafOperator
$(psuch dimensions ?op
((,_Member ?iiter (,_Range ?ilow ?ihigh))
(,_Member ?jiter (,_Range ?jlow
?jhigh))))
$(por ($(spanto ?taglessremain (tags))
?thetags)
$(psucceed)))
`(,leaf ?newleaf (tags (commasplice ?newtaglist)))
enablePartitioningCompositeLeaf nil all)
WHERE
(defconstant LeafOperator
`$(por (,leaf ?op) $(pand $(ptest atom)
?op)))
DSLGen Internal State
AST before rewrite = (leaf d (tags (itype colorimage)))
AST after rewrite = (leaf colorpixel1 (tags (itype
colorpixel) (constraints loop2d1)))
________________________________________________
__
(dimension d) = ((_Member iiter6 (_Range 0 99 1))
(_Member jiter6 (_Range 0 99 1)))
________________________________________________
__
Bindings After Matching and Preroutine =
((?newleaf colorpixel1) (?idx1 idx1) (?idx2 idx2)
(?theapc loop2d1) (?inewtype colorpixel)
(?newtaglist ((itype colorpixel) (constraints loop2d1)))
(?thetags
(tags (itype colorpixel) (constraints loop2d1)))
(?taglessremain (leaf d)) (?jhigh 99) (?jlow 0)
(?jiter jiter6) (?ihigh 99) (?ilow 0) (?iiter iiter6)
(?op d) (?phase localizeandpartition) (?defclass image)
(?transformname partitioningcompositeleaf))


Pattern Language used to specify LHS
Transformations



Format
Preroutines and postroutines (like before and after
methods)
Inheritance – Up type hierarchy
 If there is no “(row sp-0-center15 …)” specialization,
“(row sp …)” will be used when in-lining definitions








Building Logical Architecture
History Debugger
Partial Evaluation Engine
Synchronizing Design Decisions
Pattern Matching Engine
Transformation Engine
Type Inference Engine
Inference Engine
(DefOPInference ImageOperators (ImageOperators image iatemplate) 1)
(DefOPInference ImageOperators (ImageOperators pixel iatemplate) 1)
(DefOPInference ImageOperators (ImageOperators channel iatemplate) 1)
(DefOPInference AOperators (AOperators DSNumber DSNumber) DSNumber)
(DefOPInference RelationalOperators (RelationalOperators (oneormore t)) DSSymbol)
(DefOPInference LogicalOperators (LogicalOperators (oneormore t)) DSSymbol)
(DefOpInference AssignOp (AssignOp t t) last)
; resultant type is infered type of the last arg
(DefOpInference ProgmOp (ProgmOp (oneormore t)) last)
(DefOpInference IfOp (IfOp t t t) 2)
(DefOpInference IfExprOp (IfExprOp t t t) 2)
(DefOpInference IfOp (IfOp t t) 2)
(DefOpInference ThenOp (ThenOp (oneormore t)) last)
(DefOpInference ElseOp (ElseOp (oneormore t)) last)
(DefOpInference ListOp (ListOp (oneormore t)) last)
(DefMethodInference IATemplate (Prange IATemplate image DSNumber DSNumber Iterator) Range)
(DefMethodInference IATemplate (Qrange IATemplate image DSNumber DSNumber Iterator) Range)
(DefMethodInference IATemplate (W IATemplate channel t t) DSNumber)








Building Logical Architecture
History Debugger
Partial Evaluation Engine
Synchronizing Design Decisions
Pattern Matching Engine
Transformation Engine
Type Inference Engine
Inference Engine

Given






(Idx1 == 0) from partitioning condition
(0 <= Idx1 <= (m -1)) from loop range
(m > 1) from :facts slot of m
Is partial evaluation of “(Idx1 == (m – 1))”
true, false or unknown for all m?
False. “(m >1)” fact eliminates the only
possible true case (i.e., for (m == 1)).
Inference engine based on Fourier-Motzkin
elimination.
/* Definitions from scope SCOPE1: */
int M = 100;
int N = 100;
BWPIXEL IMAGEAVG (DSNUMBER M, DSNUMBER N, BWIMAGE A[M][N], BWIMAGE B[M][N])
{{
/* DSLGen (Version 0 Revision 2) generated this program at 3:26:38 pm on 11/Jun/2009 */
int IDX3 ; int IDX4 ; int P5 ; int Q6 ;
int ANS1 ;
{/*Initial values from scope SCOPE3 are ((IDX4 0) (IDX3 0))*/
int IDX4 = 0;
int IDX3 = 0;
for (IDX3=0; IDX3<=(M - 1); ++IDX3)
{{
for (IDX4=0; IDX4<=(N - 1); ++IDX4)
{{{/*Initial values from scope SCOPE4 are ((ANS1 0) (Q6 0) (P5 0))*/
int ANS1 = 0;
int Q6 = 0; int P5 = 0;
for (P5=((IDX3 == 0) ? 1:0); P5<=((IDX3 == (M - 1)) ? 1:2); ++P5)
{{for (Q6=((IDX4 == 0) ? 1:0); Q6<=((IDX4 == (N - 1)) ? 1:2); ++Q6)
{{ANS1 +=
((*((*(A + ((IDX3 + (P5 + -1))*N))) + (IDX4 + (Q6 + -1)))) *
((((IDX3 == 0) || (IDX3 == (M - 1))) &&
((IDX4 == 0) || (IDX4 == (N - 1)))) ? 0.25:
(((IDX3 == 0) ||
((IDX3 == (M - 1)) || ((IDX4 == 0) || (IDX4 == (N - 1)))))
? 0.166666666666667:0.111111111111111)));
}}}}
(*((*(B + (IDX3*N))) + IDX4)) = ANS1;
}}}}}}}}
Download