SkePU 0.7
Public Member Functions | Static Public Member Functions
skepu::Generate< GenerateFunc > Class Template Reference

A class representing the Generate skeleton. More...

#include <generate.h>

Collaboration diagram for skepu::Generate< GenerateFunc >:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 Generate (GenerateFunc *generateFunc)
 ~Generate ()
template<typename T >
void setConstant (T constant1)
void finishAll ()
template<typename T >
void operator() (unsigned int numElements, Vector< T > &output)
void replaceText (std::string &text, std::string find, std::string replace)
void createOpenCLProgram ()

Static Public Member Functions

template<typename T >
static void cpu_func (void *buffers[], void *arg)
template<typename T >
static void omp_func (void *buffers[], void *arg)
template<typename T >
static void cuda_func (void *buffers[], void *arg)
template<typename T >
static void opencl_func (void *buffers[], void *arg)

Detailed Description

template<typename GenerateFunc>
class skepu::Generate< GenerateFunc >

A class representing the Generate skeleton.

Author:
Johan Enmyren, Usman Dastgeer
Version:
0.7

This class defines the Generate skeleton, It can be used to generate a specified number of elements using a user defined function. It is similar to the Unary Map skeleton, applying a function to each element of a vector. But the Generate skeleton generates all the elements instead of copying the existing elements and applying a function on them.

Once the Generate object is instantiated, it is meant to be used as a function and therefore overloading operator(). It takes SkePU vector as arguments.

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 GenerateFunc >
skepu::Generate< GenerateFunc >::Generate ( GenerateFunc *  generateFunc)

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

Parameters:
generateFuncA pointer to a valid user function. Will be deleted in the destructor.

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

Here is the call graph for this function:

template<typename GenerateFunc >
skepu::Generate< GenerateFunc >::~Generate ( )

When the Generate skeleton is destroyed, it deletes the user function it was created with. Furthermore, it destroy OpenCL handlers (if created) and StarPU codelet.


Member Function Documentation

template<typename GenerateFunc >
template<typename T >
void skepu::Generate< GenerateFunc >::cpu_func ( void *  buffers[],
void *  arg 
) [static]

A static function called by the StarPU if CPU backend is selected for a skeleton invocation that is used with StarPU codelet. It generates a set of numbers.

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

A function called by the constructor. It creates the OpenCL program for the skeleton using StarPU helper functions and stores the kernel name. The program is built from a string containing the user function (specified when constructing the skeleton) and a generic Generate 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::GenerateKernel_CL().

Here is the call graph for this function:

template<typename GenerateFunc >
template<typename T >
void skepu::Generate< GenerateFunc >::cuda_func ( void *  buffers[],
void *  arg 
) [static]

A static function called by the StarPU if CUDA backend is selected for a skeleton invocation that is used with StarPU codelet. It generates a set of numbers.

Parameters:
buffersContain all StarPU managed data which in this case consists of one write buffer.
argA read only argument which is used to pass handler to the object as this is a static function.
template<typename GenerateFunc>
void skepu::Generate< GenerateFunc >::finishAll ( ) [inline]

Makes sure all operations on devices are finished.

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

Here is the call graph for this function:

template<typename GenerateFunc >
template<typename T >
void skepu::Generate< GenerateFunc >::omp_func ( void *  buffers[],
void *  arg 
) [static]

A static function called by the StarPU if OpenMP backend is selected for a skeleton invocation that is used with StarPU codelet. OpenMP backend is selected if SKEPU_OPENMP is defined which overwrite sequential CPU implementation with OpenMP implementation for each skeleton call. It generates a set of numbers.

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

A static function called by the StarPU if OpenCL backend is selected for a skeleton invocation that is used with StarPU codelet. It generates a set of numbers.

Parameters:
buffersContain all StarPU managed data which in this case consists of one write buffer.
argA read only argument which is used to pass handler to the object as this is a static function.
template<typename GenerateFunc >
template<typename T >
void skepu::Generate< GenerateFunc >::operator() ( unsigned int  numElements,
Vector< T > &  output 
)

Generates a number of elements using the user function which the skeleton was created with. The elements are saved in an output vector.

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:
numElementsThe number of elements to be generated.
outputThe output vector which will be overwritten with the generated values.

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

Here is the call graph for this function:

template<typename GenerateFunc >
void skepu::Generate< GenerateFunc >::replaceText ( std::string &  text,
std::string  find,
std::string  replace 
)

A helper function 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 GenerateFunc>
template<typename T >
void skepu::Generate< GenerateFunc >::setConstant ( constant1) [inline]

This function sets the constant that can be used in the generate user function.


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