-
Notifications
You must be signed in to change notification settings - Fork 4
/
p3a_execution.hpp
146 lines (102 loc) · 2.59 KB
/
p3a_execution.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#pragma once
#include "p3a_macros.hpp"
#include "p3a_simd.hpp"
#include <exception>
#include <string>
#include <Kokkos_Core.hpp>
#ifdef KOKKOS_ENABLE_HIP
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wignored-attributes"
#include <hip/hip_runtime.h>
#pragma clang diagnostic pop
#endif
#include <Kokkos_Core.hpp>
namespace p3a {
namespace execution {
class sequenced_policy {
public:
P3A_ALWAYS_INLINE constexpr void synchronize() const {}
using simd_abi_type = simd_abi::scalar;
};
inline constexpr sequenced_policy seq = {};
class hot_policy {
public:
P3A_ALWAYS_INLINE P3A_HOST_DEVICE inline constexpr
void synchronize() const {}
using simd_abi_type = simd_abi::scalar;
};
inline constexpr hot_policy hot = {};
class kokkos_serial_policy {
public:
void synchronize() const {}
using simd_abi_type = simd_abi::ForSpace<Kokkos::DefaultHostExecutionSpace>;
using kokkos_execution_space = Kokkos::Serial;
};
inline constexpr kokkos_serial_policy kokkos_serial = {};
}
#ifdef KOKKOS_ENABLE_CUDA
class cuda_exception : public std::exception
{
std::string error_string;
public:
cuda_exception(cudaError_t error);
virtual const char* what() const noexcept override;
};
namespace details {
void handle_cuda_error(cudaError_t error);
}
namespace execution {
class cuda_policy {
public:
void synchronize() const;
using simd_abi_type = simd_abi::scalar;
using kokkos_execution_space = Kokkos::Cuda;
};
inline constexpr cuda_policy cuda = {};
}
#endif
#ifdef KOKKOS_ENABLE_HIP
class hip_exception : public std::exception
{
std::string error_string;
public:
hip_exception(hipError_t error);
virtual const char* what() const noexcept override;
};
namespace details {
void handle_hip_error(hipError_t error);
}
namespace execution {
class hip_policy {
public:
void synchronize() const;
using simd_abi_type = simd_abi::scalar;
using kokkos_execution_space = Kokkos::HIP;
};
inline constexpr hip_policy hip = {};
}
#endif
#ifdef KOKKOS_ENABLE_OPENMP
namespace execution {
class openmp_policy {
public:
void synchronize() const {}
using simd_abi_type = simd_abi::ForSpace<Kokkos::DefaultHostExecutionSpace>;
using kokkos_execution_space = Kokkos::OpenMP;
};
inline constexpr openmp_policy openmp = {};
}
#endif
namespace execution {
#if defined(KOKKOS_ENABLE_CUDA)
using parallel_policy = cuda_policy;
#elif defined(KOKKOS_ENABLE_HIP)
using parallel_policy = hip_policy;
#elif defined(KOKKOS_ENABLE_OPENMP)
using parallel_policy = openmp_policy;
#else
using parallel_policy = kokkos_serial_policy;
#endif
inline constexpr parallel_policy par = {};
}
}