HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros 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 <UT/UT_StringStream.h>
21 #include "GAS_OpenCLParms.proto.h"
22 
23 class GA_CEAttribute;
24 
26 {
27 public:
28  GAS_OpenCLParms &param() { return myParms; }
29  const GAS_OpenCLParms &param() const { return myParms; }
30 
31 // static call for retrieving values
32  static bool getParmB(OP_Node * me, const char * str, int idx, fpreal t );
33  static int getParmI(OP_Node * me, const char * str, int idx, fpreal t );
34  static void getParmS(OP_Node * me, const char * str, int idx, fpreal t,
35  UT_String &ret );
36 
37 // Generate a kernel argument signature for the selected parameters
38  static void getArgumentSign( OP_Node * me, int param, int maxparm, fpreal t,
40  UT_String &firstwriteable
41  );
42 
43 // Generate kernel
44  static void generateKernel( OP_Node * me, fpreal t, UT_WorkBuffer &str );
45 
46 // Static display callback
47  static int displayKernel(void * data, int, fpreal t, const PRM_Template*);
48 
49 protected:
50  explicit GAS_OpenCL(const SIM_DataFactory *factory);
51  virtual ~GAS_OpenCL();
52 
53  /// Creates a SIM_QueryArrays object to treat impact as a record
55  {
56  return new SIM_QueryCombine(BaseClass::createQueryObjectSubclass(), param().createQueryObject(this));
57  }
58  virtual void makeEqualSubclass(const SIM_Data *source)
59  {
60  BaseClass::makeEqualSubclass(source);
61  const GAS_OpenCL *src = SIM_DATA_CASTCONST(source, GAS_OpenCL);
62  if (src)
63  {
64  param() = src->param();
65  }
66  }
67  virtual void saveSubclass(std::ostream &os) const
68  {
69  BaseClass::saveSubclass(os);
70  myParms.save(os);
71  }
72  virtual bool loadSubclass(UT_IStream &is)
73  {
74  if (!BaseClass::loadSubclass(is))
75  return false;
76  if (!myParms.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  virtual bool solveGasSubclass(SIM_Engine &engine,
84  SIM_Object *obj,
85  SIM_Time time,
86  SIM_Time timestep);
87 
88 
89 private:
90  GAS_OpenCLParms myParms;
91 
92  /// We define this to be a DOP_Auto node which means we do not
93  /// need to implement a DOP_Node derivative for this data. Instead,
94  /// this description is used to define the interface.
95  static const SIM_DopDescription *getDopDescription();
96 
97 #ifdef CE_ENABLED
98 
99  // forces alignment of CE_Grids
100  void forceAlign( CE_Grid *&ret, SIM_RawField *src, const SIM_RawField *ex );
101 
102 
103  bool setAndExecuteKernel(cl::Kernel &kernel, const UT_Array<UT_Array< CE_Grid *> > &fields,
104  cl::NDRange global,
105  cl::NDRange local,
106  SIM_Object *obj,
107  fpreal time,
108  fpreal timestep);
109 
110  bool setAndExecuteKernel(cl::Kernel &kernel, const UT_Array<UT_Array< CE_Grid *> > &fields,
112  const UT_Int32Array &sizes,
113  const UT_Array<cl::NDRange> &globals,
114  const UT_Array<cl::NDRange> &locals,
115  SIM_Object *obj,
116  fpreal time,
117  fpreal timestep);
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 
125  bool setKernelArgument( cl::Kernel &kernel, int i, int &argidx,
126  const UT_Array<UT_Array< CE_Grid *> > &grids,
127  SIM_Object *obj,
129  fpreal timestep,
130  UT_StringHolder &geoname,
131  const SIM_Geometry *&geo,
132  SIM_GeometryCopy *&geocopy);
133 
134  void createOptionalAttributeOptions( SIM_Object *obj, UT_WorkBuffer &options );
135 
136  // Main Kernel Execution versions
137 
138  bool executeOpenCLKernel(cl::Kernel &kernel, SIM_Object * obj,
139  fpreal time, fpreal timestep);
140 
141  // Kernel Execution versions
142  bool executeOpenCLKernelUnaligned(cl::Kernel &kernel, SIM_Object * obj, fpreal time, fpreal timestep);
143  bool executeOpenCLKernelAligned( cl::Kernel &kernel, SIM_Object * obj, fpreal time, fpreal timestep);
144  bool executeOpenCLKernelAlignedSingleAlign( cl::Kernel &kernel,
145  SIM_Object * obj, fpreal time, fpreal timestep);
146  bool executeOpenCLKernelAlignedMultiAlign( cl::Kernel &kernel,
147  SIM_Object * obj, fpreal time, fpreal timestep);
148  bool executeOpenCLKernelGeometry(cl::Kernel &kernel, SIM_Object * obj, fpreal time, fpreal timestep);
149 
150 #endif
151  /// These macros are necessary to bind our node to the factory and
152  /// ensure useful constants like BaseClass are defined.
156  "Gas OpenCL",
157  getDopDescription());
158 };
159 
160 #endif
161 
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:29
#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:67
virtual SIM_Query * createQueryObjectSubclass() const
Creates a SIM_QueryArrays object to treat impact as a record.
Definition: GAS_OpenCL.h:54
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:58
GAS_OpenCLParms & param()
Definition: GAS_OpenCL.h:28
const GLuint * buffers
Definition: glcorearb.h:660
double fpreal
Definition: SYS_Types.h:269
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:72
GLenum src
Definition: glcorearb.h:1792
This implements a SIM_Geometry that copies the source geometry.