HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CE_Array< T > Class Template Reference

A simple OpenCL-based array class. More...

#include <CE_Array.h>

+ Inheritance diagram for CE_Array< T >:

Public Types

typedef T value_type
 
using reduce_t = typename std::conditional< std::is_integral< T >::value, exint, fpreal64 >::type
 
- Public Types inherited from CE_BufferDevice< T >
typedef T value_type
 

Public Member Functions

exint size () const
 
bool isEmpty () const
 
void init (exint size)
 
const cl::Bufferbuffer () const
 
 CE_Array ()
 
 CE_Array (exint size)
 
 CE_Array (cl::Buffer &&buf, exint size=-1)
 
 CE_Array (const CE_Array< T > &a)
 
 CE_Array (CE_Array< T > &&a) noexcept
 Move constructor. Steals the buffer from the original. More...
 
 CE_Array (CE_BufferDevice< T > &&b) noexcept
 Move constructor. Steals the buffer from the original. More...
 
CE_Array< T > & operator= (CE_Array< T > &&other)
 
CE_Array< T > & operator= (const CE_Array< T > &other)=delete
 
 ~CE_Array ()
 CE_BufferDevice base class will release buffer. More...
 
CE_ArrayView< Tview ()
 
const CE_ArrayView< Tview () const
 
template<typename V >
void initFromBuffer (const CE_BufferDevice< V > &src, int offset)
 
template<typename V >
void initAndConvertFrom (const CE_Array< V > &src, int src_tuplesize=1, int dst_tuplesize=1, T default_value=0)
 
template<typename V , typename I >
void initAndConvertFromIndices (const CE_Array< V > &src, const CE_Array< I > &indices, int src_tuplesize=1, int dst_tuplesize=1, T default_value=0)
 
template<typename V >
void convertFrom (const CE_Array< V > &src, int src_tuplesize=1, int dst_tuplesize=1, exint src_offset=0, exint dst_offset=0, exint nelements=-1, T default_value=0)
 
template<typename V , typename I >
void convertFromIndices (const CE_Array< V > &src, const CE_Array< I > &indices, int src_tuplesize=1, int dst_tuplesize=1, exint dst_offset=0, T default_value=0)
 
void extractChannel (CE_Array< T > &dst, int tuplesize, int comp) const
 Extract the channel from this into dst. More...
 
void insertChannel (const CE_Array< T > &src, int tuplesize, int comp)
 Insert the channel from src into this. More...
 
void prefixSum (CE_Array< T > &dst, bool exclusive=true, CE_ScanOp op=CE_ScanOp::ADD) const
 
void iota ()
 
T readValue (int idx) const
 
void writeValue (int idx, const T &val, bool blocking=true)
 
void sort (bool is_descending=false, int maxbits=0)
 Sort the array. More...
 
template<typename V >
void sortValues (CE_Array< V > &vals, bool is_descending=false, int maxbits=0)
 Sort the array and the values. More...
 
reduce_t min (int tuplesize=1, int comp=0) const
 
reduce_t minAbs (int tuplesize=1, int comp=0) const
 
reduce_t minLength (int tuplesize=1) const
 
reduce_t max (int tuplesize=1, int comp=0) const
 
reduce_t maxAbs (int tuplesize=1, int comp=0) const
 
reduce_t maxLength (int tuplesize=1) const
 
reduce_t sum (int tuplesize=1, int comp=0) const
 
reduce_t sumAbs (int tuplesize=1, int comp=0) const
 
reduce_t sumSqr (int tuplesize=1, int comp=0) const
 
fpreal64 average (int tuplesize=1, int comp=0) const
 
fpreal64 rms (int tuplesize=1, int comp=0) const
 
reduce_t dot (const CE_Array< T > &b) const
 
void constant (T cval)
 
template<typename I >
void reorder (const CE_Array< I > &order)
 
cl::KernelFunctor bind (cl::Kernel &k) const
 
cl::KernelFunctor bind (const char *kernel_name) const
 
- Public Member Functions inherited from CE_BufferDevice< T >
 CE_BufferDevice ()
 Empty buffer constructor. More...
 
 CE_BufferDevice (exint size)
 Allocated an uninitialized buffer of specified size (if > 0). More...
 
 CE_BufferDevice (cl::Buffer &&buf, exint size=-1)
 
 CE_BufferDevice (const CE_BufferDevice< T > &b)=delete
 No copy constructor. More...
 
 CE_BufferDevice (CE_BufferDevice< T > &&b) noexcept
 
 ~CE_BufferDevice ()
 
template<typename V >
CE_ArrayView< V > arrayView ()
 
template<typename V >
const CE_ArrayView< V > arrayView () const
 
cl::Buffer release ()
 
void reset (cl::Buffer &&buf, exint size=-1)
 
void init (exint size)
 
void initFromArray (const UT_Array< T > &src, exint len=-1, bool block=true)
 Initialize from a UT_Array. If len >= 0, only len elements are copied. More...
 
void matchAndCopyToArray (UT_Array< T > &dst, exint len=-1, bool block=true) const
 
void initFromData (const T *data, exint nelem, bool block=true)
 Initialize from raw data block of T elements of length nelem. More...
 
exint size () const
 Returns the buffer length. More...
 
bool isEmpty () const
 Returns true iff there are no occupied elements in the buffer. More...
 
const cl::Bufferbuffer () const
 
void copyFrom (const CE_BufferDevice< T > &b, exint len=-1)
 

Detailed Description

template<typename T>
class CE_Array< T >

A simple OpenCL-based array class.

Definition at line 28 of file CE_Array.h.

Member Typedef Documentation

template<typename T>
using CE_Array< T >::reduce_t = typename std::conditional<std::is_integral<T>::value, exint, fpreal64>::type

Reduce to long for integral types and fpreal64 for floats, since the caller can always downcast after the fact if desired.

Definition at line 243 of file CE_Array.h.

template<typename T>
typedef T CE_Array< T >::value_type

Definition at line 32 of file CE_Array.h.

Constructor & Destructor Documentation

template<typename T>
CE_Array< T >::CE_Array ( )
inline

Initialize to empty, and init must be called later with the desired size.

Definition at line 41 of file CE_Array.h.

template<typename T>
CE_Array< T >::CE_Array ( exint  size)
inline

Initialize to given size. Size can be zero in which case no allocation is done, and init must be called later with the desired size.

Definition at line 47 of file CE_Array.h.

template<typename T>
CE_Array< T >::CE_Array ( cl::Buffer &&  buf,
exint  size = -1 
)
inline

Move construct from a raw cl::Buffer, which this object now owns. If size is not provided, calc from the buffer size and type. The input cl::Buffer is empty after this call.

Definition at line 53 of file CE_Array.h.

template<typename T>
CE_Array< T >::CE_Array ( const CE_Array< T > &  a)
inlineexplicit

Copy constructor. It duplicates the data. It's marked explicit so that it's not accidentally passed by value.

Definition at line 58 of file CE_Array.h.

template<typename T>
CE_Array< T >::CE_Array ( CE_Array< T > &&  a)
inlinenoexcept

Move constructor. Steals the buffer from the original.

Definition at line 65 of file CE_Array.h.

template<typename T>
CE_Array< T >::CE_Array ( CE_BufferDevice< T > &&  b)
inlinenoexcept

Move constructor. Steals the buffer from the original.

Definition at line 69 of file CE_Array.h.

template<typename T>
CE_Array< T >::~CE_Array ( )
inline

CE_BufferDevice base class will release buffer.

Definition at line 79 of file CE_Array.h.

Member Function Documentation

template<typename T>
fpreal64 CE_Array< T >::average ( int  tuplesize = 1,
int  comp = 0 
) const
inline

Definition at line 264 of file CE_Array.h.

template<typename T>
cl::KernelFunctor CE_Array< T >::bind ( cl::Kernel k) const
template<typename T>
cl::KernelFunctor CE_Array< T >::bind ( const char *  kernel_name) const
template<typename T>
const cl::Buffer& CE_Array< T >::buffer ( ) const
inline

Definition at line 37 of file CE_Array.h.

template<typename T>
void CE_Array< T >::constant ( T  cval)
inline

Definition at line 272 of file CE_Array.h.

template<typename T>
template<typename V >
void CE_Array< T >::convertFrom ( const CE_Array< V > &  src,
int  src_tuplesize = 1,
int  dst_tuplesize = 1,
exint  src_offset = 0,
exint  dst_offset = 0,
exint  nelements = -1,
T  default_value = 0 
)
inline

Copy/convert data from an array of another type and/or tuple size. Does not allocate or reallocate this array's underlying cl::Buffer. Extra tuple components in the source array are discarded. Extra tuple components in the destination array are set to the default. It's up to the caller to ensure that the types can convert with sufficient precision. src_offset, dst_offset, and nelements each expect a number of tuples. If nelements >= 0, only the given number of tuples are copied.

Definition at line 167 of file CE_Array.h.

template<typename T>
template<typename V , typename I >
void CE_Array< T >::convertFromIndices ( const CE_Array< V > &  src,
const CE_Array< I > &  indices,
int  src_tuplesize = 1,
int  dst_tuplesize = 1,
exint  dst_offset = 0,
T  default_value = 0 
)
inline

The same as convertFrom(), except this converts a selection of tuples listed in the index array. The indices should be in the range [0, src.size()/src_tuplesize - 1].

Definition at line 186 of file CE_Array.h.

template<typename T>
reduce_t CE_Array< T >::dot ( const CE_Array< T > &  b) const
inline

Definition at line 269 of file CE_Array.h.

template<typename T>
void CE_Array< T >::extractChannel ( CE_Array< T > &  dst,
int  tuplesize,
int  comp 
) const

Extract the channel from this into dst.

template<typename T>
void CE_Array< T >::init ( exint  size)
inline

Definition at line 36 of file CE_Array.h.

template<typename T>
template<typename V >
void CE_Array< T >::initAndConvertFrom ( const CE_Array< V > &  src,
int  src_tuplesize = 1,
int  dst_tuplesize = 1,
T  default_value = 0 
)
inline

Initialize the array from an array of another type and/or tuple size. Extra tuple components in the source array are discarded. Extra tuple components in the destination array are set to the default. It's up to the caller to ensure that the types can convert with sufficient precision.

Definition at line 125 of file CE_Array.h.

template<typename T>
template<typename V , typename I >
void CE_Array< T >::initAndConvertFromIndices ( const CE_Array< V > &  src,
const CE_Array< I > &  indices,
int  src_tuplesize = 1,
int  dst_tuplesize = 1,
T  default_value = 0 
)
inline

The same as initAndConvertFrom(), except this converts a selection of tuples listed in the index array. The indices should be in the range [0, src.size()/src_tuplesize - 1].

Definition at line 142 of file CE_Array.h.

template<typename T>
template<typename V >
void CE_Array< T >::initFromBuffer ( const CE_BufferDevice< V > &  src,
int  offset 
)
inline

Initalize the array of elements of type T that are at the offset within type V in the buffer.

Definition at line 90 of file CE_Array.h.

template<typename T>
void CE_Array< T >::insertChannel ( const CE_Array< T > &  src,
int  tuplesize,
int  comp 
)

Insert the channel from src into this.

template<typename T>
void CE_Array< T >::iota ( )
inline

Definition at line 214 of file CE_Array.h.

template<typename T>
bool CE_Array< T >::isEmpty ( ) const
inline

Definition at line 35 of file CE_Array.h.

template<typename T>
reduce_t CE_Array< T >::max ( int  tuplesize = 1,
int  comp = 0 
) const
inline

Definition at line 251 of file CE_Array.h.

template<typename T>
reduce_t CE_Array< T >::maxAbs ( int  tuplesize = 1,
int  comp = 0 
) const
inline

Definition at line 253 of file CE_Array.h.

template<typename T>
reduce_t CE_Array< T >::maxLength ( int  tuplesize = 1) const
inline

Definition at line 255 of file CE_Array.h.

template<typename T>
reduce_t CE_Array< T >::min ( int  tuplesize = 1,
int  comp = 0 
) const
inline

Definition at line 245 of file CE_Array.h.

template<typename T>
reduce_t CE_Array< T >::minAbs ( int  tuplesize = 1,
int  comp = 0 
) const
inline

Definition at line 247 of file CE_Array.h.

template<typename T>
reduce_t CE_Array< T >::minLength ( int  tuplesize = 1) const
inline

Definition at line 249 of file CE_Array.h.

template<typename T>
CE_Array<T>& CE_Array< T >::operator= ( CE_Array< T > &&  other)
inline

Move assignment. Note that copy assignment is intentionally deleted.

Definition at line 74 of file CE_Array.h.

template<typename T>
CE_Array<T>& CE_Array< T >::operator= ( const CE_Array< T > &  other)
delete
template<typename T>
void CE_Array< T >::prefixSum ( CE_Array< T > &  dst,
bool  exclusive = true,
CE_ScanOp  op = CE_ScanOp::ADD 
) const
inline

Sum entries of this into dst. exclusive true will have dst elements only include the values of this strictly prior to itself. oneifnonzero will count number of non-zero entries in this.

Definition at line 207 of file CE_Array.h.

template<typename T>
T CE_Array< T >::readValue ( int  idx) const

Reads a single value from the array, blocking. May throw CE Exceptions

template<typename T>
template<typename I >
void CE_Array< T >::reorder ( const CE_Array< I > &  order)
inline

Definition at line 277 of file CE_Array.h.

template<typename T>
fpreal64 CE_Array< T >::rms ( int  tuplesize = 1,
int  comp = 0 
) const
inline

Definition at line 266 of file CE_Array.h.

template<typename T>
exint CE_Array< T >::size ( ) const
inline

Definition at line 34 of file CE_Array.h.

template<typename T>
void CE_Array< T >::sort ( bool  is_descending = false,
int  maxbits = 0 
)
inline

Sort the array.

Definition at line 227 of file CE_Array.h.

template<typename T>
template<typename V >
void CE_Array< T >::sortValues ( CE_Array< V > &  vals,
bool  is_descending = false,
int  maxbits = 0 
)
inline

Sort the array and the values.

Definition at line 234 of file CE_Array.h.

template<typename T>
reduce_t CE_Array< T >::sum ( int  tuplesize = 1,
int  comp = 0 
) const
inline

Definition at line 257 of file CE_Array.h.

template<typename T>
reduce_t CE_Array< T >::sumAbs ( int  tuplesize = 1,
int  comp = 0 
) const
inline

Definition at line 259 of file CE_Array.h.

template<typename T>
reduce_t CE_Array< T >::sumSqr ( int  tuplesize = 1,
int  comp = 0 
) const
inline

Definition at line 261 of file CE_Array.h.

template<typename T>
CE_ArrayView<T> CE_Array< T >::view ( )
inline

Definition at line 82 of file CE_Array.h.

template<typename T>
const CE_ArrayView<T> CE_Array< T >::view ( ) const
inline

Definition at line 84 of file CE_Array.h.

template<typename T>
void CE_Array< T >::writeValue ( int  idx,
const T val,
bool  blocking = true 
)

Writes a single value to the array. May throw CE Exceptions


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