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

Exclusive scan (prefix sum) primitive. More...

#include <scan.h>

Inheritance diagram for clogs::Scan:
Collaboration diagram for clogs::Scan:

Public Member Functions

 Scan ()
 Default constructor. More...
 
 Scan (const cl::Context &context, const cl::Device &device, const Type &type)
 Constructor. More...
 
 Scan (const cl::Context &context, const cl::Device &device, const ScanProblem &problem)
 Constructor. More...
 
 ~Scan ()
 Destructor.
 
void enqueue (const cl::CommandQueue &commandQueue, const cl::Buffer &buffer,::size_t elements, const void *offset=NULL, const VECTOR_CLASS< cl::Event > *events=NULL, cl::Event *event=NULL)
 Enqueue a scan operation on a command queue (in-place). More...
 
void enqueue (const cl::CommandQueue &commandQueue, const cl::Buffer &inBuffer, const cl::Buffer &outBuffer,::size_t elements, const void *offset=NULL, const VECTOR_CLASS< cl::Event > *events=NULL, cl::Event *event=NULL)
 Enqueue a scan operation on a command queue. More...
 
void enqueue (cl_command_queue commandQueue, cl_mem inBuffer, cl_mem outBuffer,::size_t elements, const void *offset=NULL, cl_uint numEvents=0, const cl_event *events=NULL, cl_event *event=NULL)
 
void enqueue (const cl::CommandQueue &commandQueue, const cl::Buffer &buffer,::size_t elements, const cl::Buffer &offsetBuffer, cl_uint offsetIndex, const VECTOR_CLASS< cl::Event > *events=NULL, cl::Event *event=NULL)
 Enqueue a scan operation on a command queue, with an offset in a buffer (in-place). More...
 
void enqueue (const cl::CommandQueue &commandQueue, const cl::Buffer &inBuffer, const cl::Buffer &outBuffer,::size_t elements, const cl::Buffer &offsetBuffer, cl_uint offsetIndex, const VECTOR_CLASS< cl::Event > *events=NULL, cl::Event *event=NULL)
 Enqueue a scan operation on a command queue, with an offset in a buffer. More...
 
void enqueue (cl_command_queue commandQueue, cl_mem inBuffer, cl_mem outBuffer,::size_t elements, cl_mem offsetBuffer, cl_uint offsetIndex, 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 elements, const void *offset, cl_uint numEvents, const cl_event *events, cl_event *event, cl_int &err, const char *&errStr)
 
void enqueue (cl_command_queue commandQueue, cl_mem inBuffer, cl_mem outBuffer,::size_t elements, cl_mem offsetBuffer, cl_uint offsetIndex, cl_uint numEvents, const cl_event *events, cl_event *event, cl_int &err, const char *&errStr)
 
void moveAssign (Scan &other)
 
- 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 (Scan &, Scan &)
 

Detailed Description

Exclusive scan (prefix sum) 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 is based on the reduce-then-scan strategy described at https://sites.google.com/site/duanemerrill/ScanTR2.pdf?attredirects=0

Constructor & Destructor Documentation

clogs::Scan::Scan ( )

Default constructor.

The object cannot be used in this state.

clogs::Scan::Scan ( const cl::Context &  context,
const cl::Device &  device,
const Type type 
)
inline

Constructor.

Parameters
contextOpenCL context to use
deviceOpenCL device to use.
typeType of the values to scan.
Exceptions
std::invalid_argumentif type is not an integral type supported on the device.
clogs::InternalErrorif there was a problem with initialization.
Deprecated:
This interface is deprecated as it does not scale with future feature additions. Use the constructor taking a clogs::ScanProblem instead.
clogs::Scan::Scan ( const cl::Context &  context,
const cl::Device &  device,
const ScanProblem problem 
)
inline

Constructor.

Parameters
contextOpenCL context to use
deviceOpenCL device to use.
problemDescription of the specific scan 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::Scan::enqueue ( const cl::CommandQueue &  commandQueue,
const cl::Buffer &  buffer,
::size_t  elements,
const void *  offset = NULL,
const VECTOR_CLASS< cl::Event > *  events = NULL,
cl::Event *  event = NULL 
)
inline

Enqueue a scan operation on a command queue (in-place).

This is equivalent to calling enqueue(commandQueue, buffer, buffer, elements, offset, events, event);

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

Enqueue a scan operation on a command queue.

An initial offset may optionally be passed in offset, which will be added to all elements of the result. The pointer must point to the type of element specified to the constructor. If no offset is desired, NULL may be passed instead.

The input and output buffers may be the same to do an in-place scan.

Parameters
commandQueueThe command queue to use.
inBufferThe buffer to scan.
outBufferThe buffer to fill with output.
elementsThe number of elements to scan.
offsetThe offset to add to all elements, or NULL.
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 device.
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.
Postcondition
  • After execution, element i will be replaced by the sum of all elements strictly before i, plus the offset (if any).
void clogs::Scan::enqueue ( cl_command_queue  commandQueue,
cl_mem  inBuffer,
cl_mem  outBuffer,
::size_t  elements,
const void *  offset = NULL,
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::Scan::enqueue ( const cl::CommandQueue &  commandQueue,
const cl::Buffer &  buffer,
::size_t  elements,
const cl::Buffer &  offsetBuffer,
cl_uint  offsetIndex,
const VECTOR_CLASS< cl::Event > *  events = NULL,
cl::Event *  event = NULL 
)
inline

Enqueue a scan operation on a command queue, with an offset in a buffer (in-place).

This is equivalent to calling enqueue(commandQueue, buffer, buffer, elements, offsetBuffer, offsetIndex);

void clogs::Scan::enqueue ( const cl::CommandQueue &  commandQueue,
const cl::Buffer &  inBuffer,
const cl::Buffer &  outBuffer,
::size_t  elements,
const cl::Buffer &  offsetBuffer,
cl_uint  offsetIndex,
const VECTOR_CLASS< cl::Event > *  events = NULL,
cl::Event *  event = NULL 
)
inline

Enqueue a scan operation on a command queue, with an offset in a buffer.

The offset is of the same type as the elements to be scanned, and is stored in a buffer. It is added to all elements of the result. It is legal for the offset to be in the same buffer as the values to scan, and it may even be safely overwritten by the scan (it will be read before being overwritten). This makes it possible to use do multi-pass algorithms with variable output. The counting pass fills in the desired allocations, a scan is used with one extra element at the end to hold the grand total, and the subsequent passes use this extra element as the offset.

The input and output buffers may be the same to do an in-place scan.

Parameters
commandQueueThe command queue to use.
inBufferThe buffer to scan.
outBufferThe buffer to fill with output.
elementsThe number of elements to scan.
offsetBufferBuffer containing a value to add to all elements.
offsetIndexIndex (in units of the scan type) into offsetBuffer.
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 device.
cl::ErrorIf the element range overruns the buffer.
cl::ErrorIf elements is zero.
cl::ErrorIf offsetBuffer is not readable.
cl::ErrorIf offsetIndex overruns offsetBuffer.
Precondition
  • commandQueue was created with the context and device given to the constructor.
Postcondition
  • After execution, element i will be replaced by the sum of all elements strictly before i, plus the offset.
void clogs::Scan::enqueue ( cl_command_queue  commandQueue,
cl_mem  inBuffer,
cl_mem  outBuffer,
::size_t  elements,
cl_mem  offsetBuffer,
cl_uint  offsetIndex,
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: