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 call for retrieving values
31  static bool getParmB(OP_Node * me, const char * str, int idx, fpreal t );
32  static int getParmI(OP_Node * me, const char * str, int idx, fpreal t );
33  static void getParmS(OP_Node * me, const char * str, int idx, fpreal t,
34  UT_String &ret );
35 
36 // Generate a kernel argument signature for the selected parameters
37  static void getArgumentSign( OP_Node * me, int param, int maxparm, fpreal t,
39  UT_String &firstwriteable
40  );
41 
42 // Generate kernel
43  static void generateKernel( OP_Node * me, fpreal t, UT_WorkBuffer &str );
44 
45 // Static display callback
46  static int displayKernel(void * data, int, fpreal t, const PRM_Template*);
47 
48 protected:
49  explicit GAS_OpenCL(const SIM_DataFactory *factory);
50  virtual ~GAS_OpenCL();
51 
52  /// Creates a SIM_QueryArrays object to treat impact as a record
54  {
55  return new SIM_QueryCombine(BaseClass::createQueryObjectSubclass(), param().createQueryObject(this));
56  }
57  virtual void makeEqualSubclass(const SIM_Data *source)
58  {
59  BaseClass::makeEqualSubclass(source);
60  const GAS_OpenCL *src = SIM_DATA_CASTCONST(source, GAS_OpenCL);
61  if (src)
62  {
63  param() = src->param();
64  }
65  }
66  virtual void saveSubclass(std::ostream &os) const
67  {
68  BaseClass::saveSubclass(os);
69  myParms.save(os);
70  }
71  virtual bool loadSubclass(UT_IStream &is)
72  {
73  if (!BaseClass::loadSubclass(is))
74  return false;
75  if (!myParms.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  virtual bool solveGasSubclass(SIM_Engine &engine,
83  SIM_Object *obj,
84  SIM_Time time,
85  SIM_Time timestep);
86 
87 
88 private:
89  GAS_OpenCLParms myParms;
90 
91  /// We define this to be a DOP_Auto node which means we do not
92  /// need to implement a DOP_Node derivative for this data. Instead,
93  /// this description is used to define the interface.
94  static const SIM_DopDescription *getDopDescription();
95 
96 #ifdef CE_ENABLED
97 
98  // forces alignment of CE_Grids
99  void forceAlign( CE_Grid *&ret, SIM_RawField *src, const SIM_RawField *ex );
100 
101 
102  bool setAndExecuteKernel(cl::Kernel &kernel, const UT_Array<UT_Array< CE_Grid *> > &fields,
103  cl::NDRange global,
104  cl::NDRange local,
105  SIM_Object *obj,
106  fpreal time,
107  fpreal timestep);
108 
109  bool setAndExecuteKernel(cl::Kernel &kernel, const UT_Array<UT_Array< CE_Grid *> > &fields,
111  const UT_Int32Array &sizes,
112  const UT_Array<cl::NDRange> &globals,
113  const UT_Array<cl::NDRange> &locals,
114  SIM_Object *obj,
115  fpreal time,
116  fpreal timestep,
117  int singleworkitems = 0);
118 
119  bool setKernelArguments(cl::Kernel &kernel, int paramcount,
120  const UT_Array<UT_Array< CE_Grid *> > &grids,
121  SIM_Object * obj,
123  fpreal time, fpreal timestep,
124  int singleworkitems = 0);
125 
126  bool setKernelArgument( cl::Kernel &kernel, int i, int &argidx,
127  const UT_Array<UT_Array< CE_Grid *> > &grids,
128  SIM_Object *obj,
130  fpreal timestep,
131  UT_StringHolder &geoname,
132  const SIM_Geometry *&geo,
133  SIM_GeometryCopy *&geocopy);
134 
135  void createOptionalAttributeOptions( SIM_Object *obj, UT_WorkBuffer &options );
136 
137  // Returns the number of workitems required to run the kernel in worksets mode
138  // in a single workgroup, else zero if not possible,
139  int maxSingleWorkgroupItems( SIM_Object *obj, cl::Kernel &kernel);
140 
141  // Main Kernel Execution versions
142 
143  bool executeOpenCLKernel(cl::Kernel &kernel, SIM_Object * obj,
144  fpreal time, fpreal timestep,
145  int singleworkitems);
146 
147  // Kernel Execution versions
148  bool executeOpenCLKernelUnaligned(cl::Kernel &kernel, SIM_Object * obj, fpreal time, fpreal timestep);
149  bool executeOpenCLKernelAligned( cl::Kernel &kernel, SIM_Object * obj, fpreal time, fpreal timestep);
150  bool executeOpenCLKernelAlignedSingleAlign( cl::Kernel &kernel,
151  SIM_Object * obj, fpreal time, fpreal timestep);
152  bool executeOpenCLKernelAlignedMultiAlign( cl::Kernel &kernel,
153  SIM_Object * obj, fpreal time, fpreal timestep);
154  bool executeOpenCLKernelGeometry(cl::Kernel &kernel, SIM_Object * obj, fpreal time, fpreal timestep,
155  int singleworkitems);
156 
157 #endif
158  /// These macros are necessary to bind our node to the factory and
159  /// ensure useful constants like BaseClass are defined.
163  "Gas OpenCL",
164  getDopDescription());
165 };
166 
167 #endif
168 
GLuint GLsizei const GLuint const GLintptr const GLsizeiptr * sizes
Definition: glcorearb.h:2620
#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
GT_API const UT_StringHolder time
#define GAS_API
Definition: GAS_API.h:10
virtual bool solveGasSubclass(SIM_Engine &engine, SIM_Object *obj, SIM_Time time, SIM_Time timestep)=0
png_uint_32 i
Definition: png.h:2877
GLuint GLsizei const GLuint const GLintptr * offsets
Definition: glcorearb.h:2620
#define DECLARE_DATAFACTORY(DataClass, SuperClass, Description, DopParms)
Definition: SIM_DataUtils.h:58
virtual void saveSubclass(std::ostream &os) const
Definition: GAS_OpenCL.h:66
virtual SIM_Query * createQueryObjectSubclass() const
Creates a SIM_QueryArrays object to treat impact as a record.
Definition: GAS_OpenCL.h:53
GLsizei GLsizei GLchar * source
Definition: glcorearb.h:802
GLboolean * data
Definition: glcorearb.h:130
int sign(T a)
Definition: ImathFun.h:63
virtual void makeEqualSubclass(const SIM_Data *source)
Definition: GAS_OpenCL.h:57
GAS_OpenCLParms & param()
Definition: GAS_OpenCL.h:27
const GLuint * buffers
Definition: glcorearb.h:660
double fpreal
Definition: SYS_Types.h:270
GLenum GLfloat param
Definition: glcorearb.h:103
NDRange interface.
Definition: cl.hpp:2456
Kernel interface that implements cl_kernel.
Definition: cl.hpp:2534
virtual bool loadSubclass(UT_IStream &is)
Definition: GAS_OpenCL.h:71
GLenum src
Definition: glcorearb.h:1792
This implements a SIM_Geometry that copies the source geometry.