forked from kokkos/kokkos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Kokkos_IterSwap.hpp
73 lines (62 loc) · 2.08 KB
/
Kokkos_IterSwap.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
//@HEADER
// ************************************************************************
//
// Kokkos v. 4.0
// Copyright (2022) National Technology & Engineering
// Solutions of Sandia, LLC (NTESS).
//
// Under the terms of Contract DE-NA0003525 with NTESS,
// the U.S. Government retains certain rights in this software.
//
// Part of Kokkos, under the Apache License v2.0 with LLVM Exceptions.
// See https://kokkos.org/LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//@HEADER
#ifndef KOKKOS_STD_ALGORITHMS_ITER_SWAP_HPP
#define KOKKOS_STD_ALGORITHMS_ITER_SWAP_HPP
#include <Kokkos_Core.hpp>
#include "impl/Kokkos_Constraints.hpp"
namespace Kokkos {
namespace Experimental {
namespace Impl {
template <class IteratorType1, class IteratorType2>
struct StdIterSwapFunctor {
IteratorType1 m_a;
IteratorType2 m_b;
KOKKOS_FUNCTION
void operator()(int i) const {
(void)i;
::Kokkos::kokkos_swap(*m_a, *m_b);
}
KOKKOS_FUNCTION
StdIterSwapFunctor(IteratorType1 _a, IteratorType2 _b)
: m_a(std::move(_a)), m_b(std::move(_b)) {}
};
template <class IteratorType1, class IteratorType2>
void iter_swap_impl(IteratorType1 a, IteratorType2 b) {
// is there a better way to do this maybe?
::Kokkos::parallel_for(
1, StdIterSwapFunctor<IteratorType1, IteratorType2>(a, b));
Kokkos::DefaultExecutionSpace().fence(
"Kokkos::iter_swap: fence after operation");
}
} // namespace Impl
//----------------------------------------------------------------------------
// iter_swap
template <class IteratorType1, class IteratorType2>
void iter_swap(IteratorType1 a, IteratorType2 b) {
Impl::iter_swap_impl(a, b);
}
#ifdef KOKKOS_ENABLE_DEPRECATED_CODE_4
template <class T>
KOKKOS_DEPRECATED_WITH_COMMENT("Use Kokkos::kokkos_swap instead!")
KOKKOS_FUNCTION
void swap(T& a, T& b) noexcept(::Kokkos::kokkos_swap(std::declval<T&>(),
std::declval<T&>())) {
::Kokkos::kokkos_swap(a, b);
}
#endif
} // namespace Experimental
} // namespace Kokkos
#endif