home *** CD-ROM | disk | FTP | other *** search
/ ftp.umcs.maine.edu / 2015-02-07.ftp.umcs.maine.edu.tar / ftp.umcs.maine.edu / pub / WISR / wisr6 / proceedings / ascii / baxter2.ascii < prev    next >
Text File  |  1993-10-19  |  23KB  |  550 lines

  1.  
  2.  
  3.  
  4.  
  5.                                               Practical  Issues  in
  6.  
  7.  
  8.                Building  Knowledge-Based  Code  Synthesis  Systems
  9.  
  10.  
  11.  
  12.                                                         Ira Baxter
  13.  
  14.  
  15.  
  16.                               Schlumberger Laboratory for Computer Science
  17.  
  18.                                              Austin, Texas, 78720 USA
  19.  
  20.                                                  Tel:  1-512-331-3714
  21.  
  22.                                                  Fax: 1-512-331-3760
  23.  
  24.                                         Email: baxter@austin.slcs.slb.com
  25.  
  26.  
  27.  
  28.                                                          Abstract
  29.  
  30.  
  31.            We present some issues and lessons on building a practical "generativereuse" system.  We
  32.        discuss the cost of building a useful system, and the tensions between prototyping and production
  33.        systems, often induced by scale demands.
  34.  
  35.  
  36.        Keywords: Synthesis, transformation, generative, knowledge-based systems
  37.  
  38.  
  39.        Workshop Goals:  Exchange  ideas  on  capture  and  mechanized  reuse  of  design  knowledge.
  40.        Particular interest in learning about other work related to knowledge acquisition for program
  41.        generation.
  42.  
  43.  
  44.        Working Groups: reuse and formal methods, reusable component certification, domain anal-
  45.        ysis/engineering
  46.  
  47.  
  48.  
  49. 1      Author's Background
  50.  
  51.  
  52.  
  53. Much  of  the  work  in  reuse  is  focused  on  code  reuse.  In  contrast, much  of  my  work  is  related
  54. to reuse of design and analysis information in a formal context,  in an effort to enhance software
  55. maintenance.
  56.  
  57.  
  58. The Draco tool [1] reused composable components resulting from domain analysis. The experience
  59. of the Advanced Software Engineering group at UC Irvine with Draco led to ideas about porting
  60. software by partial domain analysis, comp onent abstraction, and re-implementation [2 ].
  61.  
  62.  
  63. Work on Design Maintenance Systems (DMS) [3 ] defined how to generate and capture a complete
  64. design rationale for a transformationally-derived program interms of specified p erformance predi-
  65. cates. The design rationale was reused (and revised) to control the modification of the synthesized
  66. program according to formal maintenance deltas, representing desired specification changes. Co de
  67. intended  for  reuse  often  needs  to  be  modified, but  few  concrete  methods  for  carrying  out  that
  68. modification have been studied. The DMS strategies can be viewed asan explicit prescription for
  69. how to modify code in a particular reuse instance.
  70.  
  71.  
  72.  
  73.                                                          Baxter- 1
  74.  
  75.  
  76. My current work is on developing infrastructure needed by the Sinapse system to generate efficient
  77. parallel programs. This work shows the value of both declarative capture of potential parallelism in
  78. abstract components [4], and the utility of conventional compiler optimizations such as paralleliza-
  79. tion detection and common subexpression elimination on abstract domains rather than low-level
  80. (i.e., Fortran) synthesizedco de.
  81.  
  82.  
  83.  
  84. 2      Position
  85.  
  86.  
  87.  
  88. Building  knowledge-based  tools  to  aid  generative  reuse is  a  difficult  process.   Both  theory  and
  89. practical  issues  must  be  addressed.  Many  of  the  theoretical  issues are  already  addressed  in  the
  90. literature: domain analysis and evolution [5], transformational development [6], etc.
  91.  
  92.  
  93. This position paper discusses a number of practical issues, using our exp erience developing Sinapse
  94. as  examples.   A good  software  engineering  process  ought  to  identify  and  address  these  issues.
  95. However, since building generative reuse systems is not yet a common SE task, we decided to risk
  96. stating the obvious for would-be reusers of our experience.
  97.  
  98.  
  99.  
  100. 2.1     Issues
  101.  
  102.  
  103.  
  104. We will discuss the following issues:
  105.  
  106.  
  107.  
  108.     fflConstruction costs
  109.  
  110.  
  111.     fflScaling up for real synthesized codes
  112.  
  113.  
  114.     fflAd hoc knowledge vs.  algorithms
  115.  
  116.  
  117.     fflCoding vs.  specifying optimization tasks
  118.  
  119.  
  120.     fflKnowledge acquisition tools vs. knowledge capture
  121.  
  122.  
  123.     fflLeveraging the synthesis tools
  124.  
  125.  
  126.     fflTesting system robustness
  127.  
  128.  
  129.  
  130. We first sketch Sinapse to provide necessary background.
  131.  
  132.  
  133.  
  134. 2.2     Sinapse Overview
  135.  
  136.  
  137.  
  138. The  Schlumberger  Laboratory  for  Computer  Science  has  develop ed a  system  called  Sinapse  [7 ]
  139. [8 ] [9 ] to synthesize mathematical modeling programs for restricted application domains.  These
  140. are primarily wave propagation problems, typically used to validate seismic or geophysical models.
  141. Sinapse accepts a 20-50 line specification which defines a set of partial differential equations (PDEs)
  142. to be solved, either directly by stating the equations, or indirectly by use of domain-specific termi-
  143. nology. Sinapse produces complete C, (sequential) Fortran, or (data parallel) Connection Machine
  144. Fortran programs that solvethe PDEs in a particular geophysical context by using finite differ-
  145. encing methods, including the necessary input and output code. Resulting programs are 500-1500
  146. lines in size.
  147.  
  148.  
  149.                                                          Baxter- 2
  150.  
  151.  
  152. Sinapse  is  a  knowledge-based  synthesis  system,  containing  knowledge  about  the  wave  propaga-
  153. tion  problem  domain, knowledge  of  abstract  algorithms  for  solution  techniques  for  problems  in
  154. that domain, parallelization methods for those codes, general programming knowledge, and control
  155. knowledge to sequence the synthesis process. The domain knowledge is used to cho ose abstract so-
  156. lutions by classifying domain-specific specifications. These solutions are transformationally refined
  157. into a production code. The system stores synthesis sequencing knowledge as a set of hierarchical,
  158. nonlinear plans. Abstract algorithms are stored in a mixed form consisting of abstract syntax trees
  159. (ASTs) with procedural attachments. Decisions about branches in the design space are handled by
  160. built-in system constraints, heuristics and defaults; because we always exp ect the system to have
  161. limited knowledge, the software engineer operating Sinapse can override any heuristic decision. Re-
  162. finements consist of tree-to-tree rewrite rules coupled withexecution of the procedural attachments.
  163. The refinement process is reminiscent of Draco's repeated refine-to-domain, optimize-within-domain
  164. method. Optimizers based on conventional compiler technology concepts were implemented to allow
  165. optimizations in abstract domains; this allows Sinapse to detect common subexpressions and con-
  166. trol parallelism by analyzing the set of PDEs rather than expecting a Fortran compiler to discover
  167. these in the final output.
  168.  
  169.  
  170.  
  171. 3      Construction Costs
  172.  
  173.  
  174.  
  175. The development of a production-quality synthesis system, even when limited to addressing restricted
  176. domains, and reusing existing tools, can easily consume 15-20 person-years.
  177.  
  178.  
  179. Sinapse today consists of 37,000 lines of code (LOC) built on top of the commercialMathematica
  180. [10 ] system. It was developed at the cost of 12 person-years, spread over 4 elapsed years. We intend
  181. to reach a production system that can be reliably used by physicists and engineers this year.
  182.  
  183.  
  184. To provide the barest indication of where the effort goes,  weinclude a system breakdown as an
  185. LOC percentage of subsystem vs. total system:
  186.  
  187.  
  188.  
  189.   5%   Textual User Interface
  190.  
  191.  
  192.   9%   Graphical User Interface
  193.  
  194.  
  195.   5%   Synthesis control
  196.  
  197.  
  198.  25%   Domain-specific synthesis knowledge
  199.  
  200.  
  201.   5%   Local optimizer:  type inference, simplification
  202.  
  203.  
  204.  16%   Conversion of ASTs to target languages: C, Fortran, CM Fortran, Lisp
  205.  
  206.  
  207.  27%   Global optimizer:  parallelization, code motion, CSE
  208.  
  209.  
  210.   4%   Computation partial order management (used by optimizer)
  211.  
  212.  
  213.   4%   Utilities/debugging tools
  214.  
  215.  
  216.  
  217. We caution the reader not to interpret these percentages as effort, because the tasks had differing
  218. complexities, and considerable activity occurred outside of coding.
  219.  
  220.  
  221. It should come as no surprise that much of the effort went into domain-specific knowledge acquisi-
  222. tion. It may be more of a surprise that significant effort went intodomain-independent optimizing
  223. technology.
  224.  
  225.  
  226.                                                          Baxter- 3
  227.  
  228.  
  229. 4      Scaling  up  for  Realistic Co des
  230.  
  231.  
  232.  
  233. One must design synthesis systems for performance with scale.  We address how prototyping and
  234. knowledge interact with scale.
  235.  
  236.  
  237.  
  238. 4.1     Prototyping vs.  Production
  239.  
  240.  
  241.  
  242. Well-intentioned reuse of existing tools may make scaling more difficult.
  243.  
  244.  
  245. As a system starts to show promise of utility, ambitions turn from small demos to practical codes,
  246. and scale difficulties begin to show up. An initially attractive system foundation may have other
  247. properties which exact a relatively large cost in comparisonto the exp ected b enefits.  One must
  248. consider these benefits carefully; engineering for scale may require payinghigher costs during the
  249. early stages of development.
  250.  
  251.  
  252. As an example, we built Sinapse on top of a symb olicmathematical system, Mathematica (MMa),
  253. because it had several attractive properties from a prototyping p oint of view.  It provided a sin-
  254. gle program development environment which contained considerable built-in knowledge useful for
  255. manipulating symbolic (algebraic and differential) equations,a procedural programming language,
  256. and a transformation system for free.  It promised p ortability of the result because MMa ran on
  257. several  platforms, and  it  was  interactive, which  eased  debugging  by  making  inspection  simpler.
  258. Early versions of Sinapse benefited because the availability of these mechanisms made it easier to
  259. prototype parts of the system, thereby selling the system concept via small demos.
  260.  
  261.  
  262. Growing sophistication caused Sinapse's internal algorithm form to become more specialized.  It
  263. became progressively more difficult to keep a form compatiblewith that of the underlying MMa
  264. system. Eventually, we gave up direct compatibility, opting for conversion to MMa's form when we
  265. needed MMa's mathematical knowledge, and then converting the result back to the Sinapse form.
  266. Happily the number of conversions per run have turned out to be infrequent. Obviously, we wish to
  267. (re)use the knowledge in a symbolic algebra system;the need for our own representations hints that
  268. staying within the environment definedby such a tool is not necessarily required. Ideally, we'd like
  269. to have a way of compiling symbolic manipulation knowledge stored in a knowledge-representation
  270. language such as KIF [11 ] into a form compatible with our desired representations. This is itself a
  271. program synthesis problem we don't knowhow to solve.
  272.  
  273.  
  274. The MMa tree-to-tree rewrite system works well onsmall trees representing "typical" size math-
  275. ematical formulas.  Unfortunately,  MMa's built-in control strategies work slowly on large sets of
  276. transformations (100's of rules) on large ASTs (10K tree no des) which are typical of the size of the
  277. codes we synthesize. Further, MMa is an interpreter without any corresponding compiler, costing
  278. us an additional runtime factor of 10x. Synthesis times without optimization run to 30 minutes on
  279. a Sparc 2 and can be much longer with the optimizations. This has made building and testing the
  280. Sinapse system components relatively painful. If one insists on using ASTs, a tree-to-tree transfor-
  281. mation system engine is cheap to replicate compared to the investment in a synthesis system; we
  282. would recommend instead looking into more efficient pro duction system tools like OPS5 [12 ].
  283.  
  284.  
  285. Even the choice of ASTs is called intoquestion by scale.  Most "purist"" transformation systems,
  286. MMa  being  no  exception, operate  by  manipulation  of  ASTs.  However,  serious  optimization  of
  287. refined code requires that dataflow analysis be performed; ASTsare a p oor choice for this.  The lion's
  288. share of the cost in the optimizer is the need to recompute the data flow analysis information after
  289. an optimization has been made. An approach we are pursuing is the use of compiler representations
  290.  
  291.  
  292.                                                          Baxter- 4
  293.  
  294.  
  295. such as Static Single Assignment form [13 ], in which the data flow has been made explicit,  and
  296. optimizations directly transform the dataflows, keeping them up to date.  An ideal solution would
  297. be to treat the data flow analysis problem as a problem in incremental re-computation,  and use
  298. finite difference methods (unfortunately, this term is common to both PDE solving and program
  299. synthesis but doesn't mean the same thing) to keep dataflows current [14 ].
  300.  
  301.  
  302. Many  difficulties  can  be  traced  to  the  tension  between  prototyping  and  production.   Synthesis
  303. systems are controversial enough so that the need to prototype them early can predispose evolutionary
  304. descendents to later scale troubles.  For conventional SE tasks, we know that prototypes are a po or
  305. foundation  for  production  code; for  knowledge-based  systems,  evidence that  a  prototype  works
  306. should similarly not be treated as evidence that the prototype can be easily extended to a pro duction
  307. code by mere incremental addition of knowledge.
  308.  
  309.  
  310.  
  311. 4.2     Ad Hoc Knowledge vs.  Algorithms
  312.  
  313.  
  314.  
  315. Special  cases  may  sometimes  be  more  easily  handled  algorithmical ly.  Knowledge-based  methods
  316. should be reserved for cases where the algorithms fail because of intractability or lack of information.
  317. System designers should be prepared to pay the price of installing the appropriate algorithms when
  318. scaling up.
  319.  
  320.  
  321. Sinapse uses some simple methods to effect certain kinds of optimizations. To ensure that reason-
  322. ably high-performance code is generated, a kind of knowledge-based code motion is used to move
  323. initialization code for refined components out of loops. Other special mechanisms were installed to
  324. allow results of computations in generated programs to be stored and reused at later points.  These
  325. mechanisms have the advantage of being easy to define and install, which is attractive for small
  326. examples.
  327.  
  328.  
  329. Both  of  these  mechanisms  are  subsumed  by  conventional  compiler  optimization  techniques  that
  330. couple code motion with common subexpression elimination.  The knowledge-based versions are
  331. somewhat fragile, and KB encoders of algorithms had to think carefully about how to use them.
  332. The compiler methods simply work without thought; this makes the system more robust,  and it
  333. makes KB augmentation faster because less has to be explicitly encoded.
  334.  
  335.  
  336. There will still be cases where compiler methods fail because the cost of inference is simply too
  337. high. In these cases, knowledge can play a useful role.
  338.  
  339.  
  340.  
  341. 5      Coding  vs.  Specifying  Optimization  tasks
  342.  
  343.  
  344.  
  345. Since many synthesis systems will have unique internal representations, there should be a way to
  346. manufacture conventional optimizers easily.
  347.  
  348.  
  349. Program specification is about defining what a program will do. Since, given a specification,one can
  350. simply try enumerate-and-test, program synthesis is onlyab out optimization.  For scale purposes,
  351. conventional optimizers seem necessary, but building them by hand is expensive. Much of the code
  352. in an optimizer consists of routines that interpret how information flows across various syntactic
  353. constructs.
  354.  
  355.  
  356. While this can be encoded by hand, we found that as Sinapse's internal form evolved and grew in
  357. complexity,the optimizer had to evolve in lock step. We often wished that we could instead specify
  358.  
  359.  
  360.                                                          Baxter- 5
  361.  
  362.  
  363. something like the denotational semantics [15],  and "compile" that into practical optimizers.  In
  364. essence, we need an optimizer generator. Basic research is needed to accomplish this task.
  365.  
  366.  
  367. Another possibility is for the synthesis community to agree on a widely usable internal form. This
  368. would allow tools to be made generically available.  We believe this avenue is unlikely because a
  369. long search for UNCOL has largely been unsuccessful, and we expect that the utility of internal
  370. forms will come from their domain specificity.
  371.  
  372.  
  373.  
  374. 6      Knowledge Acquisition  Tools  vs.  Knowledge  Capture
  375.  
  376.  
  377.  
  378. System designers must choose between capturing knowledge themselves and defining knowledge ac-
  379. quisition tools.  Experts often havelittle patience for unfamiliar detail.  Failure to get them directly
  380. involved in knowledge capture can limit the rate at which a system's ability grows.
  381.  
  382.  
  383. Much of Sinapse's knowledge is coded in MMa notation for defining trees or as MMa procedures.
  384. This required that encoders know MMa well, and made it difficult to prevent some low-level imple-
  385. mentation details of Sinapse from leaking into thecomp onents.  Attempts to get wave propagation
  386. experts, who  were  expert  parallel  machine  programmers, directly  involved  in  the  knowledge  en-
  387. coding task were not very successful because of the high cost of learning the system.  The system
  388. designers have had to substitute for the experts when encoding the knowledge, making the designers
  389. a bottleneck in the acquisition process.
  390.  
  391.  
  392. Getting the experts involved requires that they be taught basic principles of knowledge represen-
  393. tation and domain analysis.  The system designers should spend their energy building knowledge
  394. acquisition tools, to allowing the experts to easily find out what the system already knows, and
  395. revise that knowledge, using notational schemes which are familiar [16 ], [17 ].
  396.  
  397.  
  398.  
  399. 7      Leveraging the  Synthesis  Tools
  400.  
  401.  
  402.  
  403. We should try for an "avalanche" technology, in which the tools can be used to enhance themselves.
  404. Much of a synthesis tool is focused around generation and optimization of mundane code.  It would
  405. be ideal if such mechanisms could be used to help generate more of the synthesizer code.
  406.  
  407.  
  408. Much of the Sinapse system was built byconventional coding methods. Considerable leverage might
  409. have been obtained if we could have used such synthesis tools to build part of Sinapse itself. As an
  410. example, data flow analyzers on arbitrary internalforms might have been built in this fashion.
  411.  
  412.  
  413.  
  414. 8      Testing  System  Robustness
  415.  
  416.  
  417.  
  418. A system must have a methodology for testing and configuration management to ensure robustness.
  419.  
  420.  
  421. We  successfully  used  some  conventional  SE  practices  to  help  ensure  the  robustness  of  Sinapse.
  422. Modules of the optimizer were tested dynamically on each system load during development. RCS,
  423. a source-code control tool, was augmented with a number of procedures to ensure that the base
  424. system had always been regression-tested, and that differences in test results from previous runs
  425.  
  426.  
  427.  
  428.                                                          Baxter- 6
  429.  
  430.  
  431. had been validated by team members.  These methods ensured that thedevelopers were always
  432. working with trusted components.
  433.  
  434.  
  435.  
  436. 9      Conclusion
  437.  
  438.  
  439.  
  440. We have presented some issues that must be faced by designers of generative reuse systems. Gener-
  441. ative systems appear to cost a lot to build; theremust be considerable payoff to justify building one.
  442. The classic tensions between the need to prototype cheaply to sell a system concept and the need
  443. to design for scale will probably appear as repeated development. Algorithmic methods should be
  444. used where known, and augmented with knowledge-based methods where they fail.  Generation of
  445. optimized code requires the construction of complex optimizers; abstract syntax trees seem to b e
  446. a weak representation for this purpose, and we have few tools to help us build even conventional
  447. optimizer mechanisms.
  448.  
  449.  
  450. Most of these issues are related to effects of scaling up, which cannot be avoided for most practical
  451. systems.
  452.  
  453.  
  454.  
  455. References
  456.  
  457.  
  458.  
  459.   [1] J. Neighbors, "The Draco Approach to Constructing Software from Reusable Components,"
  460.       IEEE Transactions on Software Engineering, vol. SE-10, Sept. 1984.
  461.  
  462.  
  463.   [2] G. Arango, I. Baxter, P. Freeman, and C. Pidgeon, "TMM: Software Maintenance by Trans-
  464.       formation," IEEE Software, vol. 3, pp. 27-39, May 1986.
  465.  
  466.  
  467.   [3] I. D. Baxter, "Design Maintenance Systems," Communications of the ACM, vol. 35, pp. 73-89,
  468.       Apr. 1992.
  469.  
  470.  
  471.   [4] I. D. Baxter and E. Kant, "Using Domain-Specific, Abstract Parallelism," in Proceedings of
  472.       Parallel-Code Generation Workshop atICLP91, IEEE Computer Society, Oct. 1991.
  473.  
  474.  
  475.   [5] G. Arango, Domain Engineering for Software Reuse.  PhD thesis,Department of Information
  476.       and Computer Science, University of California at Irvine, July 1988.  ICS-RTP-88-27.
  477.  
  478.  
  479.   [6] H. A. Partsch, Specification and Transformation of Programs.  Springer-Verlag, 1990.  ISBN
  480.       52356-1.
  481.  
  482.  
  483.   [7] E. Kant, F. Daube, W. MacGregor, and J. Wald, "Automated Synthesis of Finite Difference
  484.       Programs," inSymbolic Computations and Their Impact on Mechanics,PVP-Volume 205, New
  485.       York, NY: The American Society of Mechanical Engineers 1990, 1990.  ISBN 0-791800598-0.
  486.  
  487.  
  488.   [8] E.  Kant,  F.  Daube,  W.  MacGregor,  and  J.  Wald,  "Scientific  Programming  by  Automated
  489.       Synthesis," in Automating Software Design (M. Lowry and R. McCartney, eds.), AAAI Press,
  490.       1991.
  491.  
  492.  
  493.   [9] E. Kant, "Synthesis of Mathematical Modeling Software," IEEE Software, vol. 10, pp. 30-41,
  494.       May 1993.
  495.  
  496.  
  497. [10]  S.  Wolfram,  Mathematica:   A  System  for  Doing  Mathematics  by  Computer.    Reading,
  498.       Massachusetts:   Addison-Wesley  Publishing  Company,  Inc.,  1988.    ISBN 0-201-19334-5,
  499.       QA76.95.W651988.
  500.  
  501.  
  502.                                                          Baxter- 7
  503.  
  504.  
  505. [11]  M.  R.  Geneserth  and  R.  E.  Fikes, "Knowledge  Interchange  Format  Version  3.0  Reference
  506.       Manual," Tech. Rep. Logic Group Report Logic-92-1, Computer Science Department, Stanford
  507.       University, June 1992.
  508.  
  509.  
  510. [12]  L. Brownston, R. Farrell, E. Kant, and N. Martin, Programming Expert Systems in OPS5:  An
  511.       Introduction to Rule-based Programming.  Addison-Wesley, 1985.  ISBN 0-201-10647-7.
  512.  
  513.  
  514. [13]  R. Cytron, J. Ferrante, B. Rosen,M. Wegman, and K. Zadeck, "Efficiently computing static
  515.       single assignment form and the control dependence graph," ACM Trans. Programming Lan-
  516.       guages and Systems, vol. 13, pp. 451-490, Oct. 1991.
  517.  
  518.  
  519. [14]  D. R. Smith, "KIDS: A Semi-Automatic Program Development System," tech. rep., Kestrel
  520.       Institute, Palo Alto, California 94304, Oct. 1989.
  521.  
  522.  
  523. [15]  F. G. Pagan, Formal Specification of Programming Languages:  A Panoramic Primer. Engle-
  524.       wood Cliffs, New Jersey 07632: Prentice-Hall, Inc., 1981. ISBN 0-13-329052-2.
  525.  
  526.  
  527. [16]  S. Marcus, "SALT: A Knowledge Acquistion Tool for Propose-and-Revise Systems," in Au-
  528.       tomating  Knowledge  Acquisition  for Expert  Systems  (S.  Marcus,  ed.),  pp. 81-123,  Boston:
  529.       Kluwer Academic Publishers, 1988.
  530.  
  531.  
  532. [17]  J. Boose and B. Gaines, The Foundations of Knowledge Acquisition, Vol. 4. New York: Aca-
  533.       demic Press, 1990.
  534.  
  535.  
  536.  
  537. 10       Biography
  538.  
  539.  
  540.  
  541. Ira D. Baxter is a research scientist with the Schlumberger Laboratory for Computer Science in
  542. Austin, Texas, working on tools to helpengineers generate scientific modeling programs for parallel
  543. computers. He received a Ph.D. in Computer Science from the University of California at Irvine in
  544. 1990.  A previous life included 20 years of system software design for mini- and micro-computers.
  545. His interests include program synthesis/transformation, software engineering, and pizza.
  546.  
  547.  
  548.  
  549.                                                          Baxter- 8
  550.