Download presentation
Presentation is loading. Please wait.
Published byEaster Wheeler Modified over 9 years ago
1
March 27, 2007HPC 07 - Norfolk, VA1 C++ Reflection for High Performance Problem Solving Environments Tharaka Devadithya 1, Kenneth Chiu 2, Wei Lu 1 1. Computer Science Department, Indiana University 2. Department of Computer Science, State University of New York, Binghamton
2
Outline Reflection Overview Problem Solving Environments (PSEs) Motivation and Goals C++ Reflection Library Performance Applications Related Work March 27, 2007HPC 07 - Norfolk, VA2
3
March 27, 2007HPC 07 - Norfolk, VA3 Reflection Involves accessing type information Two main types Compile-time reflection E.g., Boost type traits Run-time reflection Some languages support reflection as part of their standard specifications E.g., Java, C#, Python C++ supports Run-Time Type Information (RTTI) Very limited features
4
March 27, 2007HPC 07 - Norfolk, VA4 Implementing Run-time Reflection Include additional metadata to compiled code. Compilers of languages that support reflection generates this metadata and inserts into the binary. Since C++ compiler does not generate this metadata, it must be generated as a separate step.
5
March 27, 2007HPC 07 - Norfolk, VA5 Problem Solving Environments (PSEs) Provides all the computational facilities necessary to solve a target class of problems. A scientist or engineer should be able to dynamically couple tasks or computations, such that the composite will lead to solving some problem. Examples Symbolic manipulation for basic mathematical expressions Visualization packages for 2-, 3-, and 4-D phenomena Geometric modelers for a broad class of shapes
6
March 27, 2007HPC 07 - Norfolk, VA6 How Reflection Aids PSE Need to dynamically couple tasks or computations. It should be possible for the back-end to dynamically invoke functionalities become known only during run-time. Reflection provides a powerful and flexible method invocation ability. E.g., request the application to dynamically load a library and invoke an arbitrary method in it.
7
March 27, 2007HPC 07 - Norfolk, VA7 Need for Reflection in C++ Reflection is not supported by modern languages used in High Performance Computing (HPC). Attempts to incorporate reflection capabilities to C++ are either intrusive, or not fully compliant with the C++ standard specification PSE developers for HPC domains have to depend on another language (e.g., Java) to “wrap” each component with a reflection enabled interface. Multiple language skill required Overhead in transferring data
8
March 27, 2007HPC 07 - Norfolk, VA8 Benefits of Reflection Develop generic algorithms. E.g., classType = ClassType::getClass(“Service1”); obj = classType.createInstance(); obj.invoke(“method1”); Capabilities resulting from this generality. Object serialization Results in a generic object persistence framework Interface to a Scripting Environment E.g., provide a Python interface to HPC code without needing language bindings for each invocation. Object Instantiation More flexible approach than using the Factory pattern.
9
March 27, 2007HPC 07 - Norfolk, VA9 Goals Run-time access to members. Invoke member functions Read from / write to data members Standard compliant. Increases portability Relatively efficient. Minimize overhead of indirect invocations Non-intrusive. Can be used with existing code Avoid programmer errors
10
March 27, 2007HPC 07 - Norfolk, VA10 C++ Reflection Library Consists of a small set of core classes, and another set of generated classes to store and present the type-specific, metadata information. generated by parsing the user-supplied target classes. Employs 2 main types of classes Meta classes Member classes
11
Code Generation Meta-data generated using source files (header files defining classes).
12
March 27, 2007HPC 07 - Norfolk, VA12 Meta classes Maintains information about user defined classes. Name and type List of data members and member functions Inheritance information Interface to instantiate a class. Example ClassType *ct = ClassType::getClass("ClassA"); string className = ct->name(); classAObj = ct->createInstance();
13
March 27, 2007HPC 07 - Norfolk, VA13 Member classes Encapsulate the members of a class. Provide means of indirectly accessing them, given their names at run-time. 2 Types Data members DataMember dm = ct->getDataMember("f1"); dm.ref (&classAObj) = 1234; Member functions MemberFunction mf = ct->getMemberFunction("m1"); mf.invoke (&classAObj);
14
March 27, 2007HPC 07 - Norfolk, VA14 Sample Usage XMLDocument dom; dom.parse(...); classType = ClassType::getClass("Service"); obj = classType.createInstance(); operationName = dom.getRoot()->getName(); memberFunction = classType.getMemberFunction(operationName); Arguments args; extractArgs(memberFunction, dom.getRoot(), args); memberFunction.genericInvoke (*obj, args);
15
Performance Invocation time Reflection overhead with 100 invocations with 100,000 invocations Reflection Vs. generated code March 27, 2007HPC 07 - Norfolk, VA15
16
Invocation Times March 27, 2007HPC 07 - Norfolk, VA16
17
Reflection Overhead (100 invocations) March 27, 2007HPC 07 - Norfolk, VA17
18
Reflection Overhead (100,000 invocations) March 27, 2007HPC 07 - Norfolk, VA18
19
Reflection Vs. Generated Code March 27, 2007HPC 07 - Norfolk, VA19
20
Applications Remote method invocation Requires ability to invoke a method, given the class and method names along with the arguments at runtime. Solving Large Sparse Linear Systems of Equations Need to try out different strategies. A PSE could help the algebraist by providing a set of components out of which he or she can choose the ones that provide the functionalities required by the current strategy. Unit testing framework Prefix each test member function name with some predefined word, (E.g., “testXXXX()”) March 27, 2007HPC 07 - Norfolk, VA20
21
Related Work Some other approaches to reflection in C++ SEAL Reflex Meta Object Protocol (MOP) CppReflect All the above approaches are either, intrusive, or not fully compliant with the C++ standard specification March 27, 2007HPC 07 - Norfolk, VA21
22
Questions March 27, 2007HPC 07 - Norfolk, VA22
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.