Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
impl_registry.hpp
Go to the documentation of this file.
1// -------------------------------------------------------//
2//
3// SHAMROCK code for hydrodynamics
4// Copyright (c) 2021-2026 Timothée David--Cléris <tim.shamrock@proton.me>
5// SPDX-License-Identifier: CeCILL Free Software License Agreement v2.1
6// Shamrock is licensed under the CeCILL 2.1 License, see LICENSE for more information
7//
8// -------------------------------------------------------//
9
10#pragma once
11
34
39#include <string_view>
40#include <string>
41#include <vector>
42
43namespace shamalgs::impl_registry {
44
53 void register_impl(std::string name, IImplVariant &impl);
54
56 std::vector<std::string> get_registered_algs();
57
59 std::vector<std::string> get_default_impl_list(std::string_view alg);
60
62 std::string get_current_impl(std::string_view alg);
63
65 bool is_impl_set(std::string_view alg);
66
68 void set_impl(std::string_view alg, std::string_view impl);
69
75 void autoselect_impl(std::string_view alg, const sham::DeviceScheduler_ptr &sched);
76
77} // namespace shamalgs::impl_registry
78
94#define SHAMALGS_REGISTER_IMPL(name, impl) \
95 [[maybe_unused]] static const shambase::call_lambda __shamrock_unique_name( \
96 shamalgs_impl_registration_) { \
97 [] { \
98 shamalgs::impl_registry::register_impl(std::string(name), impl); \
99 } \
100 }
Generic std::variant-based implementation selector.
Call a lambda at static or local scope construction time.
std::vector< std::string > get_registered_algs()
Get the names of every registered algorithm, sorted.
void set_impl(std::string_view alg, std::string_view impl)
Select the implementation of alg from a config json string.
void register_impl(std::string name, IImplVariant &impl)
Register an implementation selector under name.
void autoselect_impl(std::string_view alg, const sham::DeviceScheduler_ptr &sched)
Select the default implementation of alg for the device behind sched.
std::string get_current_impl(std::string_view alg)
Get the current implementation of alg as a config json string, "null" if unset.
bool is_impl_set(std::string_view alg)
Whether an implementation of alg has been selected yet.
std::vector< std::string > get_default_impl_list(std::string_view alg)
Get the list of available implementations of alg, as config json strings.
Provides macros for generating unique identifiers at compile time.