HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GAS_OpenCL.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: GAS_OpenCL.h ( GAS Library, C++)
7  *
8  * COMMENTS:
9  */
10 
11 #ifndef __GAS_OpenCL_h__
12 #define __GAS_OpenCL_h__
13 
14 #include "GAS_SubSolver.h"
15 #include "GAS_Utils.h"
16 #include <GA/GA_SplittableRange.h>
17 #include <CE/CE_Context.h>
18 #include <SIM/SIM_Query.h>
19 #include <SIM/SIM_QueryCombine.h>
20 #include "GAS_OpenCLParms.proto.h"
21 
22 class GA_CEAttribute;
23 
25 {
26 public:
27  // The live parameters we are solving with
28  // These are transitory for the solve.
29  const GAS_OpenCLParms &param() const { return myAtParms; }
30 
31  // The parameters we set from tne node, representing our original
32  // parameters (before @ binding)
33  GAS_OpenCLParms &nodeParam() { return myNodeParms; }
34  const GAS_OpenCLParms &nodeParam() const { return myNodeParms; }
35 
36  OP_VERSION versionParms() const { return myVersion; }
37  void setVersionParms(OP_VERSION version) { myVersion = version; }
38 
39  // Static display callback
40  static int displayKernel(void * data, int, fpreal t, const PRM_Template*);
41  static int expandKernel(void * data, int, fpreal t, const PRM_Template*);
42 
43  // Populate a GAS_OpenCLParms from an OP_Node using our default
44  // names
45  static void loadParmsFromOp(GAS_OpenCLParms &parms, const OP_Node *node, fpreal t);
46 
47 protected:
48  explicit GAS_OpenCL(const SIM_DataFactory *factory);
49  ~GAS_OpenCL() override;
50 
51  /// Creates a SIM_QueryArrays object to treat impact as a record
53  {
54  return new SIM_QueryCombine(BaseClass::createQueryObjectSubclass(), nodeParam().createQueryObject(this));
55  }
56  void makeEqualSubclass(const SIM_Data *source) override
57  {
58  BaseClass::makeEqualSubclass(source);
59  const GAS_OpenCL *src = SIM_DATA_CASTCONST(source, GAS_OpenCL);
60  if (src)
61  {
62  nodeParam() = src->nodeParam();
63  setVersionParms(src->versionParms());
64  }
65  }
66  void saveSubclass(std::ostream &os) const override
67  {
68  BaseClass::saveSubclass(os);
69  myNodeParms.save(os);
70  }
71  bool loadSubclass(UT_IStream &is) override
72  {
73  if (!BaseClass::loadSubclass(is))
74  return false;
75  if (!myNodeParms.load(is))
76  return false;
77  return true;
78  }
79  /// The overloaded callback that GAS_SubSolver will invoke to
80  /// perform our actual computation. We are giving a single object
81  /// at a time to work on.
82  bool solveGasSubclass(SIM_Engine &engine,
83  SIM_Object *obj,
84  SIM_Time time,
85  SIM_Time timestep) override;
86 
87 
88 private:
89  GAS_OpenCLParms myNodeParms;
90  GAS_OpenCLParms myAtParms;
91  OP_VERSION myVersion;
92 
93  /// We define this to be a DOP_Auto node which means we do not
94  /// need to implement a DOP_Node derivative for this data. Instead,
95  /// this description is used to define the interface.
96  static const SIM_DopDescription *getDopDescription();
97 
98 #ifdef CE_ENABLED
99 
100  // forces alignment of CE_Grids
101  void forceAlign( CE_Grid *&ret, SIM_RawField *src, const SIM_RawField *ex );
102 
103 
104  bool setAndExecuteKernel(cl::Kernel &kernel, const UT_Array<UT_Array< CE_Grid *> > &fields,
105  cl::NDRange global,
106  cl::NDRange local,
107  exint numtiles,
108  cl::Buffer tilestarts,
109  SIM_Object *obj,
110  fpreal time,
111  int frame,
112  fpreal timestep);
113 
114  bool setAndExecuteKernel(cl::Kernel &kernel,
115  cl::Kernel &singlekernel,
116  int singlekernelmaxitems,
117  const UT_Array<UT_Array< CE_Grid *> > &fields,
119  const UT_Int32Array &sizes,
120  const UT_Int32Array &singleitems,
121  const UT_Array<cl::NDRange> &globals,
122  const UT_Array<cl::NDRange> &locals,
123  exint numtiles,
124  cl::Buffer tilestarts,
125  SIM_Object *obj,
126  fpreal time,
127  int frame,
128  fpreal timestep);
129 
130  bool setKernelArguments(cl::Kernel &kernel, int paramcount,
131  const UT_Array<UT_Array< CE_Grid *> > &grids,
132  SIM_Object * obj,
133  UT_ErrorManager *errors,
135  fpreal time, int frame, fpreal timestep,
136  int singleworkitems = 0);
137 
138  void createOptionalAttributeOptions( SIM_Object *obj, UT_WorkBuffer &options );
139 
140  // Returns the number of items that can be run int single workgroup
141  // mode, zero if not possible.
142  int maxSingleWorkgroupItems( SIM_Object *obj, cl::Kernel &kernel);
143 
144  // Main Kernel Execution versions
145 
146  bool executeOpenCLKernel(cl::Kernel &kernel,
147  cl::Kernel &singlekernel,
148  int singlekernelmaxitems,
149  SIM_Object * obj,
150  fpreal time, int frame, fpreal timestep);
151 
152  // Kernel Execution versions
153  bool executeOpenCLKernelUnaligned(cl::Kernel &kernel, SIM_Object * obj, fpreal time,
154  int frame, fpreal timestep);
155  bool executeOpenCLKernelAligned( cl::Kernel &kernel, SIM_Object * obj, fpreal time,
156  int frame, fpreal timestep);
157  bool executeOpenCLKernelAlignedSingleAlign( cl::Kernel &kernel,
158  SIM_Object * obj, fpreal time, int frame, fpreal timestep);
159  bool executeOpenCLKernelAlignedMultiAlign( cl::Kernel &kernel,
160  SIM_Object * obj, fpreal time, int frame, fpreal timestep);
161  bool executeOpenCLKernelGeometry(cl::Kernel &kernel,
162  cl::Kernel &singlekernel,
163  int singlekernelmaxitems,
164  SIM_Object * obj,
165  fpreal time, int frame, fpreal timestep);
166  bool executeOpenCLKernelVDB(cl::Kernel &kernel,
167  SIM_Object * obj,
168  fpreal time, int frame, fpreal timestep);
169 
170 #endif
171  /// These macros are necessary to bind our node to the factory and
172  /// ensure useful constants like BaseClass are defined.
176  "Gas OpenCL",
177  getDopDescription());
178 };
179 
180 #endif
181 
GLuint GLsizei const GLuint const GLintptr const GLsizeiptr * sizes
Definition: glcorearb.h:2621
void setVersionParms(OP_VERSION version)
Definition: GAS_OpenCL.h:37
#define DECLARE_STANDARD_GETCASTTOTYPE()
Definition: SIM_DataUtils.h:50
#define SIM_DATA_CASTCONST(Data, DataClass)
Definition: SIM_Utils.h:34
const GAS_OpenCLParms & param() const
Definition: GAS_OpenCL.h:29
uint64 OP_VERSION
Definition: OP_Version.h:6
GT_API const UT_StringHolder time
#define GAS_API
Definition: GAS_API.h:10
int64 exint
Definition: SYS_Types.h:125
virtual bool solveGasSubclass(SIM_Engine &engine, SIM_Object *obj, SIM_Time time, SIM_Time timestep)=0
OP_VERSION versionParms() const
Definition: GAS_OpenCL.h:36
bool setKernelArguments(const UT_Array< Binding > &bindings, BindingPrecision nodeprecision, cl::Kernel &kernel, int &argidx, UT_Array< cl::Buffer > &buffers, fpreal timestep, UT_ErrorManager *error, UT_ErrorSeverity missingseverity, const OP &op)
GLuint GLsizei const GLuint const GLintptr * offsets
Definition: glcorearb.h:2621
#define DECLARE_DATAFACTORY(DataClass, SuperClass, Description, DopParms)
Definition: SIM_DataUtils.h:63
bool loadSubclass(UT_IStream &is) override
Definition: GAS_OpenCL.h:71
GLsizei GLsizei GLchar * source
Definition: glcorearb.h:803
const GLuint * buffers
Definition: glcorearb.h:661
GAS_OpenCLParms & nodeParam()
Definition: GAS_OpenCL.h:33
GLdouble t
Definition: glad.h:2397
GT_API const UT_StringHolder version
fpreal64 fpreal
Definition: SYS_Types.h:277
const GAS_OpenCLParms & nodeParam() const
Definition: GAS_OpenCL.h:34
A global error manager scope.
Memory buffer interface.
Definition: cl.hpp:1867
NDRange interface.
Definition: cl.hpp:2466
Kernel interface that implements cl_kernel.
Definition: cl.hpp:2544
void saveSubclass(std::ostream &os) const override
Definition: GAS_OpenCL.h:66
void makeEqualSubclass(const SIM_Data *source) override
Definition: GAS_OpenCL.h:56
SIM_Query * createQueryObjectSubclass() const override
Creates a SIM_QueryArrays object to treat impact as a record.
Definition: GAS_OpenCL.h:52
Definition: format.h:895
GLenum src
Definition: glcorearb.h:1793