-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathp3a_error_code.hpp
49 lines (42 loc) · 1.02 KB
/
p3a_error_code.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
#pragma once
#include <type_traits>
#include <Kokkos_Core.hpp>
#include "p3a_dynamic_array.hpp"
namespace p3a {
class device_error_code {
int* m_pointer;
public:
device_error_code(int* pointer_arg)
:m_pointer(pointer_arg)
{
}
device_error_code(device_error_code&&) = default;
device_error_code(device_error_code const&) = default;
device_error_code& operator=(device_error_code&&) = default;
device_error_code& operator=(device_error_code const&) = default;
template <class T,
std::enable_if_t<std::is_enum_v<T> || std::is_integral_v<T>, bool> = false>
P3A_HOST_DEVICE void operator=(T const& rhs) const
{
Kokkos::atomic_store(m_pointer, static_cast<int>(rhs));
}
};
class error_code {
host_pinned_array<int> m_array;
public:
error_code()
{
m_array.resize(1, 0);
}
device_error_code on_device()
{
return device_error_code(m_array.data());
}
template <class T>
T value() const
{
p3a::execution::par.synchronize();
return static_cast<T>(m_array[0]);
}
};
}