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< 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...
 
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 >
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)
 
void prefixSum (CE_Array< T > &dst, bool exclusive=true, bool oneifnonzero=false)
 
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)
 
template<typename V >
void sortValues (CE_Array< V > &vals, bool is_descending=false, int maxbits=0)
 
reduce_t min (int tuplesize=1, int comp=0) const
 
reduce_t minAbs (int tuplesize=1, int comp=0) const
 
reduce_t max (int tuplesize=1, int comp=0) const
 
reduce_t maxAbs (int tuplesize=1, int comp=0) 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)
 
void reorder (const CE_Array< uint32_t > &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 ()
 
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)
 

Protected Types

using scalar_arg_t = typename std::conditional_t< std::is_same_v< T, fpreal16 >, fpreal32, T >
 

Protected Member Functions

cl::Kernel loadKernel (const char *kernel_name, const char *opt=NULL) const
 
reduce_t doReduce (const char *reduce_flags, const CE_Array< T > *a, int tuplesize=1, int comp=0) const
 
template<typename V >
reduceGroup (CE_Array< V > &out, uint groupsize, const char *reduce_flags) const
 
template<typename V >
void sortInternal (CE_Array< V > &vals, bool is_descending, int maxbits)
 
scalar_arg_t scalarKernelArg (T v)
 
- Protected Member Functions inherited from CE_BufferDevice< T >
void initInternal (exint size, bool doalloc=true)
 
const cl::BufferallocBuffer () const
 
void releaseBuffer ()
 

Static Protected Member Functions

template<typename V >
static void appendElemType (UT_WorkBuffer &wb)
 

Additional Inherited Members

- Protected Attributes inherited from CE_BufferDevice< T >
cl::Buffer myBuffer
 
exint mySize
 

Detailed Description

template<typename T>
class CE_Array< T >

A simple OpenCL-based array class.

Definition at line 24 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 211 of file CE_Array.h.

template<typename T>
using CE_Array< T >::scalar_arg_t = typename std::conditional_t< std::is_same_v<T, fpreal16>, fpreal32, T>
protected

Definition at line 270 of file CE_Array.h.

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

Definition at line 28 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 37 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 43 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 49 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 54 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 61 of file CE_Array.h.

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

CE_BufferDevice base class will release buffer.

Definition at line 71 of file CE_Array.h.

Member Function Documentation

template<typename T >
template<typename V >
void CE_Array< T >::appendElemType ( UT_WorkBuffer wb)
staticprotected

Definition at line 23 of file CE_ArraySortImpl.h.

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

Definition at line 221 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 33 of file CE_Array.h.

template<typename T>
void CE_Array< T >::constant ( T  cval)
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 133 of file CE_Array.h.

template<typename T>
reduce_t CE_Array< T >::doReduce ( const char *  reduce_flags,
const CE_Array< T > *  a,
int  tuplesize = 1,
int  comp = 0 
) const
protected
template<typename T>
reduce_t CE_Array< T >::dot ( const CE_Array< T > &  b) const
template<typename T>
void CE_Array< T >::init ( exint  size)
inline

Definition at line 32 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 111 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 76 of file CE_Array.h.

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

Definition at line 31 of file CE_Array.h.

template<typename T>
cl::Kernel CE_Array< T >::loadKernel ( const char *  kernel_name,
const char *  opt = NULL 
) const
protected
template<typename T>
reduce_t CE_Array< T >::max ( int  tuplesize = 1,
int  comp = 0 
) const
template<typename T>
reduce_t CE_Array< T >::maxAbs ( int  tuplesize = 1,
int  comp = 0 
) const
template<typename T>
reduce_t CE_Array< T >::min ( int  tuplesize = 1,
int  comp = 0 
) const
template<typename T>
reduce_t CE_Array< T >::minAbs ( int  tuplesize = 1,
int  comp = 0 
) const
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 66 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,
bool  oneifnonzero = false 
)

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.

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 V >
V CE_Array< T >::reduceGroup ( CE_Array< V > &  out,
uint  groupsize,
const char *  reduce_flags 
) const
protected
template<typename T>
void CE_Array< T >::reorder ( const CE_Array< uint32_t > &  order)
template<typename T>
fpreal64 CE_Array< T >::rms ( int  tuplesize = 1,
int  comp = 0 
) const
inline

Definition at line 228 of file CE_Array.h.

template<typename T>
scalar_arg_t CE_Array< T >::scalarKernelArg ( T  v)
inlineprotected

Definition at line 272 of file CE_Array.h.

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

Definition at line 30 of file CE_Array.h.

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

Sort the array. Note the underlying buffer object could change for an odd number of internal sorting passes. maxbits limits the number of significant bits to consider if greater than zero.

Definition at line 191 of file CE_Array.h.

template<typename T >
template<typename V >
void CE_Array< T >::sortInternal ( CE_Array< V > &  vals,
bool  is_descending,
int  maxbits 
)
protected

Definition at line 52 of file CE_ArraySortImpl.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. Note the underlying buffer objects could change for an odd number of internal sorting passes. maxbits limits the number of significant bits to consider if greater than zero.

Definition at line 202 of file CE_Array.h.

template<typename T>
reduce_t CE_Array< T >::sum ( int  tuplesize = 1,
int  comp = 0 
) const
template<typename T>
reduce_t CE_Array< T >::sumAbs ( int  tuplesize = 1,
int  comp = 0 
) const
template<typename T>
reduce_t CE_Array< T >::sumSqr ( int  tuplesize = 1,
int  comp = 0 
) const
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 files: