SkePU(integratedwithStarPU)  0.8.1
 All Classes Namespaces Files Functions Enumerations Friends Macros Groups Pages
Public Member Functions | Static Public Member Functions | List of all members
skepu::MapArray< MapArrayFunc, T, c_type > Class Template Reference

A class representing the MapArray skeleton. More...

#include <maparray.h>

Inheritance diagram for skepu::MapArray< MapArrayFunc, T, c_type >:
Inheritance graph
[legend]
Collaboration diagram for skepu::MapArray< MapArrayFunc, T, c_type >:
Collaboration graph
[legend]

Public Member Functions

 MapArray (MapArrayFunc *mapArrayFunc)
 
 MapArray (MapArrayFunc *mapArrayFunc, Vector< T > *in1, Vector< T > *in2, Vector< T > *out, int _parts=1)
 
 ~MapArray ()
 
void run_async ()
 
void operator() (Vector< T > &input1, Vector< T > &input2, Vector< T > &output)
 
void operator() (Vector< T > &input1, Vector< T > &input2, Vector< T > &output, 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 MapArrayFunc, typename T, skepu_container_type c_type = VECTOR>
class skepu::MapArray< MapArrayFunc, T, c_type >

A class representing the MapArray skeleton.

This class defines the MapArray skeleton for a vector container, MapArray is yet another variant of Map. It produces a result vector from two input vectors where each element of the result, is a function of the corresponding element of one of the input vectors, and any number of elements from the other input vector. This means that at each call to the user defined function, which is done for each element in input two, all elements from input one can be accessed. 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.

This class defines the MapArray skeleton for a matrix container, MapArray is yet another variant of Map. It produces a result from two input operands where each element of the result matrix, is a function of the corresponding element of the second operand, and any number of elements from the the first operand. This means that at each call to the user defined function, which is done for each element in input two, all elements from input one can be accessed. 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.

This class defines the MapArray skeleton for a sparse-matrix container, MapArray is yet another variant of Map. It produces a result from two input operands where each element of the result sparse-matrix, is a function of set of elements of the input sparse-matrix, and any number of elements from the the input vector. This means that at each call to the user defined function, which is done for each element in input two, all elements from input one can be accessed. 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 MapArrayFunc, typename T , skepu_container_type c_type>
skepu::MapArray< MapArrayFunc, T, c_type >::MapArray ( MapArrayFunc *  mapArrayFunc)

When creating an instance of the MapArray skeleton for vector, a pointer to an array user function must be provided. Also the environment is set and if SKEPU_OPENCL is defined, the appropriate OpenCL program is created. Also creates a default execution plan which the skeleton will use if no other is specified.

Parameters
mapArrayFuncA pointer to a valid array user function. Will be deleted in the destructor.

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

Here is the call graph for this function:

template<typename MapArrayFunc, typename T, skepu_container_type c_type>
skepu::MapArray< MapArrayFunc, T, c_type >::MapArray ( MapArrayFunc *  mapArrayFunc,
Vector< T > *  in1,
Vector< T > *  in2,
Vector< T > *  out,
int  _parts = 1 
)

When creating an instance of the MapArray skeleton for vector, a pointer to an array user function must be provided. Also the environment is set and if SKEPU_OPENCL is defined, the appropriate OpenCL program is created. Also creates a default execution plan which the skeleton will use if no other is specified. 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
mapArrayFuncA pointer to a valid array user function. Will be deleted in the destructor.
in1A pointer to first input Vector object.
in2A pointer to second input Vector object.
outA pointer to a output Vector object.
_partsAn integer specifying number of partitions(subtasks) to be created when maparray is called.

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

Here is the call graph for this function:

template<typename MapArrayFunc , typename T , skepu_container_type c_type>
skepu::MapArray< MapArrayFunc, T, c_type >::~MapArray ( )

When the MapArray skeleton for vector is destroyed, it deletes the user function it was created with. Furthermore, it destroy OpenCL handler and performance model objects (if created) and StarPU codelet.

Member Function Documentation

template<typename MapArrayFunc , typename T , skepu_container_type c_type>
void skepu::MapArray< MapArrayFunc, T, c_type >::cpu_func ( void *  buffers[],
void *  arg 
)
static

A static function used with StarPU codelet for MapArray with Vector container 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 either two read and one write buffer.
argA read only argument which is used to pass handler to the object and related data as this is a static function.
template<typename MapArrayFunc , typename T , skepu_container_type c_type>
void skepu::MapArray< MapArrayFunc, T, c_type >::createOpenCLProgram ( )

A function called by the constructor. It creates the OpenCL program for the skeleton and saves a the kernel name. The program is built from a string containing the user function (specified when constructing the skeleton) and a generic MapArray 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.

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

References skepu::MapArrayKernel_CL().

Here is the call graph for this function:

template<typename MapArrayFunc , typename T , skepu_container_type c_type>
void skepu::MapArray< MapArrayFunc, T, c_type >::cuda_func ( void *  buffers[],
void *  arg 
)
static

A static function used with StarPU codelet for MapArray with Vector container 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 either two read and one write buffer.
argA read only argument which is used to pass handler to the object and related data as this is a static function.
template<typename MapArrayFunc , typename T , skepu_container_type c_type>
void skepu::MapArray< MapArrayFunc, T, c_type >::omp_func ( void *  buffers[],
void *  arg 
)
static

A static function used with StarPU codelet for MapArray with Vector container 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 either two read and one write buffer.
argA read only argument which is used to pass handler to the object and related data as this is a static function.
template<typename MapArrayFunc , typename T , skepu_container_type c_type>
void skepu::MapArray< MapArrayFunc, T, c_type >::opencl_func ( void *  buffers[],
void *  arg 
)
static

A static function used with StarPU codelet for MapArray with Vector container 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 either 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 MapArrayFunc , typename T, skepu_container_type c_type>
void skepu::MapArray< MapArrayFunc, T, c_type >::operator() ( Vector< T > &  input1,
Vector< T > &  input2,
Vector< T > &  output 
)

Performs the MapArray on the two Vectors specified. A seperate output vector is used.

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
input1First vector, which can be accessed entirely for each element in second vector.
input2Second vector, each value of this vector can be mapped to several values from first Vector.
outputThe result vector, will be overwritten with the result and resized if needed.

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

Here is the call graph for this function:

template<typename MapArrayFunc , typename T, skepu_container_type c_type>
void skepu::MapArray< MapArrayFunc, T, c_type >::operator() ( Vector< T > &  input1,
Vector< T > &  input2,
Vector< T > &  output,
int  parts 
)

Performs the MapArray on the two Vectors specified. A seperate output vector is used.

Depending on which backend was used, appropriate backend will be registered. It has support for creating multiple tasks using filters/partitioning. In case of multiple backends (e.g. CPU and CUDA) StarPU will decide at runtime which one to use.

Parameters
input1First vector, which can be accessed entirely for each element in second vector.
input2Second vector, each value of this vector can be mapped to several values from first Vector.
outputThe result vector, will be overwritten with the result and resized if needed.
partsThe number of parts (StarPU tasks) that will be created for this skeleton call dividing the work equally between different created tasks.

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

Here is the call graph for this function:

template<typename MapArrayFunc , typename T , skepu_container_type c_type>
void skepu::MapArray< MapArrayFunc, T, c_type >::replaceText ( std::string &  text,
std::string  find,
std::string  replace 
)

A helper function for MapArray with Vector, used by createOpenCLProgram(). 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 MapArrayFunc , typename T , skepu_container_type c_type>
void skepu::MapArray< MapArrayFunc, T, c_type >::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: