SkePU(integratedwithStarPU)
0.8.1
|
A class representing the Generate skeleton. More...
#include <generate.h>
Public Member Functions | |
Generate (GenerateFunc *generateFunc) | |
~Generate () | |
template<typename U > | |
void | setConstant (U constant1) |
void | finishAll () |
template<typename T > | |
void | operator() (unsigned int numElements, Vector< T > &output, int parts=1) |
template<typename T > | |
void | operator() (unsigned int numRows, unsigned int numCols, Matrix< T > &output, int parts=1) |
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 | cpu_func_mat (void *buffers[], void *arg) |
template<typename T > | |
static void | omp_func (void *buffers[], void *arg) |
template<typename T > | |
static void | omp_func_mat (void *buffers[], void *arg) |
template<typename T > | |
static void | cuda_func (void *buffers[], void *arg) |
template<typename T > | |
static void | cuda_func_mat (void *buffers[], void *arg) |
template<typename T > | |
static void | opencl_func (void *buffers[], void *arg) |
template<typename T > | |
static void | opencl_func_mat (void *buffers[], void *arg) |
A class representing the Generate skeleton.
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.
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.
generateFunc | A pointer to a valid user function. Will be deleted in the destructor. |
References skepu::Environment< T >::getInstance().
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.
|
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.
buffers | Contain all StarPU managed data which in this case consists of one write buffer for vector. |
arg | A read only argument which is used to pass handler to the object as this is a static function. |
|
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.
buffers | Contain all StarPU managed data which in this case consists of one write buffer for matrix. |
arg | A read only argument which is used to pass handler to the object as this is a static function. |
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(), skepu::GenerateKernel_CL_Matrix(), skepu::read_file_into_string(), and skepu::replaceTextInString().
|
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.
buffers | Contain all StarPU managed data which in this case consists of one write buffer. |
arg | A read only argument which is used to pass handler to the object as this is a static function. |
|
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.
buffers | Contain all StarPU managed data which in this case consists of one write buffer for matrix. |
arg | A read only argument which is used to pass handler to the object as this is a static function. |
|
inline |
Makes sure all operations on devices are finished.
References skepu::Environment< T >::finishAll().
|
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.
buffers | Contain all StarPU managed data which in this case consists of one write buffer. |
arg | A read only argument which is used to pass handler to the object as this is a static function. |
|
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.
buffers | Contain all StarPU managed data which in this case consists of one write buffer for matrix. |
arg | A read only argument which is used to pass handler to the object as this is a static function. |
|
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.
buffers | Contain all StarPU managed data which in this case consists of one write buffer. |
arg | A read only argument which is used to pass handler to the object as this is a static function. |
|
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.
buffers | Contain all StarPU managed data which in this case consists of one write buffer for matrix. |
arg | A read only argument which is used to pass handler to the object as this is a static function. |
void skepu::Generate< GenerateFunc >::operator() | ( | unsigned int | numElements, |
Vector< T > & | output, | ||
int | parts = 1 |
||
) |
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.
numElements | The number of elements to be generated. |
output | The output vector which will be overwritten with the generated values. |
References skepu::Vector< T >::clear(), skepu::Vector< T >::registerPartitions(), skepu::Vector< T >::resize(), and skepu::Vector< T >::size().
void skepu::Generate< GenerateFunc >::operator() | ( | unsigned int | numRows, |
unsigned int | numCols, | ||
Matrix< T > & | output, | ||
int | parts = 1 |
||
) |
Generates a number of elements for a matrix object using the user function which the skeleton was created with. The elements are saved in an output matrix.
Depending on which backend was used, different versions of the skeleton is called. If SKEPU_CUDA
is defined, the CUDA backend is used, similarly if SKEPU_OPENCL
or SKEPU_OPENMP
are defined then the OpenCL or OpenMP backend is used. As a fallback there is always a CPU version.
numRows | The number of rows to be generated. |
numCols | The number of columns to be generated. |
output | The output matrix which will be overwritten with the generated values. |
References skepu::Matrix< T >::clear(), skepu::Matrix< T >::registerPartitions(), skepu::Matrix< T >::resize(), skepu::Matrix< T >::total_cols(), and skepu::Matrix< T >::total_rows().
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.
text | A std::string which is searched. |
find | The std::string which is searched for and replaced. |
replace | The relpacement std::string . |
|
inline |
This function sets the constant that can be used in the generate user function.