23.08
|
Basic implementation of a CPU memory tensor allocator. More...
#include <TensorAllocator.h>
Public Member Functions | |
TensorAllocator (IMemoryManageable *owner) | |
Default constructor. More... | |
~TensorAllocator () | |
Default destructor. More... | |
TensorAllocator (const TensorAllocator &)=delete | |
Prevent instances of this class from being copied (As this class contains pointers) More... | |
TensorAllocator & | operator= (const TensorAllocator &)=delete |
Prevent instances of this class from being copy assigned (As this class contains pointers) More... | |
TensorAllocator (TensorAllocator &&) noexcept | |
Allow instances of this class to be moved. More... | |
TensorAllocator & | operator= (TensorAllocator &&) noexcept |
Allow instances of this class to be moved. More... | |
void | init (const TensorAllocator &allocator, const Coordinates &coords, TensorInfo &sub_info) |
Shares the same backing memory with another tensor allocator, while the tensor info might be different. More... | |
uint8_t * | data () const |
Returns the pointer to the allocated data. More... | |
void | allocate () override |
Allocate size specified by TensorInfo of CPU memory. More... | |
void | free () override |
Free allocated CPU memory. More... | |
Status | import_memory (void *memory) |
Import an existing memory as a tensor's backing memory. More... | |
void | set_associated_memory_group (IMemoryGroup *associated_memory_group) |
Associates the tensor with a memory group. More... | |
void | init (const TensorInfo &input, size_t alignment=0) |
Make ITensorAllocator's init methods available. More... | |
![]() | |
ITensorAllocator ()=default | |
Default constructor. More... | |
ITensorAllocator (const ITensorAllocator &)=default | |
Allow instances of this class to be copy constructed. More... | |
ITensorAllocator & | operator= (const ITensorAllocator &)=default |
Allow instances of this class to be copied. More... | |
ITensorAllocator (ITensorAllocator &&)=default | |
Allow instances of this class to be move constructed. More... | |
ITensorAllocator & | operator= (ITensorAllocator &&)=default |
Allow instances of this class to be moved. More... | |
virtual | ~ITensorAllocator ()=default |
Default virtual destructor. More... | |
void | init (const TensorInfo &input, size_t alignment=0) |
Initialize a tensor based on the passed TensorInfo. More... | |
void | soft_init (TensorInfo &input, size_t alignment=0) |
Initialize a tensor based with a reference TensorInfo. More... | |
TensorInfo & | info () |
Return a reference to the tensor's metadata. More... | |
const TensorInfo & | info () const |
Return a constant reference to the tensor's metadata. More... | |
size_t | alignment () const |
Return underlying's tensor buffer alignment. More... | |
Basic implementation of a CPU memory tensor allocator.
Definition at line 42 of file TensorAllocator.h.
TensorAllocator | ( | IMemoryManageable * | owner | ) |
Default constructor.
[in] | owner | Memory manageable owner |
Definition at line 68 of file TensorAllocator.cpp.
~TensorAllocator | ( | ) |
Default destructor.
Definition at line 73 of file TensorAllocator.cpp.
References ITensorAllocator::info(), and TensorInfo::set_is_resizable().
|
delete |
Prevent instances of this class from being copied (As this class contains pointers)
|
noexcept |
|
overridevirtual |
Allocate size specified by TensorInfo of CPU memory.
Implements ITensorAllocator.
Definition at line 132 of file TensorAllocator.cpp.
References ITensorAllocator::alignment(), IMemoryGroup::finalize_memory(), ITensorAllocator::info(), TensorInfo::set_is_resizable(), Memory::set_owned_region(), and TensorInfo::total_size().
Referenced by NETensorHandle::allocate(), CPPBoxWithNonMaximaSuppressionLimit::configure(), CPPDetectionPostProcessLayer::configure(), NEFFT2D::configure(), NERNNLayer::configure(), NEL2NormalizeLayer::configure(), NEFFT1D::configure(), NEReductionOperation::configure(), NEInstanceNormalizationLayer::configure(), NEDetectionPostProcessLayer::configure(), NENormalizationLayer::configure(), NEFFTConvolutionLayer::configure(), NEGenerateProposalsLayer::configure(), NELSTMLayerQuantized::configure(), NELSTMLayer::configure(), NEDeconvolutionLayer::configure(), NEQLSTMLayer::configure(), CpuAuxTensorHandler::CpuAuxTensorHandler(), main(), NumPyAccessor::NumPyAccessor(), NEFFTConvolutionLayer::prepare(), NEDeconvolutionLayer::prepare(), NELSTMLayerQuantized::prepare(), NEQLSTMLayer::prepare(), NEFullyConnectedLayerReshapeWeightsManaged::run(), and arm_compute::test::validation::TEST_CASE().
uint8_t * data | ( | ) | const |
Returns the pointer to the allocated data.
Definition at line 127 of file TensorAllocator.cpp.
References IMemoryRegion::buffer(), and Memory::region().
Referenced by Tensor::buffer().
|
overridevirtual |
Free allocated CPU memory.
Implements ITensorAllocator.
Definition at line 147 of file TensorAllocator.cpp.
References ITensorAllocator::info(), TensorInfo::set_is_resizable(), and Memory::set_region().
Referenced by CpuDirectConv2d::configure(), CpuDirectConv3d::configure(), NETensorHandle::free(), NEFFTConvolutionLayer::prepare(), NELSTMLayerQuantized::prepare(), NEFullyConnectedLayerReshapeWeightsManaged::release(), NETensorHandle::release_if_unused(), and arm_compute::test::validation::TEST_CASE().
Status import_memory | ( | void * | memory | ) |
Import an existing memory as a tensor's backing memory.
[in] | memory | Raw memory pointer to be used as backing memory |
Definition at line 153 of file TensorAllocator.cpp.
References ITensorAllocator::alignment(), ARM_COMPUTE_RETURN_ERROR_ON, arm_compute::utility::check_aligned(), ITensorAllocator::info(), TensorInfo::set_is_resizable(), and Memory::set_owned_region().
Referenced by CpuAuxTensorHandler::CpuAuxTensorHandler(), NEFFTConvolutionLayer::run(), CpuGemmConv2d::run(), and arm_compute::test::validation::TEST_CASE().
void init | ( | const TensorAllocator & | allocator, |
const Coordinates & | coords, | ||
TensorInfo & | sub_info | ||
) |
Shares the same backing memory with another tensor allocator, while the tensor info might be different.
In other words this can be used to create a sub-tensor from another tensor while sharing the same memory.
[in] | allocator | The allocator that owns the backing memory to be shared. Ownership becomes shared afterwards. |
[in] | coords | The starting coordinates of the new tensor inside the parent tensor. |
[in] | sub_info | The new tensor information (e.g. shape etc) |
Definition at line 107 of file TensorAllocator.cpp.
References arm_compute::test::validation::allocator(), ARM_COMPUTE_ERROR_ON, ARM_COMPUTE_UNUSED, TensorInfo::format(), TensorInfo::init(), TensorInfo::offset_element_in_bytes(), TensorInfo::offset_first_element_in_bytes(), TensorInfo::strides_in_bytes(), TensorInfo::tensor_shape(), and TensorInfo::total_size().
Referenced by CPPBoxWithNonMaximaSuppressionLimit::configure(), NERNNLayer::configure(), NEFFT1D::configure(), NEReductionOperation::configure(), NENormalizationLayer::configure(), NEFFTConvolutionLayer::configure(), NEGenerateProposalsLayer::configure(), NELSTMLayerQuantized::configure(), NELSTMLayer::configure(), NEDeconvolutionLayer::configure(), NEQLSTMLayer::configure(), main(), NETensorHandle::NETensorHandle(), NumPyAccessor::NumPyAccessor(), and arm_compute::test::validation::TEST_CASE().
void init |
Make ITensorAllocator's init methods available.
Definition at line 33 of file ITensorAllocator.cpp.
|
delete |
Prevent instances of this class from being copy assigned (As this class contains pointers)
|
noexcept |
Allow instances of this class to be moved.
Definition at line 89 of file TensorAllocator.cpp.
References ITensorAllocator::operator=().
void set_associated_memory_group | ( | IMemoryGroup * | associated_memory_group | ) |
Associates the tensor with a memory group.
[in] | associated_memory_group | Memory group to associate the tensor with |
Definition at line 165 of file TensorAllocator.cpp.
References ARM_COMPUTE_ERROR_ON, IMemoryRegion::buffer(), and Memory::region().
Referenced by Tensor::associate_memory_group(), and arm_compute::test::validation::TEST_CASE().