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

Radix-sort interface. More...

#include <radixsort.h>

Inheritance diagram for clogs::Radixsort:
Collaboration diagram for clogs::Radixsort:

Public Member Functions

 Radixsort ()
 Default constructor. More...
 
 Radixsort (const cl::Context &context, const cl::Device &device, const Type &keyType, const Type &valueType=Type())
 Constructor. More...
 
 Radixsort (const cl::Context &context, const cl::Device &device, const RadixsortProblem &problem)
 Constructor. More...
 
 ~Radixsort ()
 Destructor.
 
void enqueue (const cl::CommandQueue &commandQueue, const cl::Buffer &keys, const cl::Buffer &values,::size_t elements, unsigned int maxBits=0, const VECTOR_CLASS< cl::Event > *events=NULL, cl::Event *event=NULL)
 Enqueue a sort operation on a command queue. More...
 
void enqueue (cl_command_queue commandQueue, cl_mem keys, cl_mem values,::size_t elements, unsigned int maxBits=0, cl_uint numEvents=0, const cl_event *events=NULL, cl_event *event=NULL)
 
void setTemporaryBuffers (const cl::Buffer &keys, const cl::Buffer &values)
 Set temporary buffers used during sorting. More...
 
void setTemporaryBuffers (cl_mem keys, cl_mem values)
 
- 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 command_queue, cl_mem keys, cl_mem values,::size_t elements, unsigned int maxBits, cl_uint numEvents, const cl_event *events, cl_event *event, cl_int &err, const char *&errStr)
 
void setTemporaryBuffers (cl_mem keys, cl_mem values, 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 (Radixsort &, Radixsort &)
 

Detailed Description

Radix-sort interface.

One instance of this class can be re-used for multiple sorts, 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 types for the keys and values. The keys can be any unsigned integral scalar type, and the values can be any built-in OpenCL type (including void to indicate that there are no values).

The implementation is loosely based on the reduce-then-scan strategy described at http://code.google.com/p/back40computing/wiki/RadixSorting, but does not appear to be as efficient.

Constructor & Destructor Documentation

clogs::Radixsort::Radixsort ( )

Default constructor.

The object cannot be used in this state.

clogs::Radixsort::Radixsort ( const cl::Context &  context,
const cl::Device &  device,
const Type keyType,
const Type valueType = Type() 
)
inline

Constructor.

Parameters
contextOpenCL context to use
deviceOpenCL device to use.
keyTypeType for the keys. Must be an unsigned integral scalar type.
valueTypeType for the values. Can be any storable type, including void.
Exceptions
std::invalid_argumentif keyType is not an unsigned integral scalar type.
std::invalid_argumentif valueType is not a storable type for device.
clogs::InternalErrorif there was a problem with initialization
Deprecated:
This constructor is deprecated, because it does not scale to future features. Use the constructor taking a clogs::RadixsortProblem instead.
clogs::Radixsort::Radixsort ( const cl::Context &  context,
const cl::Device &  device,
const RadixsortProblem problem 
)
inline

Constructor.

Parameters
contextOpenCL context to use
deviceOpenCL device to use.
problemProblem parameters.
Exceptions
std::invalid_argumentif problem.keyType is not an unsigned integral scalar type.
std::invalid_argumentif problem.valueType is not a storable type for device.
clogs::InternalErrorif there was a problem with initialization

Member Function Documentation

void clogs::Radixsort::enqueue ( const cl::CommandQueue &  commandQueue,
const cl::Buffer &  keys,
const cl::Buffer &  values,
::size_t  elements,
unsigned int  maxBits = 0,
const VECTOR_CLASS< cl::Event > *  events = NULL,
cl::Event *  event = NULL 
)
inline

Enqueue a sort operation on a command queue.

If the range of the keys is known to be smaller than the range of the the type holding them, passing an appropriate maxBits can improve performance. If no maximum is known, passing 0 (the default) indicates that the worst case should be assumed.

Parameters
commandQueueThe command queue to use.
keysThe keys to sort.
valuesThe values associated with the keys.
elementsThe number of elements to sort.
maxBitsUpper bound on the number of bits in any key, or 0.
eventsEvents to wait for before starting.
eventEvent that will be signaled on completion.
Exceptions
cl::ErrorIf keys or values is not read-write.
cl::ErrorIf the element range overruns either buffer.
cl::ErrorIf elements or maxBits is zero.
cl::ErrorIf maxBits is greater than the number of bits in the key type.
Precondition
  • commandQueue was created with the context and device given to the constructor.
  • keys and values do not overlap in memory.
  • maxBits is zero, or all keys are strictly less than 2maxBits.
Postcondition
  • After execution, the keys will be sorted (with stability), and the values will be in the same order as the keys.
void clogs::Radixsort::enqueue ( cl_command_queue  commandQueue,
cl_mem  keys,
cl_mem  values,
::size_t  elements,
unsigned int  maxBits = 0,
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::Radixsort::setTemporaryBuffers ( const cl::Buffer &  keys,
const cl::Buffer &  values 
)
inline

Set temporary buffers used during sorting.

These buffers are used if they are big enough (as big as the buffers that are being sorted); otherwise temporary buffers are allocated on the fly. Providing suitably large buffers guarantees that no buffer storage is allocated by enqueue.

It is legal to set either or both values to cl::Buffer() to clear the temporary buffer, in which case enqueue will revert to allocating its own temporary buffers as needed.

This object will retain references to the buffers, so it is safe for the caller to release its reference.

void clogs::Radixsort::setTemporaryBuffers ( cl_mem  keys,
cl_mem  values 
)
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: