Viskores
1.0
viskores
Swap.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
19
#ifndef viskores_Swap_h
20
#define viskores_Swap_h
21
22
#include <
viskores/internal/ExportMacros.h
>
23
24
#include <algorithm>
25
26
// Below there is some code to deal with conflicts between Viskores's Swap and the Swap that comes
27
// with CUDA's CUB. We need to make sure that the Swap function gets included so that our
28
// defensive code works either way.
29
#if defined(VISKORES_CUDA) && defined(VISKORES_CUDA_DEVICE_PASS) && \
30
defined(VISKORES_CUDA_VERSION_MAJOR) && (VISKORES_CUDA_VERSION_MAJOR >= 12)
31
#include <cub/thread/thread_sort.cuh>
32
#endif
33
34
namespace
viskores
35
{
36
38
#if defined(VISKORES_CUDA) && defined(VISKORES_CUDA_DEVICE_PASS)
39
// CUDA 12 adds a `cub::Swap` function that creates ambiguity with `viskores::Swap`.
40
// This happens when a function from the `cub` namespace is called with an object of a class
41
// defined in the `viskores` namespace as an argument. If that function has an unqualified call to
42
// `Swap`, it results in ADL being used, causing the templated functions `cub::Swap` and
43
// `viskores::Swap` to conflict.
44
#if defined(VISKORES_CUDA_VERSION_MAJOR) && (VISKORES_CUDA_VERSION_MAJOR >= 12)
45
using
cub::Swap
;
46
#else
47
template
<
typename
T>
48
VISKORES_EXEC_CONT
inline
void
Swap
(T& a, T& b)
49
{
50
T temp = a;
51
a = b;
52
b = temp;
53
}
54
#endif
55
#elif defined(VISKORES_HIP)
56
template
<
typename
T>
57
__host__
inline
void
Swap
(T& a, T& b)
58
{
59
using
std::swap;
60
swap(a, b);
61
}
62
template
<
typename
T>
63
__device__
inline
void
Swap
(T& a, T& b)
64
{
65
T temp = a;
66
a = b;
67
b = temp;
68
}
69
#else
70
template
<
typename
T>
71
VISKORES_EXEC_CONT
inline
void
Swap
(T& a, T& b)
72
{
73
using
std::swap;
74
swap(a, b);
75
}
76
#endif
77
78
}
// end namespace viskores
79
80
#endif //viskores_Swap_h
VISKORES_EXEC_CONT
#define VISKORES_EXEC_CONT
Definition:
ExportMacros.h:60
ExportMacros.h
viskores
Groups connected points that have the same field value.
Definition:
Atomic.h:27
viskores::Swap
void Swap(T &a, T &b)
Performs a swap operation. Safe to call from cuda code.
Definition:
Swap.h:71
Generated by
1.8.17