28 using Registry = std::map<std::string, shamalgs::IImplVariant *, std::less<>>;
31 Registry &get_registry() {
37 std::string registered_names_str() {
39 for (
const auto &[name, impl] : get_registry()) {
54 "no implementation registered under the name \"" + std::string(alg)
55 +
"\", registered names are: [" + registered_names_str() +
"]");
62namespace shamalgs::impl_registry {
65 Registry ®istry = get_registry();
66 if (registry.find(name) != registry.end()) {
68 "an implementation is already registered under the name \"" + name +
"\"");
70 registry.emplace(std::move(name), &impl);
74 std::vector<std::string> ret;
75 ret.reserve(get_registry().size());
76 for (
const auto &[name, impl] : get_registry()) {
83 return get_impl(alg).get_default_config_list();
87 return get_impl(alg).get_current_config();
90 bool is_impl_set(std::string_view alg) {
return get_impl(alg).is_set(); }
92 void set_impl(std::string_view alg, std::string_view impl) {
93 get_impl(alg).set(impl);
95 shamlog_info_ln(
"algs",
"setting", alg,
"implementation to impl :", impl);
99 void autoselect_impl(std::string_view alg,
const sham::DeviceScheduler_ptr &sched) {
102 impl.autoselect(sched);
105 "algs",
"defaulting", alg,
"implementation to impl :", impl.get_current_config());
Non-template virtual interface exposed by ImplVariantGlobal, for code that needs to hold or pass arou...
This header file contains utility functions related to exception handling in the code.
Name-keyed registry of the implementation selectors (IImplVariant) of every algorithm.
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.
T & get_check_ref(const std::unique_ptr< T > &ptr, SourceLocation loc=SourceLocation())
Takes a std::unique_ptr and returns a reference to the object it holds. It throws a std::runtime_erro...
ExcptTypes make_except_with_loc(std::string message, SourceLocation loc=SourceLocation{})
Create an exception with a message and a location.
i32 world_rank()
Gives the rank of the current process in the MPI communicator.
Functions related to the MPI communicator.