WorkletBase.h 14.1 KB
Newer Older
1
2
3
4
5
6
7
8
//============================================================================
//  Copyright (c) Kitware, Inc.
//  All rights reserved.
//  See LICENSE.txt for details.
//  This software is distributed WITHOUT ANY WARRANTY; without even
//  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
//  PURPOSE.  See the above copyright notice for more information.
//
Kenneth Moreland's avatar
Kenneth Moreland committed
9
//  Copyright 2014 National Technology & Engineering Solutions of Sandia, LLC (NTESS).
10
//  Copyright 2014 UT-Battelle, LLC.
11
//  Copyright 2014 Los Alamos National Security.
12
//
Kenneth Moreland's avatar
Kenneth Moreland committed
13
//  Under the terms of Contract DE-NA0003525 with NTESS,
14
15
16
17
18
19
20
21
22
//  the U.S. Government retains certain rights in this software.
//
//  Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
//  Laboratory (LANL), the U.S. Government retains certain rights in
//  this software.
//============================================================================
#ifndef vtk_m_worklet_internal_WorkletBase_h
#define vtk_m_worklet_internal_WorkletBase_h

23
#include <vtkm/TopologyElementTag.h>
24
#include <vtkm/TypeListTag.h>
25

26
27
28
#include <vtkm/exec/FunctorBase.h>
#include <vtkm/exec/arg/BasicArg.h>
#include <vtkm/exec/arg/FetchTagExecObject.h>
29
#include <vtkm/exec/arg/FetchTagWholeCellSetIn.h>
30
31
#include <vtkm/exec/arg/InputIndex.h>
#include <vtkm/exec/arg/OutputIndex.h>
32
#include <vtkm/exec/arg/ThreadIndices.h>
33
#include <vtkm/exec/arg/ThreadIndicesBasic.h>
34
#include <vtkm/exec/arg/VisitIndex.h>
35
36
#include <vtkm/exec/arg/WorkIndex.h>

37
#include <vtkm/cont/arg/ControlSignatureTagBase.h>
38
#include <vtkm/cont/arg/TransportTagAtomicArray.h>
39
#include <vtkm/cont/arg/TransportTagCellSetIn.h>
40
#include <vtkm/cont/arg/TransportTagExecObject.h>
41
42
43
44
#include <vtkm/cont/arg/TransportTagWholeArrayIn.h>
#include <vtkm/cont/arg/TransportTagWholeArrayInOut.h>
#include <vtkm/cont/arg/TransportTagWholeArrayOut.h>
#include <vtkm/cont/arg/TypeCheckTagArray.h>
45
#include <vtkm/cont/arg/TypeCheckTagAtomicArray.h>
46
#include <vtkm/cont/arg/TypeCheckTagCellSet.h>
47
#include <vtkm/cont/arg/TypeCheckTagExecObject.h>
48

49
50
#include <vtkm/worklet/ScatterIdentity.h>

51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
namespace vtkm
{
namespace placeholders
{

template <int ControlSignatureIndex>
struct Arg : vtkm::exec::arg::BasicArg<ControlSignatureIndex>
{
};

/// Basic execution argument tags
struct _1 : Arg<1>
{
};
struct _2 : Arg<2>
{
};
struct _3 : Arg<3>
{
};
struct _4 : Arg<4>
{
};
struct _5 : Arg<5>
{
};
struct _6 : Arg<6>
{
};
struct _7 : Arg<7>
{
};
struct _8 : Arg<8>
{
};
struct _9 : Arg<9>
{
};
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
struct _10 : Arg<10>
{
};
struct _11 : Arg<11>
{
};
struct _12 : Arg<12>
{
};
struct _13 : Arg<13>
{
};
struct _14 : Arg<14>
{
};
struct _15 : Arg<15>
{
};
struct _16 : Arg<16>
{
};
struct _17 : Arg<17>
{
};
struct _18 : Arg<18>
{
};
struct _19 : Arg<19>
{
};
struct _20 : Arg<20>
{
};
122
123
}

124
125
126
127
namespace worklet
{
namespace internal
{
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144

/// Base class for all worklet classes. Worklet classes are subclasses and a
/// operator() const is added to implement an algorithm in VTK-m. Different
/// worklets have different calling semantics.
///
class WorkletBase : public vtkm::exec::FunctorBase
{
public:
  typedef vtkm::placeholders::_1 _1;
  typedef vtkm::placeholders::_2 _2;
  typedef vtkm::placeholders::_3 _3;
  typedef vtkm::placeholders::_4 _4;
  typedef vtkm::placeholders::_5 _5;
  typedef vtkm::placeholders::_6 _6;
  typedef vtkm::placeholders::_7 _7;
  typedef vtkm::placeholders::_8 _8;
  typedef vtkm::placeholders::_9 _9;
145
146
147
148
149
150
151
152
153
154
155
  typedef vtkm::placeholders::_10 _10;
  typedef vtkm::placeholders::_11 _11;
  typedef vtkm::placeholders::_12 _12;
  typedef vtkm::placeholders::_13 _13;
  typedef vtkm::placeholders::_14 _14;
  typedef vtkm::placeholders::_15 _15;
  typedef vtkm::placeholders::_16 _16;
  typedef vtkm::placeholders::_17 _17;
  typedef vtkm::placeholders::_18 _18;
  typedef vtkm::placeholders::_19 _19;
  typedef vtkm::placeholders::_20 _20;
156
157

  /// \c ExecutionSignature tag for getting the work index.
158
  ///
159
160
  typedef vtkm::exec::arg::WorkIndex WorkIndex;

161
162
163
164
  /// \c ExecutionSignature tag for getting the input index.
  ///
  typedef vtkm::exec::arg::InputIndex InputIndex;

165
  /// \c ExecutionSignature tag for getting the output index.
166
167
168
  ///
  typedef vtkm::exec::arg::OutputIndex OutputIndex;

169
170
171
172
  /// \c ExecutionSignature tag for getting the thread indices.
  ///
  typedef vtkm::exec::arg::ThreadIndices ThreadIndices;

173
174
175
176
  /// \c ExecutionSignature tag for getting the visit index.
  ///
  typedef vtkm::exec::arg::VisitIndex VisitIndex;

177
  /// \c ControlSignature tag for execution object inputs.
178
179
  struct ExecObject : vtkm::cont::arg::ControlSignatureTagBase
  {
180
    typedef vtkm::cont::arg::TypeCheckTagExecObject TypeCheckTag;
181
182
183
184
185
186
187
    typedef vtkm::cont::arg::TransportTagExecObject TransportTag;
    typedef vtkm::exec::arg::FetchTagExecObject FetchTag;
  };

  /// Default input domain is the first argument. Worklet subclasses can
  /// override this by redefining this type.
  typedef _1 InputDomain;
188

189
190
191
192
193
194
195
196
  /// All worklets must define their scatter operation. The scatter defines
  /// what output each input contributes to. The default scatter is the
  /// identity scatter (1-to-1 input to output).
  typedef vtkm::worklet::ScatterIdentity ScatterType;

  /// In addition to defining the scatter type, the worklet must produce the
  /// scatter. The default ScatterIdentity has no state, so just return an
  /// instance.
197
  VTKM_CONT
198
199
  ScatterType GetScatter() const { return ScatterType(); }

200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
  /// \brief A type list containing the type vtkm::Id.
  ///
  /// This is a convenience type to use as template arguments to \c
  /// ControlSignature tags to specify the types of worklet arguments.
  typedef vtkm::TypeListTagId IdType;

  /// \brief A type list containing the type vtkm::Id2.
  ///
  /// This is a convenience type to use as template arguments to \c
  /// ControlSignature tags to specify the types of worklet arguments.
  typedef vtkm::TypeListTagId2 Id2Type;

  /// \brief A type list containing the type vtkm::Id3.
  ///
  /// This is a convenience type to use as template arguments to \c
  /// ControlSignature tags to specify the types of worklet arguments.
  typedef vtkm::TypeListTagId3 Id3Type;

218
219
220
221
222
223
  /// \brief A type list containing the type vtkm::IdComponent.
  ///
  /// This is a convenience type to use as template arguments to \c
  /// ControlSignature tags to specify the types of worklet arguments.
  typedef vtkm::TypeListTagIdComponent IdComponentType;

224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
  /// \brief A list of types commonly used for indexing.
  ///
  /// This is a convenience type to use as template arguments to \c
  /// ControlSignature tags to specify the types of worklet arguments.
  typedef vtkm::TypeListTagIndex Index;

  /// \brief A list of types commonly used for scalar fields.
  ///
  /// This is a convenience type to use as template arguments to \c
  /// ControlSignature tags to specify the types of worklet arguments.
  typedef vtkm::TypeListTagFieldScalar Scalar;

  /// \brief A list of all basic types used for scalar fields.
  ///
  /// This is a convenience type to use as template arguments to \c
  /// ControlSignature tags to specify the types of worklet arguments.
  typedef vtkm::TypeListTagScalarAll ScalarAll;

  /// \brief A list of types commonly used for vector fields of 2 components.
  ///
  /// This is a convenience type to use as template arguments to \c
  /// ControlSignature tags to specify the types of worklet arguments.
  typedef vtkm::TypeListTagFieldVec2 Vec2;

  /// \brief A list of types commonly used for vector fields of 3 components.
  ///
  /// This is a convenience type to use as template arguments to \c
  /// ControlSignature tags to specify the types of worklet arguments.
  typedef vtkm::TypeListTagFieldVec3 Vec3;

  /// \brief A list of types commonly used for vector fields of 4 components.
  ///
  /// This is a convenience type to use as template arguments to \c
  /// ControlSignature tags to specify the types of worklet arguments.
  typedef vtkm::TypeListTagFieldVec4 Vec4;

  /// \brief A list of all basic types used for vector fields.
  ///
  /// This is a convenience type to use as template arguments to \c
  /// ControlSignature tags to specify the types of worklet arguments.
  typedef vtkm::TypeListTagVecAll VecAll;

  /// \brief A list of types (scalar and vector) commonly used in fields.
  ///
  /// This is a convenience type to use as template arguments to \c
  /// ControlSignature tags to specify the types of worklet arguments.
  typedef vtkm::TypeListTagField FieldCommon;

  /// \brief A list of vector types commonly used in fields.
  ///
  /// This is a convenience type to use as template arguments to \c
  /// ControlSignature tags to specify the types of worklet arguments.
  typedef vtkm::TypeListTagVecCommon VecCommon;

  /// \brief A list of generally common types.
  ///
  /// This is a convenience type to use as template arguments to \c
  /// ControlSignature tags to specify the types of worklet arguments.
  typedef vtkm::TypeListTagCommon CommonTypes;

  /// \brief A list of all basic types.
  ///
  /// This is a convenience type to use as template arguments to \c
  /// ControlSignature tags to specify the types of worklet arguments.
  typedef vtkm::TypeListTagAll AllTypes;
289

290
291
292
293
294
295
296
297
298
299
  /// \c ControlSignature tag for whole input arrays.
  ///
  /// The \c WholeArrayIn control signature tag specifies an \c ArrayHandle
  /// passed to the \c Invoke operation of the dispatcher. This is converted
  /// to an \c ArrayPortal object and passed to the appropriate worklet
  /// operator argument with one of the default args.
  ///
  /// The template operator specifies all the potential value types of the
  /// array. The default value type is all types.
  ///
300
301
302
  template <typename TypeList = AllTypes>
  struct WholeArrayIn : vtkm::cont::arg::ControlSignatureTagBase
  {
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
    typedef vtkm::cont::arg::TypeCheckTagArray<TypeList> TypeCheckTag;
    typedef vtkm::cont::arg::TransportTagWholeArrayIn TransportTag;
    typedef vtkm::exec::arg::FetchTagExecObject FetchTag;
  };

  /// \c ControlSignature tag for whole output arrays.
  ///
  /// The \c WholeArrayOut control signature tag specifies an \c ArrayHandle
  /// passed to the \c Invoke operation of the dispatcher. This is converted to
  /// an \c ArrayPortal object and passed to the appropriate worklet operator
  /// argument with one of the default args. Care should be taken to not write
  /// a value in one instance that will be overridden by another entry.
  ///
  /// The template operator specifies all the potential value types of the
  /// array. The default value type is all types.
  ///
319
320
321
  template <typename TypeList = AllTypes>
  struct WholeArrayOut : vtkm::cont::arg::ControlSignatureTagBase
  {
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
    typedef vtkm::cont::arg::TypeCheckTagArray<TypeList> TypeCheckTag;
    typedef vtkm::cont::arg::TransportTagWholeArrayOut TransportTag;
    typedef vtkm::exec::arg::FetchTagExecObject FetchTag;
  };

  /// \c ControlSignature tag for whole input/output arrays.
  ///
  /// The \c WholeArrayOut control signature tag specifies an \c ArrayHandle
  /// passed to the \c Invoke operation of the dispatcher. This is converted to
  /// an \c ArrayPortal object and passed to the appropriate worklet operator
  /// argument with one of the default args. Care should be taken to not write
  /// a value in one instance that will be read by or overridden by another
  /// entry.
  ///
  /// The template operator specifies all the potential value types of the
  /// array. The default value type is all types.
  ///
339
340
341
  template <typename TypeList = AllTypes>
  struct WholeArrayInOut : vtkm::cont::arg::ControlSignatureTagBase
  {
342
343
344
345
346
    typedef vtkm::cont::arg::TypeCheckTagArray<TypeList> TypeCheckTag;
    typedef vtkm::cont::arg::TransportTagWholeArrayInOut TransportTag;
    typedef vtkm::exec::arg::FetchTagExecObject FetchTag;
  };

347
348
349
350
351
352
353
354
355
356
357
358
  /// \c ControlSignature tag for whole input/output arrays.
  ///
  /// The \c AtomicArrayInOut control signature tag specifies an \c ArrayHandle
  /// passed to the \c Invoke operation of the dispatcher. This is converted to
  /// a \c vtkm::exec::AtomicArray object and passed to the appropriate worklet
  /// operator argument with one of the default args. The provided atomic
  /// operations can be used to resolve concurrency hazards, but have the
  /// potential to slow the program quite a bit.
  ///
  /// The template operator specifies all the potential value types of the
  /// array. The default value type is all types.
  ///
359
360
361
  template <typename TypeList = AllTypes>
  struct AtomicArrayInOut : vtkm::cont::arg::ControlSignatureTagBase
  {
362
363
364
365
366
    typedef vtkm::cont::arg::TypeCheckTagAtomicArray<TypeList> TypeCheckTag;
    typedef vtkm::cont::arg::TransportTagAtomicArray TransportTag;
    typedef vtkm::exec::arg::FetchTagExecObject FetchTag;
  };

367
368
  /// \c ControlSignature tag for whole input topology.
  ///
369
  /// The \c WholeCellSetIn control signature tag specifies an \c CellSet
370
371
372
373
374
  /// passed to the \c Invoke operation of the dispatcher. This is converted to
  /// a \c vtkm::exec::Connectivity* object and passed to the appropriate worklet
  /// operator argument with one of the default args. This can be used to
  /// global lookup for arbitrary topology information

375
376
  using Cell = vtkm::TopologyElementTagCell;
  using Point = vtkm::TopologyElementTagPoint;
377
378
379
  template <typename FromType = Point, typename ToType = Cell>
  struct WholeCellSetIn : vtkm::cont::arg::ControlSignatureTagBase
  {
380
    typedef vtkm::cont::arg::TypeCheckTagCellSet TypeCheckTag;
381
    typedef vtkm::cont::arg::TransportTagCellSetIn<FromType, ToType> TransportTag;
382
    typedef vtkm::exec::arg::FetchTagWholeCellSetIn FetchTag;
383
384
  };

385
386
387
388
389
  /// \brief Creates a \c ThreadIndices object.
  ///
  /// Worklet types can add additional indices by returning different object
  /// types.
  ///
390
  VTKM_SUPPRESS_EXEC_WARNINGS
391
392
393
  template <typename T,
            typename OutToInArrayType,
            typename VisitArrayType,
394
395
            typename InputDomainType>
  VTKM_EXEC vtkm::exec::arg::ThreadIndicesBasic GetThreadIndices(
396
397
398
399
400
    const T& threadIndex,
    const OutToInArrayType& outToIn,
    const VisitArrayType& visit,
    const InputDomainType&,
    const T& globalThreadIndexOffset = 0) const
401
  {
402
403
    return vtkm::exec::arg::ThreadIndicesBasic(
      threadIndex, outToIn.Get(threadIndex), visit.Get(threadIndex), globalThreadIndexOffset);
404
  }
405
406
407
408
409
410
};
}
}
} // namespace vtkm::worklet::internal

#endif //vtk_m_worklet_internal_WorkletBase_h