Skip to content

Commit

Permalink
Documented creation of new reduction kind
Browse files Browse the repository at this point in the history
  • Loading branch information
ddemidov committed Sep 9, 2013
1 parent cdeab01 commit 6d54cab
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions vexcl/reductor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,29 @@ namespace vex {

/// Summation. Should be used as a template parameter for Reductor class.
struct SUM {
/* In order to define a reduction kind for vex::Reductor, one should:
*
* 1. Define initial value (e.g. 0 for sums, 1 for products, plus-minus
* infinity for extrema):
*/
template <typename T>
static T initial() {
return T();
};

/*
* 2. Provide an OpenCL function that will be used on compute device to do
* incremental reductions. That is nested struct "function":
*/
template <typename T>
struct function : UserFunction<function<T>, T(T, T)> {
static std::string body() { return "return prm1 + prm2;"; }
};

/*
* 3. Provide a host-side function that will be used for final reduction of
* small result vector on host:
*/
template <class Iterator>
static typename std::iterator_traits<Iterator>::value_type
reduce(Iterator begin, Iterator end) {
Expand Down

0 comments on commit 6d54cab

Please sign in to comment.