VTK-m  2.0
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 static std::vector<vtkm::cont::internal::Buffer> CreateBuffers()
107  {
108  DiscardMetaData metaData;
109  metaData.NumberOfValues = 0;
110  return vtkm::cont::internal::CreateBuffers(metaData);
111  }
112 
113  VTKM_CONT static void ResizeBuffers(vtkm::Id numValues,
114  const std::vector<vtkm::cont::internal::Buffer>& buffers,
117  {
118  VTKM_ASSERT(numValues >= 0);
119  buffers[0].GetMetaData<DiscardMetaData>().NumberOfValues = numValues;
120  }
121 
122  VTKM_CONT static vtkm::Id GetNumberOfValues(
123  const std::vector<vtkm::cont::internal::Buffer>& buffers)
124  {
125  return buffers[0].GetMetaData<DiscardMetaData>().NumberOfValues;
126  }
127 
128  VTKM_CONT static void Fill(const std::vector<vtkm::cont::internal::Buffer>&,
129  const ValueType&,
130  vtkm::Id,
131  vtkm::Id,
133  {
134  // Fill is a NO-OP.
135  }
136 
137  VTKM_CONT static ReadPortalType CreateReadPortal(const std::vector<vtkm::cont::internal::Buffer>&,
140  {
141  throw vtkm::cont::ErrorBadValue("Cannot read from ArrayHandleDiscard.");
142  }
143 
144  VTKM_CONT static WritePortalType CreateWritePortal(
145  const std::vector<vtkm::cont::internal::Buffer>& buffers,
148  {
149  return WritePortalType(GetNumberOfValues(buffers));
150  }
151 };
152 
153 template <typename ValueType_>
154 struct ArrayHandleDiscardTraits
155 {
156  using ValueType = ValueType_;
157  using StorageTag = StorageTagDiscard;
159 };
160 
161 } // end namespace internal
162 
166 template <typename ValueType_>
167 class ArrayHandleDiscard : public internal::ArrayHandleDiscardTraits<ValueType_>::Superclass
168 {
169 public:
173 };
174 
176 template <typename T>
177 struct IsArrayHandleDiscard : std::false_type
178 {
179 };
180 
181 template <typename T>
182 struct IsArrayHandleDiscard<ArrayHandle<T, internal::StorageTagDiscard>> : std::true_type
183 {
184 };
185 
186 } // end namespace cont
187 } // end namespace vtkm
188 
189 #endif // vtk_m_cont_ArrayHandleDiscard_h
vtkm::cont::ArrayHandle
Manages an array-worth of data.
Definition: ArrayHandle.h:283
ArrayHandle.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_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::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:167
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:177
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