A class representing the Generate skeleton. More...
#include <generate.h>
Public Member Functions | |
Generate (GenerateFunc *generateFunc) | |
~Generate () | |
template<typename T > | |
void | setConstant (T constant1) |
void | finishAll () |
template<typename T > | |
void | operator() (size_t numElements, Vector< T > &output) |
template<typename T > | |
void | operator() (size_t numRows, size_t numCols, Matrix< T > &output) |
template<typename OutputIterator > | |
void | operator() (size_t numElements, OutputIterator outputBegin) |
template<typename T > | |
void | CPU (size_t numElements, Vector< T > &output) |
template<typename T > | |
void | CPU (size_t numRows, size_t numCols, Matrix< T > &output) |
template<typename OutputIterator > | |
void | CPU (size_t numElements, OutputIterator outputBegin) |
template<typename T > | |
void | OMP (size_t numElements, Vector< T > &output) |
template<typename T > | |
void | OMP (size_t numRows, size_t numCols, Matrix< T > &output) |
template<typename OutputIterator > | |
void | OMP (size_t numElements, OutputIterator outputBegin) |
template<typename T > | |
void | CU (size_t numElements, Vector< T > &output, int useNumGPU=1) |
template<typename T > | |
void | CU (size_t numRows, size_t numCols, Matrix< T > &output, int useNumGPU=1) |
template<typename OutputIterator > | |
void | CU (size_t numElements, OutputIterator outputBegin, int useNumGPU=1) |
template<typename T > | |
void | CL (size_t numElements, Vector< T > &output, int useNumGPU=1) |
template<typename T > | |
void | CL (size_t numRows, size_t numCols, Matrix< T > &output, int useNumGPU=1) |
template<typename OutputIterator > | |
void | CL (size_t numElements, OutputIterator outputBegin, int useNumGPU=1) |
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 for both vector and matrix containers. 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()
. There are different overloaded versions of this operator, one which takes iterators as inputs and one that takes whole vectors/matrix.
If a certain back end is to be used, functions with the same interface as operator()
but by the names CPU
, CU
, CL
, OMP
exists for CPU, CUDA, OpenCL and OpenMP respectively.
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 and kernel 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.
void skepu::Generate< GenerateFunc >::CL | ( | size_t | numElements, |
Vector< T > & | output, | ||
int | useNumGPU = 1 |
||
) |
Generates a number of elements using the user function which the skeleton was created with. The elements are saved in an output vector which is resized to numElements. A wrapper for CL(size_t numElements, OutputIterator outputBegin, int useNumGPU). For the OpenCL backend.
numElements | The number of elements to be generated. |
output | The output vector which will be overwritten with the generated values. |
useNumGPU | Integer specifying how many devices to use. 0 = Implementation decides. |
References skepu::Vector< T >::begin(), skepu::Vector< T >::clear(), skepu::Vector< T >::resize(), and skepu::Vector< T >::size().
void skepu::Generate< GenerateFunc >::CL | ( | size_t | numRows, |
size_t | numCols, | ||
Matrix< T > & | output, | ||
int | useNumGPU = 1 |
||
) |
Generates a number of elements using the user function which the skeleton was created with. The elements are saved in an output matrix which is resized to numElements. For the OpenCL backend.
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. |
useNumGPU | Integer specifying how many devices to use. 0 = Implementation decides. |
References skepu::Matrix< T >::at(), MAX_GPU_DEVICES, and skepu::printCLError().
void skepu::Generate< GenerateFunc >::CL | ( | size_t | numElements, |
OutputIterator | outputBegin, | ||
int | useNumGPU = 1 |
||
) |
Generates a number of elements using the user function which the skeleton was created with. The elements are saved in an output range. For the OpenCL backend. Calls generateNumDevices_CL(size_t numElements, OutputIterator outputBegin, int useNumGPU).
numElements | The number of elements to be generated. |
outputBegin | An iterator pointing to the first element in the range which will be overwritten with generated values. |
useNumGPU | Integer specifying how many devices to use. 0 = Implementation decides. |
void skepu::Generate< GenerateFunc >::CPU | ( | size_t | 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 which is resized to numElements. A wrapper for CPU(size_t numElements, OutputIterator outputBegin). For the CPU backend.
numElements | The number of elements to be generated. |
output | The output vector which will be overwritten with the generated values. |
References skepu::Vector< T >::begin(), skepu::Vector< T >::clear(), skepu::Vector< T >::resize(), and skepu::Vector< T >::size().
void skepu::Generate< GenerateFunc >::CPU | ( | size_t | numRows, |
size_t | numCols, | ||
Matrix< T > & | output | ||
) |
Generates a number of elements using the user function which the skeleton was created with. The elements are saved in an output matrix which is resized to numElements. For the CPU backend.
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. |
void skepu::Generate< GenerateFunc >::CPU | ( | size_t | numElements, |
OutputIterator | outputBegin | ||
) |
Generates a number of elements using the user function which the skeleton was created with. The elements are saved in an output range. For the CPU backend.
numElements | The number of elements to be generated. |
outputBegin | An iterator pointing to the first element in the range which will be overwritten with generated values. |
void skepu::Generate< GenerateFunc >::CU | ( | size_t | numElements, |
Vector< T > & | output, | ||
int | useNumGPU = 1 |
||
) |
Generates a number of elements using the user function which the skeleton was created with. The elements are saved in an output vector which is resized to numElements. A wrapper for CU(size_t numElements, OutputIterator outputBegin, int useNumGPU). For the CUDA backend.
numElements | The number of elements to be generated. |
output | The output vector which will be overwritten with the generated values. |
useNumGPU | Integer specifying how many devices to use. 0 = Implementation decides. |
References skepu::Vector< T >::begin(), skepu::Vector< T >::clear(), skepu::Vector< T >::resize(), and skepu::Vector< T >::size().
void skepu::Generate< GenerateFunc >::CU | ( | size_t | numRows, |
size_t | numCols, | ||
Matrix< T > & | output, | ||
int | useNumGPU = 1 |
||
) |
Generates a number of elements using the user function which the skeleton was created with. The elements are saved in an output matrix which is resized to numElements. For the CUDA backend.
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. |
useNumGPU | Integer specifying how many devices to use. 0 = Implementation decides. |
References skepu::GenerateKernel_CU_Matrix(), and MAX_GPU_DEVICES.
void skepu::Generate< GenerateFunc >::CU | ( | size_t | numElements, |
OutputIterator | outputBegin, | ||
int | useNumGPU = 1 |
||
) |
Generates a number of elements using the user function which the skeleton was created with. The elements are saved in an output range. For the CUDA backend. Decides whether to use one device and generateSingleThread_CU or multiple devices and create new threads which calls generateThreadFunc_CU. In the case of several devices the input range is divided evenly among the threads created.
numElements | The number of elements to be generated. |
outputBegin | An iterator pointing to the first element in the range which will be overwritten with generated values. |
useNumGPU | Integer specifying how many devices to use. 0 = Implementation decides. |
References skepu::GenerateKernel_CU(), skepu::max(), MAX_GPU_DEVICES, and skepu::min().
|
inline |
Makes sure all operations on devices are finished.
References skepu::Environment< T >::finishAll().
void skepu::Generate< GenerateFunc >::OMP | ( | size_t | 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 which is resized to numElements. A wrapper for OMP(size_t numElements, OutputIterator outputBegin). For the OpenMP backend.
numElements | The number of elements to be generated. |
output | The output vector which will be overwritten with the generated values. |
References skepu::Vector< T >::begin(), skepu::Vector< T >::clear(), skepu::Vector< T >::resize(), and skepu::Vector< T >::size().
void skepu::Generate< GenerateFunc >::OMP | ( | size_t | numRows, |
size_t | numCols, | ||
Matrix< T > & | output | ||
) |
Generates a number of elements using the user function which the skeleton was created with. The elements are saved in an output matrix which is resized to numElements. For the OpenMP backend.
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. |
void skepu::Generate< GenerateFunc >::OMP | ( | size_t | numElements, |
OutputIterator | outputBegin | ||
) |
Generates a number of elements using the user function which the skeleton was created with. The elements are saved in an output range. For the OpenMP backend.
numElements | The number of elements to be generated. |
outputBegin | An iterator pointing to the first element in the range which will be overwritten with generated values. |
void skepu::Generate< GenerateFunc >::operator() | ( | size_t | 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, 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.
numElements | The number of elements to be generated. |
output | The output vector which will be overwritten with the generated values. |
void skepu::Generate< GenerateFunc >::operator() | ( | size_t | numRows, |
size_t | numCols, | ||
Matrix< T > & | output | ||
) |
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. |
void skepu::Generate< GenerateFunc >::operator() | ( | size_t | numElements, |
OutputIterator | outputBegin | ||
) |
Generates a number of elements using the user function which the skeleton was created with. The elements are saved in an output range.
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.
numElements | The number of elements to be generated. |
outputBegin | An iterator pointing to the first element in the range which will be overwritten with generated values. |
|
inline |
This function sets the constant that can be used in the generate user function.