GridFire v0.7.6rc4.0 General Purpose Nuclear Network

Loading...
Searching...
No Matches
Classes | Namespaces | Concepts
blob.h File Reference

Container class for managing multiple scratchpad instances. More...

`#include "gridfire/engine/scratchpads/scratchpad_abstract.h"`
`#include "gridfire/engine/scratchpads/types.h"`
`#include "gridfire/exceptions/error_scratchpad.h"`
`#include <unordered_map>`
`#include <memory>`
`#include <expected>`
`#include <unordered_set>`
Include dependency graph for blob.h:
This graph shows which files directly or indirectly include this file:

## Classes
class | gridfire::engine::scratch::StateBlob
| Container for managing a collection of typed scratchpad instances. More...

## Namespaces
namespace | gridfire
namespace | gridfire::engine
namespace | gridfire::engine::scratch
| Scratchpad memory management for computational engines.

## Concepts
concept | gridfire::engine::scratch::IsScratchPad
| Concept that constrains types to valid scratchpad implementations.

## Detailed Description

Container class for managing multiple scratchpad instances.

This header defines the StateBlob class, which serves as a centralized registry for managing multiple scratchpad instances used by computational engines. It provides type-safe enrollment, retrieval, and cloning of scratchpads using compile-time type checking via C++20 concepts.

Purpose
  The StateBlob provides:
  - A fixed-size array of scratchpad slots indexed by ScratchPadType
  - Type-safe enrollment ensuring one instance per scratchpad type
  - Compile-time verified retrieval with optional initialization checks
  - Deep cloning of all enrolled scratchpads for parallel execution
  - Status tracking for each scratchpad slot

Examples
  #include "gridfire/engine/scratchpads/blob.h"
  #include "gridfire/engine/scratchpads/engine_graph_scratchpad.h"
  using namespace gridfire::engine::scratch;
  // Create a StateBlob and enroll scratchpads
  StateBlob blob;
  blob.enroll<GraphEngineScratchPad>();
  // Retrieve a scratchpad (returns std::expected)
  auto result = blob.get<GraphEngineScratchPad>();
  if (result.has_value()) {
  GraphEngineScratchPad* scratch = result.value();
  scratch->initialize(engine);
  }
  // Retrieve with initialization check
  auto checked = blob.get<GraphEngineScratchPad, true>();
  if (!checked.has_value()) {
  if (checked.error() == StateBlob::Error::SCRATCHPAD_NOT_INITIALIZED) {
  // Handle uninitialized scratchpad
  }
  }
  // Clone for parallel execution
  auto worker_blob = blob.clone_structure();
  blob.h
  Container class for managing multiple scratchpad instances.
  gridfire::engine::scratch::StateBlob
  Container for managing a collection of typed scratchpad instances.
  Definition blob.h:114
  gridfire::engine::scratch::StateBlob::Error::SCRATCHPAD_NOT_INITIALIZED
  @ SCRATCHPAD_NOT_INITIALIZED
  Scratchpad exists but is not initialized.
  Definition blob.h:122
  gridfire::engine::scratch::StateBlob::enroll
  void enroll()
  Enroll a new scratchpad type into the blob.
  Definition blob.h:196
  gridfire::engine::scratch::StateBlob::clone_structure
  std::unique_ptr< StateBlob > clone_structure() const
  Create a deep copy of this blob with all enrolled scratchpads.
  Definition blob.h:361
  gridfire::engine::scratch::StateBlob::get
  std::expected< CTX *, Error > get() const
  Retrieve a scratchpad by type.
  Definition blob.h:230
  engine_graph_scratchpad.h
  Scratchpad implementation for the GraphEngine using CppAD automatic differentiation.
  gridfire::engine::scratch
  Scratchpad memory management for computational engines.
  Definition blob.h:69
  gridfire::engine
  Definition dynamic_engine_diagnostics.h:39
  gridfire::engine::scratch::GraphEngineScratchPad
  Scratchpad for storing CppAD automatic differentiation state for GraphEngine.
  Definition engine_graph_scratchpad.h:83

Thread Safety
  The StateBlob class is not thread-safe. Each thread should have its own StateBlob instance. Use clone_structure() to create independent copies for parallel workers. The cloned blob contains deep copies of all enrolled scratchpads.

See also
  AbstractScratchPad
  ScratchPadType