VTK-m  2.2
ArrayCopyDevice.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_ArrayCopyDevice_h
11 #define vtk_m_cont_ArrayCopyDevice_h
12 
13 #include <vtkm/cont/Algorithm.h>
14 #include <vtkm/cont/ArrayHandle.h>
17 #include <vtkm/cont/Logging.h>
19 
21 
22 // TODO: When virtual arrays are available, compile the implementation in a .cxx/.cu file. Common
23 // arrays are copied directly but anything else would be copied through virtual methods.
24 
25 namespace vtkm
26 {
27 namespace cont
28 {
29 
30 namespace detail
31 {
32 
33 template <typename T1, typename S1, typename T2, typename S2>
34 VTKM_CONT void ArrayCopyImpl(const vtkm::cont::ArrayHandle<T1, S1>& source,
36 {
37  VTKM_STATIC_ASSERT((!std::is_same<T1, T2>::value || !std::is_same<S1, S2>::value));
38 
39  // Current implementation of Algorithm::Copy will first try to copy on devices where the
40  // data is already available.
41  vtkm::cont::Algorithm::Copy(source, destination);
42 }
43 
44 template <typename T, typename S>
45 VTKM_CONT void ArrayCopyImpl(const vtkm::cont::ArrayHandle<T, S>& source,
46  vtkm::cont::ArrayHandle<T, S>& destination)
47 {
48  destination.DeepCopyFrom(source);
49 }
50 
51 } // namespace detail
52 
74 template <typename InValueType, typename InStorage, typename OutValueType, typename OutStorage>
77 {
80  using SameTypes = std::is_same<InArrayType, OutArrayType>;
81  using IsWritable = vtkm::cont::internal::IsWritableArrayHandle<OutArrayType>;
82 
83  // There are three cases handled here:
84  // 1. The arrays are the same type:
85  // -> Deep copy the buffers and the Storage object
86  // 2. The arrays are different and the output is writable:
87  // -> Do element-wise copy
88  // 3. The arrays are different and the output is not writable:
89  // -> fail (cannot copy)
90 
91  // Give a nice error message for case 3:
92  VTKM_STATIC_ASSERT_MSG(IsWritable::value || SameTypes::value,
93  "Cannot copy to a read-only array with a different "
94  "type than the source.");
95 
96  // Static dispatch cases 1 & 2
97  detail::ArrayCopyImpl(source, destination);
98 }
99 
101 
102 }
103 } // namespace vtkm::cont
104 
105 #endif //vtk_m_cont_ArrayCopyDevice_h
vtkm::cont::ArrayHandle
Manages an array-worth of data.
Definition: ArrayHandle.h:300
ArrayHandle.h
vtkm::cont::ArrayCopyDevice
void ArrayCopyDevice(const vtkm::cont::ArrayHandle< InValueType, InStorage > &source, vtkm::cont::ArrayHandle< OutValueType, OutStorage > &destination)
Does a deep copy from one array to another array.
Definition: ArrayCopyDevice.h:75
vtkm
Groups connected points that have the same field value.
Definition: Atomic.h:19
DeviceAdapterTag.h
UnknownArrayHandle.h
VTKM_STATIC_ASSERT
#define VTKM_STATIC_ASSERT(condition)
Definition: StaticAssert.h:16
Algorithm.h
VTKM_STATIC_ASSERT_MSG
#define VTKM_STATIC_ASSERT_MSG(condition, message)
Definition: StaticAssert.h:18
vtkm_cont_export.h
VTKM_CONT
#define VTKM_CONT
Definition: ExportMacros.h:57
vtkm::cont::Algorithm::Copy
static bool Copy(vtkm::cont::DeviceAdapterId devId, const vtkm::cont::ArrayHandle< T, CIn > &input, vtkm::cont::ArrayHandle< U, COut > &output)
Definition: Algorithm.h:411
ErrorExecution.h
vtkm::cont::ArrayHandle::DeepCopyFrom
void DeepCopyFrom(const vtkm::cont::ArrayHandle< ValueType, StorageTag > &source) const
Deep copies the data in the array.
Definition: ArrayHandle.h:707
Logging.h
Logging utilities.