Class Resource

Base Type

Derived Types

class Resource : public holoscan::Component

Base class for all resources.

Resources such as system memory or a GPU memory pool that an Operator needs to perform its job. Resources are allocated during the initialization phase of the application. This matches the semantics of GXF’s Memory Allocator or any other components derived from the Component class in GXF.

Subclassed by holoscan::Endpoint, holoscan::gxf::GXFResource

Public Types

enum class ResourceType

Resource type used for the initialization of the resource.

Values:

enumerator kNative

Native resource.

enumerator kGXF

GXF resource.

Public Functions

Resource() = default

Resource(Resource&&) = default

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

Construct a new Resource object.

Parameters

args – The arguments to be passed to the resource.

~Resource() override = default

inline ResourceType resource_type() const

Get the resource type.

Returns

The resource type.

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

Set the name of the resource.

Parameters

name – The name of the resource.

Returns

The reference to the resource.

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

Set the name of the resource.

Parameters

name – The name of the resource.

Returns

The reference to the resource.

inline Resource &fragment(Fragment *fragment)

Set the fragment of the resource.

Parameters

fragment – The pointer to the fragment of the resource.

Returns

The reference to the resource.

inline Resource &spec(const std::shared_ptr<ComponentSpec> &spec)

Set the component specification to the resource.

Parameters

spec – The component specification.

Returns

The reference to the resource.

inline ComponentSpec *spec()

Get the component specification of the resource.

Returns

The pointer to the component specification.

inline std::shared_ptr<ComponentSpec> spec_shared()

Get the shared pointer to the component spec.

Returns

The shared pointer to the component spec.

inline virtual void setup(ComponentSpec &spec)

Define the resource specification.

Parameters

spec – The reference to the component specification.

virtual void initialize() override

Initialize the component.

This method is called only once when the component is created for the first time, and use of light-weight initialization.

virtual YAML::Node to_yaml_node() const override

Get a YAML representation of the resource.

Returns

YAML node including spec of the resource in addition to the base component properties.

inline const std::string &name() const

Get the name of the component.

Returns

The name of the component.

inline Fragment *fragment()

Get a pointer to Fragment object.

Returns

The Pointer to Fragment object.

inline void add_arg(const Arg &arg)

Add an argument to the component.

Parameters

arg – The argument to add.

inline void add_arg(Arg &&arg)

Add an argument to the component.

Parameters

arg – The argument to add.

inline void add_arg(const ArgList &arg)

Add a list of arguments to the component.

Parameters

arg – The list of arguments to add.

inline void add_arg(ArgList &&arg)

Add a list of arguments to the component.

Parameters

arg – The list of arguments to add.

Protected Attributes

ResourceType resource_type_ = ResourceType::kNative

The type of the resource.

std::shared_ptr<ComponentSpec> spec_

The component specification.

bool is_initialized_ = false

Whether the resource is initialized.

© Copyright 2022-2023, NVIDIA. Last updated on Sep 13, 2023.