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

#include <CE_ArrayView.h>

Classes

class  Buffer
 

Public Types

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

Public Member Functions

exint size () const
 Returns the number of elements in the array. More...
 
bool isEmpty () const
 
const cl::Bufferbuffer () const
 
 CE_ArrayView (const cl::Buffer &b, exint size=-1)
 
 CE_ArrayView (const CE_BufferDevice< T > &b)
 
CE_BufferDevice< Tharden () const
 
template<typename V >
void convertFrom (const CE_ArrayView< 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_ArrayView< V > &src, const CE_ArrayView< I > &indices, int src_tuplesize=1, int dst_tuplesize=1, exint dst_offset=0, T default_value=0)
 
void extractChannel (CE_ArrayView< T > &dst, int tuplesize, int comp) const
 Extract the channel from this into dst. More...
 
void insertChannel (const CE_ArrayView< T > &src, int tuplesize, int comp)
 Insert the channel from src into this. More...
 
void prefixSum (CE_ArrayView< 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 readIntoArray (UT_Array< T > &array) const
 
void sort (bool is_descending=false, int maxbits=0)
 Sort the array. More...
 
template<typename V >
void sortValues (CE_ArrayView< 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_ArrayView< T > &b) const
 
void constant (T cval)
 
template<typename I >
void reorder (const CE_ArrayView< I > &order)
 
cl::KernelFunctor bind (cl::Kernel &k) const
 
cl::KernelFunctor bind (const char *kernel_name) const
 

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_ArrayView< T > *a, int tuplesize=1, int comp=0) const
 
template<typename V >
reduceGroup (CE_ArrayView< V > &out, uint groupsize, const char *reduce_flags) const
 
template<typename V >
void sortInternal (CE_ArrayView< V > &vals, bool is_descending, int maxbits)
 
scalar_arg_t scalarKernelArg (T v)
 

Static Protected Member Functions

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

Protected Attributes

const cl::Buffer myBuffer
 
const exint mySize
 

Friends

template<typename V >
class CE_Array
 

Detailed Description

template<typename T>
class CE_ArrayView< T >

Shares an existing OpenCL buffer and views it as an array. The lifetime of the shared buffer must exceed the lifetime of this object.

Definition at line 41 of file CE_ArrayView.h.

Member Typedef Documentation

template<typename T>
using CE_ArrayView< 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 127 of file CE_ArrayView.h.

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

Definition at line 188 of file CE_ArrayView.h.

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

Definition at line 44 of file CE_ArrayView.h.

Constructor & Destructor Documentation

template<typename T>
CE_ArrayView< T >::CE_ArrayView ( const cl::Buffer b,
exint  size = -1 
)

Size expects the number of elements in the buffer. If size is not provided, it is calculated from the buffer size.

template<typename T>
CE_ArrayView< T >::CE_ArrayView ( const CE_BufferDevice< T > &  b)
explicit

Member Function Documentation

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

Definition at line 59 of file CE_ArraySortImpl.h.

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

Definition at line 139 of file CE_ArrayView.h.

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

Definition at line 49 of file CE_ArrayView.h.

template<typename T>
void CE_ArrayView< T >::constant ( T  cval)
template<typename T >
template<typename V >
void CE_ArrayView< T >::convertFrom ( const CE_ArrayView< 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 
)

Copy/convert data 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. 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 88 of file CE_ArraySortImpl.h.

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

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 130 of file CE_ArraySortImpl.h.

template<typename T>
reduce_t CE_ArrayView< T >::doReduce ( const char *  reduce_flags,
const CE_ArrayView< T > *  a,
int  tuplesize = 1,
int  comp = 0 
) const
protected
template<typename T>
reduce_t CE_ArrayView< T >::dot ( const CE_ArrayView< T > &  b) const
template<typename T>
void CE_ArrayView< T >::extractChannel ( CE_ArrayView< T > &  dst,
int  tuplesize,
int  comp 
) const

Extract the channel from this into dst.

template<typename T>
CE_BufferDevice<T> CE_ArrayView< T >::harden ( ) const

Harden the view into a buffer, which now owns a copy of the array data. You must include CE_BufferDevice.h to use this.

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

Insert the channel from src into this.

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

Definition at line 48 of file CE_ArrayView.h.

template<typename T>
cl::Kernel CE_ArrayView< T >::loadKernel ( const char *  kernel_name,
const char *  opt = NULL 
) const
protected
template<typename T>
reduce_t CE_ArrayView< T >::max ( int  tuplesize = 1,
int  comp = 0 
) const
template<typename T>
reduce_t CE_ArrayView< T >::maxAbs ( int  tuplesize = 1,
int  comp = 0 
) const
template<typename T>
reduce_t CE_ArrayView< T >::maxLength ( int  tuplesize = 1) const
template<typename T>
reduce_t CE_ArrayView< T >::min ( int  tuplesize = 1,
int  comp = 0 
) const
template<typename T>
reduce_t CE_ArrayView< T >::minAbs ( int  tuplesize = 1,
int  comp = 0 
) const
template<typename T>
reduce_t CE_ArrayView< T >::minLength ( int  tuplesize = 1) const
template<typename T>
void CE_ArrayView< T >::prefixSum ( CE_ArrayView< T > &  dst,
bool  exclusive = true,
CE_ScanOp  op = CE_ScanOp::ADD 
) const

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>
void CE_ArrayView< T >::readIntoArray ( UT_Array< T > &  array) const

Reads the entire array into a UT_Array, resizing UT_Array to be our size. May throw CE Exceptions.

template<typename T>
T CE_ArrayView< 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_ArrayView< T >::reduceGroup ( CE_ArrayView< V > &  out,
uint  groupsize,
const char *  reduce_flags 
) const
protected
template<typename T >
template<typename I >
void CE_ArrayView< T >::reorder ( const CE_ArrayView< I > &  order)

Definition at line 171 of file CE_ArraySortImpl.h.

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

Definition at line 146 of file CE_ArrayView.h.

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

Definition at line 190 of file CE_ArrayView.h.

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

Returns the number of elements in the array.

Definition at line 47 of file CE_ArrayView.h.

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

Sort the array.

Definition at line 109 of file CE_ArrayView.h.

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

Definition at line 202 of file CE_ArraySortImpl.h.

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

Sort the array and the values.

Definition at line 118 of file CE_ArrayView.h.

template<typename T>
reduce_t CE_ArrayView< T >::sum ( int  tuplesize = 1,
int  comp = 0 
) const
template<typename T>
reduce_t CE_ArrayView< T >::sumAbs ( int  tuplesize = 1,
int  comp = 0 
) const
template<typename T>
reduce_t CE_ArrayView< T >::sumSqr ( int  tuplesize = 1,
int  comp = 0 
) const
template<typename T>
void CE_ArrayView< T >::writeValue ( int  idx,
const T val,
bool  blocking = true 
)

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

Friends And Related Function Documentation

template<typename T>
template<typename V >
friend class CE_Array
friend

Definition at line 193 of file CE_ArrayView.h.

Member Data Documentation

template<typename T>
const cl::Buffer CE_ArrayView< T >::myBuffer
protected

Definition at line 198 of file CE_ArrayView.h.

template<typename T>
const exint CE_ArrayView< T >::mySize
protected

Definition at line 199 of file CE_ArrayView.h.


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