20 template <
typename Config>
23 if constexpr (
requires { std::declval<Config&>().method; }) {
24 return std::type_identity<decltype(std::declval<Config&>().method)> {};
25 }
else if constexpr (
requires { std::declval<Config&>().operation; }) {
26 return std::type_identity<decltype(std::declval<Config&>().operation)> {};
27 }
else if constexpr (
requires { std::declval<Config&>().algorithm; }) {
28 return std::type_identity<decltype(std::declval<Config&>().algorithm)> {};
30 return std::type_identity<void> {};
36template <
typename Config>
45 std::type_index
type {
typeid(void) };
55 template <
typename E,
typename Op,
typename Config = default_config_t<Op>>
56 requires std::is_enum_v<E>
58 std::type_identity_t<std::function<std::shared_ptr<Op>(
Config)>> factory = {},
int priority = 50)
64 template <
typename Op,
typename E,
typename Config = default_config_t<Op>>
65 requires std::is_enum_v<E>
67 std::type_identity_t<std::function<std::shared_ptr<Op>(
Config)>> factory = {},
int priority = 50)
78 template <
typename Op>
79 requires requires {
typename Op::supports; }
82 Op::supports::each([&]<
typename Config>() {
84 static_assert(!std::is_void_v<Selection>,
"The config has no method, operation or algorithm selector");
91 [[nodiscard]] std::vector<Binding>
resolve(
94 std::vector<Binding> bindings;
96 if (
auto binding = registration(signature, config)) {
97 bindings.push_back(std::move(*binding));
104 template <
typename E,
typename Op,
typename Config>
106 std::function<std::shared_ptr<Op>(
Config)> factory,
int priority)
109 [only, factory = std::move(factory), priority](
111 const auto selection = signature.template selection<E>(0);
112 if (signature.
size() != 1 || !selection || (only && *only != *selection)) {
117 if constexpr (std::same_as<Config, OperationConfig>) {
120 const auto* typed = supplied->template get<Config>();
127 if constexpr (
requires { config.method = *selection; }
128 ||
requires { config.operation = *selection; }
129 ||
requires { config.algorithm = *selection; }) {
133 std::source_location::current(),
134 "Catalog a single enum selection for an implementation without a method selector");
136 std::shared_ptr<Op> operation;
138 operation = factory(config);
139 }
else if constexpr (std::constructible_from<Op, Config>) {
140 operation = std::make_shared<Op>(config);
141 }
else if constexpr (std::default_initializable<Op>) {
142 operation = std::make_shared<Op>();
145 std::source_location::current(),
"Catalog a factory for this operation");
149 std::source_location::current(),
"Catalog factory returned no operation");
151 if constexpr (
requires { operation->set_config(config); }) {
152 operation->set_config(config);
154 using Input = std::remove_cvref_t<decltype(std::declval<typename Op::input_type>().data)>;
155 using Output = std::remove_cvref_t<decltype(std::declval<typename Op::output_type>().data)>;
156 std::shared_ptr<ComputeOperation<Input, Output>> base = std::move(operation);
158 .type = std::type_index(
typeid(Op)),
160 const auto* typed = std::any_cast<typename Op::input_type>(&input);
161 return typed && base->validate_input(*typed);
163 .executor = [base](
const std::any& input,
const ExecutionContext& ctx) -> std::any {
165 base->set_last_execution_context(ctx);
166 return base->apply_operation(safe_any_cast_or_throw<typename Op::input_type>(input));
168 .priority = priority,
Ordered operation selections, preserving each enum's type and value.
std::function< bool(const std::any &, const ExecutionContext &)> MatcherFunc
OperationRegistry & catalog_impl(std::optional< E > only, std::function< std::shared_ptr< Op >(Config)> factory, int priority)
OperationRegistry & add(int priority=50)
Catalog an implementation for every config it supports.
std::vector< Registration > m_registrations
std::function< std::optional< Binding >(const ComputationSignature &, const OperationConfig *)> Registration
OperationRegistry & catalog(std::type_identity_t< std::function< std::shared_ptr< Op >(Config)> > factory={}, int priority=50)
Catalog an implementation for an enum vocabulary.
std::vector< Binding > resolve(const ComputationSignature &signature, const OperationConfig *config=nullptr) const
Construct all registered implementations accepting this signature and config type.
OperationRegistry & catalog(E selection, std::type_identity_t< std::function< std::shared_ptr< Op >(Config)> > factory={}, int priority=50)
Catalog an implementation for one selection within an enum vocabulary.
Explicitly owned registrations connecting enum vocabularies, configs, and implementations.
Globlal configuration for MayaFlux.
@ Runtime
General runtime operations (default fallback).
@ Yantra
DSP algorithms, computational units, matrix operations, Grammar.
constexpr auto selector_field()
void apply_context_parameters(std::shared_ptr< OperationType > operation, const ExecutionContext &ctx)
Applies context settings to an operation.
std::function< float(const std::any &)> Fitness
How well a candidate suits an input.
constexpr Target target_of_v
The target an operation class declares through static constexpr Target target, or the CPU when it dec...
constexpr bool stateful_v
Whether the class keeps state between calls and must stay on its candidate.
Fitness fitness_of()
The candidate's fitness for an erased input.
typename detail::UnwrapEnum< typename decltype(detail::selector_field< Config >())::type >::type selection_t
The enum a config selects its method from, or void when it has no selector.
OperationRegistry make_default_registry()
A registry holding the library's own operations, each in its standard instantiations.
Config select_operation(E selection, Config config)
Set the config's method selector from its corresponding operation enum.
Context information controlling how a compute operation executes.
Base of every operation's config struct.
std::function< std::any(const std::any &, const ExecutionContext &)> executor
Matcher::MatcherFunc matcher
A constructed implementation with its erased input and execution contracts.
A set of (device, runtime) pairs.