Well-Founded Touch Optimization for Futures

Well-Founded Touch Optimization for Futures

WellFounded Touch Optimization for Futures Cormac Flanagan Matthias Fel leisen Rice COMP TR Octob er Department of Computer Science Rice University PO Box Houston TX c Copyright by Cormac Flanagan and Matthias Felleisen WellFounded Touch Optimization for Futures Cormac Flanagan Matthias Felleisen Department of Computer Science Rice University Houston TX Abstract The future annotations of MultiLisp provide a simple metho d for taming the implicit par allelism of functional programs but require touch op erations within all placeholderstrict prim itives to ensure prop er synchronization b etween threads These touch op erations contribute substantially to program execution times We use an op erational semantics of future devel op ed in a previous pap er to derive a program analysis algorithm and an optimization algorithm based on the analysis that removes provablyredundant touch op erationsExp eriments with the Gambit compiler indicate that this optimization substantially reduces program execution times Supp orted in part by NSF grant CCR and a sabbatical at Carnegie Mellon University Contents Futures Touches and Transparency Review The Language and Its Parallel Semantics Touch Optimization Nontouching Primitives The Touch Optimization Algorithm SetBased Analysis for Futures Deriving Set Constraints for Program Variables Soundness of the Set Constraints From Set Constraints to SetBased Analysis Solving the Set Constraints Exp erimental Results Related Work Conclusion A Correctness Pro of for Abstract Representation B Set Based Analysis Algorithm Novemb er DRAFT Futures Touches and Transparency Programs in functional languages oer numerous opp ortunities for executing program comp onents in parallel In a callbyvalue language for example the evaluation of every function application could spawn a parallel thread for each argument expression However if such a strategy were applied indiscriminately the execution of a program would generate far to o many parallel threads The overhead of managing these threads would clearly outweigh any b enets from parallel execution The future annotations of MultiLisp and its Scheme successors provide a simple metho d for taming the implicit parallelism of functional programs If a programmer b elieves that the par allel evaluation of some expression outweighs the overhead of creating a separate task he may annotate the expression with the keyword future An annotated functional program has the same observable b ehavior as the original program but the runtime system maycho ose to evaluate the future expression in parallel to the rest of the program If it do es the evaluation will pro ceed as if the annotated expression had immediately returned Instead of a prop er value though it returns a placeholder which contains enough information for retrieving the actual result of the annotated expression when needed When a program op eration requires sp ecic knowledge ab out the value of some sub computation but nds a placeholder the runtime system p erforms a touch op era tion whichsynchronizes the appropriate parallel threads and eventually retrieves the necessary information The standard way of implementing touch op erations on placeholders requires a mo dication of all program op erations that need to know sp ecic asp ects of values For example pro cedure application must know that the value of the rst subexpression is a pro cedure an ifexpression demands a prop er value in the test p osition not only a placeholder and addition can only add its inputs if they are numb ers Hence these op erations must b e mo died so that they rst check whether the appropriate arguments are placeholders or prop er values and must p ossibly p erform some synchronization Past researchonfutures has concentrated on the ecient implementation of the underlying task creation and on the extension of the concept to higherorder control constructs Little eort has gone into the development of a semantic characterization of the idea or the use of such a semantic framework for the optimization of task creation or co ordination In contrast the driving force b ehind our eort is the desire to develop semantically wellfounded optimizations for the execution of futures The sp ecic example wecho ose to consider is the developmentofan algorithm that safely eliminates as many touch op erations as p ossible Other optimizations will b e the sub ject of future eorts In a previous pap er we develop ed a series of semantics for an idealized functional language with future The last semantics is particularly suited to the develelopment of analysis and opti mization algorithms since it exp oses appropriate details regarding program executions Wenow use that semantics to derive a program analysis algorithm and a provablycorrect touch optimization algorithm based on the analysis An implementation of the optimization on the Gambit Scheme compiler pro duced signicant sp eedups on a standard set of b enchmarks We b elieve that this development can b e extended to larger languages and other implementation techniques The presentation of our results pro ceeds as follows The second section intro duces a sim ple functional language with futures and recalls the lowlevel parallel abstract machine for the language The third section discusses the cost of touch op erations and presents a provably cor rect algorithm for eliminating unnecessary touch op erations The latter is based on the setbased analysis algorithm of the fourth section The fth section describ es the implementation of these algorithms on the Gambit compiler and compares the mo died compiler to the original compiler on a standard set of b enchmarks The sixth section discusses related work Novemb er DRAFT Review The Language and Its Parallel Semantics Given the goal of developing a semantics that is useful for proving the soundness of optimizations we develop the denitional semantics for futures for an intermediate representation of an idealized functional language Sp ecicallywe use the subset of Anormal forms of an extended calcu luslike language that includes conditionals and a future construct see Figure M x Terms a j let xV M j let x future M M j let x car y M j let x cdr y M j let x if yM M M j let x apply yz M V Value c j x j x M j cons xy Values x Vars fxyzg Variables Const ftrue false g Constants c Figure The Anormalized Language a In a previous pap er we develop ed a series of abstract machines each sp ecifying the semantics of futures at a dierent level of abstraction The last of these machines called the P CEK machine is particularly suited to the development of program analyses since contains explicit binding information relating program variables to their values The machine is also suited to the developmentofatouch optimization algorithm since it exp oses the use of explicit placeholder ob jects and p erforms touch op erations on these ob jects We use this machine dened in Figures and as the basis for the development of this pap er Notation We use the following notations throughout the pap er P denotes the p owerset con structor f A B denotes that f is a total function from A to B f A B denotes that f p is a partial function from A to B M P denotes that the term M o ccurs in the program P and har x M E i refers to either a normal activation record har x M E i or a tagged activation record har y x M E i Touch Optimization The P CEKmachine p erforms touch op erations on arguments in placeholderstrict p ositions of all rst mention of program op erations These implicit touch op erations guarantee the transparency of placeholders phstrict whichmakes futurebased parallelism so convenient to use Unfortunately these compilerinserted touch op erations imp ose a signicantoverhead on the execution of annotated programs For ex ample an annotated doublyrecursiveversion of b p erforms million touch op erations during the computation of b Due to the dynamic typing of Scheme the cost of each touch op eration dep ends on the program op eration that invoked it If a program op eration already p erforms a typ e dispatch to ensure that Novemb er DRAFT Evaluator eval Answers ferror g pcek a unload E x if hP i hx E i pcek pcek error if hP i error pcek eval P pcek if i N S State n m N such that i pcek i i n m i i m S hP i and S S i i i pcek Data Sp ecications S State hM E K ij errorflet pS S States pcek M Anf Language a E Env Vars Value Environments pcek p pcek V Value PValue j PhObj RunTime Values pcek pcek pcek W PValue c j x j Cl j Pair Prop er Values pcek pcek pcek Cl hx M Ei Closures pcek Pair cons VV Pairs pcek PhObj hph p ijhph pVi Placeholder Values pcek K Cont jhar x M E iK jhar y x M E iK Continuations pcek F FinalState hx E ij error Final States pcek A Answers c j procedure j cons AA Answers Auxiliary Functions touch Value PValue fg unload Value Answers pcek pcek pcek pcek pcek touch hph p i unload c c pcek pcek touch hph pVi touch V unload hx M Ei procedure pcek pcek pcek touch W W unload cons V V cons V V pcek pcek where V unload V pcek i i unload hph pVi unload V pcek pcek Placeholder Substitution S p V pVi M p V M with all o ccurrences of hph p i up dated to hph flet p S p V S if p p flet p S S p V flet p S p V S p V if p p Figure The P CEKmachine Evaluator and Data Sp ecications its arguments have the appropriate

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    30 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us