75 {
swap(*
this, other); other.init(0);
return *
this; }
105 region[0] =
sizeof(
T);
106 region[1] = src.
size();
110 size_t src_row_pitch =
sizeof(V);
111 size_t dst_row_pitch =
sizeof(
T);
115 src_origin, dst_origin, region,
116 src_row_pitch, 0, dst_row_pitch, 0);
124 template <
typename V>
126 int src_tuplesize = 1,
int dst_tuplesize = 1,
129 UT_ASSERT(src_tuplesize >= 1 && dst_tuplesize >= 1);
130 if (!(src_tuplesize >= 1 && dst_tuplesize >= 1))
133 exint nelem = src.
size() / src_tuplesize;
134 init(nelem * dst_tuplesize);
135 convertFrom(src, src_tuplesize, dst_tuplesize, 0, 0, nelem, default_value);
141 template <
typename V,
typename I>
144 int src_tuplesize = 1,
int dst_tuplesize = 1,
148 UT_ASSERT(src_tuplesize >= 1 && dst_tuplesize >= 1);
149 if (!(src_tuplesize >= 1 && dst_tuplesize >= 1))
152 init(indices.
size() * dst_tuplesize);
153 convertFromIndices(src, indices,
154 src_tuplesize, dst_tuplesize,
166 template <
typename V>
168 int src_tuplesize = 1,
int dst_tuplesize = 1,
170 exint nelements = -1,
T default_value = 0)
172 UT_ASSERT(src_tuplesize >= 1 && dst_tuplesize >= 1);
173 if (!(src_tuplesize >= 1 && dst_tuplesize >= 1))
176 view().convertFrom(src.
view(),
177 src_tuplesize, dst_tuplesize,
178 src_offset, dst_offset,
179 nelements, default_value);
185 template <
typename V,
typename I>
188 int src_tuplesize = 1,
int dst_tuplesize = 1,
189 exint dst_offset = 0,
192 view().convertFromIndices(src.
view(), indices.
view(),
193 src_tuplesize, dst_tuplesize,
199 void extractChannel(
CE_Array<T> &
dst,
int tuplesize,
int comp)
const;
202 void insertChannel(
const CE_Array<T> &
src,
int tuplesize,
int comp);
211 view().prefixSum(dstview, exclusive,
op);
221 T readValue(
int idx)
const;
224 void writeValue(
int idx,
const T &
val,
bool blocking=
true);
227 void sort(
bool is_descending =
false,
int maxbits = 0)
229 view().sort(is_descending, maxbits);
233 template <
typename V>
237 view().sortValues(valsview, is_descending, maxbits);
246 {
return view().min(tuplesize, comp); }
248 {
return view().minAbs(tuplesize, comp); }
250 {
return view().minLength(tuplesize); }
252 {
return view().max(tuplesize, comp); }
254 {
return view().maxAbs(tuplesize, comp); }
256 {
return view().maxLength(tuplesize); }
258 {
return view().sum(tuplesize, comp); }
260 {
return view().sumAbs(tuplesize, comp); }
262 {
return view().sumSqr(tuplesize, comp); }
265 {
return view().average(tuplesize, comp); }
267 {
return view().rms(tuplesize, comp); }
270 {
return view().dot(b.
view()); }
273 {
return view().constant(cval); }
276 template <
typename I>
278 {
return view().reorder(order.
view()); }
286 cl::Kernel loadKernel(
const char *kernel_name,
287 const char *opt = NULL)
const;
290 template <
typename V>
298 std::is_same_v<T, fpreal16>,
301 scalar_arg_t scalarKernelArg(
T v) {
return static_cast<scalar_arg_t
>(
v); }
323 template <
typename V>
334 int elemsize =
sizeof(V);
reduce_t sumSqr(int tuplesize=1, int comp=0) const
GLenum GLuint GLenum GLsizei const GLchar * buf
A simple OpenCL-based array class.
#define SYS_STATIC_ASSERT(expr)
reduce_t min(int tuplesize=1, int comp=0) const
GLsizei GLenum const void * indices
void initFromBuffer(const CE_BufferDevice< V > &src, int offset)
typename std::conditional< B, T, F >::type conditional_t
GLsizei const GLfloat * value
void sortValues(CE_Array< V > &vals, bool is_descending=false, int maxbits=0)
Sort the array and the values.
CE_Array(CE_Array< T > &&a) noexcept
Move constructor. Steals the buffer from the original.
GLboolean GLboolean GLboolean GLboolean a
reduce_t minLength(int tuplesize=1) const
void copyFrom(const CE_BufferDevice< T > &b, exint len=-1)
GLdouble GLdouble GLdouble q
exint size() const
Returns the buffer length.
cl::CommandQueue getQueue() const
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 initAndConvertFromIndices(const CE_Array< V > &src, const CE_Array< I > &indices, int src_tuplesize=1, int dst_tuplesize=1, T default_value=0)
fpreal64 average(int tuplesize=1, int comp=0) const
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)
CE_Array< float > CE_FloatArray
void sort(bool is_descending=false, int maxbits=0)
Sort the array.
static CE_Context * getContext(bool gl_shared=true, bool shared_fallback=true)
reduce_t dot(const CE_Array< T > &b) const
void initAndConvertFrom(const CE_Array< V > &src, int src_tuplesize=1, int dst_tuplesize=1, T default_value=0)
~CE_Array()
CE_BufferDevice base class will release buffer.
reduce_t max(int tuplesize=1, int comp=0) const
fpreal64 rms(int tuplesize=1, int comp=0) const
void prefixSum(CE_Array< T > &dst, bool exclusive=true, CE_ScanOp op=CE_ScanOp::ADD) const
GLdouble GLdouble GLint GLint order
CE_Array< int > CE_Int32Array
typename std::conditional< std::is_integral< int >::value, exint, fpreal64 >::type reduce_t
const cl::Buffer & buffer() const
CE_Array< T > & operator=(CE_Array< T > &&other)
GLboolean GLboolean GLboolean b
const CE_ArrayView< T > view() const
CE_ScanOp
CE_Array prefix sum operators.
reduce_t sum(int tuplesize=1, int comp=0) const
CE_Array(cl::Buffer &&buf, exint size=-1)
CE_Array(const CE_Array< T > &a)
friend void swap(CE_BufferDevice< T > &a, CE_BufferDevice< T > &b)
void reorder(const CE_Array< I > &order)
CommandQueue interface for cl_command_queue.
reduce_t minAbs(int tuplesize=1, int comp=0) const
reduce_t sumAbs(int tuplesize=1, int comp=0) const
reduce_t maxAbs(int tuplesize=1, int comp=0) const
LeafData & operator=(const LeafData &)=delete
Kernel functor interface.
CE_Array(CE_BufferDevice< T > &&b) noexcept
Move constructor. Steals the buffer from the original.
CE_Array< uint32_t > CE_UInt32Array
const cl::Buffer & buffer() const
Kernel interface that implements cl_kernel.
CE_EXTERN_TEMPLATE(CE_Array< uint8 >)
cl::KernelFunctor bind(cl::Kernel &k) const
void CEreorderBuffer(const CE_BufferDevice< V > &src, CE_BufferDevice< V > &dst, const CE_UInt32Array &order)
bool isEmpty() const
Returns true iff there are no occupied elements in the buffer.
reduce_t maxLength(int tuplesize=1) const