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 <CE/CE_Snippet.h>
19 #include <SIM/SIM_Query.h>
20 #include <SIM/SIM_QueryCombine.h>
21 #include "GAS_OpenCLParms.proto.h"
22 
23 class GA_CEAttribute;
24 
26 {
27 public:
28  // The live parameters we are solving with
29  // These are transitory for the solve.
30  const GAS_OpenCLParms &param() const { return myAtParms; }
31 
32  // The parameters we set from tne node, representing our original
33  // parameters (before @ binding)
34  GAS_OpenCLParms &nodeParam() { return myNodeParms; }
35  const GAS_OpenCLParms &nodeParam() const { return myNodeParms; }
36 
37  OP_VERSION versionParms() const { return myVersion; }
38  void setVersionParms(OP_VERSION version) { myVersion = version; }
39 
40  // Static display callback
41  static int displayKernel(void * data, int, fpreal t, const PRM_Template*);
42  static int expandKernel(void * data, int, fpreal t, const PRM_Template*);
43 
44  // Populate a GAS_OpenCLParms from an OP_Node using our default
45  // names
46  static void loadParmsFromOp(GAS_OpenCLParms &parms, const OP_Node *node, fpreal t);
47 
48 protected:
49  explicit GAS_OpenCL(const SIM_DataFactory *factory);
50  ~GAS_OpenCL() override;
51 
52  /// Creates a SIM_QueryArrays object to treat impact as a record
54  {
55  return new SIM_QueryCombine(BaseClass::createQueryObjectSubclass(), nodeParam().createQueryObject(this));
56  }
57  void makeEqualSubclass(const SIM_Data *source) override
58  {
59  BaseClass::makeEqualSubclass(source);
60  const GAS_OpenCL *src = SIM_DATA_CASTCONST(source, GAS_OpenCL);
61  if (src)
62  {
63  nodeParam() = src->nodeParam();
64  setVersionParms(src->versionParms());
65  }
66  }
67  void saveSubclass(std::ostream &os) const override
68  {
69  BaseClass::saveSubclass(os);
70  myNodeParms.save(os);
71  }
72  bool loadSubclass(UT_IStream &is) override
73  {
74  if (!BaseClass::loadSubclass(is))
75  return false;
76  if (!myNodeParms.load(is))
77  return false;
78  return true;
79  }
80  /// The overloaded callback that GAS_SubSolver will invoke to
81  /// perform our actual computation. We are giving a single object
82  /// at a time to work on.
83  bool solveGasSubclass(SIM_Engine &engine,
84  SIM_Object *obj,
85  SIM_Time time,
86  SIM_Time timestep) override;
87 
88 
89 private:
90  GAS_OpenCLParms myNodeParms;
91  GAS_OpenCLParms myAtParms;
92  OP_VERSION myVersion;
93 
94  /// We define this to be a DOP_Auto node which means we do not
95  /// need to implement a DOP_Node derivative for this data. Instead,
96  /// this description is used to define the interface.
97  static const SIM_DopDescription *getDopDescription();
98 
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,
105  CE_Snippet::RunOver runover,
106  const UT_Array<UT_Array< CE_Grid *> > &fields,
107  cl::NDRange global,
108  cl::NDRange local,
109  exint numtiles,
110  cl::Buffer tilestarts,
111  SIM_Object *obj,
112  fpreal time,
113  int frame,
114  fpreal timestep);
115 
116  bool setAndExecuteKernel(cl::Kernel &kernel,
117  cl::Kernel &singlekernel,
118  int singlekernelmaxitems,
119  CE_Snippet::RunOver runover,
120  const UT_Array<UT_Array< CE_Grid *> > &fields,
122  const UT_Int32Array &sizes,
123  const UT_Int32Array &singleitems,
124  const UT_Array<cl::NDRange> &globals,
125  const UT_Array<cl::NDRange> &locals,
126  exint numtiles,
127  cl::Buffer tilestarts,
128  SIM_Object *obj,
129  fpreal time,
130  int frame,
131  fpreal timestep);
132 
133  bool setKernelArguments(cl::Kernel &kernel, int paramcount,
134  CE_Snippet::RunOver runover,
135  const UT_Array<UT_Array< CE_Grid *> > &grids,
136  SIM_Object * obj,
137  UT_ErrorManager *errors,
138  UT_Array<cl::Buffer> &owned_buffers,
139  UT_Array<cl::Buffer> &referenced_buffers,
140  fpreal time, int frame, fpreal timestep,
141  int singleworkitems = 0);
142 
143  void createOptionalAttributeOptions( CE_Snippet::RunOver runover, SIM_Object *obj, UT_WorkBuffer &options );
144 
145  // Returns the number of items that can be run int single workgroup
146  // mode, zero if not possible.
147  int maxSingleWorkgroupItems( SIM_Object *obj, cl::Kernel &kernel);
148 
149  // Main Kernel Execution versions
150 
151  bool executeOpenCLKernel(cl::Kernel &kernel,
152  cl::Kernel &singlekernel,
153  int singlekernelmaxitems,
154  CE_Snippet::RunOver runover,
155  SIM_Object * obj,
156  fpreal time, int frame, fpreal timestep);
157 
158  // Kernel Execution versions
159  bool executeOpenCLKernelUnaligned(cl::Kernel &kernel, SIM_Object * obj, fpreal time,
160  int frame, fpreal timestep);
161  bool executeOpenCLKernelAligned( cl::Kernel &kernel, SIM_Object * obj, fpreal time,
162  int frame, fpreal timestep);
163  bool executeOpenCLKernelAlignedSingleAlign( cl::Kernel &kernel,
164  SIM_Object * obj, fpreal time, int frame, fpreal timestep);
165  bool executeOpenCLKernelAlignedMultiAlign( cl::Kernel &kernel,
166  SIM_Object * obj, fpreal time, int frame, fpreal timestep);
167  bool executeOpenCLKernelGeometry(cl::Kernel &kernel,
168  cl::Kernel &singlekernel,
169  int singlekernelmaxitems,
170  CE_Snippet::RunOver runover,
171  SIM_Object * obj,
172  fpreal time, int frame, fpreal timestep);
173  bool executeOpenCLKernelVDB(cl::Kernel &kernel,
174  CE_Snippet::RunOver runover,
175  SIM_Object * obj,
176  fpreal time, int frame, fpreal timestep);
177 
178  /// These macros are necessary to bind our node to the factory and
179  /// ensure useful constants like BaseClass are defined.
183  "Gas OpenCL",
184  getDopDescription());
185 };
186 
187 #endif
188 
GLuint GLsizei const GLuint const GLintptr const GLsizeiptr * sizes
Definition: glcorearb.h:2621
void setVersionParms(OP_VERSION version)
Definition: GAS_OpenCL.h:38
#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:30
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:37
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:72
GLsizei GLsizei GLchar * source
Definition: glcorearb.h:803
GAS_OpenCLParms & nodeParam()
Definition: GAS_OpenCL.h:34
GLdouble t
Definition: glad.h:2397
GT_API const UT_StringHolder version
GA_API const UT_StringHolder parms
fpreal64 fpreal
Definition: SYS_Types.h:278
bool setKernelArguments(const UT_Array< Binding > &bindings, BindingPrecision nodeprecision, cl::Kernel &kernel, int &argidx, UT_Array< cl::Buffer > &owned_buffers, UT_Array< cl::Buffer > &referenced_buffers, fpreal timestep, UT_ErrorManager *error, UT_ErrorSeverity missingseverity, const OP &op)
const GAS_OpenCLParms & nodeParam() const
Definition: GAS_OpenCL.h:35
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:67
void makeEqualSubclass(const SIM_Data *source) override
Definition: GAS_OpenCL.h:57
SIM_Query * createQueryObjectSubclass() const override
Creates a SIM_QueryArrays object to treat impact as a record.
Definition: GAS_OpenCL.h:53
Definition: format.h:1821
GLenum src
Definition: glcorearb.h:1793