NeoN
A framework for CFD software
Loading...
Searching...
No Matches
executor.hpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2023 - 2025 NeoN authors
2//
3// SPDX-License-Identifier: MIT
4
5#pragma once
6
7#include <string>
8#include <variant>
9
13#include "NeoN/core/error.hpp"
14#include "NeoN/core/logging.hpp"
15
16namespace NeoN
17{
18
19using Executor = std::variant<SerialExecutor, CPUExecutor, GPUExecutor>;
20
21/* @brief calls Kokkos::fence to wait for GPU kernels to be finished */
22inline void fence(const Executor& exec)
23{
24 if (std::holds_alternative<NeoN::GPUExecutor>(exec))
25 {
26 Kokkos::fence();
27 }
28}
29
30/*@brief convenience function to get access to associated logger */
31inline std::shared_ptr<const Logging::BaseLogger> getLogger(const Executor& exec)
32{
33 return std::visit([](auto e) { return e.getLogger(); }, exec);
34}
35
36/*@brief convenience function to get access to associated logger */
37inline void setLogger(Executor& exec, std::shared_ptr<Logging::BaseLogger> logger)
38{
39 std::visit([logger](auto& e) { e.setLogger(logger); }, exec);
40}
41
42
49[[nodiscard]] inline bool operator==(const Executor& lhs, const Executor& rhs)
50{
51 return std::visit(
52 []<typename ExecLhs,
53 typename ExecRhs>([[maybe_unused]] const ExecLhs&, [[maybe_unused]] const ExecRhs&)
54 {
55 if constexpr (std::is_same_v<ExecLhs, ExecRhs>)
56 {
57 return typename ExecLhs::exec() == typename ExecRhs::exec();
58 }
59 else
60 {
61 return false;
62 }
63 },
64 lhs,
65 rhs
66 );
67};
68
76[[nodiscard]] inline bool operator!=(const Executor& lhs, const Executor& rhs)
77{
78 return !(lhs == rhs);
79};
80
81} // namespace NeoN
Definition array.hpp:20
void setLogger(Executor &exec, std::shared_ptr< Logging::BaseLogger > logger)
Definition executor.hpp:37
void fence(const Executor &exec)
Definition executor.hpp:22
std::shared_ptr< const Logging::BaseLogger > getLogger(const Executor &exec)
Definition executor.hpp:31
std::variant< SerialExecutor, CPUExecutor, GPUExecutor > Executor
Definition executor.hpp:19
bool operator==(const Executor &lhs, const Executor &rhs)
Checks if two executors are equal, i.e. they are of the same type.
Definition executor.hpp:49
bool operator!=(const Executor &lhs, const Executor &rhs)
Checks if two executors are not equal, i.e. they are not of the same type.
Definition executor.hpp:76