## gpucv

[/] [experimental/] [trunk/] [gpucv/] [doc/] [GPUCVSwitch/] [tuto_use_switch.dox] - Rev 584

 /*! \page TUTO_USE_SWITCH Using the auto-switch mechanisms  * \section TUTO_USE_SWITCH__SCT_INTRO Intro  * \par "PRE-REQUIS"

• none
•
\sa  \author Yannick Allusse  \version GpuCV v1.0.0 rev 580  \note Turorial tag: TUTO_USE_SWITCH_TAG    *
In this tutorial, we will describe how to use the switch mechanism into an existing application.

Follow the key tag TUTO_USE_SWITCH_TAG* in full project source code to have the correspondance of each steps:

1. \ref TUTO_USE_SWITCH__STP1__PRESENTAION
2.
3. \ref TUTO_USE_SWITCH__STP2__INTEGRATION
4.
5. \ref TUTO_USE_SWITCH__STP3__CUSTOMIZATION
6.
7. \ref TUTO_USE_SWITCH__STP4__BENCHMARKS
8.
\par Files to edit First, open/create the corresponding file:

• your main source files and project files
* \section TUTO_USE_SWITCH__STP1__PRESENTAION Global idea The switch mecanism introduced into GpuCV can be quite handy, but also quite complex to anderstand and manipulate correclty. So let starts from scratch. * \subsection TUTO_USE_SWITCH__STP1__SUB1_WHAT What is it? The switch mecanism acts as a function multiplexer, from one input function call it will select and execute another function among several depending on the context or the input parameters. Here is an example:
Algorithm ALGO-A is supposed to process a set of data, FctA-1 and FctA-2 are two different implementations of this algorithm, they differ from some code optimisations or hardware support.
Without a switch, the code would look like: \code //performing ALGO-A if(OPTION_XX)         FctA-1(..); else         FctA-2(..); \endcode Here goes some questions of interrest:
• What if I call ALGO-A hundreds times in my source code?
• What if I have a new implementation FctA-3 available?
• What if I FctA-2 is not supported by any developper and does not work any more, crashs or return wrong results?
• How to find the best implementation to call?
GpuCV supply a complex switch mecanism design to offer easy solution for developers to all this anoying questions. Here is what your new code might look like: \code //performing process FctA threw a switch operator         FctA-Switch(..); \endcode Now, what about theses anoying questions: \par What if I call ALGO-A hundreds times in my source code? I can be really easy to redirect function FctA to FctA-Switch, in fact one line is required in the corresponding header file: \code ... #define FctA Fct-Switch ... \endcode -> No painful code update...
\par What if I have a new implementation FctA-3 available? The switch mecanism supplies a plugin system to allow as many implementations has required. You just need to provide the DLLs and some meta-data to help the switch to operate correclty.
\par What if I FctA-2 is not supported by any developper and does not work any more, crashs or return wrong results? The switch mecanism can enable/disable plugins or some functions using an external XML file, so no need to edit your code to control the plugin behavior. In some advanced usage, such as 'non regression testing', you can tell the switch that a given function is not working properly with corresponding set of input parameters so it will not be called again.
\par How to find the best implementation to call? The current switch mecanism choose the best implementation to call depending on these parameters:
• Implementations available
• Hardware compatibility
• Depending on input parameters:

• Implementation performances
•
• Implementation compatibility with input parameters
•
• Implementation correct processing
•
• Possible data tranfer required
•

* \subsection TUTO_USE_SWITCH__STP1__SUB2_WHY Why do we need to switch between operators? Some domains such as GPGPU offers many possibilities to implement a task that will behave differently based on:
• Technology used: OpenGL + Shaders, CUDA, OpenCL...
• Host hardware performances: CPU and GPU family, speed, memory...
• Implementation quality and performances
• Input data properties: size, type, location in RAM or VRAM...
There are two many parameters and they are varying from years to years so it is not possible to develop an application that will try to handle everythning manually. We need a easy-to-use mecanism to manage this complex task for us. * \section TUTO_USE_SWITCH__STP2__INTEGRATION Integrate the switch mechanism into an existing application * Tag: TUTO_USE_SWITCH_TAG__STP1__INTEGRATION
\par headers and libs... \par source code update (what to avoid) * \section TUTO_USE_SWITCH__STP3__CUSTOMIZATION Customize the switch mechanism * Tag: TUTO_USE_SWITCH_TAG__STP2__CUSTOMIZATION
* \section TUTO_USE_SWITCH__STP4__BENCHMARKS Get performances feedbacks * Tag: TUTO_USE_SWITCH_TAG__STP3__BENCHMARKS
*/  

Powered by WebSVN v1.61