Class anira::ProcessorContext#

class ProcessorContext#

Collaboration diagram for anira::ProcessorContext:

digraph {
    graph [bgcolor="#00000000"]
    node [shape=rectangle style=filled fillcolor="#FFFFFF" font=Helvetica padding=2]
    edge [color="#1414CE"]
    "1" [label="anira::ProcessorContext" tooltip="anira::ProcessorContext" fillcolor="#BFBFBF"]
    "2" [label="anira_processor_ctx" tooltip="anira_processor_ctx"]
    "1" -> "2" [dir=forward tooltip="usage"]
}

What a phase callback of a Processor sees: a view of the anira_processor_ctx anira fills on its own stack for the call, with the six context accessors of anira/abi/processor.h on it, one C call per method. The tensors and the rings are not in the record: a processor asks per slot, the tensor’s position in the model configuration’s input or output list (the number every entry of anira_handler uses). Valid until the callback returns, and never kept beyond it.

What a phase exposes: pre_process the input rings and the model’s input tensors (a State input has no host end there), before_inference the input tensors, after_inference the output tensors, post_process the output tensors (State outputs excepted) and the output rings. Every accessor returns a status and fills an out-parameter, reset on any status but ANIRA_OK. A slot always has a role; asking for a ring or a tensor the slot does not have in this phase is a bug in the processor, not an answer: a processor knows what a slot is, from its model config or by asking the role first, so the accessor answers ANIRA_ERROR_INVALID_STATE and records it in anira_handler_rt_error with one latched record per kind naming the entry, the slot and the phase, as it records a slot out of range (ANIRA_ERROR_INVALID_ARGUMENT).

[driver-thread | inference-thread] [callback-safe], nonblocking: every method is noexcept and allocates nothing, one C call per method.

Public Functions

inline explicit ProcessorContext(const anira_processor_ctx *ctx) noexcept#

Wraps the record a phase callback received; never NULL (anira hands out none).

inline anira_phase phase() const noexcept#

The phase this call runs in.

inline EngineRef engine() const noexcept#

anira_processor_engine: the engine of the plan the chunk was submitted under, as the pair (ANIRA_ENGINE_CUSTOM with the id for a custom one). Valid for the duration of the call.

inline ProviderRef provider() const noexcept#

anira_processor_provider: the provider of that plan, as the pair (ANIRA_PROVIDER_CUSTOM with the name for a custom one).

inline uint32_t variant() const noexcept#

The variant of that plan; 0 in this pre-release.

inline uint32_t num_inputs() const noexcept#

The tensors of the model’s input list, State tensors included: the input slots.

inline uint32_t num_outputs() const noexcept#

The tensors of the model’s output list, State tensors included: the output slots.

inline anira_ticket ticket() const noexcept#

The ticket of the submitting job under an Async contract; ANIRA_TICKET_INVALID under a Hard one.

inline uint32_t entry() const noexcept#

The entry this chunk occupies, 0 .. anira_handler_num_entries() - 1: the same value in all four phases of the chunk, reused by a later chunk once this one has completed. The index of a per-chunk scratch a processor sized in its prepare (one slot per entry), so that what pre_process pops or computes is found again by before_inference, without an allocation: one entry holds one chunk at a time, however many are in flight.

inline anira_status input_role(uint32_t slot, Role &out) const noexcept#

anira_processor_input_role: fills out with what the tensor of an input slot is, the same answer in every phase; the first question about a slot the processor does not know from its model config.

Returns:

ANIRA_OK; ANIRA_ERROR_INVALID_ARGUMENT for a slot at or beyond num_inputs(), recorded, with out ANIRA_ROLE_FORCE32, which is no role. A slot always has a role: never ANIRA_ERROR_INVALID_STATE.

inline anira_status output_role(uint32_t slot, Role &out) const noexcept#

anira_processor_output_role: the output twin, against num_outputs().

inline anira_status input_ring(uint32_t slot, RingView &out) const noexcept#

anira_processor_input_ring: fills out with a view of the ring of a Streamed input in pre_process, the phase that moves the input rings.

Returns:

ANIRA_OK; ANIRA_ERROR_INVALID_STATE for a tensor of another role and in every other phase, which is the processor’s bug and is recorded, ANIRA_ERROR_INVALID_ARGUMENT for a slot out of range; out is then a view of no ring.

inline anira_status output_ring(uint32_t slot, RingView &out) const noexcept#

anira_processor_output_ring: fills out with a view of the ring of a Streamed output in post_process, the phase that moves the output rings.

Returns:

as input_ring.

inline anira_status input_tensor(uint32_t slot, Tensor &out) const noexcept#

anira_processor_input_tensor: fills out with the model end of an input slot, the tensor the engine binds (before_inference: every slot; pre_process: every slot with a host end, which a State slot has not). Built by this call over the memory the tensor has right now: ask again in every callback, keep neither the descriptor nor its data pointer.

Returns:

ANIRA_OK; ANIRA_ERROR_INVALID_STATE in a phase that exposes the outputs and for a State slot in pre_process, which is the processor’s bug and is recorded, ANIRA_ERROR_INVALID_ARGUMENT for a slot out of range; out is then all-zero.

inline anira_status output_tensor(uint32_t slot, Tensor &out) const noexcept#

anira_processor_output_tensor: fills out with the model end of an output slot, the tensor the engine wrote (after_inference: every slot; post_process: every slot with a host end, which a State slot has not).

Returns:

as input_tensor, against the phases that expose the outputs.

inline const anira_processor_ctx *native() const noexcept#