NVIDIA Holoscan SDK v1.0.3
Holoscan 1.0.3

Class Fragment

Derived Types

class Fragment

The fragment of the application.

A fragment is a building block of the Application. It is a directed graph of operators. A fragment can be assigned to a physical node of a Holoscan cluster during execution. The run-time execution manages communication across fragments. In a Fragment, Operators (Graph Nodes) are connected to each other by flows (Graph Edges).

Subclassed by holoscan::Application, holoscan::gxf::OperatorWrapperFragment

Public Functions

Fragment() = default
virtual ~Fragment() = default
Fragment(Fragment&&) = default
Fragment &operator=(Fragment&&) = default
Fragment &name(const std::string &name) &

Set the name of the operator.

Parameters
Returns
Fragment &&name(const std::string &name) &&

Set the name of the operator.

Parameters
Returns
const std::string &name() const

Get the name of the fragment.

Returns
Fragment &application(Application *app)

Set the application of the fragment.

Parameters
Returns
Application *application() const

Get the application of the fragment.

Returns
void config(const std::string &config_file, const std::string &prefix = "")

Set the configuration of the fragment.

The configuration file is a YAML file that has the information of GXF extension paths and some parameter values for operators.

The extensions field in the YAML configuration file is a list of GXF extension paths. The paths can be absolute or relative to the current working directory, considering paths in LD_LIBRARY_PATH environment variable.

The paths can consist of the following parts:

  • GXF core extensions

    • built-in extensions such as libgxf_std.so and libgxf_cuda.so.

    • libgxf_std.so, libgxf_cuda.so, libgxf_multimedia.so, libgxf_serialization.so are always loaded by default.

    • GXF core extensions are copied to the lib directory of the build/installation directory.

  • Other GXF extensions

    • GXF extensions that are required for operators that this fragment uses.

    • some core GXF extensions such as libgxf_stream_playback.so are always loaded by default.

    • these paths are usually relative to the build/installation directory.

The extension paths are used to load dependent GXF extensions at runtime when run() method is called.

For other fields in the YAML file, you can freely define the parameter values for operators/fragments.

For example:

You can get the value of this configuration file by calling from_config() method.

If the application is executed with --config option or HOLOSCAN_CONFIG_PATH environment, the configuration file is overridden by the configuration file specified by the option or environment variable.

Parameters
void config(std::shared_ptr<Config> &config)

Set the configuration of the fragment.

If you want to set the configuration of the fragment manually, you can use this method. However, it is recommended to use config(const std::string&, const std::string&) method because once you set the configuration manually, you cannot get the configuration from the override file (through --config option or HOLOSCAN_CONFIG_PATH environment variable).

Parameters
Config &config()

Get the configuration of the fragment.

Returns
OperatorGraph &graph()

Get the graph of the fragment.

Returns
Executor &executor()

Get the executor of the fragment.

Returns
std::shared_ptr<Scheduler> scheduler()

Get the scheduler used by the executor.

Returns
void scheduler(const std::shared_ptr<Scheduler> &scheduler)
std::shared_ptr<NetworkContext> network_context()

Get the network context used by the executor.

Returns
void network_context(const std::shared_ptr<NetworkContext> &network_context)
ArgList from_config(const std::string &key)

Get the Argument(s) from the configuration file.

For the given key, this method returns the value of the configuration file.

For example:

from_config("aja") returns an ArgList (vector-like) object that contains the following items:

  • Arg("width") = 1920

  • Arg("height") = 1080

  • Arg("rdma") = true

You can use ‘.’ (dot) to access nested fields.

from_config("aja.rdma") returns an ArgList object that contains only one item and it can be converted to bool through ArgList::as() method:

Parameters
Returns
std::unordered_set<std::string> config_keys()

Determine the set of keys present in a Fragment’s config.

Returns
template<typename OperatorT, typename StringT, typename ...ArgsT, typename = std::enable_if_t<std::is_constructible_v<std::string, StringT>>>
inline std::shared_ptr<OperatorT> make_operator(const StringT &name, ArgsT&&... args)

Create a new operator.

Template Parameters
Parameters
Returns
template<typename OperatorT, typename ...ArgsT>
inline std::shared_ptr<OperatorT> make_operator(ArgsT&&... args)

Create a new operator.

Template Parameters
Parameters
Returns
template<typename ResourceT, typename StringT, typename ...ArgsT, typename = std::enable_if_t<std::is_constructible_v<std::string, StringT>>>
inline std::shared_ptr<ResourceT> make_resource(const StringT &name, ArgsT&&... args)

Create a new (operator) resource.

Template Parameters
Parameters
Returns
template<typename ResourceT, typename ...ArgsT>
inline std::shared_ptr<ResourceT> make_resource(ArgsT&&... args)

Create a new (operator) resource.

Template Parameters
Parameters
Returns
template<typename ConditionT, typename StringT, typename ...ArgsT, typename = std::enable_if_t<std::is_constructible_v<std::string, StringT>>>
inline std::shared_ptr<ConditionT> make_condition(const StringT &name, ArgsT&&... args)

Create a new condition.

Template Parameters
Parameters
Returns
template<typename ConditionT, typename ...ArgsT>
inline std::shared_ptr<ConditionT> make_condition(ArgsT&&... args)

Create a new condition.

Template Parameters
Parameters
Returns
template<typename SchedulerT, typename StringT, typename ...ArgsT, typename = std::enable_if_t<std::is_constructible_v<std::string, StringT>>>
inline std::shared_ptr<SchedulerT> make_scheduler(const StringT &name, ArgsT&&... args)

Create a new scheduler.

Template Parameters
Parameters
Returns
template<typename SchedulerT, typename ...ArgsT>
inline std::shared_ptr<SchedulerT> make_scheduler(ArgsT&&... args)

Create a new scheduler.

Template Parameters
Parameters
Returns
template<typename NetworkContextT, typename StringT, typename ...ArgsT, typename = std::enable_if_t<std::is_constructible_v<std::string, StringT>>>
inline std::shared_ptr<NetworkContextT> make_network_context(const StringT &name, ArgsT&&... args)

Create a new network context.

Template Parameters
Parameters
Returns
template<typename NetworkContextT, typename ...ArgsT>
inline std::shared_ptr<NetworkContextT> make_network_context(ArgsT&&... args)

Create a new network context.

Template Parameters
Parameters
Returns
virtual void add_operator(const std::shared_ptr<Operator> &op)

Add an operator to the graph.

The information of the operator is stored in the Graph object. If the operator is already added, this method does nothing.

Parameters
virtual void add_flow(const std::shared_ptr<Operator> &upstream_op, const std::shared_ptr<Operator> &downstream_op)

Add a flow between two operators.

An output port of the upstream operator is connected to an input port of the downstream operator. The information about the flow (edge) is stored in the Graph object.

If the upstream operator or the downstream operator is not in the graph, it will be added to the graph.

If there are multiple output ports in the upstream operator or multiple input ports in the downstream operator, it shows an error message.

Parameters
virtual void add_flow(const std::shared_ptr<Operator> &upstream_op, const std::shared_ptr<Operator> &downstream_op, std::set<std::pair<std::string, std::string>> port_pairs)

Add a flow between two operators.

An output port of the upstream operator is connected to an input port of the downstream operator. The information about the flow (edge) is stored in the Graph object.

If the upstream operator or the downstream operator is not in the graph, it will be added to the graph.

In port_pairs, an empty port name (“”) can be used for specifying a port name if the operator has only one input/output port.

If a non-existent port name is specified in port_pairs, it first checks if there is a parameter with the same name but with a type of std::vector<holoscan::IOSpec*> in the downstream operator. If there is such a parameter (e.g., receivers), it creates a new input port with a specific label (<parameter name>:<index>. e.g., receivers:0), otherwise it shows an error message.

For example, if a parameter receivers want to have an arbitrary number of receivers,

Instead of creating a fixed number of input ports (e.g., source_video and tensor) and assigning them to the parameter (receivers): You can skip the creation of input ports and assign them to the parameter (receivers) as follows: This makes the following code possible in the Application’s compose() method: Instead of: By using the parameter (receivers) with std::vector<holoscan::IOSpec*> type, the framework creates input ports (receivers:0 and receivers:1) implicitly and connects them (and adds the references of the input ports to the receivers vector).

Parameters
virtual void compose()
virtual void run()
virtual std::future<void> run_async()

Initialize the graph and run the graph asynchronously.

This method calls compose() to compose the graph, and runs the graph asynchronously.

Returns
DataFlowTracker &track(uint64_t num_start_messages_to_skip = kDefaultNumStartMessagesToSkip, uint64_t num_last_messages_to_discard = kDefaultNumLastMessagesToDiscard, int latency_threshold = kDefaultLatencyThreshold)

Turn on data frame flow tracking.

A reference to a DataFlowTracker object is returned rather than a pointer so that the developers can use it as an object without unnecessary pointer dereferencing.

Parameters
Returns
inline DataFlowTracker *data_flow_tracker()

Get the DataFlowTracker object for this fragment.

Returns
virtual void compose_graph()
FragmentPortMap port_info() const

Get an easily serializable summary of port information.

The FragmentPortMap class is used by distributed applications to send port information between application workers and the driver.

Returns

Protected Functions

template<typename ConfigT, typename ...ArgsT>
inline std::shared_ptr<Config> make_config(ArgsT&&... args)
template<typename GraphT>
inline std::unique_ptr<GraphT> make_graph()
template<typename ExecutorT>
inline std::shared_ptr<Executor> make_executor()
template<typename ExecutorT, typename ...ArgsT>
inline std::unique_ptr<Executor> make_executor(ArgsT&&... args)

Protected Attributes

std::string name_
Application *app_ = nullptr
std::shared_ptr<Config> config_
std::unique_ptr<OperatorGraph> graph_
std::shared_ptr<Executor> executor_
std::shared_ptr<Scheduler> scheduler_
std::shared_ptr<NetworkContext> network_context_
std::shared_ptr<DataFlowTracker> data_flow_tracker_
bool is_composed_ = false

Friends

friend class Application
friend class AppDriver

Previous Template Class FlowGraph
Next Class FragmentAllocationStrategy
© Copyright 2022-2023, NVIDIA. Last updated on Apr 19, 2024.