JayBeams  0.1
Another project to have fun coding.
Public Member Functions | Static Public Member Functions | List of all members
jb::opencl::reducer_concept Class Reference

The interface for reducers assumed by jb::opencl::generic_reducer. More...

Inheritance diagram for jb::opencl::reducer_concept:

Public Member Functions

 reducer_concept (std::size_t size, boost::compute::command_queue const &queue)
 Constructor. More...
 

Static Public Member Functions

static std::string combine_body (char const *accumulated, char const *value)
 Produce a code segment to combine two values. More...
 
static std::string initialize_body (char const *dst)
 Produce a code segment to initialize a variable for name lhs. More...
 
static std::string transform_body (char const *dst, char const *src, char const *offset)
 Produce the code segment for the initial transform of the input. More...
 

Detailed Description

The interface for reducers assumed by jb::opencl::generic_reducer.

The generic reduce algorithm is implemented using the Curiously Recurring Template Pattern (CRTP), the derived class must provide the following interface, and derive from generic_reduced with the derived class as a template parameter.

The reducer just provides three small code segments:

  1. the reduction function itself, in combine_body().
  2. an initializer for the results, in initialize_body().
  3. the initial transformation of the inputs. Some reducers (for example argmax), need to transform the input data before they can start work on it.

Definition at line 20 of file reducer_concept.dox.

Constructor & Destructor Documentation

◆ reducer_concept()

jb::opencl::reducer_concept::reducer_concept ( std::size_t  size,
boost::compute::command_queue const &  queue 
)
inline

Constructor.

Definition at line 24 of file reducer_concept.dox.

Member Function Documentation

◆ combine_body()

static std::string jb::opencl::reducer_concept::combine_body ( char const *  accumulated,
char const *  value 
)
inlinestatic

Produce a code segment to combine two values.

Parameters
accumulatedthe name of the variable used as an accumulator.
valuethe new value to be considered
Returns
a code segment initializing updating the accumulated variable. For example, if this was the MIN reduction the code might be:
if (*accumulated > *value) { *accumulated = *value; }
or
*accumulated = min(*accumulated, *value);
both as strings, of course.

Definition at line 46 of file reducer_concept.dox.

◆ initialize_body()

static std::string jb::opencl::reducer_concept::initialize_body ( char const *  dst)
inlinestatic

Produce a code segment to initialize a variable for name lhs.

Parameters
dstthe name of the variable to initialize.
Returns
a code segment initializing the variable, for example, if this was the MAX reduction the code might be:
*lhs = MIN_FLOAT;

Definition at line 59 of file reducer_concept.dox.

◆ transform_body()

static std::string jb::opencl::reducer_concept::transform_body ( char const *  dst,
char const *  src,
char const *  offset 
)
inlinestatic

Produce the code segment for the initial transform of the input.

Some reductions make a transformation of the data in the first transform, this is a hook to create the body of this function. Most reductions would simply use "*lhs = *value".

Parameters
dstthe name of the variable where the result will be stored.
srcthe name of the variable where the input value is stored.
offsetthe name of the variable where the input offset (in the global input vector) is stored.
Returns
a code segment implementing the initial transform phase. For example, if we are implementing "max of imaginary part" this could be:
*lhs = value->y;
Likewise, if we are implementing "ARGMAX" this could be implemented as:
dst->offset = offset; dst->value = *src;

Definition at line 89 of file reducer_concept.dox.


The documentation for this class was generated from the following file: