1 / 19

Program Optimizations in Specware/Designware

Program Optimizations in Specware/Designware. Douglas R. Smith. Kestrel Institute www.kestrel.edu. WG2.1 Meeting, 14-19 June 99, Potsdam, Germany. Software Development by Refinement. CAT. semantics : SPEC op. category of models for Spec 0. denotes. Spec 0. reduct functor. Spec 1.

ktapia
Télécharger la présentation

Program Optimizations in Specware/Designware

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Program Optimizations in Specware/Designware Douglas R. Smith Kestrel Institute www.kestrel.edu WG2.1 Meeting, 14-19 June 99, Potsdam, Germany

  2. Software Development by Refinement CAT semantics: SPECop category of models for Spec0 denotes Spec0 reduct functor Spec1 models for Spec1 refinement in SPEC models for Spec2 Spec2 … … Specn models for Specn  code generation a model (for Specn)  Code Code generation via a logic morphism from SPEC to the logic of a programming language

  3. Morphisms Partial-OrderInteger E integer le  axioms theorems Interpretation ( Between Theories) Partial-OrderInteger E  integer le (x, y) x mod y = 0 axioms theorems Specifications and Morphisms Spec Partial-Order sort E op _le_: E, EBoolean axiom reflexive x le x axiom transitive x le y  y le z  x le axiom antisymmetric x le y  y le x  x = y Specifications Represent Domain models Transportation, Resource, Task Software Requirements Crew Scheduling Algorithm Theories Global-Search Abstract Data Types Set(Time) Software Architecture Scheduling-System Code Modules Network-Flow Morphisms Represent Spec Structuring TaskSchedulingResource Parameter Binding Time Integer Spec Refinement Partial-OrderInteger Algorithm Design Global-SearchScheduling Knowledge Refinement Constraint SatisfactionInteger Programming Datatype Refinement Set(Integer)Bit Vector

  4. spec REFLEXIVE-RELATION is sort E op _rr_ : E, E Boolean axiom reflexivity is a rr a end-spec spec BINARY-RELATION is sort E op _br_ : E, E Boolean end-spec spec TRANSITIVE -RELATION is sort E op _tr_ : E, E Boolean axiom transitivity is a trb  btrc  atrc end-spec spec PREORDER-RELATION is sort E op  : E, E Boolean axiom reflexivity is a  a axiom transitivity is a  b  b  c  a  c end-spec Calculating a Colimit in SPEC

  5. REFLEXIVE-RELATION BINARY-RELATION E br E rr x rr x po {E,E,E}rename E {br, rr, tr}rename  axiom x  x axiom x  y  y  z  x  z E tr axiom x tr y  y tr z  x tr z TRANSITIVE-RELATION PREORDER-RELATION Calculating a Colimit in SPEC Collect equivalence classes of sorts and ops from all specs in the diagram.

  6. Instantiating a Parameter Spec INTEGER sort Integer … integer structure and axioms spec 1-SORT is sort E end-spec po spec SET-OF-INTEGER is sorts Integer, Set-of-Integer const empty-set : Set-of-Integer op insert: Integer, Set-of-Integer Set-of-Integer axiom condensation is insert(e, insert (e, S)) = insert(e, S) … set structure and axioms … integer structure and axioms end-spec spec SET is sorts E, Set const empty-set : Set op insert: E, SetSet axiom idempotence is insert(e, insert (e, S)) = insert(e, S) … set structure and axioms end-spec

  7. Library of Refinements A E A C A po B Spec1 C F B D H po D E Spec2 E H B J po A F Spec3 G I D K po DP theory Expression + Context Set H Spec4 Dynamic Programming Algorithm Bit Vector Context-dependent Simplification Applying Abstract Refinements Spec0

  8. Time, Quantity Resource Task A, B, C Reservation = ResourceTaskTime Set(ABC) Schedule = set(Reservation) Time, Quantity Resource A, B, C Task Reservation = ResourceTaskTime Map(A, Set(ABC)) Map Schedule = Map(Resource, Set(Reservation)) Map Refining the Schedule datatype

  9. Refinements (green arrows) are organized into a taxonomy A B S0+   B classifying the structure of S0 C S0++    C E  D S0+++ D applying the refinement D  E po S1 E Design by Classification Refinements are accessed and applied incrementally via a ladder construction A S0

  10. Taxonomy of Algorithm Theories Problem Theory (D|I  R|O) generate-and-test Constraint Satisfaction (R = set of maps) Global Structure (R = set + recursive partition) global search binary Search backtrack branch-and-bound Local Structure (R = set + relation) genetic algorithms Problem Reduction Structure Linear Programming simplex method interior point primal dual Local Structure (R = set + relation) local search hill climbing simulated annealing tabu search Divide-and-Conquer divide-and-conquer Complement Reduction sieves Integer Linear Programming 0-1 methods GS-CSP (R = recursively partitioned set of maps) Problem Reduction Generators dynamic programming branch-and-bound game tree search Network Flow specialized simplex Ford-Fulkerson Local Poset Structure (R = set + partial order) GS-Horn-CSP (Horn-like Constraints) constraint propagation Monotone Deflationary Function fixed point iteration Local Semilattice Structure (R = semilattice) Transportation NW algorithm Assignment Problem Hungarian method

  11. context analysis determines that a=0 so we can safely replace a*e by 0 Program Optimization Techniques Context-Dependent Simplification Idea: simplify an expression with respect to its context while a0 do ….. if a>0 then ….. else F( a*e, …..) ….. end • Equational Rewriting • Context-Dependent Simplification • Finite Differencing • Partial Evaluation • Common Subexpression Elimination • Dead Code Removal • Loop Fusion • Deforestation • Tabulation • Tupling

  12. How to optimize in Designware? Goal: express optimization rules in terms of specs and morphisms; find basic mechanisms for applying them. Fact: Cannot replace one expression by another using colimit of spec morphisms; we need a morphism-constructing substitution operation: metatheorem LEIBNITZ if e1 expressions(S) & C = context(e1, S) & |-S C  e1=e2 & m = make-morphism-by-subst(e1, e2, S) then isomorphism?(m) make-morphism-by-subst spec S’ is . . . [e2] thm C  e1=e2 end-spec spec S is . . . [e1] thm C  e1=e2 end-spec

  13. How to optimize in Designware? metatheorem LEIBNITZ if e1 expressions(S) & C = context(e1, S) & |-S C  e1=e2 & m = make-morphism-by-subst(e1, e2, S) then isomorphism?(m) How to use Leibnitz: 1. Apply a (meta)theorem to create an equational theorem in spec S 2. Apply make-morphism-by-subst to create an isomorphism according to Leibnitz or 1. Use pushout on an optimization refinement to create a theorem in spec S 2. Apply make-morphism-by-subst to create an isomorphism according to Leibnitz

  14. Metatheorems to use with Leibnitz To apply a given equational law: metatheorem APPLY-LAW if |-S d1=d2 & e1 expressions(S) &  = match(d1, e1) & C = context(e1, S) then |-S d1 =d2 Context-Dependent Simplification metatheorem CD-SIMPLIFY if e1 expressions(S) & C = context(e1, S) & X = vars(e1) & Z = vars(C) & e2= find-witness(`X y Z/X C  e1= y’, S) then |-S C  e1= e2

  15. Transformation Rules in Designware source pattern target pattern + conditions what is the source expression? expression theory requirement spec S0 match the source pattern and check conditions source theory S1 po target theory instantiate the target pattern S2 S2 is an extension of S0 with new function definitions and theorems (to be used by the simplifier)

  16. A Fusion Law if f(x  y) = x  f(y) and  and  are associative then f(foldr(, xs, unit)) = foldr(, xs, f(unit)) spec FOLDR-FUSION is import Seq-of-A sort E op f: A  E op : A  A  A axiom associative?( ) op unit: A op foldr : (A  A  A)  Seq-of-A  A  A def foldr(g,as,u) = ... op : A  E  E axiom associative?( ) op foldr : (A  E  E)  Seq-of-A  A  E def foldr(g,as,u) = ... theorem foldr-fusion-law is xf(y) = f (x  y)  f(foldr(, xs, unit)) = foldr( , xs, f(unit)) end-spec

  17. A Fusion Law if f(x  y) = x  f(y) and  and  are associative then f(foldr(, xs, unit)) = foldr(, xs, f(unit)) Spec EXPR is sort E op expr : E spec foldr-fusion is import EXPR, Seq-of-A op f: A  E op : A  A  A op foldr : (A  A  A)  Seq-of-A  A  A op : A  E  E axiom associativity of ,  axiom expr = f(foldr(, xs, unit)) axiom f (x  y) = xf(y) end-spec spec fold-fusion-law is import fold-fusion op foldr : (A  E  E)  Seq-of-A  A  E theoremexpr = foldr( , xs, f(unit)) end-spec

  18. | | | | | | | | | | Applying the Fusion Law size(queens(k)) = … size(reduce(, SS, {})) Nat size(reduce(, SS, {})) E expr E expr f foldr  unit  Nat size(reduce(, SS, {})) size reduce  (disjoint union) {} (x,sz) size(x) + sz f(foldr(, xs, unit)) = foldr( , xs, f(unit)) size(reduce(, SS, e)) = foldr((x,sz) size(x) + sz , SS, size({}))

  19. Observations on generating an equational theoremvia pushout with library refinement • optimization refinements expressed in the same format • as algorithm theory and datatype refinements • morphism construction generalizes matching • can’t designate a particular expression in an object-level spec • can’t exploit local context • cumbersome mechanism

More Related