SkePU 0.7
Public Member Functions | Static Public Member Functions
skepu::MapReduce< MapFunc, ReduceFunc, T, c_type > Class Template Reference

A class representing the MapReduce skeleton. More...

#include <mapreduce.h>

Inheritance diagram for skepu::MapReduce< MapFunc, ReduceFunc, T, c_type >:
Inheritance graph
[legend]
Collaboration diagram for skepu::MapReduce< MapFunc, ReduceFunc, T, c_type >:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 MapReduce (MapFunc *mapFunc, ReduceFunc *reduceFunc)
 MapReduce (MapFunc *mapFunc, ReduceFunc *reduceFunc, Vector< T > *in, T *out)
 ~MapReduce ()
void run_async ()
operator() (Vector< T > &input)
operator() (Vector< T > &input, int parts)
void replaceText (std::string &text, std::string find, std::string replace)
void createOpenCLProgram ()

Static Public Member Functions

static void cpu_func (void *buffers[], void *arg)
static void omp_func (void *buffers[], void *arg)
static void cuda_func (void *buffers[], void *arg)
static void opencl_func (void *buffers[], void *arg)

Detailed Description

template<typename MapFunc, typename ReduceFunc, typename T, skepu::FuncType c_type = UNARY>
class skepu::MapReduce< MapFunc, ReduceFunc, T, c_type >

A class representing the MapReduce skeleton.

Author:
Johan Enmyren, Usman Dastgeer
Version:
0.7

This class defines the MapReduce skeleton for unary user function. MapReduce is a combination of the Map and Reduce operations. It produces the same result as if one would first Map one or more vectors to a result vector, then do a reduction on that result. It is provided since it combines the mapping and reduction in the same computation kernel and therefore avoids some synchronization, which speeds up the calculation. Once instantiated, it is meant to be used as a function and therefore overloading operator().

It uses StarPU as a backend and choice between different backends can be controlled by using defines. SKEPU_OPENMP can be used to use OpenMP whose support is currently limited in StarPU, hence not recommended, SKEPU_CUDA will register CUDA backend along other defined (atleast CPU if nothing else is defined) SKEPU_OPENCL will register OpenCL backend along other defined (atleast CPU if nothing else is defined) CUDA_ONLY will eliminate all other backends (even CPU) and will force StarPU to use CUDA only. if no above macro is defined, it will use sequential CPU backend.

Author:
Usman Dastgeer
Version:
0.7

This class defines the MapReduce skeleton for binary user function. MapReduce is a combination of the Map and Reduce operations. It produces the same result as if one would first Map one or more vectors to a result vector, then do a reduction on that result. It is provided since it combines the mapping and reduction in the same computation kernel and therefore avoids some synchronization, which speeds up the calculation. Once instantiated, it is meant to be used as a function and therefore overloading operator().

It uses StarPU as a backend and choice between different backends can be controlled by using defines. SKEPU_OPENMP can be used to use OpenMP whose support is currently limited in StarPU, hence not recommended, SKEPU_CUDA will register CUDA backend along other defined (atleast CPU if nothing else is defined) SKEPU_OPENCL will register OpenCL backend along other defined (atleast CPU if nothing else is defined) CUDA_ONLY will eliminate all other backends (even CPU) and will force StarPU to use CUDA only. if no above macro is defined, it will use sequential CPU backend.

Author:
Usman Dastgeer
Version:
0.7

This class defines the MapReduce skeleton for ternary user function. MapReduce is a combination of the Map and Reduce operations. It produces the same result as if one would first Map one or more vectors to a result vector, then do a reduction on that result. It is provided since it combines the mapping and reduction in the same computation kernel and therefore avoids some synchronization, which speeds up the calculation. Once instantiated, it is meant to be used as a function and therefore overloading operator().

It uses StarPU as a backend and choice between different backends can be controlled by using defines. SKEPU_OPENMP can be used to use OpenMP whose support is currently limited in StarPU, hence not recommended, SKEPU_CUDA will register CUDA backend along other defined (atleast CPU if nothing else is defined) SKEPU_OPENCL will register OpenCL backend along other defined (atleast CPU if nothing else is defined) CUDA_ONLY will eliminate all other backends (even CPU) and will force StarPU to use CUDA only. if no above macro is defined, it will use sequential CPU backend.


Constructor & Destructor Documentation

template<typename MapFunc , typename ReduceFunc , typename T >
skepu::MapReduce< MapFunc, ReduceFunc, T >::MapReduce ( MapFunc *  mapFunc,
ReduceFunc *  reduceFunc 
)

When creating an instance of the MapReduce skeleton, for a unary user function and Vector container type, two pointers need to be provided. One for a unary mapping function and one for a binary reduce function. Also the environment is set and if SKEPU_OPENCL is defined, the appropriate OpenCL program are created.

Parameters:
mapFuncA pointer to a valid unary, binary or trinary user function. Will be deleted in the destructor.
reduceFuncA pointer to a valid binary user function. Will be deleted in the destructor.

When creating an instance of the MapReduce skeleton, for a binary user function and Vector container type, two pointers need to be provided. One for a unary mapping function and one for a binary reduce function. Also the environment is set and if SKEPU_OPENCL is defined, the appropriate OpenCL program are created.

Parameters:
mapFuncA pointer to a valid unary, binary or trinary user function. Will be deleted in the destructor.
reduceFuncA pointer to a valid binary user function. Will be deleted in the destructor.

References skepu::Environment< T >::getInstance().

Here is the call graph for this function:

template<typename MapFunc , typename ReduceFunc , typename T , skepu::FuncType c_type>
skepu::MapReduce< MapFunc, ReduceFunc, T, c_type >::MapReduce ( MapFunc *  mapFunc,
ReduceFunc *  reduceFunc,
Vector< T > *  in,
T *  out 
)

When creating an instance of the MapReduce skeleton, for a unary user function and Vector container type, two pointers need to be provided. One for a unary mapping function and one for a binary reduce function. Also the environment is set and if SKEPU_OPENCL is defined, the appropriate OpenCL program are created. This constructor is used to assist in calling map skeleton in a task-parallel skeleton(e.g. farm) by implementing Task class "run_async()" method. The parameters for map call should be specified before e.g. using this constructor.

Parameters:
mapFuncA pointer to a valid unary, binary or trinary user function. Will be deleted in the destructor.
reduceFuncA pointer to a valid binary user function. Will be deleted in the destructor.
inA pointer to a input Vector object.
outA pointer to an output variable.

References skepu::Environment< T >::getInstance().

Here is the call graph for this function:

template<typename MapFunc , typename ReduceFunc , typename T >
skepu::MapReduce< MapFunc, ReduceFunc, T >::~MapReduce ( )

When the MapReduce skeleton with a unary user function and Vector container type is destroyed, it deletes the user functions it was created with. Furthermore, it destroy OpenCL handler and performance model objects (if created) and StarPU codelet.

When the MapReduce skeleton with a binary user function and Vector container type is destroyed, it deletes the user functions it was created with. Furthermore, it destroy OpenCL handler and performance model objects (if created) and StarPU codelet.


Member Function Documentation

template<typename MapFunc , typename ReduceFunc , typename T >
void skepu::MapReduce< MapFunc, ReduceFunc, T >::cpu_func ( void *  buffers[],
void *  arg 
) [static]

A static function used with StarPU codelet for MapReduce for unary user function and is called by the StarPU if CPU backend is selected for a skeleton invocation.

Parameters:
buffersContain all StarPU managed data which in this case consists of one read and one write buffer.
argA read only argument which is used to pass handler to the object as this is a static function.

A static function used with StarPU codelet for MapReduce for binary user function and is called by the StarPU if CPU backend is selected for a skeleton invocation.

Parameters:
buffersContain all StarPU managed data which in this case consists of two read and one write buffer.
argA read only argument which is used to pass handler to the object as this is a static function.
template<typename MapFunc , typename ReduceFunc , typename T >
void skepu::MapReduce< MapFunc, ReduceFunc, T >::createOpenCLProgram ( )

A function called by the constructor for unary user function. It creates the OpenCL program for the skeleton and saves the the kernel name. The program is built from a string containing the user functions (specified when constructing the skeleton) and a generic MapReduce kernel. The type and function names in the generic kernel are relpaced by user function specific code before it is compiled by the OpenCL JIT compiler. Both a MapReduce kernel and a regular Reduce kernel are built.

Also handles the use of doubles automatically by including "#pragma OPENCL EXTENSION cl_khr_fp64: enable" if doubles are used.

A function called by the constructor for binary user function. It creates the OpenCL program for the skeleton and saves the the kernel name. The program is built from a string containing the user functions (specified when constructing the skeleton) and a generic MapReduce kernel. The type and function names in the generic kernel are relpaced by user function specific code before it is compiled by the OpenCL JIT compiler. Both a MapReduce kernel and a regular Reduce kernel are built.

Also handles the use of doubles automatically by including "#pragma OPENCL EXTENSION cl_khr_fp64: enable" if doubles are used.

References skepu::ReduceKernel_CL(), and skepu::UnaryMapReduceKernel_CL().

Here is the call graph for this function:

template<typename MapFunc , typename ReduceFunc , typename T >
void skepu::MapReduce< MapFunc, ReduceFunc, T >::cuda_func ( void *  buffers[],
void *  arg 
) [static]

A static function used with StarPU codelet for MapReduce for unary user function and is called by the StarPU if CUDA backend is selected for a skeleton invocation.

Parameters:
buffersContain all StarPU managed data which in this case consists of one read and one write buffer.
argA read only argument which is used to pass handler to the object as this is a static function.

A static function used with StarPU codelet for MapReduce for binary user function and is called by the StarPU if CUDA backend is selected for a skeleton invocation.

Parameters:
buffersContain all StarPU managed data which in this case consists of two read and one write buffer.
argA read only argument which is used to pass handler to the object as this is a static function.
template<typename MapFunc , typename ReduceFunc , typename T >
void skepu::MapReduce< MapFunc, ReduceFunc, T >::omp_func ( void *  buffers[],
void *  arg 
) [static]

A static function used with StarPU codelet for MapReduce for unary user function and is called by the StarPU if OpenMP backend is selected for a skeleton invocation.

Parameters:
buffersContain all StarPU managed data which in this case consists of one read and one write buffer.
argA read only argument which is used to pass handler to the object as this is a static function.

A static function used with StarPU codelet for MapReduce for binary user function and is called by the StarPU if OpenMP backend is selected for a skeleton invocation.

Parameters:
buffersContain all StarPU managed data which in this case consists of two read and one write buffer.
argA read only argument which is used to pass handler to the object as this is a static function.
template<typename MapFunc , typename ReduceFunc , typename T >
void skepu::MapReduce< MapFunc, ReduceFunc, T >::opencl_func ( void *  buffers[],
void *  arg 
) [static]

A static function used with StarPU codelet for MapReduce for unary user function and is called by the StarPU if OpenCL backend is selected for a skeleton invocation.

Parameters:
buffersContain all StarPU managed data which in this case consists of one read and one write buffer.
argA read only argument which is used to pass handler to the object as this is a static function.

A static function used with StarPU codelet for MapReduce for binary user function and is called by the StarPU if OpenCL backend is selected for a skeleton invocation.

Parameters:
buffersContain all StarPU managed data which in this case consists of two read and one write buffer.
argA read only argument which is used to pass handler to the object as this is a static function.
template<typename MapFunc , typename ReduceFunc , typename T , skepu::FuncType c_type>
T skepu::MapReduce< MapFunc, ReduceFunc, T, c_type >::operator() ( Vector< T > &  input)

Performs the Map on one Vector and Reduce on the result. Returns a scalar result.

Depending on which backend was used, appropriate backend will be registered. In case of multiple backends (e.g. CPU and CUDA) StarPU will decide at runtime which one to use.

Parameters:
inputA vector which the map and reduce will be performed on.
Returns:
The scalar result of the map-reduce combination performed.
template<typename MapFunc , typename ReduceFunc , typename T , skepu::FuncType c_type>
T skepu::MapReduce< MapFunc, ReduceFunc, T, c_type >::operator() ( Vector< T > &  input,
int  parts 
)

Performs the Map on one Vector and Reduce on the result. It has support for creating multiple tasks using filters/partitioning. Returns a scalar result.

Depending on which backend was used, appropriate backend will be registered. In case of multiple backends (e.g. CPU and CUDA) StarPU will decide at runtime which one to use.

Parameters:
inputA vector which the map and reduce will be performed on.
partsThe number of parts (StarPU tasks) that will be created for this skeleton call dividing the work equally between different created tasks.
Returns:
The scalar result of the map-reduce combination performed.

References skepu::Vector< T >::registerPartitions(), skepu::Vector< T >::resize(), and skepu::Vector< T >::size().

Here is the call graph for this function:

template<typename MapFunc , typename ReduceFunc , typename T >
void skepu::MapReduce< MapFunc, ReduceFunc, T >::replaceText ( std::string &  text,
std::string  find,
std::string  replace 
)

A helper function used by createOpenCLProgram() for unary user function. It finds all instances of a string in another string and replaces it with a third string.

Parameters:
textA std::string which is searched.
findThe std::string which is searched for and replaced.
replaceThe relpacement std::string.

A helper function used by createOpenCLProgram() for binary user function. It finds all instances of a string in another string and replaces it with a third string.

Parameters:
textA std::string which is searched.
findThe std::string which is searched for and replaced.
replaceThe relpacement std::string.
template<typename MapFunc , typename ReduceFunc , typename T >
void skepu::MapReduce< MapFunc, ReduceFunc, T >::run_async ( ) [virtual]

This is an abstract method defined in the Task class which every data-parallel skeleton implements to allow itself to be used within task-parallel skeletons (e.g. farm). It relies on the fact that parameters for the function call are already provided e.g. via constructor or setter methods available in the public interface of the class.

Implements skepu::Task.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Enumerations Friends Defines