Towards High Performance Multi-stage Programming ...

3 downloads 8019 Views 156KB Size Report
Oct 7, 2014 - simple built-in domain-specific optimiser to assist in model production. We blur the lines .... The variables position and velocities are host-allocated memory segments. These need not be ... buy more shares sell shares.
Technical Report CSTN-226

Towards High Performance Multi-stage Programming for Generative Agent-based Modelling A.V. Husselmann, K.A. Hawick Computer Science Institute of Information & Mathematical Sciences Massey University at Albany, Auckland, New Zealand Email: {a.v.husselmann | k.a.hawick}@massey.ac.nz October 7, 2014 Abstract Multi-stage programming (MSP) allows for pragmatic use of run-time code generation and execution. Terra is a new language which makes extensive use of this concept. Not only does the language make MSP more accessible, high performance extensions are also provided for programming graphical processing units (GPUs). In addition, inherent optimisations such as automatic vectorisation with SSE and AVX instructions are provided by LLVM among others with zero additional configuration, all compiled to machine code in memory. Domain specific languages (DSLs) are therefore naturally constructed using Terra due to its ability to generate arbitrary code during run-time. We report on the creation of a simple DSL for agent-based modelling (ABM) with a simple built-in domain-specific optimiser to assist in model production. We blur the lines between parametric optimisation of models, and global model induction by instead allowing a modeller to concisely express uncertain small portions of a model in terms of domain-specific knowledge. We also present some performance data.

1

Introduction

In June 2013, DeVito and colleagues of Stanford University published Terra [6], a low-level language designed from the outset to be fully cooperative with Lua [10]. Lua, a scripting language with 12 major releases since its inception in 1996 [9] is promoted as a very extensible embedded language. The combination of Lua and Terra enables users to build new domain-specific languages (DSLs) with high performance extensions, in considerable elegance [6]. Terra makes use of LuaJIT [19], LLVM [14] and Clang (the C frontend to LLVM). Together, these allow the run-time compiling, importing and execution of system functions linked to the executable. Creating domain specific languages using Terra is made possible by the ability to insert evaluate Lua expressions directly into Terra code before compilation. The quote operator allows the programmer to create Terra statements, and the backtick operator creates Terra expressions to insert into other Terra functions. Terra functions are also first-class Lua values. The use of Terra and Lua for scientific computing is attractive also for the optimisations within LLVM, including vectorisation [14], particularly the Intel SSE and AVX SIMD instruction sets. Terra provides direct support for this, as well as support for NVidia’s CUDA [18] for programming graphical processing units (GPUs). GPUs have shown an impressive ability to accelerate scientific computations (particularly agent-based modelling) [8], and any visualisations involved. Chitty, however, asserts that the immense uptake of GPU programming has neglected recent advances in CPU-based SIMD technology [4]. Agent-based Modelling (ABM) has seen many domain-specific languages (DSLs) since 1990, almost too numerous to enumerate. A comparison of some of these is available [3]. Perhaps the most prominent DSL is NetLogo [22], 1

CSTN-226

which is a conceptually simple modelling language designed to make models as concise as possible. The language is interpreted using Java. There are many software packages dedicated to ABMs, most of which are clearly domain-specific themselves, such as Protoswarm (swarm robotics) [2], SWARM (holonic [7] agents) [17], RePast (general-purpose object-oriented Java libraries inspired in part from SWARM) [5], MASON (also Java, though promoted for performance) [15]. These are but a very small selection of the software already available.

2

Generative Agent-based Modelling

Not only is ABM considered a generative approach to macro-level phenomena, ABM has itself become the subject of top-down approaches. There have been numerous attempts to give rise to generative ABM, including the recent work of van Berkel [23, 24], as well as Junges and Kl¨ ugl [11–13], also recent. These attempts have focussed on the use of a global optimiser to systematically explore the (immense) parameter and program spaces associated with ABMs. The work of van Berkel is clearly limited by the very carefully articulated set of individual instructions for the example models evolved. The most recent work of Junges and Kl¨ ugl focus on a specialised modelling methodology adapted for machine learning [13]. A single overarching objective function is among the steps in their “MABLe” methodology. Objective functions are notoriously difficult to craft, and its successful derivation is often in fact a considerable portion of research, such as in softbot team coordination [16] (a multi-agent example). The authors use Q-learning in combination with a decision tree algorithm to accomplish agent learning [12]. Babovic put forward GP as a model induction method for experimental data [1]. Stonedahl [21] put forward an extension to NetLogo to search through the parameter space of an ABM. While adequate for fine tuning, such optimisers are invariably limited to parameters, which do not modify the semantic structure of the model on which they are built. We propose a compiled internal DSL which takes a stance midway between global synthesis of ABMs using atomic building blocks and parameter optimisers, and a fully hand-written, hand-tuned ABM. At this point DSLs have been employed to improve the modelling experience, not necessarily enhance it beyond its ability to represent models. Using a high performance language such as Terra, a DSL can be constructed which not only JIT compiles itself to memory, but also makes use of processor-specific optimisations in LLVM, and with little additional effort, GPUs. As an example, consider the proof of concept Lua-Terra code shown in listing 1. This code is entirely valid Terra, except for the second line. sol move towards ex a done is invalid syntax, made valid by extending the Lua lexer using a Pratt parser [20] provided as a library extending the Terra parser. The same line is actually JIT compiled as well, using the Terra quote operator to combine statements together. The grammar of this short code segment is very simple, and will be extended in the very near future. At present, such a statement (when compiled) returns a Terra function, taking no arguments and returning one vector. The rest of the code in this listing is library code. The stepAll() function is a Terra function which maps the agent.step() function to all agents in the simulation, splicing in a variable from Lua named agent count, as well as the Lua table containing the step function. The variables position and velocities are host-allocated memory segments. These need not be allocated on the host, however. The novelty here lies in the ability to automatically make use of SIMD instructions and GPU programming. In the future we anticipate the addition of a statement such as either. Conceptually its use would look similar to listings 2 and 3. Using this type of syntax would allow the user to ensure a concise ABM program, as well as deal with uncertainty. Simultaneously, it will allow the user to reduce the search space by injecting as much domain-specific knowledge as possible (and available) into the program, before attempting to obtain a certain part of the model from an optimiser seeking to minimise/maximise a desired quantity. It is often not pragmatic to design a full Genetic Programming (GP) algorithm for three or four instructions or symbols, and may not be practical to attempt to synthesise an entire model from building blocks which were designed by the user. 2

CSTN-226

Listing 1: Proof of concept Lua-Terra listing. a = {0.1 ,0.2 ,0.3} tempf = s o l move towards ex a done tempfunc = tempf . impl a g e n t = {} a g e n t . s t e p = t e r r a ( a l l p o s : &f l o a t , a l l v e l : &f l o a t , pos : &v e c t o r ( f l o a t , 3 ) , var t = tempfunc ( ) @vel = @vel + ( t − @pos ) ∗ 0 . 0 0 1 @pos = @pos + @vel ∗ 0 . 1 end

v e l : &v e c t o r ( f l o a t , 3 ) , a g e n t c o u n t : i n t )

t e r r a s t e p A l l ( p o s i t i o n s : &f l o a t , v e l o c i t i e s : &f l o a t ) agent . s e t a l l p o s ( p o s i t i o n s ) ; agent . s e t a l l v e l ( v e l o c i t i e s ) ; f o r i = 0 , [ a g e n t c o u n t ] do [ agent . step ] ( p o s i t i o n s , v e l o c i t i e s , [& v e c t o r ( f l o a t , 3 ) ] ( p o s i t i o n s +3∗ i ) , [& v e c t o r ( f l o a t , 3 ) ] ( v e l o c i t i e s +3∗ i ) , [ agent count ] ) end end stepAll : compile ( ) parameters . setStepallFunc ( getFunctionPointer ( s t e p A l l ) )

Listing 2: Keyword concept. when ( r a i n i n g ) do e i t h e r { buy more s h a r e s s e l l shares } t o maximise ( p r o f i t ) ;

Listing 3: Keyword concept. s e t c l o s e a g e n t d i s t a n c e s = d i s t a n c e −t o c l o s e −a g e n t s ( ) f o r ( a l l −a g e n t s ) { do e i t h e r { move towards ( o t h e r −a g e n t s ) move c l o s e r ( o t h e r −a g e n t s ) } t o m i n i m i s e (maximum ( c l o s e a g e n t d i s t a n c e s ) ) and maximise ( minimum ( c l o s e a g e n t d i s t a n c e s ) ) ; }

3

Conclusion

We have presented a short introduction to the multi-stage programming paradigm of Terra and Lua, as well as a preliminary discussion on its usefulness pertaining to Agent-based Modelling. Making use of a radically different syntax within an existing language, while still having it JIT compiled to machine code is an enormous advantage. In the past, speed and elegance have been mutually exclusive to some extent. In the future, we anticipate higher 3

CSTN-226

level constructs which allow us to embed a suitable optimiser or heuristic to deal with modelling uncertainty, as opposed to obtaining a model by combinatorial optimisation of carefully designed building blocks.

References [1] Vladan Babovic and Maarten Keijzer. Genetic programming as a model induction engine. Journal of Hydroinformatics, 2(1):35–60, 2000. [2] Jonathan Bachrach, James McLurkin, and Anthony Grue. Protoswarm: a language for programming multi-robot systems using the amorphous medium abstraction. In Proceedings of the 7th international joint conference on Autonomous agents and multiagent systems-Volume 3, pages 1175–1178. International Foundation for Autonomous Agents and Multiagent Systems, 2008. [3] Jacob Beal, Stefan Dulman, Kyle Usbeck, Mirko Viroli, and Nikolaus Correll. Organizing the aggregate: Languages for spatial computing. In M. Mernik, editor, Formal and Practical Aspects of Domain-Specific Languages: Recent Developments, pages 436–501. IGI Global, August 2013. [4] Darren M. Chitty. Fast parallel genetic programming: multi-core cpu versus many-core gpu. Soft. Comput., 16:1795– 1814, 2012. [5] Collier. Repast: An extensible framework for agent simulation. Technical report, Social Science Research Computing, University of Chicago, 2003. [6] Zachary DeVito, James Hegarty, Alex Aiken, Pat Hanrahan, and Jan Vitek. Terra: a multi-stage language for highperformance computing. In PLDI, pages 105–116, 2013. [7] Christian Gerber, J¨ org Siekmann, and Gero Vierke. Holonic multi-agent systems. Deustches Forschungzentrum f¨ ur K¨ unstliche Intelligenz GmbH, May 1999.

Technical Report RR-99-03,

[8] A.V. Husselmann and K.A. Hawick. Simulating species interactions and complex emergence in multiple flocks of boids with gpus. In T. Gonzalez, editor, Proc. IASTED International Conference on Parallel and Distributed Computing and Systems (PDCS 2011), pages 100–107, Dallas, USA, 14-16 Dec 2011. IASTED. [9] Roberto Ierusalimschy, Luiz Henrique de Figueiredo, and Waldemar Celes. The evolution of Lua. In Proceedings of the third ACM SIGPLAN conference on History of programming languages, pages 2–1–2–26. ACM, 2007. [10] Roberto Ierusalimschy, Luiz Henrique de Figueiredo, and Waldemar Celes Filho. Lua: An extensible extension language. Software: Practice and Experience, 26:635–652, 1996. [11] Robert Junges and Franziska Kl¨ ugl. Evaluation of techniques for a learning-driven modeling methodology in multiagent simulation. In Jrgen Dix and Cees Witteveen, editors, Multiagent System Technologies, volume 6251 of Lecture Notes in Computer Science, pages 185–196. Springer Berlin Heidelberg, 2010. [12] Robert Junges and Franziska Kl¨ ugl. Programming agent behavior by learning in simulation models. Applied Artificial Intelligence, 26:349–375, 2012. [13] Robert Junges and Franziska Kl¨ ugl. Learning tools for agent-based modeling and simulation. K¨ unstliche Intelligenz, 27:273–280, 2013. [14] Chris Lattner and Vikram Adve. Llvm: A compilation framework for lifelong program analysis & transformation. In Code Generation and Optimization, 2004. CGO 2004. International Symposium on, pages 75–86. IEEE, 2004. [15] Sean Luke, Claudio Cioffi-Revilla, Liviu Panait, Keith Sullivan, and Gabriel Balan. MASON: A multiagent simulation environment. Simulation, 81:517–527, 2005. [16] Sean Luke, Charles Hohn, Jonathan Farris, Gary Jackson, and James Hendler. Co-evolving soccer softbot team coordination with genetic programming. RoboCup-97: Robot soccer world cup I, 1:398–411, 1998. [17] Nelson Minar, Roger Burkhart, Chris Langton, and Manor Askenazi. The swarm simulation system: A toolkit for building multi-agent simulations. Technical report, Santa Fe Institute, 1399 Hyde Park Rd. Santa Fe, NM 87501, June 1996. [18] NVIDIA. CUDA C Programming Guide, 5.0 edition, October 2012. [19] Mike Pall. The luajit project, 2008. [20] Vaughan R. Pratt. Top down operator precedence. In 1973 Proceedings of the 1st annual ACM SIGACT-SIGPLAN symposium on Principles of programming languages, 1973. [21] Forrest Stonedahl and Uri Wilensky. Finding forms of flocking: Evolutionary search in abm parameter-spaces. In Multi-Agent-Based Simulation XI. Springer, 2011.

4

CSTN-226

[22] Tisue and Wilensky. NetLogo: A simple environment for modeling complexity. In International Conference on Complex Systems, 2004. [23] S van Berkel, D Turi, A Pruteanu, and S Dulman. Automatic discovery of algorithms for multi-agent systems. In Proceedings of the fourteenth international conference on Genetic and evolutionary computation conference companion, pages 337–334, July 2012. [24] Sjors van Berkel. Automatic discovery of distributed algorithms for large-scale systems. Master’s thesis, Delft University of Technology, 2012.

5

Suggest Documents