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
MODELICA SySML
Simula6on Visualiza6on Valida6on
Parallel programming and mul6core processing
SkePU skeleton programming Sequen6al interface
Heterogeneous systems Pla[orm agnos6c High-‐level constructs
Use
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 [email protected]
Modelica – A Cyber-Physical Modeling Language for Systems Engineering and the OpenModelica
Environment
6
What is Modelica?
• Robotics • Control • Automotive • Aircraft • Satellites • Power plants • Systems biology
A language for modeling of complex cyber-physical systems
7
What is Special about Modelica?
Multi-Domain Modeling
Cyber-Physical Modeling
Physical
Cyber
3 domains - electric - mechanics - control
8
inertialxy
axis1
axis2
axis3
axis4
axis5
axis6r3Drive1
1r3Motor
r3ControlqdRef1
S
qRef1
S
k2
i
k1
i
qddRef cut joint
q: angleqd: angular velocity
qdd: angular acceleration
qd
tn
Jmotor=J
gear=i
spring=c
fric=Rv0
Srel
joint=0
S
Vs
-
+diff
-
+pow er
emf
La=(250/(2*D*wm))
Ra=250
Rd2=100
C=0.004*D/w m
-
+OpI
Rd1=100
Ri=10
Rp1=200
Rp2=
50
Rd4=100
hall2
Rd3=
100
g1
g2
g3
hall1
g4
g5
rw
cut in
iRef
qd q
rate2
b(s)
a(s)
rate3
340.8
S
rate1
b(s)
a(s)
tacho1
PT1
Kd
0.03
wSum
-
sum
+1
+1
pSum
-
Kv
0.3
tacho2
b(s)
a(s)
q qd
iRefqRef
qdRef
Courtesy of Martin Otter
What is Special about Modelica?
Visual Acausal Hierarchical Component
Modeling
Multi-Domain Modeling
Hierarchical system modeling
Srel = n*transpose(n)+(identity(3)- n*transpose(n))*cos(q)- skew(n)*sin(q); wrela = n*qd; zrela = n*qdd; Sb = Sa*transpose(Srel); r0b = r0a; vb = Srel*va; wb = Srel*(wa + wrela); ab = Srel*aa; zb = Srel*(za + zrela + cross(wa, wrela));
9
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 connect(DC.p,R.n); connect(R.p,L.n); connect(L.p, EM.n); connect(EM.p, DC.n); connect(DC.n,G.p); connect(EM.flange,load.flange); end DCMotor
load
EM DC
G
R L
10
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
11
Modelica Standard Library Open Source, Developed by Modelica Association
• 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
The Modelica Standard Library contains components from various application areas, including the following sublibraries:
12
• 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
12
• OMEdit graphic Editor • OMDebugger for equations • OMOptim optimization tool • OM Dynamic optimizer collocation • ModelicaML UML Profile • MetaModelica extension • ParModelica extension
The OpenModelica Open Source Environment www.openmodelica.org
13
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
Open-source community services • Website and Support Forum • Version-controlled source base • Bug database • Development courses • www.openmodelica.org
Code Statistics • 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
University members
OSMC – International Consortium for Open Source Model-based Development Tools, 46 members Mar 2014
Founded Dec 4, 2007 • 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
14
OpenModelica MDT Eclipse Plug-in with OpenModelica Algorithmic Code Debugger
15
General Tool Interoperability & Model Exchange Functional Mock-up Interface (FMI)
• 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
The FMI development a result of the MODELISAR 29-partner project
Engine with ECU
Gearbox with ECU
Thermal systems
Automated cargo door
Chassis components, roadway, ECU (e.g. ESP)
etc.
functional mockup interface for model exchange and tool coupling courtesy Daimler
16
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
17
ParModelica – Modelica Parallel Algorithmic Programming Execution on GPUs and CPUs via portable OPENCL code generation
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
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
0.0625 0.125
0.25 0.5
1 2 4 8
16 32 64
128 256 512
Sim
ulat
ion
Tim
e (s
econ
d)
4.36 13.41 24.76 26.34 0.61 4.61
35.95
114.67
64 128 256 512 Parameter M (Matrix sizes MxM)
Speedup CPU E5520 GPU M2050
Matrix Multiplication application
18
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
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.High-Level Programmingfor 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
20" "
The Computer Engineer’s Solution Today: Heterogeneous Multicore"
Programmable Hardware Accelerator
"
Offload certain
computation#
Data transfer#
###
Device#memory#
Core#
Core#
Core#
Core#
Main Memory#
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"
21" "
The Application Programmer’s Nightmare: Heterogeneous Multicore"
Programmable Hardware Accelerator
"
Offload certain
computation#
Data transfer#
###
Device#memory#
Core#
Core#
Core#
Core#
Main Memory#
L Distributed Memory or Non-coherent Shared Memory#L Different Programming Models#L Low Abstraction Level#L Require Architecture- specific Optimization#
General-purpose" CPU"
22" "
Common: GPU-Based Systems"
CPU"
GPU "
Offload heavy
computation#
Data transfer#
###
Device#memory#
Core#
Core#
Core#
Core#
Main Memory#
L Distributed Memory#L Different Programming Models#L Low Abstraction Level#L Require Architecture- specific Optimization#
23" "
Common: GPU-Based Systems"
CPU"
GPU "
Offload heavy
computation#
Data transfer#
###
Device#memory#
Core#
Core#
Core#
Core#
Main Memory#
###
Device#memory#
…#GPU "
L Distributed Memory#L Different Programming Models#L Low Abstraction Level#L Require Architecture- specific Optimization#
24" "
Programming of GPU-based Systems … with OpenCL™ (?)- Code portability J - Programmability L (low level) - Performance portability L (requires reoptimization)#
CPU"
GPU "
Offload heavy
computation#
Data transfer#
###
Device#memory#
Core#
Core#
Core#
Core#
Main Memory#
25" "
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, …)#
26" "
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#
27" "
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!#