VTK-m  2.2
Swap.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 
11 #ifndef vtk_m_Swap_h
12 #define vtk_m_Swap_h
13 
15 
16 #ifdef VTKM_CUDA
17 #include <thrust/swap.h>
18 #else
19 #include <algorithm>
20 #endif
21 
22 namespace vtkm
23 {
24 
26 #if defined(VTKM_CUDA)
27 // CUDA 12 adds a `cub::Swap` function that creates ambiguity with `vtkm::Swap`.
28 // This happens when a function from the `cub` namespace is called with an object of a class
29 // defined in the `vtkm` namespace as an argument. If that function has an unqualified call to
30 // `Swap`, it results in ADL being used, causing the templated functions `cub::Swap` and
31 // `vtkm::Swap` to conflict.
32 #if defined(VTKM_CUDA_VERSION_MAJOR) && (VTKM_CUDA_VERSION_MAJOR >= 12) && \
33  defined(VTKM_CUDA_DEVICE_PASS)
34 using cub::Swap;
35 #else
36 template <typename T>
37 VTKM_EXEC_CONT inline void Swap(T& a, T& b)
38 {
39  using thrust::swap;
40  swap(a, b);
41 }
42 #endif
43 #elif defined(VTKM_HIP)
44 template <typename T>
45 __host__ inline void Swap(T& a, T& b)
46 {
47  using std::swap;
48  swap(a, b);
49 }
50 template <typename T>
51 __device__ inline void Swap(T& a, T& b)
52 {
53  T temp = a;
54  a = b;
55  b = temp;
56 }
57 #else
58 template <typename T>
59 VTKM_EXEC_CONT inline void Swap(T& a, T& b)
60 {
61  using std::swap;
62  swap(a, b);
63 }
64 #endif
65 
66 } // end namespace vtkm
67 
68 #endif //vtk_m_Swap_h
vtkm
Groups connected points that have the same field value.
Definition: Atomic.h:19
VTKM_EXEC_CONT
#define VTKM_EXEC_CONT
Definition: ExportMacros.h:52
ExportMacros.h
vtkm::Swap
void Swap(T &a, T &b)
Performs a swap operation. Safe to call from cuda code.
Definition: Swap.h:59