330 likes | 449 Vues
This paper delves into addressing antagonistic goals in programming through domain-specific languages (DSLs) and control localization techniques. By utilizing high-level operators and operands capable of programming variations, we present methods to enhance image processing algorithms, such as Sobel Edge Detection, while preventing code fragmentation. We discuss optimization strategies like code sharing and reorganization, along with inter-phase optimization, to manage complex search spaces and improve performance through refined programming paradigms.
E N D
Control Localization in Domain Specific Translation Ted J. Biggerstaff tbiggerstaff@austin.rr.com
Overriding 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)
x Constraint x Constraint Propagation NP Complete Reuse Library Alternative Refinements of Program Refine to
Existing Explosion Control: DS Reductionism • Implicit Phases based on Distinct DSLs • Mutually Exclusive DSL Operators & Operands • Inter-Phase Optimization • Metaprogram = {Refine DSL; Optimize Refined DSL} • Result: Group Rules by Phase • One large search space to several small ones
(p, q : a i+p , j+q) (i, j : a i , j) Image a (p, q (sp , q * a i+p , j+q)) * s-1,-1 * s-1,0 b[i,j] + * s-1,1 * s1,1 If hanging then b[i,j]=0 else sum of products loop b[i,j]=0 Large Grain Data & Operators Imply Control b=(a s)
DSL for Sobel Edge Detection b=[(a s)2 + (a s’)2]1/2 a b
Large Grain Extended Expressions (p, q (a i+p , j+q * sp , q)) (p, q (a v+p , w+q * s’p , q)) b=((a s)2 + (a s’)2 )1/2 (d,e: a d,e) (i, j : a i , j) (v,w: a v , w)
Weave Explosion Control • DSL-> DSL translation phases • DS optimizations • Specialized metaprograms (Control Localization)
Localizing Implied Control b=((a s)2 + (a s’)2 )1/2 b=(((i, j : a i , j) s)2 + ((v, w : a v , w) s’)2 )1/2 b=(((i, j : (p,q:ai+p , j+q * sp,q))2) +((v, w:(p,q:a v+p , q+w*s’p,q))2))1/2
Localizing Implied Control b=(((i, j : (p,q:ai+p , j+q * sp,q))2) +((v, w:(p,q:a v+p , w+q*s’p, q))2))1/2 b=((i, j : ((p,q: ai+p , j+q * sp,q))2) +(v, w:((p,q: a v+p , w+q*s’p, q))2))1/2 b=(i, j : (((p,q:ai , j * si+p,j+q))2) + (((p,q: a i+p , j+q*s’p, q))2))1/2
Localizing Implied Control b=(i, j : (((p,q:ai , j * si+p,j+q))2) + (((p,q: a i+p , j+q*s’p, q))2))1/2 b=i, j : ((((p,q:ai , j * si+p,j+q))2) +(((p,q: a i+p , j+q*s’p, q))2))1/2 (d, e:bd , e)=i, j : ((((p,q:ai , j*si+p,j+q))2) + (((p,q: a i+p , j+q*s’p, q))2))1/2
Localizing Implied Control (d, e:bd , e) =i, j : ((((p,q:ai , j*si+p,j+q))2) + (((p,q: a i+p , j+q*s’p, q))2))1/2 (i, j : (b i, j=(((p,q:ai , j*si+p,j+q))2) + (((p,q: a i+p , j+q*s’p, q))2))1/2)
Weave Explosion Control • DSL-> DSL translation phases • DS optimizations • Specialized metaprograms (Control Localization) • Group rules by object & phase • Use domain knowledge
Example (Idealized) AST Transformation b=((a s)2 + (a s’)2 )1/2 b=(((i, j : a i , j) s)2 + (a s’)2 )1/2
Example (Actual) AST Transformation b=((a s)2 + (a s’)2 )1/2 b=((( idx2139, idx2145: bwpixel2136) s)2 + (a s’)2 )1/2 Wherebwpixel2136 =a idx2139, idx2145
CLOS Object Property List (leaf a (tags (itype image))) b=((( idx2139, idx2145: bwpixel2136) s)2 + (a s’)2 )1/2 (leaf bwpixel2136 (tags (_q (_forall (idx2139 idx2145) (_suchthat (_member idx2139 (_range 0 (- m 1))) (_member idx2145 (_range 0 (- n 1))) (mappings (bwpixel2136) (a))))) (itype bwpixel))) Example (Implementation) AST Transformation b=((a s)2 + (a s’)2 )1/2
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
RHS Rewrite Form `(leaf ?newleaf (tags (commasplice ?pretags) (_q (_forall (?idx1 ?idx2) (suchthat (_member ?idx1 (_range ?ilow ?ihigh)) (_member ?idx2 (_range ?jlow ?jhigh)) (mappings (?newleaf) (?op))))) (itype BWPixel) (commasplice ?posttags)))
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 (?idx1 ?idx2) (suchthat (_member ?idx1 (_range ?ilow ?ihigh)) (_member ?idx2 (_range ?jlow ?jhigh)) (mappings (?newleaf) (?op))))) (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 idx2139 ?idx2 idx2145 ?newleaf bwpixel2136 ?op { ?spaceover Behind The Scenes { { (leaf a (tags (itype image))) ?posttags ?pre ?itype ?pretags
Rewrite Result b=[(bwpixel2136 s)2+ (a s’)2]1/2 `(leaf ?newleaf (tags (commasplice ?pretags) (_q (_forall (?idx1 ?idx2) (suchthat (_member ?idx1 (_range ?ilow ?ihigh)) (_member ?idx2 (_range ?jlow ?jhigh)) (mappings (?newleaf) (?op))))) (itype BWPixel) (commasplice ?posttags))) (leaf bwpixel2136 (tags (_q (_forall (idx2139 idx2145) (_suchthat (_member idx2139 (_range 0 (- m 1))) (_member idx2145 (_range 0 (- n 1))) (mappings (bwpixel2136) (a))))) (itype bwpixel)))
Bindings Before History After Transform Shown In Debugger
Speculative Refinement • Dynamically build coordinated rules to express constraint set bwpixel2034 b idx2037, idx2043 idx2139 idx2037 idx2145 idx2043 bwpixel2987 bwpixel2136 bwpixel2136 a idx2037, idx2043
Explosion Control • DSL-> DSL translation phases • DSL specific optimizations • Simplification & DS Optimizations • Key Point: DS Reductions Not Combinations • Localization • Separate Parts Woven into Computational Form • Group Rules by Object & Phase • Use Domain Knowledge • Architectural Shaping • Interdependent, Composed Parts Changed per Global Constraints
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.