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
26// clang-format off
29using AvailableExecSpaces = std::variant<
30#if defined(KOKKOS_ENABLE_SERIAL)
31 Kokkos::Serial
32#endif
33#if defined(KOKKOS_ENABLE_OPENMP)
34 , Kokkos::OpenMP
35#endif
36#if defined(KOKKOS_ENABLE_THREADS)
37 , Kokkos::Threads
38#endif
39#if defined(KOKKOS_ENABLE_CUDA)
40 , Kokkos::Cuda
41#endif
42#if defined(KOKKOS_ENABLE_HIP)
43 , Kokkos::HIP
44#endif
45#if defined(KOKKOS_ENABLE_SYCL)
46 , Kokkos::SYCL
47#endif
48>;
49// clang-format on
50
52static inline AvailableExecSpaces MakeExecSpace(const unsigned char s) {
53 // clang-format off
54 switch (s) {
56#if defined(KOKKOS_ENABLE_SERIAL)
57 return Kokkos::Serial{};
58#else
59 std::cerr << "Kokkos::Serial is not enabled! Please recompile Kokkos with Kokkos_ENABLE_SERIAL!" << std::endl;
61#endif
63#if defined(KOKKOS_ENABLE_OPENMP)
64 return Kokkos::OpenMP{};
65#else
66 std::cerr << "Kokkos::OpenMP is not enabled! Please recompile Kokkos with Kokkos_ENABLE_OPENMP!" << std::endl;
68#endif
70#if defined(KOKKOS_ENABLE_THREADS)
71 return Kokkos::Threads{};
72#else
73 std::cerr << "Kokkos::Threads is not enabled! Please recompile Kokkos with Kokkos_ENABLE_THREADS!" << std::endl;
75#endif
77#if defined(KOKKOS_ENABLE_CUDA)
78 return Kokkos::Cuda{};
79#else
80 std::cerr << "Kokkos::Cuda is not enabled! Please recompile Kokkos with Kokkos_ENABLE_CUDA!" << std::endl;
82#endif
83 case ExecSpaces::HIP:
84#if defined(KOKKOS_ENABLE_HIP)
85 return Kokkos::HIP{};
86#else
87 std::cerr << "Kokkos::HIP is not enabled! Please recompile Kokkos with Kokkos_ENABLE_HIP!" << std::endl;
89#endif
91#if defined(KOKKOS_ENABLE_SYCL)
92 return Kokkos::SYCL{};
93#else
94 std::cerr << "Kokkos::SYCL is not enabled! Please recompile Kokkos with Kokkos_ENABLE_SYCL!" << std::endl;
96#endif
97 default:
98 std::cerr << "execspace: Serial, OpenMP, Threads, Cuda, HIP, SYCL" << std::endl;
100 }
101 // clang-format on
102}
103
104} // namespace PACMAN
std::variant< > AvailableExecSpaces
A type variant which defines the enabled Kokkos execution spaces.
static AvailableExecSpaces MakeExecSpace(const unsigned char s)
Converts an execution-space selector byte to a variant type.
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