Skip to main content

Crate tcontract_exec

Crate tcontract_exec 

Source
Expand description

CPU resources for the tcontract stack: scratch memory and contraction policy.

Placement (where tasks run, and how many at once) belongs to threadteam: a host owns a threadteam::Pool, lends it through Pool, and each operation takes an Exec, a bundle of one threadteam::Exec token, an optional workspace and a BatchPolicy. This crate starts no task and exposes no scheduler type. See PERFORMANCE_TIPS.md, CPU Threading Contract.

§Examples

use tcontract_exec::{Exec, Pool};
let sp = threadteam::Pool::builder().threads(2).build().unwrap();
let pool = Pool::borrow(&sp);
let mut exec = Exec::new(&pool, 2).unwrap();
assert_eq!(exec.budget(), pool.size().min(2));
let total = std::sync::atomic::AtomicUsize::new(0);
exec.token().for_ranges(100, 1.try_into().unwrap(), |r| {
    total.fetch_add(r.len(), std::sync::atomic::Ordering::Relaxed);
});
assert_eq!(total.into_inner(), 100);

Re-exports§

pub use batch::BatchDecision;
pub use batch::BatchPolicy;
pub use batch::BatchQuery;
pub use batch::BatchStrategy;
pub use batch::WorkModel;
pub use host::HostClass;

Modules§

batch
Batch lane policy: the shared vocabulary and the one decision function.
host
Host class and the serial GEMM rate of each class.

Structs§

ArenaProvider
A workspace owner: per-thread worker slots plus a free list of team sets.
Exec
The resources one operation runs with: a placement token, optional reusable scratch, and the batch lane policy.
Pool
The CPU resources one owner lends to every operation: a threadteam::Pool (where tasks run) and an ArenaProvider (where scratch lives).
TeamLease
An exclusive loan of a team set, returned to its owner on drop.
Workspace
A caller-owned, bounded workspace: an ArenaProvider pre-sized to one WorkspaceReq, so a steady-state execute whose requirement is within the bound allocates nothing.
WorkspaceReq
Bytes and counts one execute needs. Buffer sizes are bytes because the provider is element-type erased: the driver knows the element type and converts its real counts once.
WorkspaceStats
What an owner currently holds and currently lends out.

Enums§

ExecError
Errors from building or using an Exec.

Traits§

WorkspaceProvider
Storage an execution may borrow. Implemented by the owner; the driver only ever sees this trait, so nothing here depends on the driver.