Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Bounded resources

known-bounds: true states that a capacity has an explicit bound. An event or FSM state attribute marked with sets-resource-bounds: true carries the generated bounds record whenever that limit changes.

YAML model

quent: alpha
model: bounded_resource

entities:
  Memory:
    resource:
      bytes:
        kind: occupancy
        known-bounds: true
    events:
      resized:
        multi: true
        attributes:
          # MemoryBounds is generated because bytes has known bounds.
          limits: { sets-resource-bounds: true }

fsms:
  Task:
    states:
      running:
        initial: true
        attributes:
          memory: { uses: Memory }
        to: [completed]
      completed: {}

The resource declaration generates both MemoryUsage and MemoryBounds. Both records use u64 for the bytes field. Resource declarations do not currently support selecting another numeric width.

Instrumentation API

The memory entity publishes its current bound. The task separately records how much of that capacity it claims.

// SPDX-FileCopyrightText: Copyright (c) 2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

#[allow(unused)]
mod instrumentation {
    include!(concat!(env!("OUT_DIR"), "/bounded_resource.rs"));
}

use instrumentation::{BoundedResource, Context, Memory, MemoryBounds, MemoryUsage, Noop, Task};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let context = Context::<BoundedResource>::try_new(Noop)?;
    let memory = context.observer::<Memory>().handle();

    memory.resized(MemoryBounds {
        bytes: 8_000_000_000,
    })?;

    let _task = context
        .observer::<Task>()
        .handle()
        .running(memory.as_entity_ref_with(MemoryUsage { bytes: 512_000_000 }))
        .completed();

    Ok(())
}
Key point

A known bound records the available capacity separately from resource usage.

Check yourself

What additional generated record comes from known-bounds: true?

What does sets-resource-bounds: true identify?