pub struct TensorBudgetManager {
pub sessions: HashMap<u64, SessionBudget>,
pub next_session_id: u64,
}Expand description
Orchestrates computational budgets across multiple concurrent inference sessions.
§Example
use ipfrs_tensorlogic::budget_manager::{TensorBudgetManager, ResourceType};
let mut mgr = TensorBudgetManager::new();
let sid = mgr.open_session(vec![
(ResourceType::Flops, 1_000_000),
(ResourceType::MemoryBytes, 256 * 1024 * 1024),
]);
mgr.consume(sid, ResourceType::Flops, 500_000).expect("example: should succeed in docs");
assert!(mgr.close_session(sid));Fields§
§sessions: HashMap<u64, SessionBudget>Active sessions keyed by session id.
next_session_id: u64Monotonically-increasing session id counter.
Implementations§
Source§impl TensorBudgetManager
impl TensorBudgetManager
Sourcepub fn open_session(&mut self, limits: Vec<(ResourceType, u64)>) -> u64
pub fn open_session(&mut self, limits: Vec<(ResourceType, u64)>) -> u64
Open a new session with the supplied resource limits.
Returns the unique session id assigned to the new session.
Sourcepub fn consume(
&mut self,
session_id: u64,
resource: ResourceType,
amount: u64,
) -> Result<(), String>
pub fn consume( &mut self, session_id: u64, resource: ResourceType, amount: u64, ) -> Result<(), String>
Consume amount units of resource for the given session.
§Errors
Err("session not found")— unknownsession_id.Err("budget exceeded")— the resource budget would be exceeded.
Sourcepub fn close_session(&mut self, session_id: u64) -> bool
pub fn close_session(&mut self, session_id: u64) -> bool
Close (remove) a session.
Returns true if the session existed and was removed, false
otherwise.
Sourcepub fn stats(&self) -> BudgetManagerStats
pub fn stats(&self) -> BudgetManagerStats
Compute aggregate statistics across all currently open sessions.
Sourcepub fn session_utilization(
&self,
session_id: u64,
) -> Option<Vec<(ResourceType, f64)>>
pub fn session_utilization( &self, session_id: u64, ) -> Option<Vec<(ResourceType, f64)>>
Return per-resource utilisation for the given session.
Returns None if the session does not exist.
Trait Implementations§
Source§impl Debug for TensorBudgetManager
impl Debug for TensorBudgetManager
Source§impl Default for TensorBudgetManager
impl Default for TensorBudgetManager
Source§fn default() -> TensorBudgetManager
fn default() -> TensorBudgetManager
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for TensorBudgetManager
impl RefUnwindSafe for TensorBudgetManager
impl Send for TensorBudgetManager
impl Sync for TensorBudgetManager
impl Unpin for TensorBudgetManager
impl UnsafeUnpin for TensorBudgetManager
impl UnwindSafe for TensorBudgetManager
Blanket Implementations§
impl<T> Allocation for T
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more