Viskores  1.0
ArrayCopyDevice.h
Go to the documentation of this file.
1 //============================================================================
2 // The contents of this file are covered by the Viskores license. See
3 // LICENSE.txt for details.
4 //
5 // By contributing to this file, all contributors agree to the Developer
6 // Certificate of Origin Version 1.1 (DCO 1.1) as stated in DCO.txt.
7 //============================================================================
8 
9 //============================================================================
10 // Copyright (c) Kitware, Inc.
11 // All rights reserved.
12 // See LICENSE.txt for details.
13 //
14 // This software is distributed WITHOUT ANY WARRANTY; without even
15 // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
16 // PURPOSE. See the above copyright notice for more information.
17 //============================================================================
18 #ifndef viskores_cont_ArrayCopyDevice_h
19 #define viskores_cont_ArrayCopyDevice_h
20 
25 #include <viskores/cont/Logging.h>
27 
29 
30 // TODO: When virtual arrays are available, compile the implementation in a .cxx/.cu file. Common
31 // arrays are copied directly but anything else would be copied through virtual methods.
32 
33 namespace viskores
34 {
35 namespace cont
36 {
37 
38 namespace detail
39 {
40 
41 template <typename T1, typename S1, typename T2, typename S2>
42 VISKORES_CONT void ArrayCopyImpl(const viskores::cont::ArrayHandle<T1, S1>& source,
44 {
45  VISKORES_STATIC_ASSERT((!std::is_same<T1, T2>::value || !std::is_same<S1, S2>::value));
46 
47  // Current implementation of Algorithm::Copy will first try to copy on devices where the
48  // data is already available.
49  viskores::cont::Algorithm::Copy(source, destination);
50 }
51 
52 template <typename T, typename S>
53 VISKORES_CONT void ArrayCopyImpl(const viskores::cont::ArrayHandle<T, S>& source,
55 {
56  destination.DeepCopyFrom(source);
57 }
58 
59 } // namespace detail
60 
82 template <typename InValueType, typename InStorage, typename OutValueType, typename OutStorage>
86 {
89  using SameTypes = std::is_same<InArrayType, OutArrayType>;
90  using IsWritable = viskores::cont::internal::IsWritableArrayHandle<OutArrayType>;
91 
92  // There are three cases handled here:
93  // 1. The arrays are the same type:
94  // -> Deep copy the buffers and the Storage object
95  // 2. The arrays are different and the output is writable:
96  // -> Do element-wise copy
97  // 3. The arrays are different and the output is not writable:
98  // -> fail (cannot copy)
99 
100  // Give a nice error message for case 3:
101  VISKORES_STATIC_ASSERT_MSG(IsWritable::value || SameTypes::value,
102  "Cannot copy to a read-only array with a different "
103  "type than the source.");
104 
105  // Static dispatch cases 1 & 2
106  detail::ArrayCopyImpl(source, destination);
107 }
108 
110 
111 }
112 } // namespace viskores::cont
113 
114 #endif //viskores_cont_ArrayCopyDevice_h
ArrayHandle.h
DeviceAdapterTag.h
viskores::cont::ArrayHandle
Manages an array-worth of data.
Definition: ArrayHandle.h:313
viskores::cont::Algorithm::Copy
static bool Copy(viskores::cont::DeviceAdapterId devId, const viskores::cont::ArrayHandle< T, CIn > &input, viskores::cont::ArrayHandle< U, COut > &output)
Definition: Algorithm.h:422
VISKORES_CONT
#define VISKORES_CONT
Definition: ExportMacros.h:65
UnknownArrayHandle.h
viskores
Groups connected points that have the same field value.
Definition: Atomic.h:27
Algorithm.h
ErrorExecution.h
VISKORES_STATIC_ASSERT_MSG
#define VISKORES_STATIC_ASSERT_MSG(condition, message)
Definition: StaticAssert.h:26
viskores::cont::ArrayCopyDevice
void ArrayCopyDevice(const viskores::cont::ArrayHandle< InValueType, InStorage > &source, viskores::cont::ArrayHandle< OutValueType, OutStorage > &destination)
Does a deep copy from one array to another array.
Definition: ArrayCopyDevice.h:83
viskores::cont::ArrayHandle::DeepCopyFrom
void DeepCopyFrom(const viskores::cont::ArrayHandle< ValueType, StorageTag > &source) const
Deep copies the data in the array.
Definition: ArrayHandle.h:723
Logging.h
Logging utilities.
VISKORES_STATIC_ASSERT
#define VISKORES_STATIC_ASSERT(condition)
Definition: StaticAssert.h:24
viskores_cont_export.h