NVIDIA Holoscan SDK v2.3.0
Holoscan v2.3.0

holoscan.decorator

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

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

class holoscan.decorator.Input(name: str, arg_map: typing.Optional[typing.Union[str, dict[str, str]]] = (), condition_type: typing.Optional[holoscan.core._core.ConditionType] = None, condition_kwargs: typing.Dict[str, typing.Any] = <factory>, connector_type: typing.Optional[holoscan.core._core.IOSpec.ConnectorType] = None, connector_kwargs: typing.Dict[str, typing.Any] = <factory>)

Bases: object

Class for specifying an input port and how the received value maps to a function’s arguments.

Parameters
namestr

The name of the input port.

arg_map: str or dict[str, str]

If arg_map is a str, the Python object received by the input port is passed to the function argument specified by arg_map. If arg_map is a dict, the input is assumed to be a TensorMap (dictionary of tensors). In this case the keys of the dict are the tensor names and the values are the names of the function arguments that the tensors map to.

condition_typeholoscan.core.ConditionType, optional

The condition type for the input port.

condition_kwargsdict[str, Any], optional

The keywords passed onto the condition specified by condition_type.

connector_typeholoscan.core.IOSpec.ConnectorType, optional

The connector type for the input port.

connector_kwargsdict[str, Any], optional

The keywords passed onto the connector specified by connector_type.

Attributes

condition_type
connector_type

Methods

create_input
__init__(name: str, arg_map: typing.Optional[typing.Union[str, dict[str, str]]] = (), condition_type: typing.Optional[holoscan.core._core.ConditionType] = None, condition_kwargs: typing.Dict[str, typing.Any] = <factory>, connector_type: typing.Optional[holoscan.core._core.IOSpec.ConnectorType] = None, connector_kwargs: typing.Dict[str, typing.Any] = <factory>) → None
arg_map: Optional[Union[str, dict[str, str]]] = ()
condition_kwargs: Dict[str, Any]
condition_type: Optional[holoscan.core._core.ConditionType] = None
connector_kwargs: Dict[str, Any]
connector_type: Optional[holoscan.core._core.IOSpec.ConnectorType] = None
create_input(spec: holoscan.core._core.PyOperatorSpec)holoscan.core._core.IOSpec
name: str
class holoscan.decorator.Output(name: str, tensor_names: typing.Optional[typing.Union[str, typing.Tuple[str]]] = (), condition_type: typing.Optional[holoscan.core._core.ConditionType] = None, condition_kwargs: typing.Dict[str, typing.Any] = <factory>, connector_type: typing.Optional[holoscan.core._core.IOSpec.ConnectorType] = None, connector_kwargs: typing.Dict[str, typing.Any] = <factory>)

Bases: object

Class for specifying an output port and how the received value maps to a function’s arguments.

Parameters
namestr

The name of the input port.

tensor_names: str, tuple(str) or None

If None, whatever Python object the func outputs is emitted on the output port. If a tuple of strings is provided it is assumed that the func returns a dictionary of tensors. The names in the tuple specify which tensors in the dict will be transmitted on the output port. There is no need to specify tensor_names if all tensors in a dict returned by the function are to be transmitted. In the case of a single tensor name, a string can be provided instead of a tuple.

condition_typeholoscan.core.ConditionType, optional

The condition type for the input port.

condition_kwargsdict[str, Any], optional

The keywords passed onto the condition specified by condition_type.

connector_typeholoscan.core.IOSpec.ConnectorType, optional

The connector type for the input port.

connector_kwargsdict[str, Any], optional

The keywords passed onto the connector specified by connector_type.

Attributes

condition_type
connector_type

Methods

create_output
__init__(name: str, tensor_names: typing.Optional[typing.Union[str, typing.Tuple[str]]] = (), condition_type: typing.Optional[holoscan.core._core.ConditionType] = None, condition_kwargs: typing.Dict[str, typing.Any] = <factory>, connector_type: typing.Optional[holoscan.core._core.IOSpec.ConnectorType] = None, connector_kwargs: typing.Dict[str, typing.Any] = <factory>) → None
condition_kwargs: Dict[str, Any]
condition_type: Optional[holoscan.core._core.ConditionType] = None
connector_kwargs: Dict[str, Any]
connector_type: Optional[holoscan.core._core.IOSpec.ConnectorType] = None
create_output(spec: holoscan.core._core.PyOperatorSpec)holoscan.core._core.IOSpec
name: str
tensor_names: Optional[Union[str, Tuple[str]]] = ()
holoscan.decorator.create_op(function_or_class=None, inputs: Union[str, holoscan.decorator.Input, Tuple[Union[str, holoscan.decorator.Input]]] = (), outputs: Union[str, holoscan.decorator.Output, Tuple[Union[str, holoscan.decorator.Output]]] = (), cast_tensors=True)

Decorator for creating an operator from a function or a class.

When the decorator is used on a class, the class must have a __call__ method that will be used as the operator function.

inputsstr, Input, or Tuple[str | Input], optional

If a str is provided, it is assumed to be the name of the input port and that the function has a variable matching that port name to which the object received on the port will be connected. If the port name does not match the name of the variable in the function signature, or if there are multiple tensors to be mapped to multiple objects, use an Input argument. A tuple of str or Input objects can be provided to specify multiple input ports. The default of an empty tuple corresponds to no input ports.

outputsstr, Output, or Tuple[str | Output], optional

If a str is provided, any value returned by the function will be emitted on an output port of that name. Otherwise, an Output object can be provided in the case that the function returns multiple outputs that should be split across multiple ports.

cast_tensorsbool, optional

If True, automatically cast any tensor-like input to a NumPy or CuPy array (for host and device tensors, respectively). If set to False, these will be left as holoscan.Tensor and the user will have to cast to the desired type within the body of the decorated function or class.

Notes

Another case where using Input or Output objects is necessary is if the user wishes to override the default connector or condition types for the port.

Previous holoscan.core
Next holoscan.executors
© Copyright 2022-2024, NVIDIA. Last updated on Sep 6, 2024.