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  GAS_OpenCLParms &param() { return myParms; }
28  const GAS_OpenCLParms &param() const { return myParms; }
29 
30 // Static display callback
31  static int displayKernel(void * data, int, fpreal t, const PRM_Template*);
32 
33 protected:
34  explicit GAS_OpenCL(const SIM_DataFactory *factory);
35  virtual ~GAS_OpenCL();
36 
37  /// Creates a SIM_QueryArrays object to treat impact as a record
39  {
40  return new SIM_QueryCombine(BaseClass::createQueryObjectSubclass(), param().createQueryObject(this));
41  }
42  virtual void makeEqualSubclass(const SIM_Data *source)
43  {
44  BaseClass::makeEqualSubclass(source);
45  const GAS_OpenCL *src = SIM_DATA_CASTCONST(source, GAS_OpenCL);
46  if (src)
47  {
48  param() = src->param();
49  }
50  }
51  virtual void saveSubclass(std::ostream &os) const
52  {
53  BaseClass::saveSubclass(os);
54  myParms.save(os);
55  }
56  virtual bool loadSubclass(UT_IStream &is)
57  {
58  if (!BaseClass::loadSubclass(is))
59  return false;
60  if (!myParms.load(is))
61  return false;
62  return true;
63  }
64  /// The overloaded callback that GAS_SubSolver will invoke to
65  /// perform our actual computation. We are giving a single object
66  /// at a time to work on.
67  virtual bool solveGasSubclass(SIM_Engine &engine,
68  SIM_Object *obj,
69  SIM_Time time,
70  SIM_Time timestep);
71 
72 
73 private:
74  GAS_OpenCLParms myParms;
75 
76  /// We define this to be a DOP_Auto node which means we do not
77  /// need to implement a DOP_Node derivative for this data. Instead,
78  /// this description is used to define the interface.
79  static const SIM_DopDescription *getDopDescription();
80 
81 #ifdef CE_ENABLED
82 
83  // forces alignment of CE_Grids
84  void forceAlign( CE_Grid *&ret, SIM_RawField *src, const SIM_RawField *ex );
85 
86 
87  bool setAndExecuteKernel(cl::Kernel &kernel, const UT_Array<UT_Array< CE_Grid *> > &fields,
88  cl::NDRange global,
89  cl::NDRange local,
90  SIM_Object *obj,
91  fpreal time,
92  int frame,
93  fpreal timestep);
94 
95  bool setAndExecuteKernel(cl::Kernel &kernel, const UT_Array<UT_Array< CE_Grid *> > &fields,
97  const UT_Int32Array &sizes,
98  const UT_Array<cl::NDRange> &globals,
99  const UT_Array<cl::NDRange> &locals,
100  SIM_Object *obj,
101  fpreal time,
102  int frame,
103  fpreal timestep,
104  int singleworkitems = 0);
105 
106  bool setKernelArguments(cl::Kernel &kernel, int paramcount,
107  const UT_Array<UT_Array< CE_Grid *> > &grids,
108  SIM_Object * obj,
110  fpreal time, int frame, fpreal timestep,
111  int singleworkitems = 0);
112 
113  void createOptionalAttributeOptions( SIM_Object *obj, UT_WorkBuffer &options );
114 
115  // Returns the number of workitems required to run the kernel in worksets mode
116  // in a single workgroup, else zero if not possible,
117  int maxSingleWorkgroupItems( SIM_Object *obj, cl::Kernel &kernel);
118 
119  // Main Kernel Execution versions
120 
121  bool executeOpenCLKernel(cl::Kernel &kernel, SIM_Object * obj,
122  fpreal time, int frame, fpreal timestep,
123  int singleworkitems);
124 
125  // Kernel Execution versions
126  bool executeOpenCLKernelUnaligned(cl::Kernel &kernel, SIM_Object * obj, fpreal time,
127  int frame, fpreal timestep);
128  bool executeOpenCLKernelAligned( cl::Kernel &kernel, SIM_Object * obj, fpreal time,
129  int frame, fpreal timestep);
130  bool executeOpenCLKernelAlignedSingleAlign( cl::Kernel &kernel,
131  SIM_Object * obj, fpreal time, int frame, fpreal timestep);
132  bool executeOpenCLKernelAlignedMultiAlign( cl::Kernel &kernel,
133  SIM_Object * obj, fpreal time, int frame, fpreal timestep);
134  bool executeOpenCLKernelGeometry(cl::Kernel &kernel, SIM_Object * obj, fpreal time,
135  int frame, fpreal timestep, int singleworkitems);
136 
137 #endif
138  /// These macros are necessary to bind our node to the factory and
139  /// ensure useful constants like BaseClass are defined.
143  "Gas OpenCL",
144  getDopDescription());
145 };
146 
147 #endif
148 
#define DECLARE_STANDARD_GETCASTTOTYPE()
Definition: SIM_DataUtils.h:45
#define SIM_DATA_CASTCONST(Data, DataClass)
Definition: SIM_Utils.h:34
const GAS_OpenCLParms & param() const
Definition: GAS_OpenCL.h:28
GLenum src
Definition: glew.h:2410
GT_API const UT_StringHolder time
#define GAS_API
Definition: GAS_API.h:10
GLuint GLsizei const GLuint const GLintptr * offsets
Definition: glew.h:4117
virtual bool solveGasSubclass(SIM_Engine &engine, SIM_Object *obj, SIM_Time time, SIM_Time timestep)=0
GLsizei GLsizei GLchar * source
Definition: glew.h:1832
GLhandleARB obj
Definition: glew.h:6236
GLfloat param
Definition: glew.h:1530
#define DECLARE_DATAFACTORY(DataClass, SuperClass, Description, DopParms)
Definition: SIM_DataUtils.h:58
virtual void saveSubclass(std::ostream &os) const
Definition: GAS_OpenCL.h:51
GLuint GLsizei const GLuint const GLintptr const GLsizeiptr * sizes
Definition: glew.h:5268
virtual SIM_Query * createQueryObjectSubclass() const
Creates a SIM_QueryArrays object to treat impact as a record.
Definition: GAS_OpenCL.h:38
GLint GLenum GLsizei GLint GLsizei const void * data
Definition: glew.h:1379
const GLuint * buffers
Definition: glew.h:1683
virtual void makeEqualSubclass(const SIM_Data *source)
Definition: GAS_OpenCL.h:42
GAS_OpenCLParms & param()
Definition: GAS_OpenCL.h:27
double fpreal
Definition: SYS_Types.h:276
NDRange interface.
Definition: cl.hpp:2456
Kernel interface that implements cl_kernel.
Definition: cl.hpp:2534
GLdouble GLdouble t
Definition: glew.h:1398
virtual bool loadSubclass(UT_IStream &is)
Definition: GAS_OpenCL.h:56