Compute Library
 22.05
Tensor Class Reference

Tensor class. More...

#include <Acl.hpp>

Collaboration diagram for Tensor:
[legend]

Public Member Functions

 Tensor (Context &ctx, const TensorDescriptor &desc, StatusCode *status=nullptr)
 Constructor. More...
 
 Tensor (Context &ctx, const TensorDescriptor &desc, bool allocate, StatusCode *status)
 Constructor. More...
 
void * map ()
 Maps the backing memory of a given tensor that can be used by the host to access any contents. More...
 
StatusCode unmap (void *handle)
 Unmaps tensor's memory. More...
 
StatusCode import (void *handle, ImportType type)
 Import external memory to a given tensor object. More...
 
uint64_t get_size ()
 Get the size of the tensor in byte. More...
 
TensorDescriptor get_descriptor ()
 Get the descriptor of this tensor. More...
 
- Public Member Functions inherited from ObjectBase< AclTensor_ >
 ~ObjectBase ()=default
 Destructor. More...
 
 ObjectBase (const ObjectBase< AclTensor_ > &)=default
 Copy constructor. More...
 
 ObjectBase (ObjectBase< AclTensor_ > &&)=default
 Move Constructor. More...
 
ObjectBase< AclTensor_ > & operator= (const ObjectBase< AclTensor_ > &)=default
 Copy assignment operator. More...
 
ObjectBase< AclTensor_ > & operator= (ObjectBase< AclTensor_ > &&)=default
 Move assignment operator. More...
 
void reset (AclTensor_ *val)
 Reset object value. More...
 
const AclTensor_get () const
 Access uderlying object. More...
 
AclTensor_get ()
 Access uderlying object. More...
 

Detailed Description

Tensor class.

Tensor is an mathematical construct that can represent an N-Dimensional space.

Note
Maximum dimensionality support is 6 internally at the moment

Definition at line 584 of file Acl.hpp.

Constructor & Destructor Documentation

◆ Tensor() [1/2]

Tensor ( Context ctx,
const TensorDescriptor desc,
StatusCode status = nullptr 
)
inline

Constructor.

Note
Tensor memory is allocated
Parameters
[in]ctxContext from where the tensor will be created from
[in]descTensor descriptor to be used
[out]statusStatus information if requested

Definition at line 595 of file Acl.hpp.

596  : Tensor(ctx, desc, true, status)
597  {
598  }
Tensor(Context &ctx, const TensorDescriptor &desc, StatusCode *status=nullptr)
Constructor.
Definition: Acl.hpp:595

◆ Tensor() [2/2]

Tensor ( Context ctx,
const TensorDescriptor desc,
bool  allocate,
StatusCode status 
)
inline

Constructor.

Parameters
[in]ctxContext from where the tensor will be created from
[in]descTensor descriptor to be used
[in]allocateFlag to indicate if the tensor needs to be allocated
[out]statusStatus information if requested

Definition at line 606 of file Acl.hpp.

References AclCreateTensor(), ObjectBase< T >::get(), and TensorDescriptor::get().

607  {
608  AclTensor tensor;
609  const auto st = detail::as_enum<StatusCode>(AclCreateTensor(&tensor, ctx.get(), desc.get(), allocate));
610  reset(tensor);
611  report_status(st, "[Compute Library] Failed to create tensor!");
612  if(status)
613  {
614  *status = st;
615  }
616  }
void reset(AclTensor_ *val)
Reset object value.
Definition: Acl.hpp:148
AclStatus AclCreateTensor(AclTensor *tensor, AclContext ctx, const AclTensorDescriptor *desc, bool allocate)
Create a Tensor object.
Definition: AclTensor.cpp:68

Member Function Documentation

◆ get_descriptor()

TensorDescriptor get_descriptor ( )
inline

Get the descriptor of this tensor.

Returns
The descriptor describing the characteristics of this tensor

Definition at line 670 of file Acl.hpp.

References AclGetTensorDescriptor().

671  {
672  AclTensorDescriptor desc;
673  const auto st = detail::as_enum<StatusCode>(AclGetTensorDescriptor(_object.get(), &desc));
674  report_status(st, "[Compute Library] Failed to get the descriptor of the tensor");
675  return TensorDescriptor(desc);
676  }
AclStatus AclGetTensorDescriptor(AclTensor tensor, AclTensorDescriptor *desc)
Get the descriptor of this tensor.
Definition: AclTensor.cpp:175

◆ get_size()

uint64_t get_size ( )
inline

Get the size of the tensor in byte.

Note
The size isn't based on allocated memory, but based on information in its descriptor (dimensions, data type, etc.).
Returns
The size of the tensor in byte

Definition at line 659 of file Acl.hpp.

References AclGetTensorSize().

660  {
661  uint64_t size{ 0 };
662  const auto st = detail::as_enum<StatusCode>(AclGetTensorSize(_object.get(), &size));
663  report_status(st, "[Compute Library] Failed to get the size of the tensor");
664  return size;
665  }
AclStatus AclGetTensorSize(AclTensor tensor, uint64_t *size)
__cplusplus
Definition: AclTensor.cpp:158

◆ import()

StatusCode import ( void *  handle,
ImportType  type 
)
inline

Import external memory to a given tensor object.

Parameters
[in]handleExternal memory handle
[in]typeType of memory to be imported
Returns
Status code

Definition at line 647 of file Acl.hpp.

References AclTensorImport(), and type.

648  {
649  const auto st = detail::as_enum<StatusCode>(AclTensorImport(_object.get(), handle, detail::as_cenum<AclImportMemoryType>(type)));
650  report_status(st, "[Compute Library] Failed to import external memory to tensor!");
651  return st;
652  }
decltype(strategy::transforms) typedef type
AclStatus AclTensorImport(AclTensor tensor, void *handle, AclImportMemoryType type)
Import external memory to a given tensor object.
Definition: AclTensor.cpp:130

◆ map()

void* map ( )
inline

Maps the backing memory of a given tensor that can be used by the host to access any contents.

Returns
A valid non-zero pointer in case of success else nullptr

Definition at line 621 of file Acl.hpp.

References AclMapTensor().

622  {
623  void *handle = nullptr;
624  const auto st = detail::as_enum<StatusCode>(AclMapTensor(_object.get(), &handle));
625  report_status(st, "[Compute Library] Failed to map the tensor and extract the tensor's backing memory!");
626  return handle;
627  }
AclStatus AclMapTensor(AclTensor tensor, void **handle)
Map a tensor&#39;s backing memory to the host.
Definition: AclTensor.cpp:97

◆ unmap()

StatusCode unmap ( void *  handle)
inline

Unmaps tensor's memory.

Parameters
[in]handleHandle to unmap
Returns
Status code

Definition at line 634 of file Acl.hpp.

References AclUnmapTensor().

635  {
636  const auto st = detail::as_enum<StatusCode>(AclUnmapTensor(_object.get(), handle));
637  report_status(st, "[Compute Library] Failed to unmap the tensor!");
638  return st;
639  }
AclStatus AclUnmapTensor(AclTensor tensor, void *handle)
Unmap the tensor&#39;s backing memory.
Definition: AclTensor.cpp:116

The documentation for this class was generated from the following file: