Skip to navigation

holoscan::Graph

Beta
View as MarkdownOpen in Claude

Own an editable cold graph declaration and replayable construction factories.

Graph is the only HSDK 5 root authoring abstraction. It performs lazy composition and cold validation but does not compile or execute a graph. The lazy-composition gate is internally synchronized, so concurrent observers share one composer and receive its terminal result. This synchronization does not make general authoring thread-safe: after composition, callers must serialize mutation with every other mutation or observation of the same Graph. Handles do not extend Graph lifetime and become invalid when the Graph is destroyed.

Every successful public compound mutation is atomic. If allocation or an injected exceptional boundary interrupts an in-progress mutation, Graph restores the prior snapshot identity, generation, IDs, ownership claims, and declaration indexes before the exception escapes. A rejected external topic declaration is the deliberate exception to counter rollback: ordinary typed validation failures consume their mixed import/export declaration ordinal, while exceptional failures restore the reserved ordinal.

#include <holoscan/graph.hpp>

The complete most-derived Graph object must remain alive until all authoring, observation, and lazy-composition calls have returned. Destruction must not race any Graph access; handle invalidation does not provide concurrent destruction synchronization.


Constructors

Graph

holoscan::Graph::Graph(
std::string_view name = ""
)

Create an empty named Graph authoring root.

Throws: RuntimeError if name is invalid.

Parameters

name
std::string_viewDefaults to ""

Optional bounded UTF-8 name copied before return.

Destructor

~Graph

virtual holoscan::Graph::~Graph()

Destroy Graph-owned prototypes, factories, and authoring state.

Destruction must not overlap any authoring, observation, composition, or handle operation associated with this Graph.


Assignment operators

operator=

The following overloads are deleted to prevent misuse:

Graph & holoscan::Graph::operator=(const Graph &) = delete;
Graph & holoscan::Graph::operator=(Graph &&) = delete;

Methods

op

template <std::derived_from< OperatorBase > Op, typename... Args>
OperatorHandle<Op> holoscan::Graph::op(
std::string_view name,
Args &&... args
)

Add one typed Operator declaration and replayable factory.

If this is the first external authoring operation on a derived Graph, Core completes or terminally fails compose() before constructing the requested Operator factory or prototype.

Obvious top-level borrowed forms, move-only values, and Graph authoring handles are rejected at compile time. Function pointers and copyable callables are accepted. String views and string literals normalize to owned strings. Checks are intentionally shallow: nested container elements, user-defined fields, and callable captures remain the application’s lifetime responsibility.

Do not call Graph authoring verbs from a derived Graph constructor; author the reusable body only in the Core-managed compose override.

Preconditions

Each normalized capture must be copy-constructible. Copies follow the captured type’s ordinary C++ semantics, including shared identity for std::shared_ptr and non-owning observation for std::weak_ptr.

Preconditions

Any legacy Operator::start or Operator::stop hook must be public, unambiguous, and have the exact zero-argument void signature. Any advanced lifecycle member callback registered by setup() must be declared by Op itself rather than by a base or unrelated class.

Returns: Copyable authoring handle that dynamically resolves current ports.

Throws: RuntimeError if construction, setup, naming, or registration fails.

Template parameters

Op
std::derived_from< OperatorBase >

Concrete Operator type.

Args
typename...

Constructor capture argument types.

Parameters

name
std::string_view

Nonempty unique bounded UTF-8 declaration name.

args
Args &&...

Constructor values normalized and copied into replayable state.

add_operator

template <std::derived_from< OperatorBase > Op, typename... Args>
OperatorHandle<Op> holoscan::Graph::add_operator(
std::string_view name,
Args &&... args
)

Add one typed Operator declaration using the exact op alias.

Returns: Copyable typed authoring handle.

Throws: RuntimeError under the same conditions as op.

Template parameters

Op
std::derived_from< OperatorBase >

Concrete Operator type.

Args
typename...

Constructor capture argument types.

Parameters

name
std::string_view

Nonempty unique bounded UTF-8 declaration name.

args
Args &&...

Constructor values copied under the same ownership precondition as op.

handle

template <std::derived_from< OperatorBase > Op>
OperatorHandle<Op> holoscan::Graph::handle(
std::string_view name
)

Resolve one existing graph-local root Operator by name and exact concrete type.

This is a cold authoring-time lookup. It does not trigger lazy composition, inspect embedded Graph operators, or participate in per-activation execution.

Whole-aggregate parameter reconstruction does not invalidate either the creation handle or a handle returned by this lookup.

Returns: Copyable typed authoring handle interchangeable with the creation handle.

Throws: RuntimeError with GRAPH_OPERATOR_NOT_FOUND when no root declaration has this name.

Throws: RuntimeError with GRAPH_OPERATOR_TYPE_MISMATCH when the named root declaration has another concrete Operator type.

Template parameters

Op
std::derived_from< OperatorBase >

Expected concrete Operator type.

Parameters

name
std::string_view

Exact local declaration name from this Graph’s root authoring inventory.

embed

template <typename G, typename... Args>
GraphHandle<G> holoscan::Graph::embed(
std::string_view instance_name,
Args &&... args
)

Independently construct, compose, and own one reusable Graph instance.

Child composition reaches a terminal state before one atomic parent publication. The child Graph is never copied or moved and remains owned by the parent until parent retirement.

Unlike replayed Operator and clock factories, embedding constructs the child once, so constructor arguments may transfer move-only ownership. The same shallow top-level borrow checks still apply, and Graph authoring handles remain rejected because they are composition-time identity.

Embedded graphs do not inherit the parent’s default clock. Declare clock dependencies in the child’s compose() using import_clock, and use set_default_clock when an imported clock is the child’s default. After embedding, the immediate parent must supply each import using bind_clock before compilation. Nested reusable graphs require an explicit binding at every boundary; clock resolution never searches ancestor scopes by name.

The handle permits interface inspection only. It does not grant mutable access to the child authoring Graph.

Returns: Read-only typed handle exposing the child’s public interface members.

Throws: RuntimeError if parent/child composition, construction, canonical remapping, name validation, or publication fails.

Template parameters

G
typename

Concrete reusable Graph type.

Args
typename...

Constructor capture argument types.

Parameters

instance_name
std::string_view

Nonempty unique local embedded-instance name.

args
Args &&...

Constructor values normalized and forwarded once into the child object.

See also: import_clock, set_default_clock, bind_clock

add_flow

template <PublishedPayload SourceT, PublishedPayload TargetT>
FlowHandle<SourceT, TargetT> holoscan::Graph::add_flow(
const Output<SourceT> &source,
const Input<TargetT> &target,
ConnectionOptions options = {}
)

Add one exact-type or exact-contract raw-POD directed queue edge.

Distinct C++ endpoint types participate only when both have explicit raw-POD contracts. Scalar, enum, Tensor, and schema-root edges require the same C++ payload type.

Returns: Typed dynamic flow handle.

Throws: RuntimeError for foreign/stale ports, fan-in, cycles, duplicate topology, unequal complete POD contracts, or invalid options.

Template parameters

SourceT
PublishedPayload

Exact admitted source payload type.

TargetT
PublishedPayload

Exact admitted target payload type.

Parameters

source
const Output<SourceT> &

Graph-owned output declaration.

target
const Input<TargetT> &

Graph-owned input declaration.

options
ConnectionOptionsDefaults to {}

Cold edge options copied before return.

export_input

template <PublishedPayload T>
void holoscan::Graph::export_input(
const Input<T> &public_port,
const Input<T> &internal_port
)

Expose an internal input through a reusable Graph input alias.

Throws: RuntimeError if alias validation fails.

Template parameters

T
PublishedPayload

Exact admitted local payload type.

Parameters

public_port
const Input<T> &

Public Graph input declaration.

internal_port
const Input<T> &

Internal Operator input declaration.

export_output

template <PublishedPayload T>
void holoscan::Graph::export_output(
const Output<T> &public_port,
const Output<T> &internal_port
)

Expose an internal output through a reusable Graph output alias.

Throws: RuntimeError if alias validation fails.

Template parameters

T
PublishedPayload

Exact admitted local payload type.

Parameters

public_port
const Output<T> &

Public Graph output declaration.

internal_port
const Output<T> &

Internal Operator output declaration.

configure

template <PublishedPayload T>
InputPortConfigurator<T> holoscan::Graph::configure(
const Input<T> &port
)

Create a throwing configurator for one Graph-owned input.

Returns: Short-lived fluent configurator referencing stable authoring identity.

Throws: RuntimeError if port is foreign, stale, or structurally unknown.

Template parameters

T
PublishedPayload

Exact admitted local payload type.

Parameters

port
const Input<T> &

Exact input declaration.

try_configure

template <PublishedPayload T>
expected<InputPortConfigurator<T>, Error> holoscan::Graph::try_configure(
const Input<T> &port
)

Try to create an input configurator without throwing.

Returns: Configurator or typed lookup/ownership error.

Template parameters

T
PublishedPayload

Exact admitted local payload type.

Parameters

port
const Input<T> &

Exact input declaration.

import_topic

template <detail::ExternalTopicPayload T>
ImportedTopic<T> holoscan::Graph::import_topic(
std::string_view uri,
TopicOptions options = {}
)

Declare an intrinsic external-to-Graph typed topic boundary.

On first external use of a derived Graph, Core completes or terminally fails composition before constructing the requested boundary port.

The value parameter is intentional: it defines one immutable authoring snapshot while Core deep-copies every view-bearing field before this call returns.

Ordinary typed validation rejection consumes the next mixed external declaration ordinal. An exception before publication restores that ordinal.

Returns: Typed handle exposing the stable Graph-side output declaration.

Throws: RuntimeError if identity, URI, options, bounds, or name validation fails.

Template parameters

T
detail::ExternalTopicPayload

Exact portable scalar, Tensor, schema-root, or explicit POD payload type.

Parameters

uri
std::string_view

Nonempty bounded holomq:// topic URI copied before return.

options
TopicOptionsDefaults to {}

Complete cold boundary contract copied before return.

export_topic

template <detail::ExternalTopicPayload T>
ExportedTopic<T> holoscan::Graph::export_topic(
std::string_view uri,
TopicOptions options = {}
)

Declare an intrinsic Graph-to-external typed topic boundary.

On first external use of a derived Graph, Core completes or terminally fails composition before constructing the requested boundary port.

The value parameter is intentional: it defines one immutable authoring snapshot while Core deep-copies every view-bearing field before this call returns.

Ordinary typed validation rejection consumes the next mixed external declaration ordinal. An exception before publication restores that ordinal.

Returns: Typed handle exposing the stable Graph-side input declaration.

Throws: RuntimeError if identity, URI, options, bounds, or name validation fails.

Template parameters

T
detail::ExternalTopicPayload

Exact portable scalar, Tensor, schema-root, or explicit POD payload type.

Parameters

uri
std::string_view

Nonempty bounded holomq:// topic URI copied before return.

options
TopicOptionsDefaults to {}

Complete cold boundary contract copied before return.

region

RegionHandle holoscan::Graph::region(
std::string_view name
)

Add one uniquely named backend-neutral policy region.

Returns: Fluent region handle.

Throws: RuntimeError if name is invalid or duplicated.

Parameters

name
std::string_view

Nonempty unique bounded UTF-8 name copied before return.

partition

PartitionHandle holoscan::Graph::partition(
std::string_view name
)

Add one uniquely named developer-preview manual execution partition.

Without auto_partition_remaining or PartitionHandle::include_all, compile requires all partitions to be nonempty and to cover every executable Operator exactly once.

Manual partitions and region declarations are orthogonal; regions may overlap partition boundaries.

Direct root Operators and selected child subtrees may anchor automatic remainder. Selected subtrees include every descendant Operator and must not declare partitions internally. A root PartitionHandle::include_all covers the complete application.

Returns: Fluent partition handle accepting direct Operators and complete embedded instances.

Throws: RuntimeError if name is invalid or duplicated.

Parameters

name
std::string_view

Nonempty unique bounded UTF-8 name copied before return.

auto_partition_remaining

void holoscan::Graph::auto_partition_remaining()

Automatically partition Operators omitted from exact authored partitions.

The request is idempotent and may precede or follow exact partition authoring. Compilation rejects a request with no nonempty exact partition anchor.

Throws: RuntimeError if a partition already uses PartitionHandle::include_all.

lifecycle

GraphLifecycleBuilder holoscan::Graph::lifecycle()

Create a lifecycle ordering/permission authoring builder.

Returns: Short-lived builder tied to this Graph.

view

GraphView holoscan::Graph::view()

Freeze and return one immutable deep-owning authoring snapshot.

Returns: Snapshot that remains valid across Graph mutation and destruction.

Throws: RuntimeError if lazy composition failed or observation is reentrant.

add_clock

template <std::derived_from< Clock > ClockT, typename... Args>
ClockKey holoscan::Graph::add_clock(
std::string_view name,
Args &&... args
)

Add one Graph-owned replayable clock declaration.

On first external use of a derived Graph, Core completes or terminally fails composition before constructing the requested clock factory.

Registration constructs one Clock for validation and discards it. A later compiler or RunSession replays the retained factory to create its own ordinary Clock; only bind_shared_clock() retains a live instance.

Preconditions

Every normalized capture is copy-constructible and follows its ordinary C++ copy semantics. Obvious top-level borrowed forms and Graph authoring handles are rejected. Checks are shallow; nested borrows remain the application’s lifetime responsibility. Construction must be repeatable, and constructor side effects are not authoritative runtime state.

Returns: Owned named cold clock key.

Throws: RuntimeError if construction, naming, or registration fails.

Template parameters

ClockT
std::derived_from< Clock >

Concrete Clock type.

Args
typename...

Constructor capture argument types.

Parameters

name
std::string_view

Nonempty unique bounded UTF-8 clock name.

args
Args &&...

Constructor values copied under the same ownership precondition as op.

bind_shared_clock

ClockKey holoscan::Graph::bind_shared_clock(
std::string_view name,
std::shared_ptr<Clock> clock
)

Bind one explicitly shared live clock into cold Graph ownership.

Returns: Owned named cold clock key.

Throws: RuntimeError if naming or pointer validation fails.

Parameters

name
std::string_view

Nonempty unique bounded UTF-8 clock name.

clock
std::shared_ptr<Clock>

Non-null shared clock retained by Graph state.

import_clock

ClockKey holoscan::Graph::import_clock(
std::string_view name
)

Declare one explicit clock dependency for a reusable Graph.

An import creates no runtime clock. Every embedded instance must be bound explicitly by its direct parent before compilation.

Returns: Owned named import key that contracts and conversions may reference.

Throws: RuntimeError if naming or registration fails.

Parameters

name
std::string_view

Nonempty unique bounded UTF-8 clock import name.

bind_clock

template <typename G>
Graph & holoscan::Graph::bind_clock(
const GraphHandle<G> &child,
ClockKey child_import,
ClockKey parent_clock
)

Bind one embedded Graph clock import to one exact parent clock.

Resolution follows only these instance-qualified records. It never searches an ancestor scope by clock name.

Returns: This Graph.

Throws: RuntimeError for a foreign/stale child handle, a non-import child key, an unknown parent key, or a duplicate/conflicting binding.

Template parameters

G
typename

Concrete reusable Graph type.

Parameters

child
const GraphHandle<G> &

Exact live child instance owned by this Graph.

child_import
ClockKey

Named clock import declared by that child root.

parent_clock
ClockKey

Named clock declaration or import in this Graph.

set_default_clock

Graph & holoscan::Graph::set_default_clock(
)

Select one previously declared named clock as Graph default.

Returns: This Graph.

Throws: RuntimeError if key is default, empty, or not declared.

Parameters

key
ClockKey

Existing non-default named key.

default_clock

ClockKey holoscan::Graph::default_clock()

Return the selected default clock key.

Returns: Named key, or the distinct default/omitted key when none was selected.

Throws: RuntimeError if lazy composition failed or observation is reentrant.

add_clock_conversion

Graph & holoscan::Graph::add_clock_conversion(
ClockKey from,
)

Add one immutable directed affine clock conversion.

Core reduces the positive ratio to lowest terms. Repeating the same pair with an equivalent canonical ratio and equal offset is idempotent.

Returns: This Graph.

Throws: RuntimeError for missing/self clocks, an invalid scale, a conflicting conversion for the same directed pair, or a directed cycle.

Parameters

from
ClockKey

Existing named source clock.

to
ClockKey

Existing distinct named destination clock.

conversion
AffineClockConversion

Positive exact rate and signed nanosecond offset.

compose

virtual void holoscan::Graph::compose()

Author a derived Graph body during Core-managed lazy composition.

Core invokes this override at most once after derived construction. Normal authoring verbs are valid inside the active transaction. Topology observers and other same-Graph paths that re-enter the composition gate fail with GRAPH_COMPOSE_REENTRANT; a terminal failure is retained and replayed.

Do not author from the derived constructor and do not call this virtual function directly. Constructor misuse and direct self-recursion have no promised runtime diagnosis.

The complete most-derived Graph must remain alive for the entire callback; concurrent destruction is outside the Graph lifetime contract.

embedding_type_identity

virtual const void * holoscan::Graph::embedding_type_identity() const noexcept

Supply a process-stable logical type identity for a language-hosted Graph adapter.

Ordinary C++ Graph subclasses should retain the default. Language bindings that host multiple logical graph types behind one C++ adapter may override this hook so recursion checks distinguish those hosted types without weakening cycle detection.

This virtual is deliberately appended after the pre-existing compose() slot so adding the hosted-language hook does not change the slot used by existing Graph subclasses.

Returns: A non-null identity shared by every instance of the same logical hosted type, or nullptr to use the concrete C++ Graph type.

add_operator_with_initial_params

template <std::derived_from< OperatorBase > Op>
OperatorHandle<Op> holoscan::Graph::add_operator_with_initial_params(
std::string_view name,
const typename Op::Params &params
)

add_flow_projected

template <PublishedPayload SchemaT>
FlowHandle<SchemaT, Tensor> holoscan::Graph::add_flow_projected(
const Output<SchemaT> &source,
const Input<Tensor> &target,
TensorFieldSelector<SchemaT> selector,
)

Register one schema-to-Tensor edge after the field identity is known.


Member variables

NameTypeDescription
state_std::shared_ptr< detail::GraphState >