22
March 27, 2007 HPC 07 - Norfolk, VA 1 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

C++ Reflection for High Performance Problem Solving Environments

  • Upload
    admon

  • View
    47

  • Download
    1

Embed Size (px)

DESCRIPTION

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 - PowerPoint PPT Presentation

Citation preview

Page 1: C++ Reflection for High Performance Problem Solving Environments

March 27, 2007 HPC 07 - Norfolk, VA 1

C++ Reflection for High Performance Problem Solving Environments

Tharaka Devadithya1, Kenneth Chiu2, Wei Lu1

1. Computer Science Department, Indiana University2. Department of Computer Science, State University of New York,

Binghamton

Page 2: C++ Reflection for High Performance Problem Solving Environments

Outline

Reflection Overview Problem Solving Environments (PSEs) Motivation and Goals C++ Reflection Library Performance Applications Related Work

March 27, 2007 HPC 07 - Norfolk, VA 2

Page 3: C++ Reflection for High Performance Problem Solving Environments

March 27, 2007 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

Page 4: C++ Reflection for High Performance Problem Solving Environments

March 27, 2007 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.

Page 5: C++ Reflection for High Performance Problem Solving Environments

March 27, 2007 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

Page 6: C++ Reflection for High Performance Problem Solving Environments

March 27, 2007 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.

Page 7: C++ Reflection for High Performance Problem Solving Environments

March 27, 2007 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

Page 8: C++ Reflection for High Performance Problem Solving Environments

March 27, 2007 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.

Page 9: C++ Reflection for High Performance Problem Solving Environments

March 27, 2007 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

Page 10: C++ Reflection for High Performance Problem Solving Environments

March 27, 2007 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

Page 11: C++ Reflection for High Performance Problem Solving Environments

Code Generation

Meta-data generated using source files (header files defining classes).

Page 12: C++ Reflection for High Performance Problem Solving Environments

March 27, 2007 HPC 07 - Norfolk, VA 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();

Page 13: C++ Reflection for High Performance Problem Solving Environments

March 27, 2007 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 membersDataMember dm = ct->getDataMember("f1");

dm.ref<int>(&classAObj) = 1234; Member functions

MemberFunction mf = ct->getMemberFunction("m1");

mf.invoke<int>(&classAObj);

Page 14: C++ Reflection for High Performance Problem Solving Environments

March 27, 2007 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);

Page 15: C++ Reflection for High Performance Problem Solving Environments

Performance

Invocation time Reflection overhead

with 100 invocations with 100,000 invocations

Reflection Vs. generated code

March 27, 2007 HPC 07 - Norfolk, VA 15

Page 16: C++ Reflection for High Performance Problem Solving Environments

Invocation Times

March 27, 2007 HPC 07 - Norfolk, VA 16

Page 17: C++ Reflection for High Performance Problem Solving Environments

Reflection Overhead (100 invocations)

March 27, 2007 HPC 07 - Norfolk, VA 17

Page 18: C++ Reflection for High Performance Problem Solving Environments

Reflection Overhead (100,000 invocations)

March 27, 2007 HPC 07 - Norfolk, VA 18

Page 19: C++ Reflection for High Performance Problem Solving Environments

Reflection Vs. Generated Code

March 27, 2007 HPC 07 - Norfolk, VA 19

Page 20: C++ Reflection for High Performance Problem Solving Environments

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

Page 21: C++ Reflection for High Performance Problem Solving Environments

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

Page 22: C++ Reflection for High Performance Problem Solving Environments

Questions

March 27, 2007 HPC 07 - Norfolk, VA 22