21.02
|
Basic implementation of a CL memory tensor allocator. More...
#include <CLTensorAllocator.h>
Public Member Functions | |
CLTensorAllocator (IMemoryManageable *owner=nullptr, CLRuntimeContext *ctx=nullptr) | |
Default constructor. More... | |
CLTensorAllocator (const CLTensorAllocator &)=delete | |
Prevent instances of this class from being copied (As this class contains pointers) More... | |
CLTensorAllocator & | operator= (const CLTensorAllocator &)=delete |
Prevent instances of this class from being copy assigned (As this class contains pointers) More... | |
CLTensorAllocator (CLTensorAllocator &&)=default | |
Allow instances of this class to be moved. More... | |
CLTensorAllocator & | operator= (CLTensorAllocator &&)=default |
Allow instances of this class to be moved. More... | |
uint8_t * | data () |
Interface to be implemented by the child class to return the pointer to the mapped data. More... | |
const cl::Buffer & | cl_data () const |
Interface to be implemented by the child class to return the pointer to the CL data. More... | |
CLQuantization | quantization () const |
Wrapped quantization info data accessor. More... | |
uint8_t * | map (cl::CommandQueue &q, bool blocking) |
Enqueue a map operation of the allocated buffer on the given queue. More... | |
void | unmap (cl::CommandQueue &q, uint8_t *mapping) |
Enqueue an unmap operation of the allocated buffer on the given queue. More... | |
void | allocate () override |
Allocate size specified by TensorInfo of OpenCL memory. More... | |
void | free () override |
Free allocated OpenCL memory. More... | |
Status | import_memory (cl::Buffer buffer) |
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... | |
Public Member Functions inherited from ITensorAllocator | |
ITensorAllocator () | |
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... | |
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 CL memory tensor allocator.
Definition at line 42 of file CLTensorAllocator.h.
CLTensorAllocator | ( | IMemoryManageable * | owner = nullptr , |
CLRuntimeContext * | ctx = nullptr |
||
) |
Default constructor.
[in] | owner | (Optional) Owner of the allocator. |
[in] | ctx | (Optional) Runtime context. |
Definition at line 107 of file CLTensorAllocator.cpp.
|
delete |
Prevent instances of this class from being copied (As this class contains pointers)
|
default |
Allow instances of this class to be moved.
|
overridevirtual |
Allocate size specified by TensorInfo of OpenCL memory.
Implements ITensorAllocator.
Definition at line 127 of file CLTensorAllocator.cpp.
References ITensorAllocator::alignment(), CLRuntimeContext::core_runtime_context(), arm_compute::test::validation::data_type, IMemoryGroup::finalize_memory(), CLScheduler::get(), ITensorAllocator::info(), arm_compute::is_data_type_quantized_per_channel(), TensorInfo::set_is_resizable(), CLMemory::set_owned_region(), and TensorInfo::total_size().
Referenced by CLTensorHandle::allocate(), CLQLSTMLayer::CLQLSTMLayer(), CLReduceMean::configure(), CLMeanStdDev::configure(), CLFFT2D::configure(), CLRNNLayer::configure(), CLFFT1D::configure(), CLHOGGradient::configure(), CLHOGDescriptor::configure(), CLArgMinMaxLayer::configure(), CLL2NormalizeLayer::configure(), CLGaussian5x5::configure(), CLSobel5x5::configure(), CLSobel7x7::configure(), CLFastCorners::configure(), CLSoftmaxLayerGeneric< IS_LOG >::configure(), CLCannyEdge::configure(), CLGEMMLowpMatrixMultiplyCore::configure(), CLWinogradConvolutionLayer::configure(), CLHarrisCorners::configure(), CLFFTConvolutionLayer::configure(), CLGenerateProposalsLayer::configure(), CLHOGMultiDetection::configure(), CLDirectDeconvolutionLayer::configure(), CLGEMMDeconvolutionLayer::configure(), CLLSTMLayerQuantized::configure(), CLConvolutionSquare< matrix_size >::configure(), CLLSTMLayer::configure(), CLQLSTMLayer::configure(), CLGEMMConvolutionLayer::configure(), arm_compute::test::validation::DATA_TEST_CASE(), CLGEMMLowpMatrixMultiplyCore::prepare(), CLWinogradConvolutionLayer::prepare(), CLGEMMDeconvolutionLayer::prepare(), CLFFTConvolutionLayer::prepare(), CLDirectDeconvolutionLayer::prepare(), CLLSTMLayerQuantized::prepare(), CLGEMM::prepare(), CLFullyConnectedLayer::prepare(), CLQLSTMLayer::prepare(), CLGEMMConvolutionLayer::prepare(), CLGEMMReshapeRHSMatrixKernelManaged::run(), and arm_compute::test::validation::TEST_CASE().
const cl::Buffer & cl_data | ( | ) | const |
Interface to be implemented by the child class to return the pointer to the CL data.
Definition at line 122 of file CLTensorAllocator.cpp.
References ICLMemoryRegion::cl_data(), CLMemory::cl_region(), and CLMemory::region().
Referenced by CLTensor::cl_buffer().
uint8_t * data | ( | ) |
Interface to be implemented by the child class to return the pointer to the mapped data.
Definition at line 117 of file CLTensorAllocator.cpp.
|
overridevirtual |
Free allocated OpenCL memory.
Implements ITensorAllocator.
Definition at line 159 of file CLTensorAllocator.cpp.
References ITensorAllocator::info(), TensorInfo::set_is_resizable(), and CLMemory::set_region().
Referenced by CLTensorHandle::free(), CLWinogradConvolutionLayer::prepare(), CLGEMMDeconvolutionLayer::prepare(), CLFFTConvolutionLayer::prepare(), CLDirectDeconvolutionLayer::prepare(), CLLSTMLayerQuantized::prepare(), CLGEMMConvolutionLayer::prepare(), CLGEMMReshapeRHSMatrixKernelManaged::release(), CLTensorHandle::release_if_unused(), and arm_compute::test::validation::TEST_CASE().
Status import_memory | ( | cl::Buffer | buffer | ) |
Import an existing memory as a tensor's backing memory.
[in] | buffer | Buffer to be used as backing memory |
Definition at line 167 of file CLTensorAllocator.cpp.
References ARM_COMPUTE_RETURN_ERROR_ON, CLScheduler::context(), CLRuntimeContext::core_runtime_context(), CLScheduler::get(), ITensorAllocator::info(), TensorInfo::set_is_resizable(), and CLMemory::set_owned_region().
Referenced by CLFFTConvolutionLayer::run(), and arm_compute::test::validation::TEST_CASE().
uint8_t * map | ( | cl::CommandQueue & | q, |
bool | blocking | ||
) |
Enqueue a map operation of the allocated buffer on the given queue.
[in,out] | q | The CL command queue to use for the mapping operation. |
[in] | blocking | If true, then the mapping will be ready to use by the time this method returns, else it is the caller's responsibility to flush the queue and wait for the mapping operation to have completed before using the returned mapping pointer. |
Definition at line 223 of file CLTensorAllocator.cpp.
References ARM_COMPUTE_ERROR_ON, IMemoryRegion::buffer(), CLMemory::cl_region(), ICLMemoryRegion::map(), and CLMemory::region().
Referenced by CLTensorAllocator::set_associated_memory_group(), and CLTensor::unmap().
|
delete |
Prevent instances of this class from being copy assigned (As this class contains pointers)
|
default |
Allow instances of this class to be moved.
CLQuantization quantization | ( | ) | const |
Wrapped quantization info data accessor.
Definition at line 112 of file CLTensorAllocator.cpp.
Referenced by CLTensor::quantization().
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 188 of file CLTensorAllocator.cpp.
References ARM_COMPUTE_ERROR_ON, IMemoryRegion::buffer(), ICLMemoryRegion::cl_data(), CLMemory::cl_region(), CLScheduler::get(), CLRuntimeContext::gpu_scheduler(), CLTensorAllocator::map(), CLScheduler::queue(), CLMemory::region(), and CLTensorAllocator::unmap().
Referenced by CLTensor::associate_memory_group().
void unmap | ( | cl::CommandQueue & | q, |
uint8_t * | mapping | ||
) |
Enqueue an unmap operation of the allocated buffer on the given queue.
[in,out] | q | The CL command queue to use for the mapping operation. |
[in] | mapping | The cpu mapping to unmap. |
Definition at line 233 of file CLTensorAllocator.cpp.
References ARM_COMPUTE_ERROR_ON, ARM_COMPUTE_UNUSED, IMemoryRegion::buffer(), CLMemory::cl_region(), CLMemory::region(), and ICLMemoryRegion::unmap().
Referenced by CLTensorAllocator::set_associated_memory_group(), and CLTensor::unmap().