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
|
#ifndef HeterogeneousCore_AlpakaInterface_interface_alpakastdAlgorithm_h
#define HeterogeneousCore_AlpakaInterface_interface_alpakastdAlgorithm_h
#include <algorithm>
#include <functional>
#include <utility>
#include <alpaka/alpaka.hpp>
// reimplementation of std algorithms able to work on device code
namespace alpaka_std {
template <typename RandomIt, typename T, typename Compare = std::less<T>>
ALPAKA_FN_HOST_ACC constexpr RandomIt lower_bound(RandomIt first, RandomIt last, const T &value, Compare comp = {}) {
auto count = last - first;
while (count > 0) {
auto it = first;
auto step = count / 2;
it += step;
if (comp(*it, value)) {
first = ++it;
count -= step + 1;
} else {
count = step;
}
}
return first;
}
template <typename RandomIt, typename T, typename Compare = std::less<T>>
ALPAKA_FN_HOST_ACC constexpr RandomIt upper_bound(RandomIt first, RandomIt last, const T &value, Compare comp = {}) {
auto count = last - first;
while (count > 0) {
auto it = first;
auto step = count / 2;
it += step;
if (!comp(value, *it)) {
first = ++it;
count -= step + 1;
} else {
count = step;
}
}
return first;
}
} // namespace alpaka_std
#endif // HeterogeneousCore_AlpakaInterface_interface_alpakastdAlgorithm_h
|