HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
CE_Vector.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: CE_VectorT.h ( CE Library, C++)
7  *
8  * COMMENTS: Compute Engine Vector.
9  */
10 
11 #ifndef __CE_Vector__
12 #define __CE_Vector__
13 
14 #include "CE_API.h"
15 
16 #include "CE_Context.h"
17 
18 #ifdef CE_ENABLED
19 
20 #include <UT/UT_Vector.h>
21 
22 /// A simple OpenCL-based vector class that at the moment just mimics just
23 /// enough of UT_Vector to be used in CE_SparseMatrixELLT::solveConjugateGradient.
24 template <typename T>
26 {
27 public:
28 
29  typedef T value_type;
30 
31  CE_VectorT();
32 
33  /// Initialize to given length.
34  CE_VectorT(exint len, bool use_pool=false, bool read=true, bool write=true, bool delayed_ogl_bind=false, bool ogl_ocl=false);
35 
36  /// Initialize to zero in in the cases when we want to
37  /// init / not init the vector based on size
38  CE_VectorT(bool use_pool,
39  bool read,
40  bool write,
41  bool delayed_ogl_bind,
42  bool ogl_ocl);
43 
44  /// Copy constructor.
45  CE_VectorT(const CE_VectorT<T> &v);
46 
47  virtual ~CE_VectorT();
48 
49  /// Initialize to given length.
50  /// NOTE- values are undefined.
51  void init(exint len);
52 
53  /// For "compatibility" with UT_Vector.
54  /// NOTE: Asserts if nl is not zero!
55  void init(exint nl, exint nh);
56 
57  /// Initialize from a UT_Vector.
58  void initFromVector(const UT_VectorT<T> &src, bool block = true);
59 
60  /// Rebing to an OGL buffer
61  virtual void rebindOGLBuffer( uint buf_obj );
62  virtual void unbindOGLBuffer();
63  virtual bool isBinded();
64  uint delayedBindBufferID() const { return myDelayedBindBufferID; }
65 
66  /// Resize the provided UT_Vector to fit and copy this vector's data there.
67  void matchAndCopyToVector(UT_VectorT<T> &dst, bool block = true) const;
68  /// Returns the vector length.
69  exint length() const { return myLen; }
70 
71  /// Returns the underlying OpenCL buffer.
72  const cl::Buffer &buffer() const { return myBuffer; }
73 
74  /// The following functions all mimic those of the same name in UT_Vector.
75  void multAndSet(const CE_VectorT<T> &a, const CE_VectorT<T> &b);
76 
77  void negPlus(const CE_VectorT<T> &a);
78 
79  void scaleAddVec(T s, const CE_VectorT<T> &a);
80 
81  fpreal64 norm(int type) const;
82 
83  void zero() { setValue(0); }
84 
85  void addScaledVec(T s, const CE_VectorT<T> &a);
86 
87  /// Apply Blend Shapes on the current buffer
88  /// bs holds all the blend shape positions concatenated together in a single buffer
89  /// wi, holds the contribution of the blend shapes with index and weights.
90  void blendShapes(const CE_VectorT<T> &bs, const CE_VectorT<T>& wi, exint num_active_shapes, bool write_half);
91 
92  /// Apply Position and Normal blend shapes at the same time in a single kernel
93  void blendShapesPointNormal(CE_VectorT<T> &n, const CE_VectorT<T> &bs, const CE_VectorT<T> &bsn, const CE_VectorT<T>& wi, exint num_active_shapes, bool write_half);
94 
95  /// Apply deform shapes on the current buffer
96  void deformShape(const CE_VectorT<T> &shape,
98  const CE_VectorT<T> &weightIndices,
99  exint num_max_regions);
100 
101  void deformShapeNormal(const CE_VectorT<T> &shape,
102  const CE_VectorT<T> &transforms,
103  const CE_VectorT<T> &weightIndices,
104  exint num_max_regions );
105 
106  void deformShapeVector(const CE_VectorT<T> &shape,
107  const CE_VectorT<T> &transforms,
108  const CE_VectorT<T> &weightIndices,
109  exint num_max_regions,
110  exint num_vec_attr);
111 
112 
113  void deformShapeQuaternion(const CE_VectorT<T> &shape,
114  const CE_VectorT<T> &xforms,
115  const CE_VectorT<T> &weightIndices,
116  exint num_max_regions,
117  exint num_vec_attr);
118 
119  void dqDeformShape(const CE_VectorT<T> &shape,
120  const CE_VectorT<T> &transforms,
121  const CE_VectorT<T> &weightIndices,
122  exint num_max_regions);
123 
124  void dqDeformShapeVector(const CE_VectorT<T> &shape,
125  const CE_VectorT<T> &transforms,
126  const CE_VectorT<T> &weightIndices,
127  exint num_max_regions,
128  exint num_vec_attr,
129  bool normalize_dst);
130 
131  // Need to refactor this into one chunk.. or something not so repeated
132  void dqDeformShapeQuaternion(const CE_VectorT<T> &shape,
133  const CE_VectorT<T> &dqs,
134  const CE_VectorT<T> &weightIndices,
135  exint num_max_regions,
136  exint num_quat_attr);
137 
138  void dqLinearBlendDeformShape(const CE_VectorT<T> &shape,
139  const CE_VectorT<T> &xforms,
140  const CE_VectorT<T> &dqs,
141  const CE_VectorT<T> &weightIndices,
142  const CE_VectorT<T> &dq_linear_blend,
143  exint num_max_regions);
144 
145  void dqLinearBlendDeformNormal(const CE_VectorT<T> &shape,
146  const CE_VectorT<T> &xforms,
147  const CE_VectorT<T> &dqs,
148  const CE_VectorT<T> &weightIndices,
149  const CE_VectorT<T> &dq_linear_blend,
150  exint num_max_regions);
151 
152  void dqLinearBlendDeformVector(const CE_VectorT<T> &shape,
153  const CE_VectorT<T> &xforms,
154  const CE_VectorT<T> &dqs,
155  const CE_VectorT<T> &weightIndices,
156  const CE_VectorT<T> &dq_linear_blend,
157  exint num_max_regions,
158  exint num_attr);
159 
160  void dqLinearBlendDeformQuaternion(const CE_VectorT<T> &shape,
161  const CE_VectorT<T> &xforms,
162  const CE_VectorT<T> &dqs,
163  const CE_VectorT<T> &weightIndices,
164  const CE_VectorT<T> &dq_linear_blend,
165  exint num_max_regions,
166  exint num_attr);
167  /// Operators
168  /// NOTE: operator= requires the destination be a matching size.
169  CE_VectorT &operator= (const CE_VectorT<T> &v);
170 
171  /// Reductions of the vector to a single value.
172  fpreal64 sum() const;
173  fpreal64 sumAbs() const;
174  fpreal64 sumSqr() const;
175  fpreal64 min() const;
176  fpreal64 minAbs() const;
177  fpreal64 max() const;
178  fpreal64 maxAbs() const;
179  fpreal64 average() const {return sum() / length();}
180 
181  /// Returns the dot product with provided vector.
182  fpreal64 dot(const CE_VectorT<T> &a) const;
183 
184  cl::KernelFunctor bind(cl::Kernel &k) const;
185  void setValue(T cval);
186  void copyFrom(const CE_VectorT<T> &v);
187 protected:
188 
189  const cl::Buffer &allocBuffer() const;
190  void releaseBuffer();
191  cl::KernelFunctor bind(const char *kernelName) const;
192  cl::Kernel loadKernel(const char *kernelName, const char *opt = NULL) const;
193 
194 
195  // Reduction helpers
196  void getReductionRanges(const cl::Kernel &k,
197  cl::NDRange &globalRange, cl::NDRange &localRange,
198  uint &groupsize, uint &ngroups,
199  size_t &accumsize) const;
200  fpreal64 reduceGroup(cl::Buffer out, uint groupsize, uint ngroups,
201  size_t accumsize, const char *reduceFlags) const;
202 
203  // Main reduction function.
204  fpreal64 doReduce(const char* reduceFlags, const CE_VectorT<T> *a=NULL) const;
205 
207  cl::NDRange myGlobalRange, myLocalRange;
209 
210  bool myRead, myWrite, myUsePool;
214 };
215 
216 template <typename T>
217 inline fpreal64
219 {
220  return a.dot(b);
221 }
222 
223 
226 
227 #else
228 template <typename T>
229 class CE_API CE_VectorT
230 {
231 };
232 
233 #endif
234 #endif
#define CE_API
Definition: CE_API.h:10
bool myUseOGLContex
Definition: CE_Vector.h:213
exint myLen
Definition: CE_Vector.h:208
png_infop int transforms
Definition: png.h:2591
cl::NDRange myLocalRange
Definition: CE_Vector.h:207
uint32 myDelayedBindBufferID
Definition: CE_Vector.h:211
const hboost::disable_if_c< VecTraits< T >::IsVec, T >::type & min(const T &a, const T &b)
Definition: Composite.h:128
const GLdouble * v
Definition: glcorearb.h:836
exint length() const
Returns the vector length.
Definition: CE_Vector.h:69
GLboolean GLboolean GLboolean GLboolean a
Definition: glcorearb.h:1221
bool myWrite
Definition: CE_Vector.h:210
uint32 myBufferObject
Definition: CE_Vector.h:212
CE_VectorT< fpreal32 > CE_VectorF
Definition: CE_Vector.h:224
void read(T &in, bool &v)
Definition: ImfXdr.h:611
const hboost::disable_if_c< VecTraits< T >::IsVec, T >::type & max(const T &a, const T &b)
Definition: Composite.h:132
virtual void unbindOGLBuffer()=0
GLdouble n
Definition: glcorearb.h:2007
const cl::Buffer & buffer() const
Returns the underlying OpenCL buffer.
Definition: CE_Vector.h:72
int64 exint
Definition: SYS_Types.h:109
double fpreal64
Definition: SYS_Types.h:185
fpreal64 dot(const CE_VectorT< T > &a, const CE_VectorT< T > &b)
Definition: CE_Vector.h:218
void zero()
Definition: CE_Vector.h:83
GLboolean GLboolean GLboolean b
Definition: glcorearb.h:1221
unsigned int uint
Definition: SYS_Types.h:33
fpreal64 dot(const CE_VectorT< T > &a) const
Returns the dot product with provided vector.
virtual void rebindOGLBuffer(uint buf_obj)=0
cl::Buffer myBuffer
Definition: CE_Vector.h:206
GLenum GLenum dst
Definition: glcorearb.h:1792
Kernel functor interface.
Definition: cl.hpp:3562
Memory buffer interface.
Definition: cl.hpp:1863
GLint GLint GLsizei GLint GLenum GLenum type
Definition: glcorearb.h:107
NDRange interface.
Definition: cl.hpp:2456
Kernel interface that implements cl_kernel.
Definition: cl.hpp:2534
fpreal64 average() const
Definition: CE_Vector.h:179
uint delayedBindBufferID() const
Definition: CE_Vector.h:64
T value_type
Definition: CE_Vector.h:29
CE_VectorT< fpreal64 > CE_VectorD
Definition: CE_Vector.h:225
void write(T &out, bool v)
Definition: ImfXdr.h:332
virtual bool isBinded()=0
GLuint GLsizei GLsizei * length
Definition: glcorearb.h:794
GLenum src
Definition: glcorearb.h:1792
unsigned int uint32
Definition: SYS_Types.h:29