Bolt  1.1
C++ template library with support for OpenCL
Functions
CL-transform_reduce

Functions

template<typename InputIterator , typename UnaryFunction , typename T , typename BinaryFunction >
bolt::cl::transform_reduce (control &ctl, InputIterator first, InputIterator last, UnaryFunction transform_op, T init, BinaryFunction reduce_op, const std::string &user_code="")
 transform_reduce fuses transform and reduce operations together, increasing performance by reducing memory passes.
 
template<typename InputIterator , typename UnaryFunction , typename T , typename BinaryFunction >
bolt::cl::transform_reduce (InputIterator first, InputIterator last, UnaryFunction transform_op, T init, BinaryFunction reduce_op, const std::string &user_code="")
 

Detailed Description

Function Documentation

template<typename InputIterator , typename UnaryFunction , typename T , typename BinaryFunction >
T bolt::cl::transform_reduce ( control &  ctl,
InputIterator  first,
InputIterator  last,
UnaryFunction  transform_op,
init,
BinaryFunction  reduce_op,
const std::string &  user_code = "" 
)

transform_reduce fuses transform and reduce operations together, increasing performance by reducing memory passes.

Logically, a transform operation is performed over the input sequence using the unary function and stored into a temporary sequence; then, a reduction operation is applied using the binary function to return a single value.

Parameters
ctlOptional Control structure to control command-queue, debug, tuning, etc.See bolt::cl::control.
firstThe beginning of the input sequence.
lastThe end of the input sequence.
transform_opA unary tranformation operation.
initThe initial value for the accumulator.
reduce_opThe binary operation used to combine two values. By default, the binary operation is plus<>().
user_codeOptional OpenCL™ code to be passed to the OpenCL compiler. The cl_code is inserted first in the generated code, before the cl_code trait.
Returns
The result of the combined transform and reduction.
Template Parameters
TThe type of the result.
InputIteratoris a model of an InputIterator. and InputIterator's value_type is convertible to BinaryFunction's first_argument_type.
UnaryFunctionis a model of Unary Function. and UnaryFunction's result_type is convertible to InputIterator's value_type.
BinaryFunctionis a model of Binary Function. and BinaryFunction's result_type is convertible to InputIterator's value_type.
int input[10] = {-5, 0, 2, 3, 2, 4, -2, 1, 2, 3};
int output;
bolt::cl::transform_reduce( input, input + 10, bolt::cl::square<int>(), 0, bolt::cl::plus<int>() );
// output is 76
See Also
http://www.sgi.com/tech/stl/InputIterator.html
http://www.sgi.com/tech/stl/OutputIterator.html
http://www.sgi.com/tech/stl/UnaryFunction.html
http://www.sgi.com/tech/stl/BinaryFunction.html