CLOGS
C++ library for sorting and searching in OpenCL applications
clogs::Reduce Class Reference

Reduction primitive. More...

#include <reduce.h>

Inheritance diagram for clogs::Reduce:
Collaboration diagram for clogs::Reduce:

Public Member Functions

 Reduce ()
 Default constructor. More...
 
 Reduce (const cl::Context &context, const cl::Device &device, const ReduceProblem &problem)
 Constructor. More...
 
 Reduce (cl_context context, cl_device_id device, const ReduceProblem &problem)
 Constructor. More...
 
 ~Reduce ()
 Destructor.
 
void enqueue (const cl::CommandQueue &commandQueue, const cl::Buffer &inBuffer, const cl::Buffer &outBuffer,::size_t first,::size_t elements,::size_t outPosition, const VECTOR_CLASS< cl::Event > *events=NULL, cl::Event *event=NULL)
 Enqueue a reduction operation on a command queue. More...
 
void enqueue (cl_command_queue commandQueue, cl_mem inBuffer, cl_mem outBuffer,::size_t first,::size_t elements,::size_t outPosition, cl_uint numEvents=0, const cl_event *events=NULL, cl_event *event=NULL)
 
void enqueue (const cl::CommandQueue &commandQueue, bool blocking, const cl::Buffer &inBuffer, void *out,::size_t first,::size_t elements, const VECTOR_CLASS< cl::Event > *events=NULL, cl::Event *event=NULL)
 Enqueue a reduction operation and read the result back to the host. More...
 
void enqueue (cl_command_queue commandQueue, bool blocking, cl_mem inBuffer, void *out,::size_t first,::size_t elements, cl_uint numEvents=0, const cl_event *events=NULL, cl_event *event=NULL)
 
- Public Member Functions inherited from clogs::Algorithm
void setEventCallback (void(*callback)(const cl::Event &, void *), void *userData, void(*free)(void *)=NULL)
 Set a callback function that will receive a list of all underlying events. More...
 
template<typename T >
void setEventCallback (const T &callback)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.The provided function object will be passed a cl::Event. More...
 
void setEventCallback (void(*callback)(cl_event, void *), void *userData, void(*free)(void *)=NULL)
 

Protected Member Functions

void enqueue (cl_command_queue commandQueue, cl_mem inBuffer, cl_mem outBuffer,::size_t first,::size_t elements,::size_t outPosition, cl_uint numEvents, const cl_event *events, cl_event *event, cl_int &err, const char *&errStr)
 
void enqueue (cl_command_queue commandQueue, bool blocking, cl_mem inBuffer, void *out,::size_t first,::size_t elements, cl_uint numEvents, const cl_event *events, cl_event *event, cl_int &err, const char *&errStr)
 
- Protected Member Functions inherited from clogs::Algorithm
void moveConstruct (Algorithm &other)
 Constructs this by stealing the pointer from other.
 
detail::Algorithm * moveAssign (Algorithm &other)
 Sets this by stealing the pointer from other, and returning the previous value.
 
void swap (Algorithm &other)
 Swaps the pointers between this and other.
 
detail::Algorithm * getDetail () const
 Returns the embedded pointer.
 
detail::Algorithm * getDetailNonNull () const
 Returns the embedded pointer. More...
 
void setDetail (detail::Algorithm *ptr)
 Set the value of the embedded pointer. More...
 

Friends

void swap (Reduce &, Reduce &)
 

Detailed Description

Reduction primitive.

One instance of this class can be reused for multiple scans, provided that

  • calls to enqueue do not overlap; and
  • their execution does not overlap.

An instance of the class is specialized to a specific context, device, and type of value to scan. Any CL integral scalar or vector type can be used.

The implementation divides the data into a number of blocks, each of which is reduced by a work-group. The last work-group handles the final reduction.

Constructor & Destructor Documentation

clogs::Reduce::Reduce ( )

Default constructor.

The object cannot be used in this state.

clogs::Reduce::Reduce ( const cl::Context &  context,
const cl::Device &  device,
const ReduceProblem problem 
)
inline

Constructor.

Parameters
contextOpenCL context to use
deviceOpenCL device to use.
problemDescription of the specific reduction problem.
Exceptions
std::invalid_argumentif problem is not supported on the device or is not initialized.
clogs::InternalErrorif there was a problem with initialization.
clogs::Reduce::Reduce ( cl_context  context,
cl_device_id  device,
const ReduceProblem problem 
)
inline

Constructor.

This class will add new references to the context and device.

Parameters
contextOpenCL context to use
deviceOpenCL device to use.
problemDescription of the specific reduction problem.
Exceptions
std::invalid_argumentif problem is not supported on the device or is not initialized.
clogs::InternalErrorif there was a problem with initialization.

Member Function Documentation

void clogs::Reduce::enqueue ( const cl::CommandQueue &  commandQueue,
const cl::Buffer &  inBuffer,
const cl::Buffer &  outBuffer,
::size_t  first,
::size_t  elements,
::size_t  outPosition,
const VECTOR_CLASS< cl::Event > *  events = NULL,
cl::Event *  event = NULL 
)
inline

Enqueue a reduction operation on a command queue.

Parameters
commandQueueThe command queue to use.
inBufferThe buffer to reduce.
outBufferThe buffer to which the result is written.
firstThe index (in elements, not bytes) to begin the reduction.
elementsThe number of elements to reduce.
outPositionThe index (in elements, not bytes) at which to write the result.
eventsEvents to wait for before starting.
eventEvent that will be signaled on completion.
Exceptions
cl::ErrorIf inBuffer is not readable on the device
cl::ErrorIf outBuffer is not writable on the devic
cl::ErrorIf the element range overruns the buffer.
cl::ErrorIf elements is zero.
Precondition
  • commandQueue was created with the context and device given to the constructor.
  • The output does not overlap with the input.
void clogs::Reduce::enqueue ( cl_command_queue  commandQueue,
cl_mem  inBuffer,
cl_mem  outBuffer,
::size_t  first,
::size_t  elements,
::size_t  outPosition,
cl_uint  numEvents = 0,
const cl_event *  events = NULL,
cl_event *  event = NULL 
)
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

void clogs::Reduce::enqueue ( const cl::CommandQueue &  commandQueue,
bool  blocking,
const cl::Buffer &  inBuffer,
void *  out,
::size_t  first,
::size_t  elements,
const VECTOR_CLASS< cl::Event > *  events = NULL,
cl::Event *  event = NULL 
)
inline

Enqueue a reduction operation and read the result back to the host.

This is a convenience wrapper that avoids the need to separately call clEnqueueReadBuffer.

void clogs::Reduce::enqueue ( cl_command_queue  commandQueue,
bool  blocking,
cl_mem  inBuffer,
void *  out,
::size_t  first,
::size_t  elements,
cl_uint  numEvents = 0,
const cl_event *  events = NULL,
cl_event *  event = NULL 
)
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.


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