Class anira::ContractHandle#
-
class ContractHandle#
An anira_contract with its lifetime: minted from a Hard or Async aggregate, loaded from a contract file, or adopted from a C entry (take_legacy_contract). Move-only.
Public Functions
-
inline explicit ContractHandle(const Hard &hard)#
- Throws:
Error – when the C entry refuses the call; the status says why.
-
inline explicit ContractHandle(const Contract &contract)#
-
inline explicit ContractHandle(anira_contract *adopt) noexcept#
Takes ownership of a handle a C entry handed out (never NULL: an empty handle is what a moved-from object is, and every query on it throws).
-
inline ~ContractHandle()#
-
ContractHandle(const ContractHandle&) = delete#
-
ContractHandle &operator=(const ContractHandle&) = delete#
-
inline ContractHandle(ContractHandle &&other) noexcept#
-
inline ContractHandle &operator=(ContractHandle &&other) noexcept#
-
inline bool empty() const noexcept#
Whether this object holds a contract (false after a move).
-
inline anira_contract_kind kind() const#
-
- Throws:
Error{ANIRA_ERROR_INVALID_ARGUMENT} – on an empty handle.
-
inline ContractHandle &hard_host_blocks(double host_block_min, double host_block_max, double host_rate)#
Patches a Hard contract’s host blocks, e.g. of one loaded from a file: the smallest and largest block in elements of the model’s anchor tensor (ModelConfig::anchor) and the host rate, the anchor’s elements per second; a block may be fractional (anira_contract_create_hard).
- Throws:
Error{ANIRA_ERROR_INVALID_ARGUMENT} – for host blocks the rules refuse, Error{ANIRA_ERROR_WRONG_CONTRACT} on an Async handle.
-
inline ContractHandle &hard_ring_dtype(std::string_view canonical, DType dtype)#
The ring dtype of one tensor under this Hard contract, by canonical name: the element type the tensor forms of the Hard entries carry across the ABI and the ring holds as is; the spec’s dtype for every tensor never set. Nothing converts: a name that is not a Streamed tensor is ANIRA_ERROR_CONFIG at anira_handler_prepare, and so is a ring dtype that differs from the spec’s dtype unless a processor of the pipeline fills the phase that moves that ring and converts (anira_pipeline_add_processor).
-
inline ContractHandle &hard_latency(std::string_view canonical, uint32_t samples)#
The declared stream latency of one output under this Hard contract, by canonical name, in samples of that output (anira_contract_hard_set_latency): what the handler reports for the slot and primes its receive ring with, replacing the computed figure. A name that is no Streamed output, or a figure below the model’s internal latency, is ANIRA_ERROR_CONFIG at anira_handler_prepare.
- Throws:
Error{ANIRA_ERROR_INVALID_ARGUMENT} – for an empty name or a figure above INT32_MAX.
-
template<class Rep, class Period>
inline ContractHandle &hard_budget(anira_budget_kind kind_value, std::chrono::duration<Rep, Period> value = {})# The per-inference budget: MEASURED, or EXPLICIT with the value.
-
inline ContractHandle &hard_budget(anira_budget_kind kind_value)#
-
inline ContractHandle &hard_warmup(anira_warmup_mode mode, uint32_t iterations = 0)#
-
inline ContractHandle &hard_on_miss(anira_miss_policy policy)#
-
inline ContractHandle &hard_miss_fn(anira_miss_fn fn, void *user_data)#
The backup function of ANIRA_MISS_CALLBACK (NULL clears it); see Hard::miss_fn.
-
inline ContractHandle &hard_wait_ratio(double ratio)#
-
inline ContractHandle &async_deadline(std::optional<std::chrono::nanoseconds> deadline)#
The per-job deadline of an Async contract; nullopt = none.
-
inline ContractHandle &async_policy(anira_late_policy on_late, anira_priority priority, uint32_t lanes, uint32_t max_in_flight, anira_delivery delivery)#
-
inline ContractHandle &edge_cost(std::optional<anira_edge_class> worst_allowed)#
The worst edge class a plan may take for any slot, on either contract kind (anira_contract_set_edge_cost, Hard::edge_cost): prepare drops a plan above it, and any limit drops a plan with an ANIRA_EDGE_UNKNOWN edge; std::nullopt restores no limit.
-
inline ContractHandle &host_domain(std::string_view canonical, Domain domain)#
The host-end domain of one tensor, by canonical name, on either contract kind (anira_contract_set_host_domain): the domain anira allocates the ring, the model tensor, the Static store and the state buffers of the slot in, and the domain every processor phase works in; ANIRA_DOMAIN_HOST for every tensor never set. Any tensor of either side, State and Static included. A name that is no tensor is ANIRA_ERROR_CONFIG at anira_handler_prepare, and in this pre-release any domain but ANIRA_DOMAIN_HOST is ANIRA_ERROR_NOT_SUPPORTED there. In a contract file: the top-level “host_domains”.
-
template<class Ext>
inline ContractHandle &ext(const Ext &value)#
-
inline ContractHandle &ext_json(std::string_view kind, std::string_view utf8)#
-
inline bool upgraded() const noexcept#
Whether this contract came out of a 2.x document (from_json, or a ModelConfig::take_legacy_contract).
-
inline Hard hard() const#
The Hard aggregate this handle holds, a loaded or legacy one alike: every field the read-back of anira/abi/config.h answers, ring_dtypes and latencies from their enumerations, and the budget’s figure rounded to the nanosecond (the handle stores double milliseconds; std::chrono::round, so 42.66 ms reads 42660000 ns). Minting the result gives an equal contract.
- Throws:
Error{ANIRA_ERROR_WRONG_CONTRACT} – on an Async handle, Error{ANIRA_ERROR_INVALID_ARGUMENT} on an empty one.
-
inline const anira_contract *native() const noexcept#
-
inline anira_contract *native() noexcept#
-
inline anira_contract *release() noexcept#
Hands the handle out (to a C entry that takes ownership); this object becomes empty.
Public Static Functions
-
static inline ContractHandle from_json(std::string_view utf8)#
A contract file (section 8.3); a 2.x document yields its Hard contract and upgraded().
-
static inline ContractHandle from_file(const std::filesystem::path &path)#
-
inline explicit ContractHandle(const Hard &hard)#