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