Class ContractHandle#
A contract (anira_contract), the web twin of anira::ContractHandle, from the same
*.contract.json a native host loads (await ContractHandle.fromUrl(anira, url)) or built
field by field (ContractHandle.hard(...)); a Hard contract file may leave the host blocks to the
host (hardHostBlocks). edgeCost (or the edgeCost field of ContractHandle.hard’s
options, the contract file’s "edge_cost": "zero_copy", "copy",
"unified_transfer" or "dedicated_transfer") is the worst edge class a plan may take for
any slot: prepare drops a plan above it, and every limit drops a plan with an
ANIRA_EDGE_UNKNOWN edge (a device provider’s, on the web). Left out, or edgeCost(undefined):
no limit, every edge admitted.
- class ContractHandle(abi, contract)#
A contract (anira_contract), the web twin of
anira::ContractHandle: the host’s terms for a handler’s prepare, from the same*.contract.jsona native host loads or built field by field. A Hard contract file may leave the host blocks to the host (the bundledextras/modelsones do):hardHostBlocksgives the host blocks and the host rate the audio context runs at. Where the web differs:fromUrlfetches the file (from_file reads a path), and the handle is destroyed withdestroy()after the prepare that takes it (no RAII).- Arguments:
abi (AniraBindings)
contract (number)
- static async fromUrl(anira, url, fetcher=globalThis.fetch)#
Fetch and parse a
*.contract.json(anira_contract_from_json).- Arguments:
anira (WithAbi)
url (string | URL)
fetcher (Fetcher)
- Returns:
Promise<ContractHandle>
- static fromJson(anira, json)#
Parse a contract’s JSON text (anira_contract_from_json).
- Arguments:
anira (WithAbi)
json (string)
- Returns:
ContractHandle
- static hard(anira, options)#
A Hard contract (anira_contract_create_hard) with the given fields.
- Arguments:
anira (WithAbi)
options (HardContractOptions)
- Returns:
ContractHandle
- hardHostBlocks(hostBlockMin, hostBlockMax, hostRate)#
Patch a Hard contract’s host blocks (anira_contract_hard_set_host_blocks): the smallest and largest block in elements of the model’s anchor tensor and the host rate, the anchor’s elements per second (a block may be fractional). What the host provides carries the host prefix (hostBlockMin,
hostBlockMax,hostRate).- Arguments:
hostBlockMin (number)
hostBlockMax (number)
hostRate (number)
- Returns:
this
- hardBudget(kind, explicitMs=0)#
The per-inference budget of this Hard contract (anira_contract_hard_set_budget, anira::ContractHandle::hard_budget):
ANIRA_BUDGET_MEASURED, what the warm-up pass measures, orANIRA_BUDGET_EXPLICITwithexplicitMs.- Arguments:
kind (number)
explicitMs (number)
- Returns:
this
- hardWarmup(mode, iterations=0)#
The warm-up pass of this Hard contract (anira_contract_hard_set_warmup, anira::ContractHandle::hard_warmup): an
anira_warmup_mode, withANIRA_WARMUP_FIXED’s count.- Arguments:
mode (number)
iterations (number)
- Returns:
this
- hardRingDtype(canonical, dtype)#
The ring dtype of one tensor under this Hard contract, by canonical name (anira_contract_hard_set_ring_dtype,
anira::ContractHandle::hard_ring_dtype): the element type the host’s samples of that tensor carry and its ring holds as is; the spec’s dtype for every tensor never set. Nothing converts: a name that is no Streamed tensor is ANIRA_ERROR_CONFIG at 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.- Arguments:
canonical (string)
dtype (number)
- Returns:
this
- edgeCost(worstAllowed)#
The worst edge class a plan may take for any slot, on either contract kind (anira_contract_set_edge_cost,
anira::ContractHandle::edge_cost; ananira_edge_classvalue): prepare drops a plan with a slot above it, any limit a plan with an ANIRA_EDGE_UNKNOWN edge, and refuses withANIRA_ERROR_EDGE_UNREACHABLEwhen no plan remains.undefinedrestores no limit (ANIRA_EDGE_UNKNOWN to the C entry).- Arguments:
worstAllowed (undefined | number)
- Returns:
this
- native()#
The
anira_contract*the raw entries take.- Returns:
number
- destroy()#