Compute Library
 22.05
CpuTensor Class Referencefinal

CPU tensor implementation class. More...

#include <CpuTensor.h>

Collaboration diagram for CpuTensor:
[legend]

Public Member Functions

 CpuTensor (IContext *ctx, const AclTensorDescriptor &desc)
 Construct a new Cpu Tensor object. More...
 
StatusCode allocate ()
 Allocates tensor. More...
 
void * map () override
 Map tensor to a host pointer. More...
 
StatusCode unmap () override
 Unmap tensor. More...
 
arm_compute::ITensortensor () const override
 Get the legacy tensor object. More...
 
StatusCode import (void *handle, ImportMemoryType type) override
 Import external memory handle. More...
 
- Public Member Functions inherited from ITensorV2
 ITensorV2 (IContext *ctx)
 Explict Operator Constructor. More...
 
virtual ~ITensorV2 ()
 Destructor. More...
 
bool is_valid () const
 Checks if a queue is valid. More...
 
size_t get_size () const
 Get the size of the tensor in byte. More...
 
AclTensorDescriptor get_descriptor () const
 Get the descriptor of this tensor. More...
 

Additional Inherited Members

- Data Fields inherited from AclTensor_
arm_compute::detail::Header header { arm_compute::detail::ObjectType::Tensor, nullptr }
 

Detailed Description

CPU tensor implementation class.

Definition at line 36 of file CpuTensor.h.

Constructor & Destructor Documentation

◆ CpuTensor()

CpuTensor ( IContext ctx,
const AclTensorDescriptor desc 
)

Construct a new Cpu Tensor object.

Parameters
[in]ctxContext to be used
[in]descTensor descriptor

Definition at line 32 of file CpuTensor.cpp.

References ARM_COMPUTE_ASSERT, arm_compute::detail::convert_to_legacy_tensor_info(), arm_compute::Cpu, and IContext::type().

33  : ITensorV2(ctx), _legacy_tensor()
34 {
35  ARM_COMPUTE_ASSERT((ctx != nullptr) && (ctx->type() == Target::Cpu));
36  _legacy_tensor = std::make_unique<Tensor>();
37  _legacy_tensor->allocator()->init(arm_compute::detail::convert_to_legacy_tensor_info(desc));
38 }
#define ARM_COMPUTE_ASSERT(cond)
Definition: Validate.h:37
TensorInfo convert_to_legacy_tensor_info(const AclTensorDescriptor &desc)
Convert a descriptor to a legacy format one.
ITensorV2(IContext *ctx)
Explict Operator Constructor.
Definition: ITensorV2.h:52

Member Function Documentation

◆ allocate()

StatusCode allocate ( )

Allocates tensor.

Returns
StatusCode A status code

Definition at line 52 of file CpuTensor.cpp.

References ARM_COMPUTE_ASSERT, and arm_compute::Success.

Referenced by CpuContext::create_tensor().

53 {
54  ARM_COMPUTE_ASSERT(_legacy_tensor.get() != nullptr);
55 
56  _legacy_tensor->allocator()->allocate();
57  return StatusCode::Success;
58 }
#define ARM_COMPUTE_ASSERT(cond)
Definition: Validate.h:37

◆ import()

StatusCode import ( void *  handle,
ImportMemoryType  type 
)
overridevirtual

Import external memory handle.

Parameters
[in]handleMemory to import
[in]typeType of imported memory
Returns
Status code

Implements ITensorV2.

Definition at line 66 of file CpuTensor.cpp.

References ARM_COMPUTE_ASSERT, ARM_COMPUTE_UNUSED, arm_compute::RuntimeError, and arm_compute::Success.

67 {
68  ARM_COMPUTE_ASSERT(_legacy_tensor.get() != nullptr);
70 
71  const auto st = _legacy_tensor->allocator()->import_memory(handle);
73 }
#define ARM_COMPUTE_ASSERT(cond)
Definition: Validate.h:37
decltype(strategy::transforms) typedef type
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
Definition: Error.h:152

◆ map()

void * map ( )
overridevirtual

Map tensor to a host pointer.

Returns
A pointer to the underlying backing memory if successful else nullptr

Implements ITensorV2.

Definition at line 40 of file CpuTensor.cpp.

References ARM_COMPUTE_ASSERT, and ARM_COMPUTE_LOG_ERROR_ACL.

41 {
42  ARM_COMPUTE_ASSERT(_legacy_tensor.get() != nullptr);
43 
44  if(_legacy_tensor == nullptr)
45  {
46  ARM_COMPUTE_LOG_ERROR_ACL("[CpuTensor:map]: Backing tensor does not exist!");
47  return nullptr;
48  }
49  return _legacy_tensor->buffer();
50 }
#define ARM_COMPUTE_ASSERT(cond)
Definition: Validate.h:37
#define ARM_COMPUTE_LOG_ERROR_ACL(msg)
Log an error message to the logger.
Definition: Log.h:77

◆ tensor()

arm_compute::ITensor * tensor ( ) const
overridevirtual

Get the legacy tensor object.

Returns
The legacy underlying tensor object

Implements ITensorV2.

Definition at line 75 of file CpuTensor.cpp.

76 {
77  return _legacy_tensor.get();
78 }

◆ unmap()

StatusCode unmap ( )
overridevirtual

Unmap tensor.

Returns
AclStatus A status cod

Implements ITensorV2.

Definition at line 60 of file CpuTensor.cpp.

References arm_compute::Success.

61 {
62  // No-op
63  return StatusCode::Success;
64 }

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