PACMAN
0.1.0
Portable Algorithms for Coupling, Mapping, and Adaptive iNterpolation
Toggle main menu visibility
Loading...
Searching...
No Matches
execspaces.hpp
Go to the documentation of this file.
1
//
2
// This file is subject to the terms and conditions defined in
3
// file 'LICENSE', which is part of this source code package.
4
//
5
6
#pragma once
7
8
#include <Kokkos_Core.hpp>
9
#include <cstdlib>
10
#include <iostream>
11
#include <variant>
12
13
namespace
PACMAN
{
14
17
struct
ExecSpaces
{
18
static
constexpr
const
unsigned
char
SERIAL
= 0x00;
19
static
constexpr
const
unsigned
char
OPENMP
= 0x01;
20
static
constexpr
const
unsigned
char
THREADS
= 0x02;
21
static
constexpr
const
unsigned
char
CUDA
= 0x03;
22
static
constexpr
const
unsigned
char
HIP
= 0x04;
23
static
constexpr
const
unsigned
char
SYCL
= 0x05;
24
};
25
28
namespace
detail
{
29
template
<
typename
... Types>
struct
TypeList
{};
30
31
template
<
typename
List,
typename
Type>
struct
Append
;
32
33
template
<
typename
... Types,
typename
Type>
34
struct
Append
<
TypeList
<Types...>, Type> {
35
using
type
=
TypeList
<Types..., Type>;
36
};
37
38
template
<
typename
List>
struct
ToVariant
;
39
40
template
<
typename
... Types>
struct
ToVariant
<
TypeList
<Types...>> {
41
using
type
= std::variant<Types...>;
42
};
43
44
using
ExecSpaces0
=
TypeList<>
;
45
#if defined(KOKKOS_ENABLE_SERIAL)
46
using
ExecSpaces1
=
typename
Append<ExecSpaces0, Kokkos::Serial>::type
;
47
#else
48
using
ExecSpaces1
=
ExecSpaces0
;
49
#endif
50
#if defined(KOKKOS_ENABLE_OPENMP)
51
using
ExecSpaces2
=
typename
Append<ExecSpaces1, Kokkos::OpenMP>::type
;
52
#else
53
using
ExecSpaces2
=
ExecSpaces1
;
54
#endif
55
#if defined(KOKKOS_ENABLE_THREADS)
56
using
ExecSpaces3
=
typename
Append<ExecSpaces2, Kokkos::Threads>::type
;
57
#else
58
using
ExecSpaces3
=
ExecSpaces2
;
59
#endif
60
#if defined(KOKKOS_ENABLE_CUDA)
61
using
ExecSpaces4
=
typename
Append<ExecSpaces3, Kokkos::Cuda>::type
;
62
#else
63
using
ExecSpaces4
=
ExecSpaces3
;
64
#endif
65
#if defined(KOKKOS_ENABLE_HIP)
66
using
ExecSpaces5
=
typename
Append<ExecSpaces4, Kokkos::HIP>::type
;
67
#else
68
using
ExecSpaces5
=
ExecSpaces4
;
69
#endif
70
#if defined(KOKKOS_ENABLE_SYCL)
71
using
ExecSpaces6
=
typename
Append<ExecSpaces5, Kokkos::SYCL>::type
;
72
#else
73
using
ExecSpaces6
=
ExecSpaces5
;
74
#endif
75
}
// namespace detail
76
77
using
AvailableExecSpaces
=
typename
detail::ToVariant<detail::ExecSpaces6>::type
;
78
80
static
inline
AvailableExecSpaces
MakeExecSpace
(
const
unsigned
char
s) {
81
// clang-format off
82
switch
(s) {
83
case
ExecSpaces::SERIAL
:
84
#if defined(KOKKOS_ENABLE_SERIAL)
85
return
Kokkos::Serial{};
86
#else
87
std::cerr <<
"Kokkos::Serial is not enabled! Please recompile Kokkos with Kokkos_ENABLE_SERIAL!"
<< std::endl;
88
exit(EXIT_FAILURE);
89
#endif
90
case
ExecSpaces::OPENMP
:
91
#if defined(KOKKOS_ENABLE_OPENMP)
92
return
Kokkos::OpenMP{};
93
#else
94
std::cerr <<
"Kokkos::OpenMP is not enabled! Please recompile Kokkos with Kokkos_ENABLE_OPENMP!"
<< std::endl;
95
exit(EXIT_FAILURE);
96
#endif
97
case
ExecSpaces::THREADS
:
98
#if defined(KOKKOS_ENABLE_THREADS)
99
return
Kokkos::Threads{};
100
#else
101
std::cerr <<
"Kokkos::Threads is not enabled! Please recompile Kokkos with Kokkos_ENABLE_THREADS!"
<< std::endl;
102
exit(EXIT_FAILURE);
103
#endif
104
case
ExecSpaces::CUDA
:
105
#if defined(KOKKOS_ENABLE_CUDA)
106
return
Kokkos::Cuda{};
107
#else
108
std::cerr <<
"Kokkos::Cuda is not enabled! Please recompile Kokkos with Kokkos_ENABLE_CUDA!"
<< std::endl;
109
exit(EXIT_FAILURE);
110
#endif
111
case
ExecSpaces::HIP
:
112
#if defined(KOKKOS_ENABLE_HIP)
113
return
Kokkos::HIP{};
114
#else
115
std::cerr <<
"Kokkos::HIP is not enabled! Please recompile Kokkos with Kokkos_ENABLE_HIP!"
<< std::endl;
116
exit(EXIT_FAILURE);
117
#endif
118
case
ExecSpaces::SYCL
:
119
#if defined(KOKKOS_ENABLE_SYCL)
120
return
Kokkos::SYCL{};
121
#else
122
std::cerr <<
"Kokkos::SYCL is not enabled! Please recompile Kokkos with Kokkos_ENABLE_SYCL!"
<< std::endl;
123
exit(EXIT_FAILURE);
124
#endif
125
default
:
126
std::cerr <<
"execspace: Serial, OpenMP, Threads, Cuda, HIP, SYCL"
<< std::endl;
127
exit(EXIT_FAILURE);
128
}
129
// clang-format on
130
}
131
132
}
// namespace PACMAN
PACMAN::detail
A type variant which defines the enabled Kokkos execution spaces.
Definition
execspaces.hpp:28
PACMAN::detail::ExecSpaces0
TypeList<> ExecSpaces0
Definition
execspaces.hpp:44
PACMAN::detail::ExecSpaces4
ExecSpaces3 ExecSpaces4
Definition
execspaces.hpp:63
PACMAN::detail::ExecSpaces2
ExecSpaces1 ExecSpaces2
Definition
execspaces.hpp:53
PACMAN::detail::ExecSpaces6
ExecSpaces5 ExecSpaces6
Definition
execspaces.hpp:73
PACMAN::detail::ExecSpaces1
ExecSpaces0 ExecSpaces1
Definition
execspaces.hpp:48
PACMAN::detail::ExecSpaces3
ExecSpaces2 ExecSpaces3
Definition
execspaces.hpp:58
PACMAN::detail::ExecSpaces5
ExecSpaces4 ExecSpaces5
Definition
execspaces.hpp:68
PACMAN
Definition
concepts.hpp:14
PACMAN::MakeExecSpace
static AvailableExecSpaces MakeExecSpace(const unsigned char s)
Converts an execution-space selector byte to a variant type.
Definition
execspaces.hpp:80
PACMAN::AvailableExecSpaces
typename detail::ToVariant< detail::ExecSpaces6 >::type AvailableExecSpaces
Definition
execspaces.hpp:77
PACMAN::ExecSpaces
Constants representing available Kokkos execution spaces as unsigned chars, usable both from C++ and ...
Definition
execspaces.hpp:17
PACMAN::ExecSpaces::OPENMP
static constexpr const unsigned char OPENMP
Definition
execspaces.hpp:19
PACMAN::ExecSpaces::SERIAL
static constexpr const unsigned char SERIAL
Definition
execspaces.hpp:18
PACMAN::ExecSpaces::SYCL
static constexpr const unsigned char SYCL
Definition
execspaces.hpp:23
PACMAN::ExecSpaces::THREADS
static constexpr const unsigned char THREADS
Definition
execspaces.hpp:20
PACMAN::ExecSpaces::HIP
static constexpr const unsigned char HIP
Definition
execspaces.hpp:22
PACMAN::ExecSpaces::CUDA
static constexpr const unsigned char CUDA
Definition
execspaces.hpp:21
PACMAN::detail::Append< TypeList< Types... >, Type >::type
TypeList< Types..., Type > type
Definition
execspaces.hpp:35
PACMAN::detail::Append
Definition
execspaces.hpp:31
PACMAN::detail::ToVariant< TypeList< Types... > >::type
std::variant< Types... > type
Definition
execspaces.hpp:41
PACMAN::detail::ToVariant
Definition
execspaces.hpp:38
PACMAN::detail::TypeList
Definition
execspaces.hpp:29
src
common
execspaces.hpp
Generated on
for PACMAN by
1.17.0