1 / 22

C++ Reflection for High Performance Problem Solving Environments

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. Outline. Reflection Overview

admon
Download Presentation

C++ Reflection for High Performance Problem Solving Environments

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. C++ Reflection for High Performance Problem Solving Environments Tharaka Devadithya1, Kenneth Chiu2, Wei Lu1 1. Computer Science Department, Indiana University 2. Department of Computer Science, State University of New York, Binghamton HPC 07 - Norfolk, VA

  2. Outline Reflection Overview Problem Solving Environments (PSEs) Motivation and Goals C++ Reflection Library Performance Applications Related Work HPC 07 - Norfolk, VA

  3. 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 HPC 07 - Norfolk, VA

  4. 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. HPC 07 - Norfolk, VA

  5. 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 HPC 07 - Norfolk, VA

  6. 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. HPC 07 - Norfolk, VA

  7. 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 HPC 07 - Norfolk, VA

  8. 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. HPC 07 - Norfolk, VA

  9. 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 HPC 07 - Norfolk, VA

  10. 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 HPC 07 - Norfolk, VA

  11. Code Generation • Meta-data generated using source files (header files defining classes).

  12. 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(); HPC 07 - Norfolk, VA

  13. 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<int>(&classAObj) = 1234; Member functions MemberFunction mf = ct->getMemberFunction("m1"); mf.invoke<int>(&classAObj); HPC 07 - Norfolk, VA

  14. 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<void>(*obj, args); HPC 07 - Norfolk, VA

  15. Performance • Invocation time • Reflection overhead • with 100 invocations • with 100,000 invocations • Reflection Vs. generated code HPC 07 - Norfolk, VA

  16. Invocation Times HPC 07 - Norfolk, VA

  17. Reflection Overhead (100 invocations) HPC 07 - Norfolk, VA

  18. Reflection Overhead (100,000 invocations) HPC 07 - Norfolk, VA

  19. Reflection Vs. Generated Code HPC 07 - Norfolk, VA

  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()”) HPC 07 - Norfolk, VA

  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 HPC 07 - Norfolk, VA

  22. Questions HPC 07 - Norfolk, VA

More Related