![]() |
Shamrock 2025.10.0
Astrophysical Code
|
Drop-in replacement for the hand-rolled "global variable + enum + name mapping. More...
#include <shamalgs/include/shamalgs/ImplVariant.hpp>
Public Types | |
| using | Variant = std::variant<Alts...> |
| using | AutoselectFn = std::function<void(const sham::DeviceScheduler_ptr &, ImplVariantGlobal &)> |
| Callable selecting the default implementation, by calling set() on the selector. | |
Public Member Functions | |
| ImplVariantGlobal (AutoselectFn fn) | |
| Construct an unset selector, whose default implementation is picked by fn. | |
| bool | is_set () const override |
| Whether an implementation has been selected yet. | |
| void | autoselect (const sham::DeviceScheduler_ptr &sched) override |
| Select the algorithm's default implementation for the device behind sched. | |
| const Variant & | get () const |
| Get the currently selected implementation. Requires is_set(). | |
| std::string | get_current_config () const override |
| std::vector< std::string > | get_default_config_list () const override |
| void | set (Variant v) |
| Directly select an alternative (e.g. to seed a default at the call site). | |
| void | set (std::string_view config_json) override |
| Select an implementation from a {"implementation": ..., "parameters": ...} json string. | |
Drop-in replacement for the hand-rolled "global variable + enum + name mapping.
json string ABI.
No implementation is selected at construction: is_set() reports whether one has been picked yet. The rule picking the algorithm's default is however given at construction, as a callable of signature void(const sham::DeviceScheduler_ptr &, ImplVariantGlobal &) that calls set() on the selector it is handed. autoselect(sched) runs it, so that the default may depend on the device behind sched (see e.g. compute_histogram.hpp), or ignore it when it is a compile-time choice:
Call sites typically check is_set() and call autoselect() right before dispatching (see e.g. segmented_sort_in_place.cpp). get() assumes is_set(); get_current_config() is the one exception and safely returns a json null instead of dereferencing an unset selection.
| Alts | the alternative types, each requiring a static constexpr std::string_view variant_type_name |
Definition at line 265 of file ImplVariant.hpp.
| using shamalgs::ImplVariantGlobal< Alts >::AutoselectFn = std::function<void(const sham::DeviceScheduler_ptr &, ImplVariantGlobal &)> |
Callable selecting the default implementation, by calling set() on the selector.
Definition at line 270 of file ImplVariant.hpp.
| using shamalgs::ImplVariantGlobal< Alts >::Variant = std::variant<Alts...> |
Definition at line 267 of file ImplVariant.hpp.
|
inlineexplicit |
Construct an unset selector, whose default implementation is picked by fn.
Definition at line 273 of file ImplVariant.hpp.
|
inlineoverridevirtual |
Select the algorithm's default implementation for the device behind sched.
Implements shamalgs::IImplVariant.
Definition at line 279 of file ImplVariant.hpp.
|
inline |
Get the currently selected implementation. Requires is_set().
Definition at line 284 of file ImplVariant.hpp.
|
inlineoverridevirtual |
Get the currently selected implementation as a single config json string, or a json null if no implementation has been selected yet (see is_set())
Implements shamalgs::IImplVariant.
Definition at line 288 of file ImplVariant.hpp.
|
inlineoverridevirtual |
List the available implementations as config json strings. Most alternatives contribute exactly one entry; alternatives opting into HasCustomDefaults contribute one entry per instance in their variant_custom_defaults() list.
Implements shamalgs::IImplVariant.
Definition at line 298 of file ImplVariant.hpp.
|
inlineoverridevirtual |
Whether an implementation has been selected yet.
Implements shamalgs::IImplVariant.
Definition at line 276 of file ImplVariant.hpp.
|
inlineoverridevirtual |
Select an implementation from a {"implementation": ..., "parameters": ...} json string.
Implements shamalgs::IImplVariant.
Definition at line 306 of file ImplVariant.hpp.
|
inline |
Directly select an alternative (e.g. to seed a default at the call site).
Definition at line 303 of file ImplVariant.hpp.