Increasing programmability with domain- specific languages Kris6an Sandahl, Peter Fritzson, Christoph Kessler PELAB Department of Computer and Informa6on Science Linköping University
PELAB at a Glance Programming environments laboratory, founded in 1981 Staff: 5 professors, 4 assistant professors, 11 phd students, 4 engineers Current topics: Compiler technology SoQware composi6on Parallel compu6ng Design and implementa6on of programming and modeling languages and systems Equa6on- based object- oriented modeling and simula6on languages Large- scale soqware engineering Requirements engineering SoQware tes6ng and debugging
Problem Produc6vity and Quality of human- made soqware
Means Raise the abstrac6on level Model- based SoQware Engineering Domain- specific Languages Skeletons and pawerns SoQware models System models Parallel programming and mul6core processing MODELICA SySML Use SkePU skeleton programming Sequen6al interface Simula6on Visualiza6on Valida6on Heterogeneous systems Pla[orm agnos6c High- level constructs
Modelica A Cyber-Physical Modeling Language for Systems Engineering and the OpenModelica Environment September 25, 2014 STEW Workshop Peter Fritzson Professor at Linköping University, Sweden Vice Chairman of Modelica Association Director of Open Source Modelica Consortium Senior Member, IEEE peter.fritzson@liu.se
What is Modelica? A language for modeling of complex cyber-physical systems Robotics Control Automotive Aircraft Satellites Power plants Systems biology 6
What is Special about Modelica? Multi-Domain Modeling Cyber-Physical Modeling Physical 3 domains - electric - mechanics - control Cyber 7
What is Special about Modelica? Multi-Domain Modeling qddref qdref 1 S qref 1 S k2 i k1 i r3control Hierarchical system modeling r3motor r3drive1 1 cut joint qd tn axis6 axis5 Visual Acausal Hierarchical Component Modeling q: angle qdref Kd 0.03 S rel qref psum - Kv 0.3 +1 +1 sum wsum - rate2 b(s) a(s) rate3 340.8 S iref Jmotor=J spring=c fric=rv0 gear=i joint=0 S axis4 axis3 rate1 tacho2 tacho1 b(s) a(s) b(s) a(s) PT1 g5 axis2 q Srel = n*transpose(n)+(identity(3)- Rd2=100 n*transpose(n))*cos(q)- skew(n)*sin(q); Ri=10 - - - + + diff + pow er OpI Vs Rd3=100 hall2 qd Rd1=100 wrela = n*qd; zrela = n*qdd; Sb = Sa*transpose(Srel); r0b = r0a; Rd4=100 vb = Srel*va; wb = Srel*(wa + wrela); ab = Srel*aa; g1 zb = Srel*(za + zrela + cross(wa, wrela)); g3 Rp2=50 C=0.004*D/w m Rp1=200 hall1 Ra=250 La=(250/(2*D*w m)) emf w r axis1 y x inertial g2 qd g4 q 8 Courtesy of Martin Otter
Graphical and Textual View A DC motor can be thought of as an electrical circuit which also contains an electromechanical component model DCMotor Resistor R(R=100); Inductor L(L=100); VsourceDC DC(f=10); Ground G; ElectroMechanicalElement EM(k=10,J=10, b=2); Inertia load; equation R connect(dc.p,r.n); connect(r.p,l.n); DC connect(l.p, EM.n); connect(em.p, DC.n); connect(dc.n,g.p); connect(em.flange,load.flange); G end DCMotor L EM load 9
Application of Modelica in Robotics Models Real-time Training Simulator for Flight, Driving Using Modelica models generating real-time code Different simulation environments (e.g. Flight, Car Driving, Helicopter) Developed at DLR Munich, Germany Dymola Modelica tool Courtesy of Martin Otter, DLR, Oberphaffenhofen, Germany 10
Modelica Standard Library Open Source, Developed by Modelica Association The Modelica Standard Library contains components from various application areas, including the following sublibraries: Blocks Library for basic input/output control blocks Constants Mathematical constants and constants of nature Electrical Library for electrical models Icons Icon definitions Fluid 1-dim Flow in networks of vessels, pipes, fluid machines, valves, etc. Math Mathematical functions Magnetic Magnetic.Fluxtubes for magnetic applications Mechanics Library for mechanical systems Media Media models for liquids and gases SIunits Type definitions based on SI units according to ISO 31-1992 Stategraph Hierarchical state machines (analogous to Statecharts) Thermal Components for thermal systems Utilities Utility functions especially for scripting 11
The OpenModelica Open Source Environment www.openmodelica.org Advanced Interactive Modelica compiler (OMC) Supports most of the Modelica Language Modelica and Python scripting Basic environment for creating models OMShell an interactive command handler OMNotebook a literate programming notebook MDT an advanced textual environment in Eclipse OMEdit graphic Editor OMDebugger for equations OMOptim optimization tool OM Dynamic optimizer collocation ModelicaML UML Profile MetaModelica extension ParModelica extension 12 12
OSMC International Consortium for Open Source Model-based Development Tools, 46 members Mar 2014 Founded Dec 4, 2007 Open-source community services Website and Support Forum Version-controlled source base Bug database Development courses www.openmodelica.org Code Statistics Industrial members Bosch Rexroth AG, Germany Siemens PLM, California, USA Siemens Turbo, Sweden CDAC Centre, Kerala, India Creative Connections, Prague DHI, Aarhus, Denmark EDF, Paris, France Equa Simulation AB, Sweden Fraunhofer IWES, Bremerhaven Frontway AB, Sweden IFP, Paris, France University members Austrian Inst. of Tech, Austria Linköping University, Sweden UC Berkeley, USA TU Berlin, Insti UEBB, Germany FH Bielefeld, Bielefeld, Germany TU Braunschweig, Germany Univ Calabria, Italy Danish Technical Univ, Denmark TU Dortmund, Germany TU Dresden, Germany Université Laval, Canada Georgia Inst. Technology, USA GTI, USA ISID Dentsu, Tokyo, Japan ITI, Dresden, Germany Maplesoft, Canada Ricardo Inc., USA STEAG, Dehli, India TLK Thermo, Germany Sozhou Tongyuan, China VTI, Linköping, Sweden VTT, Finland Wolfram MathCore, Sweden Ghent University, Belgium Halmstad University, Sweden Heidelberg University, Germany TU Hamburg/Harburg Germany KTH, Stockholm, Sweden Univ of Maryland, Syst Eng USA Univ of Maryland, CEEE, USA Politecnico di Milano, Italy Ecoles des Mines, CEP, France Mälardalen University, Sweden Univ Pisa, Italy Telemark Univ College, Norway 13
14 OpenModelica MDT Eclipse Plug-in with OpenModelica Algorithmic Code Debugger
General Tool Interoperability & Model Exchange Functional Mock-up Interface (FMI) The FMI development a result of the MODELISAR 29-partner project FMI development initiated by Daimler Improved Software/Model/Hardware-in-the-Loop Simulation, of physical models and of AUTOSAR controller models from different vendors for automotive applications with different levels of detail. Open Standard, standardized by Modelica Association 14 automotive use cases for evaluation > 40 tool vendors are supporting it etc. Engine with ECU Gearbox with ECU Thermal systems Automated cargo door Chassis components, roadway, ECU (e.g. ESP) functional mockup interface for model exchange and tool coupling courtesy Daimler 15
Simulation and Requirements Checking Tank system example Req. 001 is instantiated 2 times (there are 2 tanks in the system) tank-height is 0.6m Req. 001 for the tank2 is violated Req. 001 for the tank1 is not violated 16
ParModelica Modelica Parallel Algorithmic Programming Execution on GPUs and CPUs via portable OPENCL code generation Matrix Multiplication application Gained speedup Intel Xeon E5520 CPU (16 cores) 26 NVIDIA Fermi-Tesla M2050 GPU (448 cores) 115 Speedup comparison to sequential algorithm on Intel Xeon E5520 CPU Speedup CPU E5520 GPU M2050 114.67 35.95 24.76 26.34 13.41 4.36 0.61 4.61 64 128 256 512 Parameter M (Matrix sizes MxM) Simulation Time (second) 512 256 128 64 32 16 8 4 2 1 0.5 0.25 0.125 0.0625 32 64 128 256 512 CPU E5520 (Serial) 0.093 0.741 5.875 58.426 465.234 CPU E5520 (Parallel) 0.137 0.17 0.438 2.36 17.66 GPU M2050 (Parallel) 1.215 1.217 1.274 1.625 4.057 17
Get More Information, Download Software Peter Fritzson Principles of Object Oriented Modeling and Simulation with Modelica 3.3 A Cyber-Physical Approach Wiley-IEEE Press, 2014 1250 pages OpenModelica www.openmodelica.org Modelica Association www.modelica.org 18
High-Level Programming The image cannot be displayed. Your computer may not have enough memory to open the image, or the image may have been corrupted. Restart your computer, and then open the file again. If the red x still appears, you may have to delete the image and then insert it again. for Heterogeneous Systems using Skeletons*" Christoph Kessler Linköping University Sweden *This research is funded by EU FP7 projects PEPPHER and EXCESS, and by SeRC" EXCESS
The Computer Engineer s Solution Today: Heterogeneous Multicore" J More energy-efficient than general-purpose sequential resp. general-purpose multicore CPU J Hardware-tailored parallel programming models J Detailed resource control General- purpose" CPU" Offload certain computation Data transfer Device memory Main Memory Programmable Hardware Accelerator " 20" "
The Application Programmer s Nightmare: Heterogeneous Multicore" L Distributed Memory or Non-coherent Shared Memory L Different Programming Models L Low Abstraction Level L Require Architecture- specific Optimization General- purpose" CPU" Offload certain computation Data transfer Device memory Main Memory Programmable Hardware Accelerator " 21" "
Common: GPU-Based Systems" L Distributed Memory L Different Programming Models L Low Abstraction Level L Require Architecture- specific Optimization CPU" Offload heavy computation Data transfer Device memory Main Memory GPU " 22" "
Common: GPU-Based Systems" L Distributed Memory L Different Programming Models L Low Abstraction Level L Require Architecture- specific Optimization CPU" Offload heavy computation Data transfer Device memory GPU " Device memory Main Memory GPU " 23" "
Programming of GPU-based Systems with OpenCL (?) - Code portability J - Programmability L (low level) - Performance portability L (requires reoptimization) CPU" Offload heavy computation Data transfer Device memory Main Memory GPU " 24" "
Skeleton Programming" A skeleton is a pre-defined generic software component that Models a common computation / dependence pattern à well-defined semantics; metadata implicit Can be customized with sequential user code" Provides a sequential interface Encapsulates all platform-specific implementation details (parallelism, heterogeneity, memory management, ) 25" "
SkePU www.ida.liu.se/~chrke/skepu C++ template library targeting GPU-based systems 6 dataparallel skeletons Map, Reduce, Scan, MapReduce, MapArray, MapOverlap (stencil) 1 task-parallel skeleton: farm STL-based containers wrapping operand data Smart containers Vector< >, Matrix< > optimizing data transfers and memory management at runtime Generation of platform-specific variants for user functions Multiple back-ends: C, OpenMP, OpenCL, CUDA, StarPU, (MPI) Hybrid CPU-GPU execution (with StarPU backend) Multi-GPU support Low overhead Auto-tunable [Dastgeer et al. IWMSE 11, MULTIPROG 12, APPT 13; PhD 14] Open-source 26" "
Summary" Domain-specific languages High level of abstraction Automatic code generation Model-based development of Cyber-Physical Systems OpenModelica open-source environment Skeleton programming Parallelism, heterogeneity, communication managed internally Performance, portability and automatic optimizations for free! 27" "