A class representing the Scan skeleton. More...
#include <scan.h>
Public Member Functions | |
Scan (ScanFunc *scanFunc) | |
~Scan () | |
template<typename T > | |
void | operator() (Vector< T > &input, ScanType type, T init=T()) |
template<typename T > | |
void | operator() (Matrix< T > &input, ScanType type, T init=T()) |
template<typename InputIterator > | |
void | operator() (InputIterator inputBegin, InputIterator inputEnd, ScanType type, typename InputIterator::value_type init=typename InputIterator::value_type()) |
template<typename T > | |
void | operator() (Vector< T > &input, Vector< T > &output, ScanType type, T init=T()) |
template<typename T > | |
void | operator() (Matrix< T > &input, Matrix< T > &output, ScanType type, T init=T()) |
template<typename InputIterator , typename OutputIterator > | |
void | operator() (InputIterator inputBegin, InputIterator inputEnd, OutputIterator outputBegin, ScanType type, typename InputIterator::value_type init=typename InputIterator::value_type()) |
template<typename T > | |
void | CPU (Vector< T > &input, ScanType type=INCLUSIVE, T init=T()) |
template<typename T > | |
void | CPU (Matrix< T > &input, ScanType type, T init=T()) |
template<typename InputIterator > | |
void | CPU (InputIterator inputBegin, InputIterator inputEnd, ScanType type=INCLUSIVE, typename InputIterator::value_type init=typename InputIterator::value_type()) |
template<typename T > | |
void | CPU (Vector< T > &input, Vector< T > &output, ScanType type=INCLUSIVE, T init=T()) |
template<typename T > | |
void | CPU (Matrix< T > &input, Matrix< T > &output, ScanType type, T init=T()) |
template<typename InputIterator , typename OutputIterator > | |
void | CPU (InputIterator inputBegin, InputIterator inputEnd, OutputIterator outputBegin, ScanType type=INCLUSIVE, typename InputIterator::value_type init=typename InputIterator::value_type()) |
template<typename T > | |
void | OMP (Vector< T > &input, ScanType type=INCLUSIVE, T init=T()) |
template<typename T > | |
void | OMP (Matrix< T > &input, ScanType type, T init=T()) |
template<typename InputIterator > | |
void | OMP (InputIterator inputBegin, InputIterator inputEnd, ScanType type=INCLUSIVE, typename InputIterator::value_type init=typename InputIterator::value_type()) |
template<typename T > | |
void | OMP (Vector< T > &input, Vector< T > &output, ScanType type=INCLUSIVE, T init=T()) |
template<typename T > | |
void | OMP (Matrix< T > &input, Matrix< T > &output, ScanType type, T init=T()) |
template<typename InputIterator , typename OutputIterator > | |
void | OMP (InputIterator inputBegin, InputIterator inputEnd, OutputIterator outputBegin, ScanType type=INCLUSIVE, typename InputIterator::value_type init=typename InputIterator::value_type()) |
template<typename T > | |
void | CU (Vector< T > &input, ScanType type=INCLUSIVE, T init=T(), int useNumGPU=1) |
template<typename InputIterator > | |
void | CU (InputIterator inputBegin, InputIterator inputEnd, ScanType type=INCLUSIVE, typename InputIterator::value_type init=typename InputIterator::value_type(), int useNumGPU=1) |
template<typename T > | |
void | CU (Vector< T > &input, Vector< T > &output, ScanType type=INCLUSIVE, T init=T(), int useNumGPU=1) |
template<typename InputIterator , typename OutputIterator > | |
void | CU (InputIterator inputBegin, InputIterator inputEnd, OutputIterator outputBegin, ScanType type=INCLUSIVE, typename InputIterator::value_type init=typename InputIterator::value_type(), int useNumGPU=1) |
template<typename T > | |
void | CL (Vector< T > &input, ScanType type=INCLUSIVE, T init=T(), int useNumGPU=1) |
template<typename InputIterator > | |
void | CL (InputIterator inputBegin, InputIterator inputEnd, ScanType type=INCLUSIVE, typename InputIterator::value_type init=typename InputIterator::value_type(), int useNumGPU=1) |
template<typename T > | |
void | CL (Vector< T > &input, Vector< T > &output, ScanType type=INCLUSIVE, T init=T(), int useNumGPU=1) |
template<typename InputIterator , typename OutputIterator > | |
void | CL (InputIterator inputBegin, InputIterator inputEnd, OutputIterator outputBegin, ScanType type=INCLUSIVE, typename InputIterator::value_type init=typename InputIterator::value_type(), int useNumGPU=1) |
A class representing the Scan skeleton.
This class defines the Scan skeleton, also known as prefix sum. It is related to the Scan operation but instead of producing a single scalar result it produces an output vector of the same length as the input with its elements being the reduction of itself all elements preceding it in the input. For example the input vector [4 3 7 6 9] would produce the result vector [4 7 14 20 29]. The Scan operation can either include or exclude the current element. It can be either inclusive or exclusive. In the previous example a inclusive scan was performed, the exclusive result would be [0 4 7 14 20]. Exclusive scan is sometimes called prescan. This Scan skeleton supports both variants by adding a parameter to the function calls, default is inclusive.
Once instantiated, it is meant to be used as a function and therefore overloading operator()
. There are a few overloaded variants of this operator depending on if a seperate output vector is provided or if vectors or iterators are used as parameters.
If a certain backend 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.
The Scan skeleton also includes a pointer to an Environment which, in turn, includes the devices available to execute on.
skepu::Scan< ScanFunc >::Scan | ( | ScanFunc * | scanFunc | ) |
When creating an instance of the Scan skeleton, a pointer to a binary 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.
scanFunc | A pointer to a valid binary user function. Will be deleted in the destructor. |
References skepu::Environment< T >::getInstance().
skepu::Scan< ScanFunc >::~Scan | ( | ) |
When the Scan skeleton is destroyed, it deletes the user function it was created with.
void skepu::Scan< ScanFunc >::CL | ( | Vector< T > & | input, |
ScanType | type = INCLUSIVE , |
||
T | init = T() , |
||
int | useNumGPU = 1 |
||
) |
Performs the Scan on a whole Vector using OpenCL with the input as output. A wrapper for CL(InputIterator inputBegin, InputIterator inputEnd, OutputIterator outputBegin, ScanType type, typename InputIterator::value_type init, int useNumGPU).
input | A vector which will be scanned. It will be overwritten with the result. |
type | The scan type, either INCLUSIVE or EXCLUSIVE. |
init | The initialization value for exclusive scans. |
useNumGPU | Integer specifying how many devices to use. 0 = Implementation decides. |
References skepu::Vector< T >::begin(), and skepu::Vector< T >::end().
void skepu::Scan< ScanFunc >::CL | ( | InputIterator | inputBegin, |
InputIterator | inputEnd, | ||
ScanType | type = INCLUSIVE , |
||
typename InputIterator::value_type | init = typename InputIterator::value_type() , |
||
int | useNumGPU = 1 |
||
) |
Performs the Scan on an input range using OpenCL with the input range also used as an output. A wrapper for CL(InputIterator inputBegin, InputIterator inputEnd, OutputIterator outputBegin, ScanType type, typename InputIterator::value_type init, int useNumGPU).
inputBegin | A Vector::iterator to the first element in the range. |
inputEnd | A Vector::iterator to the last element of the range. |
type | The scan type, either INCLUSIVE or EXCLUSIVE. |
init | The initialization value for exclusive scans. |
useNumGPU | Integer specifying how many devices to use. 0 = Implementation decides. |
void skepu::Scan< ScanFunc >::CL | ( | Vector< T > & | input, |
Vector< T > & | output, | ||
ScanType | type = INCLUSIVE , |
||
T | init = T() , |
||
int | useNumGPU = 1 |
||
) |
Performs the Scan on a whole Vector using OpenCL with a separate Vector as output. The output Vector will be resized an overwritten. A wrapper for CL(InputIterator inputBegin, InputIterator inputEnd, OutputIterator outputBegin, ScanType type, typename InputIterator::value_type init, int useNumGPU).
input | A vector which will be scanned. |
output | The result vector, will be overwritten with the result and resized if needed. |
type | The scan type, either INCLUSIVE or EXCLUSIVE. |
init | The initialization value for exclusive scans. |
useNumGPU | Integer specifying how many devices to use. 0 = Implementation decides. |
References skepu::Vector< T >::begin(), skepu::Vector< T >::clear(), skepu::Vector< T >::end(), skepu::Vector< T >::resize(), and skepu::Vector< T >::size().
void skepu::Scan< ScanFunc >::CL | ( | InputIterator | inputBegin, |
InputIterator | inputEnd, | ||
OutputIterator | outputBegin, | ||
ScanType | type = INCLUSIVE , |
||
typename InputIterator::value_type | init = typename InputIterator::value_type() , |
||
int | useNumGPU = 1 |
||
) |
Performs the Scan on a range of elements. Returns a scalar result. The function decides whether to perform the reduction on one device, calling scanSingle_CL or on multiple devices, calling scanNumDevices_CL. Using OpenCL as backend.
inputBegin | A Vector::iterator to the first element in the range. |
inputEnd | A Vector::iterator to the last element of the range. |
outputBegin | A Vector::iterator to the first element of the output range. |
type | The scan type, either INCLUSIVE or EXCLUSIVE. |
init | The initialization value for exclusive scans. |
useNumGPU | Integer specifying how many devices to use. 0 = Implementation decides. |
void skepu::Scan< ScanFunc >::CPU | ( | Vector< T > & | input, |
ScanType | type = INCLUSIVE , |
||
T | init = T() |
||
) |
Performs the Scan on a whole Vector on the CPU with itself as output. A wrapper for CPU(InputIterator inputBegin, InputIterator inputEnd, ScanType type, typename InputIterator::value_type init).
input | A vector which will be scanned. It will be overwritten with the result. |
type | The scan type, either INCLUSIVE or EXCLUSIVE. |
init | The initialization value for exclusive scans. |
References skepu::Vector< T >::begin(), and skepu::Vector< T >::end().
void skepu::Scan< ScanFunc >::CPU | ( | Matrix< T > & | input, |
ScanType | type, | ||
T | init = T() |
||
) |
void skepu::Scan< ScanFunc >::CPU | ( | InputIterator | inputBegin, |
InputIterator | inputEnd, | ||
ScanType | type = INCLUSIVE , |
||
typename InputIterator::value_type | init = typename InputIterator::value_type() |
||
) |
Performs the Scan on a range of elements on the CPU with the same range as output.
inputBegin | A Vector::iterator to the first element in the range. |
inputEnd | A Vector::iterator to the last element of the range. |
type | The scan type, either INCLUSIVE or EXCLUSIVE. |
init | The initialization value for exclusive scans. |
void skepu::Scan< ScanFunc >::CPU | ( | Vector< T > & | input, |
Vector< T > & | output, | ||
ScanType | type = INCLUSIVE , |
||
T | init = T() |
||
) |
Performs the Scan on a whole Vector on the CPU with a seperate output vector. Wrapper for CPU(InputIterator inputBegin, InputIterator inputEnd, OutputIterator outputBegin, ScanType type, typename InputIterator::value_type init).
input | A vector which will be scanned. |
output | The result vector, will be overwritten with the result and resized if needed. |
type | The scan type, either INCLUSIVE or EXCLUSIVE. |
init | The initialization value for exclusive scans. |
References skepu::Vector< T >::begin(), skepu::Vector< T >::clear(), skepu::Vector< T >::end(), skepu::Vector< T >::resize(), and skepu::Vector< T >::size().
void skepu::Scan< ScanFunc >::CPU | ( | Matrix< T > & | input, |
Matrix< T > & | output, | ||
ScanType | type, | ||
T | init = T() |
||
) |
Performs the row-wise Scan on a whole Matrix on the CPU with a separate Matrix as output.
input | A matrix which will be scanned. |
output | The result matrix, will be overwritten with the result and resized if needed. |
type | The scan type, either INCLUSIVE or EXCLUSIVE. |
init | The initialization value for exclusive scans. |
void skepu::Scan< ScanFunc >::CPU | ( | InputIterator | inputBegin, |
InputIterator | inputEnd, | ||
OutputIterator | outputBegin, | ||
ScanType | type = INCLUSIVE , |
||
typename InputIterator::value_type | init = typename InputIterator::value_type() |
||
) |
Performs the Scan on a range of elements on the CPU with a seperate output range.
inputBegin | A Vector::iterator to the first element in the range. |
inputEnd | A Vector::iterator to the last element of the range. |
outputBegin | A Vector::iterator to the first element of the output range. |
type | The scan type, either INCLUSIVE or EXCLUSIVE. |
init | The initialization value for exclusive scans. |
void skepu::Scan< ScanFunc >::CU | ( | Vector< T > & | input, |
ScanType | type = INCLUSIVE , |
||
T | init = T() , |
||
int | useNumGPU = 1 |
||
) |
Performs the Scan on a whole Vector using CUDA with the input as output. A wrapper for CU(InputIterator inputBegin, InputIterator inputEnd, OutputIterator outputBegin, ScanType type, typename InputIterator::value_type init, int useNumGPU).
input | A vector which will be scanned. It will be overwritten with the result. |
type | The scan type, either INCLUSIVE or EXCLUSIVE. |
init | The initialization value for exclusive scans. |
useNumGPU | Integer specifying how many devices to use. 0 = Implementation decides. |
References skepu::Vector< T >::begin(), and skepu::Vector< T >::end().
void skepu::Scan< ScanFunc >::CU | ( | InputIterator | inputBegin, |
InputIterator | inputEnd, | ||
ScanType | type = INCLUSIVE , |
||
typename InputIterator::value_type | init = typename InputIterator::value_type() , |
||
int | useNumGPU = 1 |
||
) |
Performs the Scan on an input range using CUDA with the input range also used as an output. A wrapper for CU(InputIterator inputBegin, InputIterator inputEnd, OutputIterator outputBegin, ScanType type, typename InputIterator::value_type init, int useNumGPU).
inputBegin | A Vector::iterator to the first element in the range. |
inputEnd | A Vector::iterator to the last element of the range. |
type | The scan type, either INCLUSIVE or EXCLUSIVE. |
init | The initialization value for exclusive scans. |
useNumGPU | Integer specifying how many devices to use. 0 = Implementation decides. |
void skepu::Scan< ScanFunc >::CU | ( | Vector< T > & | input, |
Vector< T > & | output, | ||
ScanType | type = INCLUSIVE , |
||
T | init = T() , |
||
int | useNumGPU = 1 |
||
) |
Performs the Scan on a whole Vector using CUDA with a separate Vector as output. The output Vector will be resized an overwritten. A wrapper for CU(InputIterator inputBegin, InputIterator inputEnd, OutputIterator outputBegin, ScanType type, typename InputIterator::value_type init, int useNumGPU).
input | A vector which will be scanned. |
output | The result vector, will be overwritten with the result and resized if needed. |
type | The scan type, either INCLUSIVE or EXCLUSIVE. |
init | The initialization value for exclusive scans. |
useNumGPU | Integer specifying how many devices to use. 0 = Implementation decides. |
References skepu::Vector< T >::begin(), skepu::Vector< T >::clear(), skepu::Vector< T >::end(), skepu::Vector< T >::resize(), and skepu::Vector< T >::size().
void skepu::Scan< ScanFunc >::CU | ( | InputIterator | inputBegin, |
InputIterator | inputEnd, | ||
OutputIterator | outputBegin, | ||
ScanType | type = INCLUSIVE , |
||
typename InputIterator::value_type | init = typename InputIterator::value_type() , |
||
int | useNumGPU = 1 |
||
) |
Performs the Scan on an input range using CUDA with a separate output range. The function decides whether to perform the scan on one device, calling scanSingleThread_CU or on multiple devices, dividing the work between multiple devices.
inputBegin | A Vector::iterator to the first element in the range. |
inputEnd | A Vector::iterator to the last element of the range. |
outputBegin | A Vector::iterator to the first element of the output range. |
type | The scan type, either INCLUSIVE or EXCLUSIVE. |
init | The initialization value for exclusive scans. |
useNumGPU | Integer specifying how many devices to use. 0 = Implementation decides. |
References skepu::min(), skepu::Vector< T >::push_back(), skepu::ScanAdd_CU(), and skepu::scanLargeVectorRecursivelyM_CU().
void skepu::Scan< ScanFunc >::OMP | ( | Vector< T > & | input, |
ScanType | type = INCLUSIVE , |
||
T | init = T() |
||
) |
Performs the Scan on a whole Vector with itself as output using OpenMP as backend. A wrapper for OMP(InputIterator inputBegin, InputIterator inputEnd, ScanType type, typename InputIterator::value_type init).
input | A vector which will be scanned. It will be overwritten with the result. |
type | The scan type, either INCLUSIVE or EXCLUSIVE. |
init | The initialization value for exclusive scans. |
References skepu::Vector< T >::begin(), and skepu::Vector< T >::end().
void skepu::Scan< ScanFunc >::OMP | ( | Matrix< T > & | input, |
ScanType | type, | ||
T | init = T() |
||
) |
void skepu::Scan< ScanFunc >::OMP | ( | InputIterator | inputBegin, |
InputIterator | inputEnd, | ||
ScanType | type = INCLUSIVE , |
||
typename InputIterator::value_type | init = typename InputIterator::value_type() |
||
) |
Performs the Scan on a range of elements with the same range as output using OpenMP as backend.
inputBegin | A Vector::iterator to the first element in the range. |
inputEnd | A Vector::iterator to the last element of the range. |
type | The scan type, either INCLUSIVE or EXCLUSIVE. |
init | The initialization value for exclusive scans. |
void skepu::Scan< ScanFunc >::OMP | ( | Vector< T > & | input, |
Vector< T > & | output, | ||
ScanType | type = INCLUSIVE , |
||
T | init = T() |
||
) |
Performs the Scan on a whole Vector with a seperate output vector using OpenMP as backend. Wrapper for OMP(InputIterator inputBegin, InputIterator inputEnd, OutputIterator outputBegin, ScanType type, typename InputIterator::value_type init).
input | A vector which will be scanned. |
output | The result vector, will be overwritten with the result and resized if needed. |
type | The scan type, either INCLUSIVE or EXCLUSIVE. |
init | The initialization value for exclusive scans. |
References skepu::Vector< T >::begin(), skepu::Vector< T >::clear(), skepu::Vector< T >::end(), skepu::Vector< T >::resize(), and skepu::Vector< T >::size().
void skepu::Scan< ScanFunc >::OMP | ( | Matrix< T > & | input, |
Matrix< T > & | output, | ||
ScanType | type, | ||
T | init = T() |
||
) |
Performs the Scan on a whole Matrix with a separate Matrix as output using OpenMP as backend.
input | A matrix which will be scanned. |
output | The result matrix, will be overwritten with the result and resized if needed. |
type | The scan type, either INCLUSIVE or EXCLUSIVE. |
init | The initialization value for exclusive scans. |
void skepu::Scan< ScanFunc >::OMP | ( | InputIterator | inputBegin, |
InputIterator | inputEnd, | ||
OutputIterator | outputBegin, | ||
ScanType | type = INCLUSIVE , |
||
typename InputIterator::value_type | init = typename InputIterator::value_type() |
||
) |
Performs the Scan on a range of elements with a seperate output range using OpenMP as backend.
inputBegin | A Vector::iterator to the first element in the range. |
inputEnd | A Vector::iterator to the last element of the range. |
outputBegin | A Vector::iterator to the first element of the output range. |
type | The scan type, either INCLUSIVE or EXCLUSIVE. |
init | The initialization value for exclusive scans. |
void skepu::Scan< ScanFunc >::operator() | ( | Vector< T > & | input, |
ScanType | type, | ||
T | init = T() |
||
) |
Performs the Scan on a whole Vector. With itself as output.
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.
input | A vector which will be scanned. It will be overwritten with the result. |
type | The scan type, either INCLUSIVE or EXCLUSIVE. |
init | The initialization value for exclusive scans. |
References skepu::Vector< T >::isModified_CU(), skepu::Vector< T >::isVectorOnDevice_CU(), and skepu::Vector< T >::size().
void skepu::Scan< ScanFunc >::operator() | ( | Matrix< T > & | input, |
ScanType | type, | ||
T | init = T() |
||
) |
Performs the Scan on a whole Matrix. With itself as output.
Depending on which backend was used, different versions of the skeleton is called. If SKEPU_OPENMP
are defined then the OpenMP backend is used. As a fallback there is always a CPU version.
input | A matrix which will be scanned. It will be overwritten with the result. |
type | The scan type, either INCLUSIVE or EXCLUSIVE. |
init | The initialization value for exclusive scans. |
void skepu::Scan< ScanFunc >::operator() | ( | InputIterator | inputBegin, |
InputIterator | inputEnd, | ||
ScanType | type, | ||
typename InputIterator::value_type | init = typename InputIterator::value_type() |
||
) |
Performs the Scan on a range of elements. With the same range as output.
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.
inputBegin | A Vector::iterator to the first element in the range. |
inputEnd | A Vector::iterator to the last element of the range. |
type | The scan type, either INCLUSIVE or EXCLUSIVE. |
init | The initialization value for exclusive scans. |
void skepu::Scan< ScanFunc >::operator() | ( | Vector< T > & | input, |
Vector< T > & | output, | ||
ScanType | type, | ||
T | init = T() |
||
) |
Performs the Scan on a whole Vector. With a seperate Vector as output.
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.
input | A vector which will be scanned. |
output | The result vector, will be overwritten with the result and resized if needed. |
type | The scan type, either INCLUSIVE or EXCLUSIVE. |
init | The initialization value for exclusive scans. |
References skepu::Vector< T >::isModified_CU(), skepu::Vector< T >::isVectorOnDevice_CU(), and skepu::Vector< T >::size().
void skepu::Scan< ScanFunc >::operator() | ( | Matrix< T > & | input, |
Matrix< T > & | output, | ||
ScanType | type, | ||
T | init = T() |
||
) |
Performs the Scan on a whole Matrix. With a seperate Matrix as output.
Depending on which backend was used, different versions of the skeleton is called. If SKEPU_OPENMP
are defined then the OpenMP backend is used. As a fallback there is always a CPU version.
input | A matrix which will be scanned. |
output | The result matrix, will be overwritten with the result and resized if needed. |
type | The scan type, either INCLUSIVE or EXCLUSIVE. |
init | The initialization value for exclusive scans. |
void skepu::Scan< ScanFunc >::operator() | ( | InputIterator | inputBegin, |
InputIterator | inputEnd, | ||
OutputIterator | outputBegin, | ||
ScanType | type, | ||
typename InputIterator::value_type | init = typename InputIterator::value_type() |
||
) |
Performs the Scan on a range of elements. With a seperate 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.
inputBegin | A Vector::iterator to the first element in the range. |
inputEnd | A Vector::iterator to the last element of the range. |
outputBegin | A Vector::iterator to the first element of the output range. |
type | The scan type, either INCLUSIVE or EXCLUSIVE. |
init | The initialization value for exclusive scans. |