
CEAL: A C-Based Language for Self-Adjusting Computation Matthew A. Hammer Umut A. Acar ∗ Yan Chen Toyota Technological Institute at Chicago fhammer,umut,[email protected] Abstract algorithms community develop so called dynamic or kinetic algo- Self-adjusting computation offers a language-centric approach to rithms or data structures that take advantage of the particular prop- writing programs that can automatically respond to modifications erties of the considered problem to update computations quickly. to their data (e.g., inputs). Except for several domain-specific Such algorithms have been studied extensively over a range of hun- implementations, however, all previous implementations of self- dreds of papers (e.g. [13, 17] for surveys). These advances show adjusting computation assume mostly functional, higher-order lan- that computations can often respond to small modifications to their guages such as Standard ML. Prior to this work, it was not known data nearly a linear factor faster than recomputing from scratch, in if self-adjusting computation can be made to work with low-level, practice delivering speedups of orders of magnitude. As a frame imperative languages such as C without placing undue burden on of comparison, note that asymptotic improvements in performance the programmer. far surpasses the goal of parallelism, where speedups are bound by We describe the design and implementation of CEAL: a C-based the number of available processors. Designing, analyzing, and im- language for self-adjusting computation. The language is fully gen- plementing dynamic/kinetic algorithms, however, can be complex eral and extends C with a small number of primitives to enable even for problems that are relatively simple in the conventional set- writing self-adjusting programs in a style similar to conventional ting, e.g., the problem of incremental planar convex hulls, whose C programs. We present efficient compilation techniques for trans- conventional version is straightforward, has been studied over two lating CEAL programs into C that can be compiled with existing decades (e.g., [32, 11]). Due to their complexity, implementing C compilers using primitives supplied by a run-time library for these algorithms is an error-prone task that is further complicated self-adjusting computation. We implement the proposed compiler by their lack of composability. and evaluate its effectiveness. Our experiments show that CEAL Self-adjusting computation (e.g., [4, 3]) offers a language- is effective in practice: compiled self-adjusting programs respond centric approach to realizing the potential speedups offered by to small modifications to their data by orders of magnitude faster incremental modifications. The approach aims to make writing than recomputing from scratch while slowing down a from-scratch self-adjusting programs, which can automatically respond to mod- run by a moderate constant factor. Compared to previous work, we ifications to their data, nearly as simple as writing conventional measure significant space and time improvements. programs that operate on unchanging data, while delivering effi- cient performance by providing an automatic update mechanism. In Categories and Subject Descriptors D.3.0 [Programming Lan- self-adjusting computation, programs are stratified into two com- guages]: General; D.3.3 [Programming Languages]: Language ponents: a meta-level mutator and a core. The mutator interacts Constructs and Features with the user or the outside world and interprets and reflects the modifications in the data to the core. The core, written like a con- General Terms Languages, Performance, Algorithms. ventional program, takes some input and produces an output. The core is self-adjusting: it can respond to modifications to its data by Keywords Self-adjusting computation, compilation, control and employing a general-purpose, built-in change propagation mech- data flow, dominators, tail calls, trampolines, performance. anism. The mutator can execute the core with some input from scratch, which we call a from-scratch or an initial run, modify the 1. Introduction data of the core, including the inputs and other computation data, and update the core by invoking change propagation. A typical mu- Researchers have long observed that in many applications, applica- tator starts by performing a from-scratch run of the program (hence tion data evolves slowly or incrementally over time, often requiring the name initial run), and then repeatedly modifies the data and only small modifications to the output. This creates the potential for updates the core via change propagation. applications to adapt to changing data significantly faster than re- At a high level, change propagation updates the computation by computing from scratch. To realize this potential, researchers in the re-executing the parts that are affected by the modifications, while ∗ leaving the unaffected parts intact. Change propagation is guaran- Acar is partially supported by a gift from Intel. teed to update the computation correctly: the output obtained via change propagation is the same as the output of a from-scratch exe- cution with the modified data. Even in the worst case, change prop- agation falls back to a from-scratch execution—asymptotically, it is Permission to make digital or hard copies of all or part of this work for personal or never slower (in an amortized sense)—but it is often significantly classroom use is granted without fee provided that copies are not made or distributed faster than re-computing from-scratch. for profit or commercial advantage and that copies bear this notice and the full citation Previous research developed language techniques for self- on the first page. To copy otherwise, to republish, to post on servers or to redistribute to lists, requires prior specific permission and/or a fee. adjusting computation and applied it to a number of application PLDI’09, June 15–20, 2009, Dublin, Ireland. domains (e.g., for a brief overview [3]). The applications show Copyright c 2009 ACM 978-1-60558-392-1/09/06. $5.00 that from-scratch executions of self-adjusting programs incur a moderate overhead compared to conventional programs but can This poses a compilation challenge: compiling CEAL programs to respond to small modifications orders-of-magnitude faster than re- self-adjusting programs requires identifying the dependence infor- computing from scratch. The experimental evaluations show that mation needed for change propagation. To address this challenge, in some cases self-adjusting programs can be nearly as efficient we describe a two-phase compilation technique (Sections 5 and 6). as the “hand-designed” and optimized dynamic/kinetic algorithms The first phase normalizes the CEAL program to make the depen- (e.g., [6]). Recent results also show that the approach can help dencies between data and parts of the program code explicit. The develop efficient solutions to challenging problems such as some second phase translates the normalized CEAL code to C by using three-dimensional motion simulation problems that have resisted primitives supplied by a run-time-system (RTS) in place of CEAL’s algorithmic approaches [5]. primitives. This requires creating closures for representing depen- Existing general-purpose implementations of self-adjusting dencies and efficiently supporting tail calls. We prove that the size computation, however, are all in high-level, mostly functional lan- of the compiled C code is no more than a multiplicative factor larger guages such as Standard ML (SML) or Haskell [27, 12]. Several than the source CEAL program, where the multiplicative factor is exist in lower-level languages such as C [6] and Java [35] but they determined by the maximum number of live variables over all pro- are domain-specific. In Shankar and Bodik’s implementation [35], gram points. The time for compilation is bounded by the size of the which targets invariant-checking applications, core programs must compiled C code and the time for live variable analysis. Section 3.2 be purely functional and functions cannot return arbitrary values or gives an overview of the compilation phases via an example. use values returned by other functions in an unrestricted way. Acar We implement the proposed compilation technique and evaluate et al’s C implementation [6] targets a domain of tree applications. its effectiveness. Our compiler, cealc, provides an implementation Neither approach offers a general-purpose programming model. of the two-level compilation strategy and relies on the RTS for sup- The most general implementation is Hammer et al’s C library [21], plying the self-adjusting-computation primitives. Our implementa- whose primary purpose is to support efficient memory manage- tion of the RTS employs the recently-proposed memory manage- ment for self-adjusting computation. The C library requires core ment techniques [21], and uses asymptotically optimal algorithms programs to be written in a style that makes dependencies between and data structures to support traces and change propagation. For program data and functions explicit, limiting its effectiveness as a practical efficiency, the compiler uses intra-procedural compilation source-level language. techniques that make it possible to use simpler, practically efficient That there is no general-purpose support for self-adjusting algorithms. Our compiler cealc is between a factor of 3–8 slower computation in low level, imperative languages such as C is not and generates binaries that are 2–5 times larger than gcc. accidental: self-adjusting computation critically relies on higher- We perform an experimental evaluation by considering a range order features of high-level languages. To perform updates effi- of benchmarks, including several primitives on lists (e.g., map, fil- ciently, change propagation must be able to re-execute a previously- ter), several sorting algorithms, and computational geometry al- executed piece of code in the same state (modulo the modifica- gorithms for computing convex hulls, the distance between con- tions), and skip over parts of the computation that are unaffected by vex objects, and the diameter of a point set. As a more complex the modifications.
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages13 Page
-
File Size-