Bolt
1.3
C++ template library with support for OpenCL
|
Functions | |
template<typename InputIterator > | |
std::iterator_traits < InputIterator >::value_type | bolt::cl::reduce (bolt::cl::control &ctl, InputIterator first, InputIterator last, const std::string &cl_code="") |
reduce returns the result of combining all the elements in the specified range using the specified binary_op. The classic example is a summation, where the binary_op is the plus operator. By default, the initial value is "0" and the binary operator is "plus<>()". | |
template<typename InputIterator > | |
std::iterator_traits < InputIterator >::value_type | bolt::cl::reduce (InputIterator first, InputIterator last, const std::string &cl_code="") |
template<typename InputIterator , typename T > | |
T | bolt::cl::reduce (bolt::cl::control &ctl, InputIterator first, InputIterator last, T init, const std::string &cl_code="") |
reduce returns the result of combining all the elements in the specified range using the specified binary_op. The classic example is a summation, where the binary_op is the plus operator. By default, the initial value is "0" and the binary operator is "plus<>()". | |
template<typename InputIterator , typename T > | |
T | bolt::cl::reduce (InputIterator first, InputIterator last, T init, const std::string &cl_code="") |
template<typename InputIterator , typename T , typename BinaryFunction > | |
T | bolt::cl::reduce (bolt::cl::control &ctl, InputIterator first, InputIterator last, T init, BinaryFunction binary_op=bolt::cl::plus< T >(), const std::string &cl_code="") |
reduce returns the result of combining all the elements in the specified range using the specified binary_op. The classic example is a summation, where the binary_op is the plus operator. By default, the binary operator is "plus<>()". The version takes a bolt::cl::control structure as a first argument. | |
template<typename InputIterator , typename T , typename BinaryFunction > | |
T | bolt::cl::reduce (InputIterator first, InputIterator last, T init, BinaryFunction binary_op, const std::string &cl_code="") |
std::iterator_traits< InputIterator >::value_type bolt::cl::reduce | ( | bolt::cl::control & | ctl, |
InputIterator | first, | ||
InputIterator | last, | ||
const std::string & | cl_code = "" |
||
) |
reduce
returns the result of combining all the elements in the specified range using the specified binary_op. The classic example is a summation, where the binary_op is the plus operator. By default, the initial value is "0" and the binary operator is "plus<>()".
reduce
requires that the binary reduction op ("binary_op") be commutative. The order in which reduce
applies the binary_op is not deterministic. If the reduction operator is not commutative then bolt::reduce should not be used. Instead, one could use inclusive_scan (which does not require commutativity) and select the last element of the output array.
The reduce
operation is similar the std::accumulate function
ctl | Optional Control structure to control command-queue, debug, tuning. |
first | The first position in the sequence to be reduced. |
last | The last position in the sequence to be reduced. |
cl_code | Optional OpenCL(TM) code to be passed to the OpenCL compiler. The cl_code is inserted first in the generated code, before the cl_code trait. |
InputIterator | An iterator that can be dereferenced for an object, and can be incremented to get to the next element in a sequence. |
T | The type of the result. |
The following code example shows the use of reduce
to sum 10 numbers, using the default plus operator.
T bolt::cl::reduce | ( | bolt::cl::control & | ctl, |
InputIterator | first, | ||
InputIterator | last, | ||
T | init, | ||
const std::string & | cl_code = "" |
||
) |
reduce
returns the result of combining all the elements in the specified range using the specified binary_op. The classic example is a summation, where the binary_op is the plus operator. By default, the initial value is "0" and the binary operator is "plus<>()".
reduce
requires that the binary reduction op ("binary_op") be commutative. The order in which reduce
applies the binary_op is not deterministic. If the reduction operator is not commutative then bolt::reduce should not be used. Instead, one could use inclusive_scan (which does not require commutativity) and select the last element of the output array.
The reduce
operation is similar the std::accumulate function
ctl | Optional Control structure to control command-queue, debug, tuning. |
first | The first position in the sequence to be reduced. |
last | The last position in the sequence to be reduced. |
init | The initial value for the accumulator. |
cl_code | Optional OpenCL(TM) code to be passed to the OpenCL compiler. The cl_code is inserted first in the generated code, before the cl_code trait. |
InputIterator | An iterator that can be dereferenced for an object, and can be incremented to get to the next element in a sequence. |
T | The type of the result. |
The following code example shows the use of reduce
to sum 10 numbers, using the default plus operator.
T bolt::cl::reduce | ( | bolt::cl::control & | ctl, |
InputIterator | first, | ||
InputIterator | last, | ||
T | init, | ||
BinaryFunction | binary_op = bolt::cl::plus<T>() , |
||
const std::string & | cl_code = "" |
||
) |
reduce
returns the result of combining all the elements in the specified range using the specified binary_op. The classic example is a summation, where the binary_op is the plus operator. By default, the binary operator is "plus<>()". The version takes a bolt::cl::control structure as a first argument.
reduce
requires that the binary reduction op ("binary_op") be commutative. The order in which reduce
applies the binary_op is not deterministic. If the reduction operator is not commutative then bolt::reduce should not be used. Instead, one could use inclusive_scan (which does not require commutativity) and select the last element of the output array.
The reduce
operation is similar the std::accumulate function.
ctl | Optional Control structure to control command-queue, debug, tuning, etc. |
first | The first position in the sequence to be reduced. |
last | The last position in the sequence to be reduced. |
init | The initial value for the accumulator. |
binary_op | The binary operation used to combine two values. By default, the binary operation is plus<>(). |
cl_code | Optional OpenCL(TM) code to be passed to the OpenCL compiler. The cl_code is inserted first in the generated code, before the cl_code trait. |
InputIterator | An iterator that can be dereferenced for an object, and can be incremented to get to the next element in a sequence. |
BinaryFunction | A function object defining an operation that is applied to consecutive elements in the sequence. |
The following code example shows the use of reduce
to find the max of 10 numbers.