Presentation is loading. Please wait.

Presentation is loading. Please wait.

Advanced BioPSE NCRR Dynamic Compilation Joint Session #1: Advanced BioPSE/SCIRun.

Similar presentations


Presentation on theme: "Advanced BioPSE NCRR Dynamic Compilation Joint Session #1: Advanced BioPSE/SCIRun."— Presentation transcript:

1 Advanced BioPSE NCRR Dynamic Compilation Joint Session #1: Advanced BioPSE/SCIRun

2 Advanced BioPSE NCRR C++ Background Inheritance Virtual methods Overloaded behavior gen_fld_ptr->interp(Point *p); Each field inherits from base and overloads their own interp appropriate to the field Templates Compile time 'virtual' Interp (Point *p); Compiler provides replacement for FLD with exact field type at compile time

3 Advanced BioPSE NCRR Field Design Field Design Library Must have uniform interface to Fields Algorithms can be general Coders can expect uniform interface Evaluate the following: Inheritance and virtual methods Template classes implementing field concept

4 Advanced BioPSE NCRR Templates vs. Virtual Test identical functions configured within a virtual method against a templated configuration. Execution times in seconds

5 Advanced BioPSE NCRR SCIRun Fields Fields and Meshes are Templated Datatypes that adhere to their concepts TetVolField LatVolField Many more... Modules implement algorithms Multiple Inputs and outputs Essentially algorithms parameterized on their inputs and outputs

6 Advanced BioPSE NCRR Template Drawbacks Template code tends to propogate All permutations must be known at compile time Not runtime extensible SCIRun modules must discover the type Ports pass all fields as base class type Massive amounts of type identification code Code maintenance nightmare

7 Advanced BioPSE NCRR Type Discovery Algo dispatch1(FieldHandle field1, callback) { string disp_name = field1->get_type_name(0); if (disp_name == "TetVol") { // test all supported sub types if (field1->get_type_name(1) == "double") { TetVol *f1 = 0; f1 = dynamic_cast *>(field1); if (f1) { return new ModuleAlgorithm >; } } else if { // The same for the rest of the TetVol types. TetVol } } else if (disp_name == "LatticeVol") { // test all supported sub types } else if (disp_name == "ContourField") { // test all supported sub types } else if (disp_name == "TriSurf") { // test all supported sub types } else { cerr << "Error: Field type not supported" << endl; } } TetVol

8 Advanced BioPSE NCRR Combinations Field Types (4) TetVolField LatVolField TriSurfField CountourField Data Types (9) double int Char float etc... An Algorithm Parameterized on One Field Type Requires 36 Field instantiations And 36 Algorithm Instantiations

9 Advanced BioPSE NCRR Combinations Parameterized On Two Fields 36 2 = 1296 Versions of the Algorithm Parameterized On Three Fields 36 3 = 46656 Versions of the Algorithm SCIRun supports more Field and Data types Very few of these combinations are needed by any one SCIRun application

10 Advanced BioPSE NCRR Solution We only compile the exact types we need Extend C++ RTTI to determine types using strings Generate C++ code to instantiate correct templates Fork a process to compile the code Dynamically link the resulting shared library Call into the lib to get an instance of the algorithm Call a single virtual function in the algorithm, passing in fields and other required parameters Execute the intended function, which uses dynamic_cast to get the known underlying field type

11 Advanced BioPSE NCRR Calling the Algorithm Void ShowField::execute() { // Get a Field from input field port. field = (FieldIPort *)get_iport("Field"); field->get(field_handle); // Get the input field's type info. const TypeDescription *td = field_handle->get_type_description(); // Get the Algorithm. CompileInfo *ci = RenderFieldBase::get_compile_info(td); if (! DynamicLoader::scirun_loader().get(*ci, rend_algo)) { error("Could not compile algorithm for ShowField -"); return; } RenderFieldBase *rf = dynamic_cast (rend_algo); // Let the templated algorithm render this field. rf->render(field_handle, /* any other parameters from gui */); // Send results downstream... } No Template Instantiations for the exact algorithm type!

12 Advanced BioPSE NCRR Summary Customize Compilation Only the algorithms and types you use are compiled They are persistent (only create once) Flexibility/Extensibility Your Fields in your Package compile with existing algorithms. Reduce Code Bloat Won't swamp your compiler Smaller libraries Shorter installation compiles


Download ppt "Advanced BioPSE NCRR Dynamic Compilation Joint Session #1: Advanced BioPSE/SCIRun."

Similar presentations


Ads by Google