NVIDIA Holoscan SDK v1.0.3
Holoscan 1.0.3

Class GXFTensor

Base Type

  • public nvidia::gxf::Tensor

class GXFTensor : public nvidia::gxf::Tensor

Class to wrap GXF Tensor holding DLPack tensor structure.

This class inherits nvidia::gxf::Tensor and is used with DLManagedTensorCtx class to wrap the GXF Tensor.

Public Functions

GXFTensor() = default

explicit GXFTensor(std::shared_ptr<DLManagedTensorCtx> &dl_ctx)

Construct a new GXFTensor object.

Parameters

dl_ctxDLManagedTensorCtx object to wrap.

explicit GXFTensor(nvidia::gxf::Tensor &tensor, int64_t id = 0)

Construct a new GXFTensor object from a GXF Tensor.

This constructor wraps a GXF Tensor object. When the GXF Tensor object is modified to point to a shared memory buffer, updates should be protected using a mutex. To mitigate thread contention when different threads access different tensors, this method uses hash-selected mutexes.

A set of mutexes is allocated in a static array. To select which mutex to lock, this method uses a simple hash function based on the provided ID. The selected mutex ensures safe access to the Tensor’s data pointer across multiple threads.

For the ID (id), the GXF component’s ID can be used to indicate a specific GXF Tensor object. If no ID is provided, the mutex associated with ID 0 is used. If the ID is -1, no mutex is utilized.

Parameters
  • tensor – The GXF Tensor object to be converted.

  • id – The ID associated with the GXF Tensor, representing the GXF component’s ID. Defaults to 0.

Returns

The GXFTensor object created from the provided GXF Tensor.

DLDevice device() const

Get DLDevice object from the GXF Tensor.

Returns

DLDevice object.

DLDataType dtype() const

Get DLDataType object from the GXF Tensor.

Returns

DLDataType object.

std::shared_ptr<holoscan::Tensor> as_tensor()

Convert GXF Tensor to Holoscan Tensor.

Returns

holoscan::Tensor object converted from GXF Tensor.

inline std::shared_ptr<DLManagedTensorCtx> &dl_ctx()

Get the internal DLManagedTensorCtx of the GXFTensor.

Returns

A shared pointer to the Tensor’s DLManagedTensorCtx.

Public Static Functions

static std::shared_ptr<GXFTensor> from_tensor(std::shared_ptr<holoscan::Tensor> tensor)

Create GXF Tensor object from Holoscan Tensor.

Parameters

tensor – Holoscan Tensor object to convert.

Returns

The shared pointer object to the GXFTensor object that is created from the given Holoscan Tensor object.

Protected Attributes

std::shared_ptr<DLManagedTensorCtx> dl_ctx_

Previous Class GXFScheduler
Next Class GXFWrapper
© Copyright 2022-2023, NVIDIA. Last updated on Apr 19, 2024.