Class to manage multiple tensors with string-based lookup.
This class provides a central repository for caching tensors, allowing easy retrieval by name and automatic memory management. All tensors added to the cache are owned by the cache and will be automatically released when the cache is destroyed.
Definition at line 511 of file sources/gst-plugins/gst-nvdsvideotemplate/ds-sparse4d/utils/tensor.h.
Public Member Functions | |
| TensorCache () | |
| Default constructor. More... | |
| ~TensorCache () | |
| Destructor that automatically releases all cached tensors. More... | |
| bool | addTensor (Tensor *tensor) |
| Add a tensor to the cache. More... | |
| Tensor * | getTensor (const std::string &name) const |
| Get a tensor by name. More... | |
| void * | getTensorBuffer (const std::string &name) const |
| Get a tensor's buffer by name. More... | |
| size_t | getTensorSize (const std::string &name) const |
| Get a tensor's size by name. More... | |
| std::vector< int > | getTensorShape (const std::string &name) const |
| Get a tensor's shape by name. More... | |
| int | getTensorGpuId (const std::string &name) const |
| Get a tensor's gpu_id by name. More... | |
| int | getTensorFrameNum (const std::string &name) const |
| Get a tensor's frame_num by name. More... | |
| torch::Tensor | getTorchTensor (const std::string &name) const |
| Get a tensor directly as PyTorch tensor by name. More... | |
| bool | updateTensorBuffer (const std::string &name, void *newBuffer) |
| Update only a tensor's buffer pointer, keeping all other properties the same. More... | |
| Tensor * | cloneTensorCPU (const std::string &name) |
| Clone a tensor to CPU memory. More... | |
| torch::Tensor | cloneTorchTensorCPU (const std::string &name) |
| Clone a tensor to CPU memory and convert to PyTorch tensor. More... | |
| bool | hasTensor (const std::string &name) const |
| Check if a tensor with the given name exists. More... | |
| bool | removeTensor (const std::string &name) |
| Remove a tensor from the cache and release its resources. More... | |
| void | releaseAll () |
| Release all tensors and clear the cache. More... | |
| size_t | size () const |
| Get the number of tensors in the cache. More... | |
| std::vector< std::string > | getTensorNames () const |
| Get a list of all tensor names in the cache. More... | |
| const std::unordered_map< std::string, Tensor * > & | getTensors () const |
| Get all tensors in the cache. More... | |
| void | display (bool print_data=false) const |
| Display information about all cached tensors. More... | |
| void | displayTensor (const std::string &name, bool print_data=false) const |
| Display information about given tensor. More... | |
| TensorCache () | |
| Default constructor. More... | |
| ~TensorCache () | |
| Destructor that automatically releases all cached tensors. More... | |
| bool | addTensor (Tensor *tensor) |
| Add a tensor to the cache. More... | |
| Tensor * | getTensor (const std::string &name) const |
| Get a tensor by name. More... | |
| void * | getTensorBuffer (const std::string &name) const |
| Get a tensor's buffer by name. More... | |
| size_t | getTensorSize (const std::string &name) const |
| Get a tensor's size by name. More... | |
| std::vector< int > | getTensorShape (const std::string &name) const |
| Get a tensor's shape by name. More... | |
| int | getTensorGpuId (const std::string &name) const |
| Get a tensor's gpu_id by name. More... | |
| int | getTensorFrameNum (const std::string &name) const |
| Get a tensor's frame_num by name. More... | |
| torch::Tensor | getTorchTensor (const std::string &name) const |
| Get a tensor directly as PyTorch tensor by name. More... | |
| bool | updateTensorBuffer (const std::string &name, void *newBuffer) |
| Update only a tensor's buffer pointer, keeping all other properties the same. More... | |
| Tensor * | cloneTensorCPU (const std::string &name) |
| Clone a tensor to CPU memory. More... | |
| torch::Tensor | cloneTorchTensorCPU (const std::string &name) |
| Clone a tensor to CPU memory and convert to PyTorch tensor. More... | |
| bool | hasTensor (const std::string &name) const |
| Check if a tensor with the given name exists. More... | |
| bool | removeTensor (const std::string &name) |
| Remove a tensor from the cache and release its resources. More... | |
| void | releaseAll () |
| Release all tensors and clear the cache. More... | |
| size_t | size () const |
| Get the number of tensors in the cache. More... | |
| std::vector< std::string > | getTensorNames () const |
| Get a list of all tensor names in the cache. More... | |
| const std::unordered_map< std::string, Tensor * > & | getTensors () const |
| Get all tensors in the cache. More... | |
| void | display (bool print_data=false) const |
| Display information about all cached tensors. More... | |
| void | displayTensor (const std::string &name, bool print_data=false) const |
| Display information about given tensor. More... | |
|
inline |
Default constructor.
Definition at line 519 of file sources/gst-plugins/gst-nvdsvideotemplate/ds-sparse4d/utils/tensor.h.
|
inline |
Destructor that automatically releases all cached tensors.
Ensures that all memory allocated for tensors is properly freed when the cache is destroyed.
Definition at line 527 of file sources/gst-plugins/gst-nvdsvideotemplate/ds-sparse4d/utils/tensor.h.
References releaseAll().
|
inline |
Default constructor.
Definition at line 519 of file 9.2/sources/gst-plugins/gst-nvdsvideotemplate/ds-sparse4d/utils/tensor.h.
|
inline |
Destructor that automatically releases all cached tensors.
Ensures that all memory allocated for tensors is properly freed when the cache is destroyed.
Definition at line 527 of file 9.2/sources/gst-plugins/gst-nvdsvideotemplate/ds-sparse4d/utils/tensor.h.
References releaseAll().
|
inline |
Add a tensor to the cache.
| tensor | Pointer to tensor object (ownership transferred to cache) |
Definition at line 538 of file sources/gst-plugins/gst-nvdsvideotemplate/ds-sparse4d/utils/tensor.h.
References Tensor::name.
|
inline |
Add a tensor to the cache.
| tensor | Pointer to tensor object (ownership transferred to cache) |
Definition at line 538 of file 9.2/sources/gst-plugins/gst-nvdsvideotemplate/ds-sparse4d/utils/tensor.h.
References Tensor::name.
|
inline |
Clone a tensor to CPU memory.
Creates a new Tensor object with a CPU buffer and copies data from the existing tensor. Works regardless of whether the source tensor is on CPU or GPU.
| name | Name of the tensor to clone |
Definition at line 675 of file sources/gst-plugins/gst-nvdsvideotemplate/ds-sparse4d/utils/tensor.h.
References Tensor::buffer, Tensor::data_type, Tensor::frame_num, getTensor(), Tensor::gpu_id, hasTensor(), Tensor::name, Tensor::shape, and Tensor::size.
Referenced by cloneTorchTensorCPU().
|
inline |
Clone a tensor to CPU memory.
Creates a new Tensor object with a CPU buffer and copies data from the existing tensor. Works regardless of whether the source tensor is on CPU or GPU.
| name | Name of the tensor to clone |
Definition at line 675 of file 9.2/sources/gst-plugins/gst-nvdsvideotemplate/ds-sparse4d/utils/tensor.h.
References Tensor::buffer, Tensor::data_type, Tensor::frame_num, getTensor(), Tensor::gpu_id, hasTensor(), Tensor::name, Tensor::shape, and Tensor::size.
|
inline |
Clone a tensor to CPU memory and convert to PyTorch tensor.
Creates a CPU copy of the specified tensor and converts it to a PyTorch tensor. Works regardless of whether the source tensor is on CPU or GPU. The function handles memory management internally, freeing the cloned tensor after creating the PyTorch tensor.
| name | Name of the tensor to clone |
Definition at line 749 of file sources/gst-plugins/gst-nvdsvideotemplate/ds-sparse4d/utils/tensor.h.
References cloneTensorCPU(), and Tensor::to_torch_tensor().
|
inline |
Clone a tensor to CPU memory and convert to PyTorch tensor.
Creates a CPU copy of the specified tensor and converts it to a PyTorch tensor. Works regardless of whether the source tensor is on CPU or GPU. The function handles memory management internally, freeing the cloned tensor after creating the PyTorch tensor.
| name | Name of the tensor to clone |
Definition at line 749 of file 9.2/sources/gst-plugins/gst-nvdsvideotemplate/ds-sparse4d/utils/tensor.h.
References cloneTensorCPU(), and Tensor::to_torch_tensor().
|
inline |
Display information about all cached tensors.
| print_data | Whether to print the tensor data values |
Definition at line 846 of file sources/gst-plugins/gst-nvdsvideotemplate/ds-sparse4d/utils/tensor.h.
|
inline |
Display information about all cached tensors.
| print_data | Whether to print the tensor data values |
Definition at line 846 of file 9.2/sources/gst-plugins/gst-nvdsvideotemplate/ds-sparse4d/utils/tensor.h.
|
inline |
Display information about given tensor.
| name | Name of the tensor to display |
| print_data | Whether to print the tensor data values |
Definition at line 862 of file sources/gst-plugins/gst-nvdsvideotemplate/ds-sparse4d/utils/tensor.h.
|
inline |
Display information about given tensor.
| name | Name of the tensor to display |
| print_data | Whether to print the tensor data values |
Definition at line 862 of file 9.2/sources/gst-plugins/gst-nvdsvideotemplate/ds-sparse4d/utils/tensor.h.
|
inline |
Get a tensor by name.
| name | Name of the tensor to retrieve |
Definition at line 553 of file 9.2/sources/gst-plugins/gst-nvdsvideotemplate/ds-sparse4d/utils/tensor.h.
|
inline |
Get a tensor by name.
| name | Name of the tensor to retrieve |
Definition at line 553 of file sources/gst-plugins/gst-nvdsvideotemplate/ds-sparse4d/utils/tensor.h.
Referenced by cloneTensorCPU(), getTorchTensor(), and updateTensorBuffer().
|
inline |
Get a tensor's buffer by name.
| name | Name of the tensor whose buffer to retrieve |
Definition at line 567 of file 9.2/sources/gst-plugins/gst-nvdsvideotemplate/ds-sparse4d/utils/tensor.h.
|
inline |
Get a tensor's buffer by name.
| name | Name of the tensor whose buffer to retrieve |
Definition at line 567 of file sources/gst-plugins/gst-nvdsvideotemplate/ds-sparse4d/utils/tensor.h.
|
inline |
Get a tensor's frame_num by name.
| name | Name of the tensor whose frame_num to retrieve |
Definition at line 623 of file 9.2/sources/gst-plugins/gst-nvdsvideotemplate/ds-sparse4d/utils/tensor.h.
|
inline |
Get a tensor's frame_num by name.
| name | Name of the tensor whose frame_num to retrieve |
Definition at line 623 of file sources/gst-plugins/gst-nvdsvideotemplate/ds-sparse4d/utils/tensor.h.
|
inline |
Get a tensor's gpu_id by name.
| name | Name of the tensor whose gpu_id to retrieve |
Definition at line 609 of file 9.2/sources/gst-plugins/gst-nvdsvideotemplate/ds-sparse4d/utils/tensor.h.
|
inline |
Get a tensor's gpu_id by name.
| name | Name of the tensor whose gpu_id to retrieve |
Definition at line 609 of file sources/gst-plugins/gst-nvdsvideotemplate/ds-sparse4d/utils/tensor.h.
|
inline |
Get a list of all tensor names in the cache.
Definition at line 823 of file 9.2/sources/gst-plugins/gst-nvdsvideotemplate/ds-sparse4d/utils/tensor.h.
|
inline |
Get a list of all tensor names in the cache.
Definition at line 823 of file sources/gst-plugins/gst-nvdsvideotemplate/ds-sparse4d/utils/tensor.h.
|
inline |
Get all tensors in the cache.
Definition at line 837 of file sources/gst-plugins/gst-nvdsvideotemplate/ds-sparse4d/utils/tensor.h.
|
inline |
Get all tensors in the cache.
Definition at line 837 of file 9.2/sources/gst-plugins/gst-nvdsvideotemplate/ds-sparse4d/utils/tensor.h.
|
inline |
Get a tensor's shape by name.
| name | Name of the tensor whose shape to retrieve |
Definition at line 595 of file sources/gst-plugins/gst-nvdsvideotemplate/ds-sparse4d/utils/tensor.h.
|
inline |
Get a tensor's shape by name.
| name | Name of the tensor whose shape to retrieve |
Definition at line 595 of file 9.2/sources/gst-plugins/gst-nvdsvideotemplate/ds-sparse4d/utils/tensor.h.
|
inline |
Get a tensor's size by name.
| name | Name of the tensor whose size to retrieve |
Definition at line 581 of file sources/gst-plugins/gst-nvdsvideotemplate/ds-sparse4d/utils/tensor.h.
|
inline |
Get a tensor's size by name.
| name | Name of the tensor whose size to retrieve |
Definition at line 581 of file 9.2/sources/gst-plugins/gst-nvdsvideotemplate/ds-sparse4d/utils/tensor.h.
|
inline |
Get a tensor directly as PyTorch tensor by name.
| name | Name of the tensor to retrieve |
Definition at line 638 of file 9.2/sources/gst-plugins/gst-nvdsvideotemplate/ds-sparse4d/utils/tensor.h.
References Tensor::buffer, getTensor(), and Tensor::to_torch_tensor().
|
inline |
Get a tensor directly as PyTorch tensor by name.
| name | Name of the tensor to retrieve |
Definition at line 638 of file sources/gst-plugins/gst-nvdsvideotemplate/ds-sparse4d/utils/tensor.h.
References Tensor::buffer, getTensor(), and Tensor::to_torch_tensor().
|
inline |
Check if a tensor with the given name exists.
| name | Name of the tensor to check |
Definition at line 766 of file sources/gst-plugins/gst-nvdsvideotemplate/ds-sparse4d/utils/tensor.h.
Referenced by cloneTensorCPU().
|
inline |
Check if a tensor with the given name exists.
| name | Name of the tensor to check |
Definition at line 766 of file 9.2/sources/gst-plugins/gst-nvdsvideotemplate/ds-sparse4d/utils/tensor.h.
|
inline |
Release all tensors and clear the cache.
Definition at line 793 of file sources/gst-plugins/gst-nvdsvideotemplate/ds-sparse4d/utils/tensor.h.
Referenced by ~TensorCache().
|
inline |
Release all tensors and clear the cache.
Definition at line 793 of file 9.2/sources/gst-plugins/gst-nvdsvideotemplate/ds-sparse4d/utils/tensor.h.
|
inline |
Remove a tensor from the cache and release its resources.
| name | Name of the tensor to remove |
Definition at line 776 of file sources/gst-plugins/gst-nvdsvideotemplate/ds-sparse4d/utils/tensor.h.
|
inline |
Remove a tensor from the cache and release its resources.
| name | Name of the tensor to remove |
Definition at line 776 of file 9.2/sources/gst-plugins/gst-nvdsvideotemplate/ds-sparse4d/utils/tensor.h.
|
inline |
Get the number of tensors in the cache.
Definition at line 814 of file sources/gst-plugins/gst-nvdsvideotemplate/ds-sparse4d/utils/tensor.h.
|
inline |
Get the number of tensors in the cache.
Definition at line 814 of file 9.2/sources/gst-plugins/gst-nvdsvideotemplate/ds-sparse4d/utils/tensor.h.
|
inline |
Update only a tensor's buffer pointer, keeping all other properties the same.
| name | Name of the tensor to update |
| newBuffer | Pointer to the new buffer (must be GPU memory with same size/layout) |
Definition at line 653 of file 9.2/sources/gst-plugins/gst-nvdsvideotemplate/ds-sparse4d/utils/tensor.h.
References Tensor::buffer, and getTensor().
|
inline |
Update only a tensor's buffer pointer, keeping all other properties the same.
| name | Name of the tensor to update |
| newBuffer | Pointer to the new buffer (must be GPU memory with same size/layout) |
Definition at line 653 of file sources/gst-plugins/gst-nvdsvideotemplate/ds-sparse4d/utils/tensor.h.
References Tensor::buffer, and getTensor().