ROOT 6 Vassilev Firstname Lastname CERN PHSFT CH1211

  • Slides: 39
Download presentation
ROOT 6 Vassilev Firstname Lastname CERN PH-SFT CH-1211 Geneva 23 root. cern. ch CERN,

ROOT 6 Vassilev Firstname Lastname CERN PH-SFT CH-1211 Geneva 23 root. cern. ch CERN, PH-SFT

ROOT Usage Scenarios Experiment X Software stack ROOT Standalone root. cern. ch vvassilev/ALICE Offline

ROOT Usage Scenarios Experiment X Software stack ROOT Standalone root. cern. ch vvassilev/ALICE Offline week 19 November 2014 2

C++ & ROOT TS: Technical Specification TR: Technical Report ROOT had to follow, offering

C++ & ROOT TS: Technical Specification TR: Technical Report ROOT had to follow, offering these features to the HEP community root. cern. ch vvassilev/ALICE Offline week 19 November 2014 3

Why Do You Want Better C++ std: : vector<My. Class*>: : const_iterator auto I

Why Do You Want Better C++ std: : vector<My. Class*>: : const_iterator auto I = vec. begin(); for(std: : vector<My. Class*>: : const_iterator I = vec. begin(), E = vec. end(); for(auto &I : vec) { // do things } The compiler will issue I != E; ++I) { error that ‘f. Renamed’ // do things } doesn’t override anything struct B { virtual void f(short) {} }; struct D : public B { virtual void f. Renamed(int)The override {} will }; issue compiler error that ‘f’ cannot be overridden. struct B { virtual void f(int) {} }; struct D : public B { virtual void f(int) override final {} }; struct F : public D { virtual void f(int) override {} }; root. cern. ch vvassilev/ALICE Offline week 19 November 2014 4

Why Do You Want Better C++ o Smart pointers Helps with defining ownerships. Improves

Why Do You Want Better C++ o Smart pointers Helps with defining ownerships. Improves readability/understandability of interfaces. o Move semantics Reduces copying objects. Improves performance. o Concurrency Threads. Mutual exclusions. Condition variables. Futures. o Many, many more. root. cern. ch vvassilev/ALICE Offline week 19 November 2014 5

ROOT’s Plan ROOT needed to catch up and offer the new C++ features keeping:

ROOT’s Plan ROOT needed to catch up and offer the new C++ features keeping: o Backward and forward compatibility o Performance ‘compatibility’ o Designing the new system having ‘concurrency’ in mind root. cern. ch vvassilev/ALICE Offline week 19 November 2014 6

How? Simple Things Didn’t Work… int f(int& arg[]) { return arg[1]; } void CINTfail()

How? Simple Things Didn’t Work… int f(int& arg[]) { return arg[1]; } void CINTfail() { int var = 13; { int var = 14; } printf("var should be 13 but is %dn", var); int arr[3] = { 12, 13, 14 }; printf("f(arr) should be an error (expected 13) but is %dn", f(arr)); } root [2]. x CINTfail. cxx var should be 13 but is 14 f(arr) should be an error (expected 13) but is 0 root. cern. ch vvassilev/ALICE Offline week 19 November 2014 7

ROOT ‘Architecture’ TPlugin. Manager TClass o Load/Store C++ objects o Runtime Dynamism C++ Types

ROOT ‘Architecture’ TPlugin. Manager TClass o Load/Store C++ objects o Runtime Dynamism C++ Types ROOT . . . Reflection Py. ROOT • TFile: : Open(“http: //. . . ”) • g. Directory->Get(“hist”) • python run. Reco. py CINT o Fast Prototyping IO Limited C++ language support for reflection and type introspection. root. cern. ch vvassilev/ALICE Offline week 19 November 2014 8

”Optimism is the essential ingredient for innovation. How else can the individual welcome change

”Optimism is the essential ingredient for innovation. How else can the individual welcome change over security, adventure over staying in safe places” R. Noyce, Intel Cofounder

In The Meanwhile: LLVM and Clang “The LLVM Project is a collection of modular

In The Meanwhile: LLVM and Clang “The LLVM Project is a collection of modular and reusable compiler and toolchain technologies. . . ” root. cern. ch vvassilev/ALICE Offline week 19 November 2014 10

ROOT’s New CINT = Cling o A new development at CERN Implemented to fit

ROOT’s New CINT = Cling o A new development at CERN Implemented to fit ROOT’s specific needs. 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. No need to compile ROOT with Clang or having clang installed on the OS root. cern. ch vvassilev/ALICE Offline week 19 November 2014 11

Full C++ Support o Templates and STL are not an issue root. cern. ch

Full C++ Support o Templates and STL are not an issue root. cern. ch vvassilev/ALICE Offline week 19 November 2014 12

Full C++ Support o Natural path to the new standards C++11/C++* root. cern. ch

Full C++ Support o Natural path to the new standards C++11/C++* root. cern. ch vvassilev/ALICE Offline week 19 November 2014 13

Full C++ Support o Natural path to the new standards C++11/C++*, just works. root.

Full C++ Support o Natural path to the new standards C++11/C++*, just works. root. cern. ch vvassilev/ALICE Offline week 19 November 2014 14

ROOT 6 Is Better Than ROOT 5 o Backward- and forward-compatible o Full C++

ROOT 6 Is Better Than ROOT 5 o Backward- and forward-compatible o Full C++ support incl. C++11, soon C++14. o Core is being developed/improved with the vision to be used in multithreaded environment root. cern. ch vvassilev/ALICE Offline week 19 November 2014 15

ROOT 6 Is More Maintainable Other ROOT – 1400 K SLOC* CINT+Reflex – 230

ROOT 6 Is More Maintainable Other ROOT – 1400 K SLOC* CINT+Reflex – 230 K SLOC* Cling – 16 K SLOC* externals: LLVM + Clang – 800 K SLOC* * No testsuites included. Credits: generated using David A. Wheeler's 'SLOCCount' root. cern. ch vvassilev/ALICE Offline week 19 November 2014 16

Diagnostics Matter! int f(int& arg[]) { return arg[1]; } int CINTfail() { int arr[3]

Diagnostics Matter! int f(int& arg[]) { return arg[1]; } int CINTfail() { int arr[3] = { 12, 13, 14 }; return f(arr); } // CINT Returns 0 instead of error. root. cern. ch vvassilev/ALICE Offline week 19 November 2014 18

Diagnostics in ROOT 6 o Column numbers and caret diagnostics Caret. Diagnostics. C: 4:

Diagnostics in ROOT 6 o Column numbers and caret diagnostics Caret. Diagnostics. C: 4: 13: warning: '. *' specified field precision is missing a matching 'int' argument printf("%. *d"); ~~^~ o Range highlighting Range. Highlight. C: 14: 39: error: invalid operands to binary expression ('int' and 'A') return y + func(y ? ((Some. A. X + 40) + Some. A) / 42 + Some. A. X : Some. A. X); ~~~~~~ ^ ~~~~~~ root. cern. ch vvassilev/ALICE Offline week 19 November 2014 19

Diagnostics in ROOT 6 o Pointer vs References input_line_410: 2: 6: error: member reference

Diagnostics in ROOT 6 o Pointer vs References input_line_410: 2: 6: error: member reference type 'TNamed' is not a pointer n. Ref->Get. Name(); ~~~~^ input_line_413: 2: 7: error: member reference type 'TNamed *' is a pointer; maybe you meant to use '->’? n. Ptr 1. Get. Name(); ~~~~^ -> o Fix-it hints Fix. It. Hints. C: 7: 27: warning: use of GNU old-style field designator extension struct point origin = { x: 0. 0, y: 0. 0 }; ^~. x = Fix. It. Hints. C: 12: 3: error: use of undeclared identifier 'floot'; did you mean 'float’? floot p; ^~~~ float root. cern. ch vvassilev/ALICE Offline week 19 November 2014 20

Diagnostics in ROOT 6 o Ambiguities. C: 20: 30: error: return type of virtual

Diagnostics in ROOT 6 o 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 'Teaching. Assistant' to base class 'Person': Person class Teaching. Assistant -> class Student -> class Person virtual void Clone() class Teaching. Assistant -> class Teacher -> class Person) virtual Teaching. Assistant* Clone() const; ^ Teacher Student Ambiguities. C: 7: 19: note: overridden virtual function is here virtual Person* Clone() const; ^ Teaching. Assistant virtual void Clone() o Templates input_line_401: 2: 2: error: use of class template Lorentz. Vector requires template arguments Lorentz. Vector v; ^ Math/Gen. Vector/Lorentz. Vectorfwd. h: 28: 39: note: template is declared here template<class Coord. System> class Lorentz. Vector; ~~~~~~~~~~~~ ^ root. cern. ch vvassilev/ALICE Offline week 19 November 2014 21

Diagnostics in ROOT 6 o Macro expansions Macro. Expansion. Information. C: 14: 7: error:

Diagnostics in ROOT 6 o Macro expansions Macro. Expansion. Information. C: 14: 7: error: invalid operands to binary expression ('int' and 'A’) X = MAX(X, *Some. A); ^~~~~~~~ Macro. Expansion. Information. 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 'Pt. Eta. Phi. EVector' (aka 'Lorentz. Vector<Pt. Eta. Phi. E 4 D<double> >’) Pt. Eta. Phi. EVector v 2( "v 1. Rho()", v 1. Eta(), v 1. Phi(), v 1. E() ); ^ ~~~~~~~~~~~~~~ Math/Gen. Vector/Lorentz. Vector. h: 77: 8: note: candidate constructor not viable: no known conversion from 'const char [9]' to 'const Scalar’ (aka 'const double') for 1 st argument Lorentz. Vector(const Scalar & a, ^ Math/Gen. Vector/Lorentz. Vector. h: 88: 17: note: candidate constructor template not viable: requires single argument 'v', but 4 arguments were provided explicit Lorentz. Vector(const Lorentz. Vector<Coords> & v ) : ^ root. cern. ch vvassilev/ALICE Offline week 19 November 2014 22

‘Data Flow’ in ROOT 6 Compilation Engine (clang) ②③④⑥ ① Cling ⑤ Transformation Engine

‘Data Flow’ in ROOT 6 Compilation Engine (clang) ②③④⑥ ① Cling ⑤ Transformation Engine ⑦ LLVM Execution Engine ⑧ Machine Code (x 86, Alpha, . . . ) root. cern. ch vvassilev/ALICE Offline week ①, ② –Text ③, ④, ⑤, ⑥ – Abstract Syntax Tree ⑦ - LLVM Bit Code ⑧ -Target Machine Code 19 November 2014 23

Compilation Engine Opens up the interpreter, allowing user extensions Clang Parser Clang Code Generator

Compilation Engine Opens up the interpreter, allowing user extensions Clang Parser Clang Code Generator Well-defined, descriptive intermediate source representations root. cern. ch vvassilev/ALICE Offline week Cling Transformation Engine LLVM Execution Engine 19 November 2014 24

Execution Engine LLVM EE-s have complete target info Thus calling into compiled libraries is

Execution Engine LLVM EE-s have complete target info Thus calling into compiled libraries is not an issue. LLI LLVM JIT No boundary interpreted/compiled world MCJIT Possible to derive from compiled classes, proper calculation of offsets and so on. �� Machine Code (x 86, Alpha, . . . ) root. cern. ch Compiled libs(. so) vvassilev/ALICE Offline week 19 November 2014 25

root. cern. ch vvassilev/ALICE Offline week 19 November 2014 26

root. cern. ch vvassilev/ALICE Offline week 19 November 2014 26

ROOT 6 Performance ”Premature optimization is the root of all evil” D. Knuth BUT

ROOT 6 Performance ”Premature optimization is the root of all evil” D. Knuth BUT o. ALICE were first to try it. Thanks for the work and feedback to Peter Hristov o. Experiments started adopting ROOT 6 and reported +1 GB more memory usage in comparison to ROOT 5 o. Execution speed slightly in favor of ROOT 6 root. cern. ch vvassilev/ALICE Offline week 19 November 2014 27

ROOT 6 Performance Footprint o Experiments started adopting ROOT 6 and reported +1 GB

ROOT 6 Performance Footprint o Experiments started adopting ROOT 6 and reported +1 GB more memory usage. We knew why. We were seeing much more reflection information, than was necessary in most cases. Also, we found out bugs and issues in the implementation in ROOT. o. For ~3 months we reduced the overhead by 900 MB to -1010 GB (i. e. 10 MB less than ROOT 5) depending on the workflows. We have a plan how to reduce it even further, C++ Modules. root. cern. ch vvassilev/ALICE Offline week 19 November 2014 28

ROOT 6 -Specific Developments o. New TTree reader o. New TFormula o. IO of

ROOT 6 -Specific Developments o. New TTree reader o. New TFormula o. IO of interpreted classes o. More to come Automatic differentiation. Runtime dictionary creation. root. cern. ch vvassilev/ALICE Offline week 19 November 2014 29

ROOT 6 -specific developments IO of interpreted classes root. cern. ch vvassilev/ALICE Offline week

ROOT 6 -specific developments IO of interpreted classes root. cern. ch vvassilev/ALICE Offline week 19 November 2014 30

ROOT 6 -specific developments ROOT’s new TTree reader root. cern. ch vvassilev/ALICE Offline week

ROOT 6 -specific developments ROOT’s new TTree reader root. cern. ch vvassilev/ALICE Offline week 19 November 2014 31

Why Using ROOT 6? o. Get latest and greatest C++ language and library features

Why Using ROOT 6? o. Get latest and greatest C++ language and library features easily o. Improve correctness o. No difference between compiled/interpreted worlds o. Backward and forward compatible o. Open up to new developments coming through ROOT o. Ensure your framework’s sustainability root. cern. ch vvassilev/ALICE Offline week 19 November 2014 32

Future Release Plans ov 6. 03/02 (end of January) ov 6. 03/04 (end of

Future Release Plans ov 6. 03/02 (end of January) ov 6. 03/04 (end of March) ov 6. 04/00 (end of May) Backporting new features to ROOT 5 not be feasible. root. cern. ch vvassilev/ALICE Offline week 19 November 2014 33

Thank you! root. cern. ch vvassilev/ALICE Offline week 19 November 2014 34

Thank you! root. cern. ch vvassilev/ALICE Offline week 19 November 2014 34

Backup slides root. cern. ch vvassilev/ALICE Offline week 19 November 2014 35

Backup slides root. cern. ch vvassilev/ALICE Offline week 19 November 2014 35

Future Plans o Migrate to MCJIT • Object file emitted to memory • Runtime

Future Plans o Migrate to MCJIT • Object file emitted to memory • Runtime dynamic linker o Windows 64 Support o Tools • Automatic Differentiation root. cern. ch vvassilev/ALICE Offline week 19 November 2014 36

Pre-Compiled Headers/Modules Carefully crafted data structures designed to improve translator's performance: o. Reduce lexical,

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 root. cern. ch vvassilev/ALICE Offline week 19 November 2014 37

Pre-Compiled Headers/Modules Design advantages: o Loading is significantly faster than re-parsing o Minimize the

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 root. cern. ch vvassilev/ALICE Offline week 19 November 2014 38

PCH PCM And thus PCM much more flexible root. cern. ch vvassilev/ALICE Offline week

PCH PCM And thus PCM much more flexible root. cern. ch vvassilev/ALICE Offline week 19 November 2014 39