VTK-m  2.2
FetchTagArrayDirectOut.h
Go to the documentation of this file.
1 //============================================================================
2 // Copyright (c) Kitware, Inc.
3 // All rights reserved.
4 // See LICENSE.txt for details.
5 //
6 // This software is distributed WITHOUT ANY WARRANTY; without even
7 // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
8 // PURPOSE. See the above copyright notice for more information.
9 //============================================================================
10 #ifndef vtk_m_exec_arg_FetchTagArrayDirectOut_h
11 #define vtk_m_exec_arg_FetchTagArrayDirectOut_h
12 
14 #include <vtkm/exec/arg/Fetch.h>
15 
16 #include <type_traits>
17 
18 namespace vtkm
19 {
20 namespace exec
21 {
22 namespace arg
23 {
24 
32 {
33 };
34 
35 template <typename ExecObjectType>
38  ExecObjectType>
39 {
40  using ValueType = typename ExecObjectType::ValueType;
41 
43  template <typename ThreadIndicesType>
44  VTKM_EXEC ValueType Load(const ThreadIndicesType& indices,
45  const ExecObjectType& arrayPortal) const
46  {
47  return this->DoLoad(
48  indices, arrayPortal, typename std::is_default_constructible<ValueType>::type{});
49  }
50 
52  template <typename ThreadIndicesType, typename T>
53  VTKM_EXEC void Store(const ThreadIndicesType& indices,
54  const ExecObjectType& arrayPortal,
55  const T& value) const
56  {
57  arrayPortal.Set(indices.GetOutputIndex(), static_cast<ValueType>(value));
58  }
59 
60 private:
62  template <typename ThreadIndicesType>
63  VTKM_EXEC ValueType DoLoad(const ThreadIndicesType&, const ExecObjectType&, std::true_type) const
64  {
65  // Load is a no-op for this fetch.
66  return ValueType();
67  }
68 
70  template <typename ThreadIndicesType>
71  VTKM_EXEC ValueType DoLoad(const ThreadIndicesType& indices,
72  const ExecObjectType& arrayPortal,
73  std::false_type) const
74  {
75  // Cannot create a ValueType object, so pull one out of the array portal. This may seem
76  // weird because an output array often has garbage in it. However, this case can happen
77  // with special arrays with Vec-like values that reference back to the array memory.
78  // For example, with ArrayHandleRecombineVec, the values are actual objects that point
79  // back to the array for on demand reading and writing. You need the buffer established
80  // by the array even if there is garbage in that array.
81  return arrayPortal.Get(indices.GetOutputIndex());
82  }
83 };
84 }
85 }
86 } // namespace vtkm::exec::arg
87 
88 #endif //vtk_m_exec_arg_FetchTagArrayDirectOut_h
VTKM_EXEC
#define VTKM_EXEC
Definition: ExportMacros.h:51
vtkm
Groups connected points that have the same field value.
Definition: Atomic.h:19
vtkm::exec::arg::FetchTagArrayDirectOut
Fetch tag for setting array values with direct indexing.
Definition: FetchTagArrayDirectOut.h:31
vtkm::exec::arg::Fetch< vtkm::exec::arg::FetchTagArrayDirectOut, vtkm::exec::arg::AspectTagDefault, ExecObjectType >::DoLoad
ValueType DoLoad(const ThreadIndicesType &, const ExecObjectType &, std::true_type) const
Definition: FetchTagArrayDirectOut.h:63
vtkm::exec::arg::Fetch::ValueType
typename ExecObjectType::ValueType ValueType
The type of value to load and store.
Definition: Fetch.h:58
vtkm::exec::arg::Fetch
Class for loading and storing values in thread instance.
Definition: Fetch.h:49
vtkm::exec::arg::Fetch< vtkm::exec::arg::FetchTagArrayDirectOut, vtkm::exec::arg::AspectTagDefault, ExecObjectType >::ValueType
typename ExecObjectType::ValueType ValueType
Definition: FetchTagArrayDirectOut.h:40
vtkm::exec::arg::Fetch< vtkm::exec::arg::FetchTagArrayDirectOut, vtkm::exec::arg::AspectTagDefault, ExecObjectType >::Load
ValueType Load(const ThreadIndicesType &indices, const ExecObjectType &arrayPortal) const
Definition: FetchTagArrayDirectOut.h:44
Fetch.h
AspectTagDefault.h
vtkm::exec::arg::AspectTagDefault
Aspect tag to use for default load/store of data.
Definition: AspectTagDefault.h:22
vtkm::exec::arg::Fetch< vtkm::exec::arg::FetchTagArrayDirectOut, vtkm::exec::arg::AspectTagDefault, ExecObjectType >::DoLoad
ValueType DoLoad(const ThreadIndicesType &indices, const ExecObjectType &arrayPortal, std::false_type) const
Definition: FetchTagArrayDirectOut.h:71
vtkm::exec::arg::Fetch< vtkm::exec::arg::FetchTagArrayDirectOut, vtkm::exec::arg::AspectTagDefault, ExecObjectType >::Store
void Store(const ThreadIndicesType &indices, const ExecObjectType &arrayPortal, const T &value) const
Definition: FetchTagArrayDirectOut.h:53
VTKM_SUPPRESS_EXEC_WARNINGS
#define VTKM_SUPPRESS_EXEC_WARNINGS
Definition: ExportMacros.h:53