PACMAN 0.1.0
Portable Algorithms for Coupling, Mapping, and Adaptive iNterpolation
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
13namespace PACMAN {
14
17struct 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
28namespace detail {
29template <typename... Types> struct TypeList {};
30
31template <typename List, typename Type> struct Append;
32
33template <typename... Types, typename Type>
34struct Append<TypeList<Types...>, Type> {
35 using type = TypeList<Types..., Type>;
36};
37
38template <typename List> struct ToVariant;
39
40template <typename... Types> struct ToVariant<TypeList<Types...>> {
41 using type = std::variant<Types...>;
42};
43
45#if defined(KOKKOS_ENABLE_SERIAL)
47#else
49#endif
50#if defined(KOKKOS_ENABLE_OPENMP)
52#else
54#endif
55#if defined(KOKKOS_ENABLE_THREADS)
57#else
59#endif
60#if defined(KOKKOS_ENABLE_CUDA)
62#else
64#endif
65#if defined(KOKKOS_ENABLE_HIP)
67#else
69#endif
70#if defined(KOKKOS_ENABLE_SYCL)
72#else
74#endif
75} // namespace detail
76
78
80static inline AvailableExecSpaces MakeExecSpace(const unsigned char s) {
81 // clang-format off
82 switch (s) {
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
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
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
A type variant which defines the enabled Kokkos execution spaces.
TypeList<> ExecSpaces0
ExecSpaces3 ExecSpaces4
ExecSpaces1 ExecSpaces2
ExecSpaces5 ExecSpaces6
ExecSpaces0 ExecSpaces1
ExecSpaces2 ExecSpaces3
ExecSpaces4 ExecSpaces5
static AvailableExecSpaces MakeExecSpace(const unsigned char s)
Converts an execution-space selector byte to a variant type.
typename detail::ToVariant< detail::ExecSpaces6 >::type AvailableExecSpaces
Constants representing available Kokkos execution spaces as unsigned chars, usable both from C++ and ...
static constexpr const unsigned char OPENMP
static constexpr const unsigned char SERIAL
static constexpr const unsigned char SYCL
static constexpr const unsigned char THREADS
static constexpr const unsigned char HIP
static constexpr const unsigned char CUDA