Class anira::Pipeline#

class Pipeline#

An anira_pipeline with its lifetime: what a handler runs. Exactly one inference stage (add_inference: the model configuration and its candidate backends), at most one Processor around it (add_processor: the custom pre- and post-processing), and the custom engines of the pipeline (add_engine). One member per C entry, named as the entry without its anira_pipeline_ prefix. A custom engine belongs to the pipeline, not to a stage: it is one more implementation the inference stage’s model entries name by its id (Engine::id; ModelConfig::add_model_path(id, path)) and its candidates resolve to. The pipeline holds the C engine of every Engine object added to it, so another Pipeline adding the same object reuses it, and handlers of both share loaded models. Move-only; copied by the handler that takes it, engines included: an addition after a handler’s create does not reach that handler.

Public Functions

inline Pipeline()#

An empty pipeline (anira_pipeline_create).

Throws:

Error – when the C entry refuses the call; the status says why.

inline ~Pipeline()#
Pipeline(const Pipeline&) = delete#
Pipeline &operator=(const Pipeline&) = delete#
inline Pipeline(Pipeline &&other) noexcept#
inline Pipeline &operator=(Pipeline &&other) noexcept#
inline Pipeline &add_inference(const ModelConfig &model, std::initializer_list<BackendId> candidates = {})#

Adds the inference stage (anira_pipeline_add_inference): one model configuration, which the pipeline copies, and its candidate backends. Empty candidates are the default set: every engine this build carries on ANIRA_PROVIDER_CPU, every custom engine an entry names (ANIRA_ENGINE_CUSTOM with its id), and every provider a model entry is pinned to, on that entry’s engine, so that a pinned entry runs on its pin and a neutral one on its engine’s home provider: the CPU path, or a custom engine’s first listed provider when it does not serve the CPU path; a plan its engine cannot use here is dropped.

Throws:

Error – when the C entry refuses it: a second inference stage is ANIRA_ERROR_CONFIG; a candidate whose provider is no value of anira_provider, carries a provider of the enum and a provider_id at once, or an empty provider_id, is ANIRA_ERROR_INVALID_ARGUMENT. Whether an engine serves a candidate’s provider is anira_handler_create’s question.

inline Pipeline &add_inference(std::initializer_list<std::reference_wrapper<const ModelConfig>> variants, std::initializer_list<BackendId> candidates)#

The inference stage over several variants of one model; the C entry refuses more than one with ANIRA_ERROR_NOT_SUPPORTED until plan sets land.

Throws:

Error – as the single form does.

inline Pipeline &add_processor(const std::shared_ptr<Processor> &processor)#

Adds the pipeline’s one Processor (anira_pipeline_add_processor), read once, here: its phases(), realtime_phases() and consumed_kinds() fill an anira_processor_desc, and only the phases of the mask reach it; its prepare runs per handler at anira_handler_prepare and the Prepared it returns runs the phases and the reset of that handler until the C unprepare deletes it. The pipeline’s carrier holds a copy of the shared_ptr, which the pipeline and every handler created from it share, so the object lives at least until the last of them is destroyed, whatever the caller does with its own pointer; Processor::release answers this addition once. The order relative to the inference stage means nothing.

Throws:

Error – ANIRA_ERROR_INVALID_STATE for a second processor; ANIRA_ERROR_INVALID_ARGUMENT for a null one, or a phases() or realtime_phases() bit that names none of the four phases and reset.

inline Pipeline &add_engine(const std::shared_ptr<Engine> &engine)#

Adds a custom engine to the pipeline under its id, Engine::id (anira_pipeline_add_engine). The object’s C engine is created at its first addition (anira_custom_engine_create: the id, and flags(), consumed_kinds() and providers() fill an anira_engine_desc whose slots are the class’s virtuals, read once, then) and reused by every later one while a Pipeline holding it lives, on another Pipeline, so handlers of all of them share loaded models of equal configurations. The C engine holds a copy of the shared_ptr, so the object lives at least until the last pipeline and handler that carry it are destroyed, whatever the caller does with its own pointer; Engine::release answers the C engine once. Legal before or after the inference stage; a model entry that names the id is a plan of the handler, an engine no entry names is not a plan and not an error, and an entry whose id no engine of the pipeline has is ANIRA_ERROR_NOT_SUPPORTED at anira_handler_create.

Throws:

Error – ANIRA_ERROR_INVALID_ARGUMENT for a null engine (before the C call), an id without a ‘.’ or with the prefix “anira.” (anira.v2.custom excepted: the id of a 2.x custom backend, anira/compat/v2.hpp), or a flags() bit anira/abi/enums.h does not define (the C engine’s create refuses them, and nothing is created); ANIRA_ERROR_INVALID_STATE when this pipeline already has an engine with the id, this object or another. A refused call keeps no reference the call created: a C engine the call created is dropped again, and Engine::release answers it.

inline PipelineCapabilities capabilities(const Context &context) const noexcept#

The backends and edges a handler of this pipeline sees on a context: the context’s rows and the custom engines’ (their Engine::query runs on every call).

inline PipelineCapabilities capabilities(const anira_context *context) const noexcept#

The same over a C context handle.

inline const anira_pipeline *native() const noexcept#
inline anira_pipeline *native() noexcept#