Skip to main content

ferrum_interfaces/vnext/operation/checkpoint/
state_port.rs

1use serde::{Deserialize, Serialize};
2
3use crate::vnext::{DynamicStorageProfile, ResolvedValueRole};
4
5/// Exact logical byte ABI promised by a provider for one state port. Both
6/// forms require a contiguous semantic tensor and one physical component;
7/// the selected storage profile may translate its logical range into pages.
8#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
9#[serde(rename_all = "snake_case", deny_unknown_fields)]
10pub enum ProviderCheckpointStateLayout {
11    /// The component contains the complete tensor value at the boundary.
12    ContiguousBoundaryValue,
13    /// Ordered token-major values with no per-token padding. The declared
14    /// stride is the entire resolved semantic tensor's byte size. Only [0,N)
15    /// is valid, regardless of how much backing capacity was reserved.
16    TokenMajorPrefix,
17}
18
19/// A declaration is specific to an operation port and physical storage ABI.
20/// Its ordinal is validated against the selected operation; it is not a
21/// semantic state name or a user-supplied resource byte range.
22#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
23#[serde(deny_unknown_fields)]
24pub struct ProviderCheckpointStatePort {
25    role: ResolvedValueRole,
26    ordinal: u32,
27    storage_profile: DynamicStorageProfile,
28    layout: ProviderCheckpointStateLayout,
29}
30
31impl ProviderCheckpointStatePort {
32    pub const fn new(
33        role: ResolvedValueRole,
34        ordinal: u32,
35        storage_profile: DynamicStorageProfile,
36        layout: ProviderCheckpointStateLayout,
37    ) -> Self {
38        Self {
39            role,
40            ordinal,
41            storage_profile,
42            layout,
43        }
44    }
45
46    pub const fn role(&self) -> ResolvedValueRole {
47        self.role
48    }
49    pub const fn ordinal(&self) -> u32 {
50        self.ordinal
51    }
52    pub const fn storage_profile(&self) -> DynamicStorageProfile {
53        self.storage_profile
54    }
55    pub const fn layout(&self) -> ProviderCheckpointStateLayout {
56        self.layout
57    }
58
59    pub(super) fn key(&self) -> (ResolvedValueRole, u32, DynamicStorageProfile) {
60        (self.role, self.ordinal, self.storage_profile)
61    }
62}