750 likes | 885 Views
A Characterization of Reuse Technologies. Ted J. Biggerstaff tbiggerstaff@austin.rr.com. Reuse Technologies. Concrete components e.g., Functions, OOP, Frameworks, DCOM, … Compositionally Derived Components e.g., Templates, GenVoca, … Pattern-directed transformation systems
E N D
A Characterization of Reuse Technologies Ted J. Biggerstaff tbiggerstaff@austin.rr.com
Reuse Technologies • Concrete components • e.g., Functions, OOP, Frameworks, DCOM, … • Compositionally Derived Components • e.g., Templates, GenVoca, … • Pattern-directed transformation systems • e.g., Draco, CAPE, IP, DMS, Sinapse, ...
Control Regimes • PD Search – Independent Local Choices • Strategically Blind – exploding search space • Biased Toward Local Syntactic Structure • Rules are General & Allow Easy Extension
Control Regimes • PD Search – Independent Local Choices • Strategically Blind – exploding search space • Biased Toward Local Syntactic Structure • Rules are General & Allow Easy Extension • MetaPrograms – Algorithmic • Strategically & Tactically Purposeful • State Dependent Actions Reduce Search Space • Representation Makes Extensions Hard
x Constraint x Constraint Propagation Problem Reuse Library Alternative Refinements of Program Refine to
PD Explosion Control • Group Rules by Phase • Implicit Phases based on Distinct DSLs • Mutually Exclusive DSL Operators & Operands
Data Base Relational Algebra Index Tuple Abstract Data Types C Code Refinements Component: Insert(Value V, Container C) {Refinement: Stack Condition: LIFO(C) Code: {Push(V,C)}} {Refinement: Sorted Container Condition: SortedOn(C, Value) Assertion: SortedOn(C, Value) Code: {Merge(V,C)}} ...}
PD Explosion Control • Group Rules by Phase • Implicit Phases based on Distinct DSLs • Mutually Exclusive DSL Operators & Operands • … and based MetaProgram • {Refine DSL; Optimize Refined DSL}
Domain to self: Join(?Relation1, Empty_Relation, ?Attribute) =>Empty_Relation Select(?Relation1,TRUE_expression) =>Relation1 Select(?Relation1,FALSE_expression) => Empty_Relation Data Base Relational Algebra Index Tuple Abstract Data Types C Code Optimizing Transforms
Kinds of Optimization • Simplification & DS Optimizations • Key Point: DS Reductions Not Combinations
Pattern-Directed Systems • Example domain: communications protocols • Benefits: • Fine grain rules allow great horizontal scaling • Small search spaces (DSL->DSL) vs. one large • Powerful in-domain optimizations • Shortcomings: • Global reorganizing optimizations can explode search space
Essence of The Technology ClassElementsOperations Concrete Reuse PL Struct. Hand Assem. Composition Abstract PL Inlining PD Generator DSL Struct. PD Xforms
Reuse Technologies • Concrete components • e.g., Functions, OOP, Frameworks, DCOM, … • Compositionally Derived Components • e.g., Templates, GenVoca, … • Pattern-directed transformation systems • e.g., Draco, CAPE, IP, DMS, Sinapse, ... • Reorganizing generator systems • AO generator (AOG), AOP, ...
DSL for Sobel Edge Detection b=[(a s)2 + (a s’)2]1/2 a b
Problem: Antagonistic Goals • High level operators and operands provide programming leverage & variations • E.g., (image neighborhood) convolution • But fracture and de-localize code pieces • b=((a s)2 + (a s’)2 )1/2 • Needed optimizations: code sharing, re-org. & re-weaving • Conventional Optimization approaches induce large search spaces (EXPLOSION)
Weave Kinds of Optimization • Simplification & DS Optimizations • Key Point: DS Reductions Not Combinations • Localization • Separate Parts Woven into Computational Form • General Interdependent Parts Problem NP Complete • Tractable Via Narrow Domain Knowledge & Grouping
Explosion Control • Group Rules by Phase • Implicit Phases based on Distinct DSLs & {Refine; Optimize} MetaProgram • Explicit Finer Grain Phases • {Loop Optimization, Code Generation, …} • Group Rules by Named Entity • E.g., Type or Operator or Arbitrary Entity • Mechanisms in AOG, Stratego, etc. • AOG Uses Both Entity and Phase
Name, Phase, Location Example Loop Opt. Transform • Refine Image to BWPixel with loop shorthand tags (=> compositeleaf fusion2 image LHS RHS PreRoutine PostRoutine)
Name, Phase, Location Example Loop Opt. Transform • Refine Image to BWPixel with loop shorthand tags (=> compositeleaf fusion2 image `$(pand $(por (leaf ?op) ?op)) …sub-pattern to get type … …sub-pattern to get dimensions of ?op…) LHS RHS PreRoutine PostRoutine)
Name, Phase, Location Example Loop Opt. Transform • Refine Image to BWPixel with loop shorthand tags (=> compositeleaf fusion2 image `$(pand $(por (leaf ?op) ?op)) ($(spanto ?pre (tags)) (tags $(spanto ?pretags (itype ?itype)) ?spaceover $(remain ?posttags))) …sub-pattern to get dimensions of ?op…) LHS RHS PreRoutine PostRoutine)
Name, Phase, Location Example Loop Opt. Transform • Refine Image to BWPixel with loop shorthand tags • Enablecompositeleaf creates ?newleaf, ?idx1, ?idx2 (=> compositeleaf fusion2 image `$(pand $(por (leaf ?op) ?op)) ($(spanto ?pre (tags)) (tags $(spanto ?pretags (itype ?itype)) ?spaceover $(remain ?posttags))) …sub-pattern to get dimensions of ?op…) LHS RHS enablecompositeleaf nil) Pre &Post Routines
Name, Phase, Location Example Loop Opt. Transform • Refine Image to BWPixel with loop shorthand tags • Enablecompositeleaf creates ?newleaf, ?idx1, ?idx2 (=> compositeleaf fusion2 image `$(pand $(por (leaf ?op) ?op)) ($(spanto ?pre (tags)) (tags $(spanto ?pretags (itype ?itype)) ?spaceover $(remain ?posttags))) …sub-pattern to get dimensions of ?op…) LHS `(leaf ?newleaf (tags (commasplice ?pretags) (_Q (_FORALL (?newleaf) (,arefop (?op) ?idx1 ?idx2))) (Itype BWPixel) (commasplice ?posttags))) RHS enablecompositeleaf nil) Pre &Post Routines
Loop Control Phase Traversal You Are Here b=[(a s)2 + (a s’)2]1/2 Property List Behind The Scenes (leaf a (tags (itype image))) CLOS Object
b=[(a s)2 + (a s’)2]1/2 Pattern Match Result `$(pand $(por (leaf ?op) ?op)) ($(spanto ?pre (tags)) (tags $(spanto ?pretags (itype ?itype)) ?spaceover $(remain ?posttags)))…) ?op { ?spaceover Behind The Scenes { { (leaf a (tags (itype image))) ?posttags ?pre ?itype ?pretags
b=[(a s)2 + (a s’)2]1/2 Pattern Match Result Define enablecompositeleaf (at, bindings) {?idx1 = Create iterator; ?idx2 = Create iterator; ?newleaf = Create bwpixel; return extended bindings} ?idx1 idx48146 ?idx2 idx48149 ?newleaf bwpixel48143 ?op { ?spaceover Behind The Scenes { { (leaf a (tags (itype image))) ?posttags ?pre ?itype ?pretags
Rewrite Result b=[(bwpixel48143 s)2+ (a s’)2]1/2 `(leaf ?newleaf (tags (commasplice ?pretags) (_Q (_FORALL (?newleaf) (,arefop (?op) ?idx1 ?idx2))) (itype bwpixel) (commasplice ?posttags))) (leaf bwpixel48143 (tags (_q (_forall (bwpixel48143) (aref (a) idx48146 idx48149))) (itype bwpixel))) Behind The Scenes
Kinds of Optimization • Simplification & DS Optimizations • Key Point: DS Reductions Not Combinations • Localization • Separate Parts Woven into Computational Form • Architectural Shaping • Interdependent, Composed Parts Changed per Global Constraints
Architectural Shaping • Computational Structure Shaped per External Constraints • SIMD (MMX), DB, UI, Middleware, Network
B=(A s) Image A * s-1,-1 * s-1,0 B[i,j] + * s-1,1 * s1,1 B[i,j]=0 Non-Parallel Architectural Effects
“b=[(a s)2 + (a s’)2]1/2” INT JM1, JP1, IM1, IP1; FOR (I=0; I < (M-1); ++I) { IM1=I-1; IP1= I+1; FOR (J=0; J < (N-1); ++J) { JM1= J-1; JP1 = J+1; IF(I==0 || J==0 || (I==(M-1)) || (J==(N-1))) THEN {B[I, J] = 0 ; } ELSE {T1=A[IP1 , JP1] - A[IP1 , JM1] + (A[I , JP1] * 2) - (A[I , JM1] * 2) + A[IM1 , JP1] - A[IM1 , JM1]; T2 = A[IP1 , JP1] + (A[IP1 , J] * 2) + A[IP1 , JM1] - A[IM1 , JP1] - (A[IM1 , J] * 2) - A[IM1 , JM1]; B[I, J] = SQRT(T1*T1 + T2*T2 );}}}
B=(A s) B[0,j]=0 Image A Pixels Weights S Pmadd3( * ) Pmadd3( * ) B[i,j] + Pmadd3( *) B[i, (n-1)]=0 B[i,0]=0 B[(m-1),j]=0 Parallel Architectural Effects
“b=[(a s)2 + (a s’)2]1/2” {int s[(-1:1), (-1:1)]={{-1, 0, 1}, {-2, 0 , 2}, {-1, 0, 1}}; int sp [(-1:1), (-1:1)]={{-1, -2, -1}, {0, 0, 0}, {-1, -2, -1}}; for (j=0; j < n; j++) b[0,j] = 0 ; for (i=0; i < m; i++) b[i,0] = 0 ; for (j=0; j < n; j++) b[(m-1),j] = 0 ; for (i=0; i < m; i++) b[i,(n-1)] = 0 ; {for (i=1; i < (m-1); i++) {for (j=1; j < (n-1); j++) {t1 = UNPACKADD(PADD2 (PADD2(PMADD3 (&(a[i-1, j-1]), &(s[-1, -1])) , PMADD3 (&(a[i, j-1]), &(s[ 0, -1]))), PMADD3 (&(a[i+1,j-1]), &(s[ 1, -1]))); t2 = UNPACKADD(PADD2 (PADD2(PMADD3 (&(a[i-1, j-1]), &(sp[-1, -1])), PMADD3 (&(a[i, j-1]), &(sp[ 0, -1]))), PMADD3 (&(a[i+1, j-1]), &(sp[ 1, -1]))))); b[i,j] = sqrt(t1*t1 + t2*t2);}}}
Architectural Shaping • Computational Structure Shaped per External Constraints • SIMD (MMX), DB, UI, Middleware, Network • Central MetaProgram Combinatorial Complexity • O(100) Transforms To Parallelize Example • Must Recognize Opportunity and Place • Must Rediscover Domain Knowledge (DK) • Much DK Known About Parts at Creation Time • Optimization Trajectories of Parts Known at Creation
Explosion Control • Constraint Propagation NP Complete • Simplify Constraint Propagation • MetaPrograms Exploit DS Knowledge • Global Constraints (MMX) Determine Cooperating, Distributed MetaPrograms • Pre-Propagation of Constraints via Tags • Pre-Plan Ordering Constraints on Distributed MetaPrograms • Result: Tag-Directed Transformations
Explosion Control • Tag-Directed Transformations • MetaPrograms Tagged onto Reusable Parts • WHAT Transformation • (SplitLoopOnCases) • WHEN to Fire • (on EventName (SplitLoopOnCases)) • WHERE to Apply • (if CaseTest then SpecialCase else GeneralCase (Tags (on … (SplitLoopOnCases))))
Example: SplitLoopOnCases for(i=0, j=0; i<m && j<n; i++, j++) if(i==0 || j==0 || i==(m-1) || j==(n-1)) ...then case...; ...else case...; for(j=0; j<n; j++)...then case with i=0...; for(j=0; j<n; j++)...then case with i=(m-1)...; for(i=0; i<m; i++)...then case with j=0...; for(i=0; i<m; i++)...then case with j=(n-1)...; for(i=1, j=1; i<(m-1) && j<(n-1); i++, j++) ...else case...;
Cooperating TD Transforms • Generate Weight Matrices • Create Loops, Unwrap, Partially Evaluate • Split Loop+If into Loop Cases • Simplify Special Case Loops • Create Loops, Infer Control, Partially Evaluate • Reshape Image Loop Body
Ordering Dependencies • Dependencies Supported • Per Strategic Plan – (on PlanStep …) • Before & After – (on (completion Xform)…) • On Local Action – (on substitutionofme …) • On Signal – (on ?signalvbl …)
Explosion Control Summary • Refinements – Implied DSL to DSL Phases • Specialized Optimizations • Simplification & DS Opt. – PE & PD Rules • Localization – Explicit Rule Grouping • Architectural Shaping –Tag-Directed Control • Distributed MetaPrograms on Reusable Parts • Avoid General NP Complete Problem • Specialized Sub-Problems & Use DK
References • Katz & Volper, Constraint Propagation in Software Libraries of Transformation Systems, IJSE&KE 2,3, 1992. • Biggerstaff, Fixing Some Transformation Problems, Proc. Of Automated Software Engineering, 1999. • Biggerstaff, A New Control Structure for Transformation-Based Generators, ICSR 2000. • Neighbors, Draco: A Method for Engineering Reusable Software Systems, inSoftware Reusability, 1989.
Reuse Technologies • Concrete components • e.g., Functions, OOP, Frameworks, DCOM, … • Compositionally Derived Components • e.g., Templates, GenVoca, …
Essence of The Technology ClassElementsOperations Concrete Reuse PL Struct. Hand Assem. Composition Abstract PL Inlining
The scaling plane Large, high payoff Vertical (Programming leverage) Reuse Payoff Small, low payoff Feature variability One-size fits all Customized Horizontal (Optimality of fit)
Reorganizing Generators • Benefits: • Inter-component optimizations (reweavings) • Small search space = reasonably fast • Shortcomings: • Technology immature • Unclear how far it can be pushed
Reuse Technologies • Concrete components • e.g., Functions, OOP, Frameworks, DCOM, …
Essence of The Technology ClassElementsOperations Concrete Reuse PL Struct. Hand Assem.