Class Operator

Base Type

Derived Types

class Operator : public holoscan::Component

Base class for all operators.

An operator is the most basic unit of work in Holoscan SDK. An Operator receives streaming data at an input port, processes it, and publishes it to one of its output ports.

This class is the base class for all operators. It provides the basic functionality for all operators.

Subclassed by holoscan::ops::AJASourceOp, holoscan::ops::AsyncPingRxOp, holoscan::ops::AsyncPingTxOp, holoscan::ops::FormatConverterOp, holoscan::ops::GXFOperator, holoscan::ops::HolovizOp, holoscan::ops::InferenceOp, holoscan::ops::InferenceProcessorOp, holoscan::ops::PingRxOp, holoscan::ops::PingTxOp, holoscan::ops::SegmentationPostprocessorOp, holoscan::ops::V4L2VideoCaptureOp, holoscan::ops::VideoStreamRecorderOp, holoscan::ops::VideoStreamReplayerOp, holoscan::ops::VirtualOperator

Public Types

enum class OperatorType

Operator type used by the executor.

Values:

enumerator kNative
enumerator kGXF
enumerator kVirtual

Public Functions

template<typename ArgT, typename ...ArgsT, typename = std::enable_if_t<!std::is_base_of_v<holoscan::Operator, std::decay_t<ArgT>> && (std::is_same_v<holoscan::Arg, std::decay_t<ArgT>> || std::is_same_v<holoscan::ArgList, std::decay_t<ArgT>> || std::is_base_of_v<holoscan::Condition, typename holoscan::type_info<ArgT>::derived_type> || std::is_base_of_v<holoscan::Resource, typename holoscan::type_info<ArgT>::derived_type>)>>
inline explicit Operator(ArgT &&arg, ArgsT&&... args)

Construct a new Operator object.

Parameters
Operator() = default
~Operator() override = default
inline OperatorType operator_type() const

Get the operator type.

Returns
inline Operator &id(int64_t id)

Set the Operator ID.

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

Set the name of the operator.

Parameters
Returns
inline Operator &fragment(Fragment *fragment)

Set the fragment of the operator.

Parameters
Returns
inline Operator &spec(const std::shared_ptr<OperatorSpec> &spec)

Set the operator spec.

Parameters
Returns
inline OperatorSpec *spec()

Get the operator spec.

Returns
inline std::shared_ptr<OperatorSpec> spec_shared()

Get the shared pointer to the operator spec.

Returns
template<typename ConditionT>
inline std::shared_ptr<ConditionT> condition(const std::string &name)

Get a shared pointer to the Condition object.

Parameters
Returns
inline std::unordered_map<std::string, std::shared_ptr<Condition>> &conditions()

Get the conditions of the operator.

Returns
template<typename ResourceT>
inline std::shared_ptr<ResourceT> resource(const std::string &name)

Get a shared pointer to the Resource object.

Parameters
Returns
inline std::unordered_map<std::string, std::shared_ptr<Resource>> &resources()

Get the resources of the operator.

Returns
inline void add_arg(const std::shared_ptr<Condition> &arg)

Add a condition to the operator.

Parameters
inline void add_arg(std::shared_ptr<Condition> &&arg)

Add a condition to the operator.

Parameters
inline void add_arg(const std::shared_ptr<Resource> &arg)

Add a resource to the operator.

Parameters
inline void add_arg(std::shared_ptr<Resource> &&arg)

Add a resource to the operator.

Parameters
inline virtual void setup(OperatorSpec &spec)

Define the operator specification.

Parameters
bool is_root()

Returns whether the operator is a root operator based on its fragment’s graph.

Returns
bool is_leaf()

Returns whether the operator is a leaf operator based on its fragment’s graph.

Returns
virtual void initialize() override
inline virtual void start()
inline virtual void stop()
inline virtual void compute(InputContext &op_input, OutputContext &op_output, ExecutionContext &context)

Implement the compute method.

This method is called by the runtime multiple times. The runtime calls this method until the operator is stopped.

Parameters
virtual YAML::Node to_yaml_node() const override

Get a YAML representation of the operator.

Returns
inline int64_t id() const

Get the identifier of the component.

By default, the identifier is set to -1. It is set to a valid value when the component is initialized.

With the default executor (GXFExecutor), the identifier is set to the GXF component ID.

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

Get the name of the component.

Returns
inline Fragment *fragment()

Get a pointer to Fragment object.

Returns
inline void add_arg(const Arg &arg)

Add an argument to the component.

Parameters
inline void add_arg(Arg &&arg)

Add an argument to the component.

Parameters
inline void add_arg(const ArgList &arg)

Add a list of arguments to the component.

Parameters
inline void add_arg(ArgList &&arg)

Add a list of arguments to the component.

Parameters

Public Static Functions

template<typename typeT>
static inline void register_converter()

Register the argument setter for the given type.

If the operator has an argument with a custom type, the argument setter must be registered using this method.

The argument setter is used to set the value of the argument from the YAML configuration.

This method can be called in the initialization phase of the operator (e.g., initialize()). The example below shows how to register the argument setter for the custom type (Vec3):

It is assumed that YAML::convert<T>::encode and YAML::convert<T>::decode are implemented for the given type. You need to specialize the YAML::convert<> template class.

For example, suppose that you had a Vec3 class with the following members:

You can define the YAML::convert<Vec3> as follows in a ‘.cpp’ file:

Please refer to the yaml-cpp documentation for more details.

Template Parameters
static std::pair<std::string, std::string> parse_port_name(const std::string &op_port_name)
template<typename typeT>
static inline void register_codec(const std::string &codec_name, bool overwrite = true)

Register the codec for serialization/deserialization of a custom type.

If the operator has an argument with a custom type, the codec must be registered using this method.

For example, suppose we want to emit using the following custom struct type:

Then, we can define codec<Coordinate> as follows where the serialize and deserialize methods would be used for serialization and deserialization of this type, respectively.

In this case, since this is a simple struct with a static size, we can use the existing serialize_trivial_type and deserialize_trivial_type implementations.

Finally, to register this custom codec at runtime, we need to make the following call within the setup method of our Operator.

Template Parameters
Parameters

Protected Functions

MessageLabel get_consolidated_input_label()

This function returns a consolidated MessageLabel for all the input ports of an Operator. If there is no input port (root Operator), then a new MessageLabel with the current Operator and default receive timestamp is returned.

Returns
inline void update_input_message_label(std::string input_name, MessageLabel m)

Update the input_message_labels map with the given MessageLabel a corresponding input_name.

Parameters
inline void reset_input_message_labels()
inline std::map<std::string, uint64_t> num_published_messages_map()

Get the number of published messages for each output port indexed by the output port name.

The function is utilized by the DFFTCollector to update the DataFlowTracker with the number of published messages for root operators.

Returns
void update_published_messages(std::string output_name)

This function updates the number of published messages for a given output port.

Parameters

Protected Attributes

OperatorType operator_type_ = OperatorType::kNative
std::shared_ptr<OperatorSpec> spec_
std::unordered_map<std::string, std::shared_ptr<Condition>> conditions_
std::unordered_map<std::string, std::shared_ptr<Resource>> resources_

Protected Static Functions

template<typename typeT>
static inline void register_argument_setter()

Register the argument setter for the given type.

Please refer to the documentation of register_converter() for more details.

Template Parameters

Friends

friend class AnnotatedDoubleBufferReceiver
friend class AnnotatedDoubleBufferTransmitter
friend class DFFTCollector

© Copyright 2022-2023, NVIDIA. Last updated on Feb 9, 2024.