Presentation is loading. Please wait.

Presentation is loading. Please wait.

Firstname Lastname CERN PH-SFT CH-1211 Geneva 23 sftweb.cern.ch root.cern.ch Cling – Past, Present and Future V. Vassilev, P. Canal, A. Naumann, P. Russo.

Similar presentations


Presentation on theme: "Firstname Lastname CERN PH-SFT CH-1211 Geneva 23 sftweb.cern.ch root.cern.ch Cling – Past, Present and Future V. Vassilev, P. Canal, A. Naumann, P. Russo."— Presentation transcript:

1 Firstname Lastname CERN PH-SFT CH-1211 Geneva 23 sftweb.cern.ch root.cern.ch Cling – Past, Present and Future V. Vassilev, P. Canal, A. Naumann, P. Russo CERN, PH-SFT & FermiLab

2 sftweb.cern.ch root.cern.ch vvassilev/ROOT Users Workshop 11-14 March 2013 Role of C++ Interpreter in ROOT o Load/Store C++ objects o Runtime Dynamism TFile::Open(“http://...”) gDirectory->Get(“hist”) python runReco.py o Fast Prototyping 2 Limited C++ language support for reflection and type introspection. ROOT CINT Reflection TPluginManager IO... PyROOT Type Info TClass

3 sftweb.cern.ch root.cern.ch vvassilev/ROOT Users Workshop 11-14 March 2013 LLVM Toolchain As an Alternative o LLVM Core “The LLVM Project is a collection of modular and reusable compiler and toolchain technologies...” More than 120 active contributors Apple, ARM, Google, Qualcomm, QuIC, NVidia, AMD and more ~250 commits/week o Clang “The goal of the Clang project is to create a new C, C++, Objective C and Objective C++ front-end for the LLVM compiler.“ More than 100 active contributors Apple, ARM, AMD and more ~150 commits/week 3

4 sftweb.cern.ch root.cern.ch vvassilev/ROOT Users Workshop 11-14 March 2013 In The Meanwhile: LLVM 4 LLVM and Clang “The LLVM Project is a collection of modular and reusable compiler and toolchain technologies...”

5 sftweb.cern.ch root.cern.ch vvassilev/ROOT Users Workshop 11-14 March 2013 Cling's Dual Personality o An interpreter – looks like an interpreter and behaves like an interpreter Cling follows the read-evaluate-print-loop (repl) concept. o More than interpreter – built on top of compiler libraries (Clang and LLVM) Contains interpreter parts and compiler parts. More of an interactive compiler or an interactive compiler interface for clang. 5 No need to compile Cling/ROOT with Clang/LLVM or having clang installed on the OS

6 sftweb.cern.ch root.cern.ch vvassilev/ROOT Users Workshop 11-14 March 2013 Cling Is Better Than CINT o Full C++ support incl. C++11 o Stable and informative intermediate representations of the source o Being developed with the vision to be used in multithreaded environment (an interpreter object per thread) 6

7 sftweb.cern.ch root.cern.ch vvassilev/ROOT Users Workshop 11-14 March 2013 Full C++ Support o Templates and STL are not an issue 7

8 sftweb.cern.ch root.cern.ch vvassilev/ROOT Users Workshop 11-14 March 2013 Full C++ Support o Natural path to the new standards C++11/C++* 8 $ cling –std=c++11

9 sftweb.cern.ch root.cern.ch vvassilev/ROOT Users Workshop 11-14 March 2013 Full C++ Support o Natural path to the new standards C++11/C++* 9 $ cling –std=c++11

10 sftweb.cern.ch root.cern.ch vvassilev/ROOT Users Workshop 11-14 March 2013 Full C++ Support o Boost is not a dream 10 Inline ASM an issue with the current JIT

11

12 sftweb.cern.ch root.cern.ch vvassilev/ROOT Users Workshop 11-14 March 2013 Diagnostics o Column numbers and caret diagnostics CaretDiagnostics.C:4:13: warning: '.*' specified field precision is missing a matching 'int' argument printf("%.*d"); ~~^~ o Range highlighting RangeHighlight.C:14:39: error: invalid operands to binary expression ('int' and 'A') return y + func(y ? ((SomeA.X + 40) + SomeA) / 42 + SomeA.X : SomeA.X); ~~~~~~~~~~~~ ^ ~~~~~~ 12

13 sftweb.cern.ch root.cern.ch vvassilev/ROOT Users Workshop 11-14 March 2013 Diagnostics 13 o Pointer vs References input_line_410:2:6: error: member reference type 'TNamed' is not a pointer nRef->GetName(); ~~~~^ input_line_413:2:7: error: member reference type 'TNamed *' is a pointer; maybe you meant to use '->’? nPtr1.GetName(); ~~~~^ -> o Fix-it hints FixItHints.C:7:27: warning: use of GNU old-style field designator extension struct point origin = { x: 0.0, y: 0.0 }; ^~.x = FixItHints.C:12:3: error: use of undeclared identifier 'floot'; did you mean 'float’? floot p; ^~~~ float

14 sftweb.cern.ch root.cern.ch vvassilev/ROOT Users Workshop 11-14 March 2013 Diagnostics o Ambiguities Ambiguities.C:20:30: error: return type of virtual function 'Clone' is not covariant with the return type of the function it overrides (ambiguous conversion from derived class 'TeachingAssistant' to base class 'Person': class TeachingAssistant -> class Student -> class Person class TeachingAssistant -> class Teacher -> class Person) virtual TeachingAssistant* Clone() const; ^ Ambiguities.C:7:19: note: overridden virtual function is here virtual Person* Clone() const; ^ o Templates input_line_401:2:2:error: use of class template LorentzVector requires template arguments LorentzVector v; ^ Math/GenVector/LorentzVectorfwd.h:28:39: note: template is declared here template class LorentzVector; ~~~~~~~~~~~~~~~~~~~~~~~~ ^ 14 Person virtual void Clone() Person virtual void Clone() TeachingAssistant virtual void Clone() TeachingAssistant virtual void Clone() Student Teacher

15 sftweb.cern.ch root.cern.ch vvassilev/ROOT Users Workshop 11-14 March 2013 Diagnostics 15 o Macro expansions MacroExpansionInformation.C:14:7: error: invalid operands to binary expression ('int' and 'A’) X = MAX(X, *SomeA); ^~~~~~~~~~~~~~ MacroExpansionInformation.C:5:24: note: expanded from macro 'MAX’ #define MAX(A, B) ((A) > (B) ? (A) : (B)) ~~~ ^ ~~~ o Template instantiations input_line_395:2:18: error: no matching constructor for initialization of 'PtEtaPhiEVector' (aka 'LorentzVector >’) PtEtaPhiEVector v2( "v1.Rho()", v1.Eta(), v1.Phi(), v1.E() ); ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Math/GenVector/LorentzVector.h:77:8: note: candidate constructor not viable: no known conversion from 'const char [9]' to 'const Scalar’ (aka 'const double') for 1st argument LorentzVector(const Scalar & a, ^ Math/GenVector/LorentzVector.h:88:17: note: candidate constructor template not viable: requires single argument 'v', but 4 arguments were provided explicit LorentzVector(const LorentzVector & v ) : ^

16 sftweb.cern.ch root.cern.ch vvassilev/ROOT Users Workshop 11-14 March 2013 16

17 sftweb.cern.ch root.cern.ch vvassilev/ROOT Users Workshop 11-14 March 2013 Data Flow 17 Machine Code (x86, Alpha,...) ① ⑦ Compilation Engine (clang) Transformation Engine ⑤②③④⑥ Cling ⑧ ①, ② – Text ③, ④, ⑤, ⑥ – Abstract Syntax Tree ⑦ - LLVM Bit Code ⑧ - Target Machine Code LLVM Execution Engine LLVM Execution Engine

18 sftweb.cern.ch root.cern.ch vvassilev/ROOT Users Workshop 11-14 March 2013 Compilation Engine 18 Well-defined, descriptive intermediate source representations Clang Parser Clang Code Generator LLVM Execution Engine LLVM Execution Engine Transformation Engine Cling

19 sftweb.cern.ch root.cern.ch vvassilev/ROOT Users Workshop 11-14 March 2013 Transformation Engine o Transaction Cling represents the incremental input as a set of AST nodes. o Transaction Transformers Cling enables each transaction to be further customized by other clients by implementing a transaction transformer. o Interpreter Callbacks Implements callbacks for the “interesting” events. 19 Cling Transformation Engine Transaction

20 sftweb.cern.ch root.cern.ch vvassilev/ROOT Users Workshop 11-14 March 2013 20 LLVM EE-s have complete target info Thus calling into compiled libraries is not an issue. No boundary interpreted/compiled world Possible to derive from compiled classes, proper calculation of offsets and so on. Machine Code (x86, Alpha,...) Compiled libs(.so) LLI LLVM JIT LLVM JIT MCJIT Execution Engine

21 sftweb.cern.ch root.cern.ch vvassilev/ROOT Users Workshop 11-14 March 2013 Challenges o Incompatible concepts like compilation and interpretation Many tasks that are trivial for an interpreter become a nightmare for a compiler. o Make C++ usable at the prompt Incorporate the experience we have with CINT. First step: adopt the successful usability extensions from CINT. 21

22 sftweb.cern.ch root.cern.ch vvassilev/ROOT Users Workshop 11-14 March 2013 Extending C++ Language 22 [root]$ sin(12); void wrapper() { sin(12); } [root]$ int i = 12; sin(i); void wrapper1() { int i = 12; } void wrapper2() { sin(i); } ? We want to be able to run statements

23 sftweb.cern.ch root.cern.ch vvassilev/ROOT Users Workshop 11-14 March 2013 Extending C++ Language 23 [root]$ void wrapper1() { int i = 12; printf("%d\n",i); } void wrapper2() { printf("%f\n", sin(i)); } int i = 12; int i = 12; printf("%d\n",i); printf("%f\n",sin(i)); o Wrap the input o Look for declarations o Extract the declarations one level up, as global declarations

24 sftweb.cern.ch root.cern.ch vvassilev/ROOT Users Workshop 11-14 March 2013 Streaming Execution Results 24 [root]$ int i = 12 (int) 12 sin(i) (double) -5.365729e-01 No semicolon (;) [root]$ std::string s = “Hello” (std::string) @0x7fff65ae783c c_str: “Hello” enum e { e1 = 12, e2 = 13, e3 = 13}; e1 (enum e) (e::e1) : (int) 12 Precise type information [root]$HelloWorld (void (void)) Function @0x108880030 at /tmp/HelloWorld.h:2: void HelloWorld() { printf("HelloWorld!\n"); } Precise location information

25 sftweb.cern.ch root.cern.ch vvassilev/ROOT Users Workshop 11-14 March 2013 Error Recovery o Filled input-by-input (aka Transaction) o Incorrect inputs must be discarded as a whole 25

26 sftweb.cern.ch root.cern.ch vvassilev/ROOT Users Workshop 11-14 March 2013 Implicit auto keyword 26 i = 5; f = new TNamed(“a”, ”b”) We meant int i = 5; or in C++11 auto i = 5; We meant int i = 5; or in C++11 auto i = 5; Cling will mark the AST Node as an implicit auto candidate and later on a custom AST pass will do the work. TNamed * f = … or in C++11 auto f = …

27 sftweb.cern.ch root.cern.ch vvassilev/ROOT Users Workshop 11-14 March 2013 Late Binding 27 if (cond) { TFile* F = 0; if (is_day_of_month_even()) F = TFile::Open("even.root"); else F = TFile::Open("odd.root"); hist->Draw(); }  Defined in the root file  Defined in the root file  The root file is gone. Issue an error.  The root file is gone. Issue an error.  Opens a dynamic scope. It tells the compiler that cling will take over the resolution of possible unknown identifiers

28 sftweb.cern.ch root.cern.ch vvassilev/ROOT Users Workshop 11-14 March 2013 Late Binding 28 o Tell the compiler the identifier will be resolved at runtime o Wrap it into valid C++ code o Partially recompile at runtime o Tell the compiler the identifier will be resolved at runtime o Wrap it into valid C++ code o Partially recompile at runtime Automatically transformed into valid C++ code on AST level if (cond) { TFile* F = 0; if (is_day_of_month_even()) F = TFile::Open("even.root"); else F = TFile::Open("odd.root"); gCling->EvaluateT ("hist->Draw()",...); } hist->Draw();

29 sftweb.cern.ch root.cern.ch vvassilev/ROOT Users Workshop 11-14 March 2013 Code Unloading 29 [root]$.L Calculator.h Calculator calc; calc.Add(3, 1) (int) 2 //WTF!?*.L Calculator.h Calculator calc; calc.Add(3, 1) (int) 4 // // Calculator.h class Calculator { int Add(int a, int b) { return a + b; }... }; // Calculator.h class Calculator { int Add(int a, int b) { return a - b; }... }; * What's That Function

30 sftweb.cern.ch root.cern.ch vvassilev/ROOT Users Workshop 11-14 March 2013 Future Plans o Migrate to MCJIT Object file emitted to memory Runtime dynamic linker o Windows 64 Support o Tools Automatic Differentiation 30

31 sftweb.cern.ch root.cern.ch vvassilev/ROOT Users Workshop 11-14 March 2013 o See Tomas Gahr’s demo later at the workshop Thank you! 31

32 sftweb.cern.ch root.cern.ch vvassilev/ROOT Users Workshop 11-14 March 2013 Backup slides 32

33 sftweb.cern.ch root.cern.ch vvassilev/ROOT Users Workshop 11-14 March 2013 Pre-Compiled Headers/Modules Carefully crafted data structures designed to improve translator's performance: o Reduce lexical, syntax and semantic analysis o Loaded “lazily” on demand 33

34 sftweb.cern.ch root.cern.ch vvassilev/ROOT Users Workshop 11-14 March 2013 Pre-Compiled Headers/Modules Design advantages: o Loading is significantly faster than re-parsing o Minimize the cost of reading o Read times don't depend on size o Cost of generating isn't large 34

35 sftweb.cern.ch root.cern.ch vvassilev/ROOT Users Workshop 11-14 March 2013 35 PCH PCM And thus PCM much more flexible

36 sftweb.cern.ch root.cern.ch vvassilev/ROOT Users Workshop 11-14 March 2013 PCH vs PCM o Where we should get it from? Who knows more about types than the translator? 36 CINT Reflection Type Info Not very descriptive GCCXML Reflex


Download ppt "Firstname Lastname CERN PH-SFT CH-1211 Geneva 23 sftweb.cern.ch root.cern.ch Cling – Past, Present and Future V. Vassilev, P. Canal, A. Naumann, P. Russo."

Similar presentations


Ads by Google