VTK-m  1.8
ArrayHandleDiscard.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_cont_ArrayHandleDiscard_h
11 #define vtk_m_cont_ArrayHandleDiscard_h
12 
13 #include <vtkm/TypeTraits.h>
14 #include <vtkm/cont/ArrayHandle.h>
16 
17 #include <type_traits>
18 
19 namespace vtkm
20 {
21 namespace exec
22 {
23 namespace internal
24 {
25 
28 template <typename ValueType_>
29 class ArrayPortalDiscard
30 {
31 public:
32  using ValueType = ValueType_;
33 
36  ArrayPortalDiscard()
37  : NumberOfValues(0)
38  {
39  } // needs to be host and device so that cuda can create lvalue of these
40 
41  VTKM_CONT
42  explicit ArrayPortalDiscard(vtkm::Id numValues)
43  : NumberOfValues(numValues)
44  {
45  }
46 
51  template <class OtherV>
52  VTKM_CONT ArrayPortalDiscard(const ArrayPortalDiscard<OtherV>& src)
53  : NumberOfValues(src.NumberOfValues)
54  {
55  }
56 
58  vtkm::Id GetNumberOfValues() const { return this->NumberOfValues; }
59 
60  ValueType Get(vtkm::Id) const
61  {
62  VTKM_UNREACHABLE("Cannot read from ArrayHandleDiscard.");
64  }
65 
66  VTKM_EXEC
67  void Set(vtkm::Id index, const ValueType&) const
68  {
69  VTKM_ASSERT(index < this->GetNumberOfValues());
70  (void)index;
71  // no-op
72  }
73 
74 private:
75  vtkm::Id NumberOfValues;
76 };
77 
78 } // end namespace internal
79 } // end namespace exec
80 
81 namespace cont
82 {
83 
84 namespace internal
85 {
86 
87 struct VTKM_ALWAYS_EXPORT StorageTagDiscard
88 {
89 };
90 
91 struct VTKM_ALWAYS_EXPORT DiscardMetaData
92 {
93  vtkm::Id NumberOfValues = 0;
94 };
95 
96 template <typename ValueType>
97 class Storage<ValueType, StorageTagDiscard>
98 {
99 public:
100  using WritePortalType = vtkm::exec::internal::ArrayPortalDiscard<ValueType>;
101 
102  // Note that this portal is write-only, so you will probably run into problems if
103  // you actually try to use this read portal.
104  using ReadPortalType = vtkm::exec::internal::ArrayPortalDiscard<ValueType>;
105 
106  VTKM_CONT constexpr static vtkm::IdComponent GetNumberOfBuffers() { return 1; }
107 
108  VTKM_CONT static void ResizeBuffers(vtkm::Id numValues,
109  vtkm::cont::internal::Buffer* buffers,
112  {
113  VTKM_ASSERT(numValues >= 0);
114  buffers[0].GetMetaData<DiscardMetaData>().NumberOfValues = numValues;
115  }
116 
117  VTKM_CONT static vtkm::Id GetNumberOfValues(const vtkm::cont::internal::Buffer* buffers)
118  {
119  return buffers[0].GetMetaData<DiscardMetaData>().NumberOfValues;
120  }
121 
122  VTKM_CONT static void Fill(vtkm::cont::internal::Buffer*,
123  const ValueType&,
124  vtkm::Id,
125  vtkm::Id,
127  {
128  // Fill is a NO-OP.
129  }
130 
131  VTKM_CONT static ReadPortalType CreateReadPortal(const vtkm::cont::internal::Buffer*,
134  {
135  throw vtkm::cont::ErrorBadValue("Cannot read from ArrayHandleDiscard.");
136  }
137 
138  VTKM_CONT static WritePortalType CreateWritePortal(vtkm::cont::internal::Buffer* buffers,
141  {
142  return WritePortalType(GetNumberOfValues(buffers));
143  }
144 };
145 
146 template <typename ValueType_>
147 struct ArrayHandleDiscardTraits
148 {
149  using ValueType = ValueType_;
150  using StorageTag = StorageTagDiscard;
152 };
153 
154 } // end namespace internal
155 
159 template <typename ValueType_>
160 class ArrayHandleDiscard : public internal::ArrayHandleDiscardTraits<ValueType_>::Superclass
161 {
162 public:
166 };
167 
169 template <typename T>
170 struct IsArrayHandleDiscard : std::false_type
171 {
172 };
173 
174 template <typename T>
175 struct IsArrayHandleDiscard<ArrayHandle<T, internal::StorageTagDiscard>> : std::true_type
176 {
177 };
178 
179 } // end namespace cont
180 } // end namespace vtkm
181 
182 #endif // vtk_m_cont_ArrayHandleDiscard_h
vtkm::cont::ArrayHandle
Manages an array-worth of data.
Definition: ArrayHandle.h:287
ArrayHandle.h
VTKM_EXEC
#define VTKM_EXEC
Definition: ExportMacros.h:51
vtkm
VTKM_NO_DEPRECATED_VIRTUAL.
Definition: Algorithms.h:18
VTKM_ASSERT
#define VTKM_ASSERT(condition)
Definition: Assert.h:43
VTKM_EXEC_CONT
#define VTKM_EXEC_CONT
Definition: ExportMacros.h:52
vtkm::Get
VTKM_SUPPRESS_EXEC_WARNINGS VTKM_EXEC_CONT auto Get(const vtkm::Tuple< Ts... > &tuple) -> decltype(tuple.template Get< Index >())
Retrieve the object from a vtkm::Tuple at the given index.
Definition: Tuple.h:83
vtkm::IdComponent
vtkm::Int32 IdComponent
Represents a component ID (index of component in a vector).
Definition: Types.h:168
vtkm::Id
vtkm::Int32 Id
Represents an ID (index into arrays).
Definition: Types.h:191
vtkm::cont::ArrayHandleDiscard
ArrayHandleDiscard is a write-only array that discards all data written to it.
Definition: ArrayHandleDiscard.h:160
vtkm::cont::Token
A token to hold the scope of an ArrayHandle or other object.
Definition: Token.h:35
TypeTraits.h
vtkm::cont::ArrayHandleDiscard::VTKM_ARRAY_HANDLE_SUBCLASS
VTKM_ARRAY_HANDLE_SUBCLASS(ArrayHandleDiscard,(ArrayHandleDiscard< ValueType_ >),(typename internal::ArrayHandleDiscardTraits< ValueType_ >::Superclass))
VTKM_CONT
#define VTKM_CONT
Definition: ExportMacros.h:57
vtkm::cont::DeviceAdapterId
Definition: DeviceAdapterTag.h:52
VTKM_UNREACHABLE
#define VTKM_UNREACHABLE(msg)
VTKM_UNREACHABLE is similar to VTK_ASSUME, with the significant difference that it is not conditional...
Definition: Unreachable.h:31
vtkm::cont::IsArrayHandleDiscard
Helper to determine if an ArrayHandle type is an ArrayHandleDiscard.
Definition: ArrayHandleDiscard.h:170
vtkm::cont::ErrorBadValue
This class is thrown when a VTKm function or method encounters an invalid value that inhibits progres...
Definition: ErrorBadValue.h:25
vtkm::CopyFlag
CopyFlag
Definition: Flags.h:16
VTKM_ALWAYS_EXPORT
#define VTKM_ALWAYS_EXPORT
Definition: ExportMacros.h:92
VTKM_SUPPRESS_EXEC_WARNINGS
#define VTKM_SUPPRESS_EXEC_WARNINGS
Definition: ExportMacros.h:53
vtkm::TypeTraits::ZeroInitialization
static VTKM_EXEC_CONT T ZeroInitialization()
Definition: TypeTraits.h:75
Unreachable.h