ArmNN
 24.08
ClTensorHandle.cpp
Go to the documentation of this file.
1 //
2 // Copyright © 2023 Arm Ltd and Contributors. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 
6 #include "ClTensorHandle.hpp"
7 
9 
10 namespace armnn
11 {
12  std::shared_ptr<ITensorHandle> ClTensorHandle::DecorateTensorHandle(const TensorInfo& tensorInfo)
13  {
14  auto* parent = const_cast<ClTensorHandle*>(this);
15  auto decorated = std::make_shared<ClTensorHandleDecorator>(parent, tensorInfo);
16  m_Decorated.emplace_back(decorated);
17  return decorated;
18  }
19 
21  : m_Original(nullptr), m_TensorInfo()
22  {
23  }
24 
25  ClTensorDecorator::ClTensorDecorator(arm_compute::ICLTensor* original, const TensorInfo& tensorInfo)
26  : m_Original(nullptr), m_TensorInfo()
27  {
28  m_TensorInfo = armcomputetensorutils::BuildArmComputeTensorInfo(tensorInfo);
29  m_Original = original;
30  }
31 
32  arm_compute::ITensorInfo* ClTensorDecorator::info() const
33  {
34  return &m_TensorInfo;
35  }
36 
37  arm_compute::ITensorInfo* ClTensorDecorator::info()
38  {
39  return &m_TensorInfo;
40  }
41 
42  const cl::Buffer& ClTensorDecorator::cl_buffer() const
43  {
44  ARM_COMPUTE_ERROR_ON(m_Original == nullptr);
45  return m_Original->cl_buffer();
46  }
47 
48  arm_compute::ICLTensor* ClTensorDecorator::parent()
49  {
50  return nullptr;
51  }
52 
53  arm_compute::CLQuantization ClTensorDecorator::quantization() const
54  {
55  return m_Original->quantization();
56  }
57 
58  void ClTensorDecorator::map(bool blocking)
59  {
60  arm_compute::ICLTensor::map(arm_compute::CLScheduler::get().queue(), blocking);
61  }
62 
64  {
65  arm_compute::ICLTensor::unmap(arm_compute::CLScheduler::get().queue());
66  }
67 
68  uint8_t* ClTensorDecorator::do_map(cl::CommandQueue& q, bool blocking)
69  {
70  if(m_Original->buffer() == nullptr)
71  {
72  m_Original->map(q, blocking);
73  }
74  return m_Original->buffer();
75  }
76 
77  void ClTensorDecorator::do_unmap(cl::CommandQueue& q)
78  {
79  m_Original->unmap(q);
80  }
81 
82 }
armnn::ClTensorDecorator::parent
arm_compute::ICLTensor * parent()
Definition: ClTensorHandle.cpp:48
armnn::ClTensorDecorator::info
virtual arm_compute::ITensorInfo * info() const override
Definition: ClTensorHandle.cpp:32
armnn::TensorInfo
Definition: Tensor.hpp:152
armnn::ClTensorDecorator::ClTensorDecorator
ClTensorDecorator()
Definition: ClTensorHandle.cpp:20
armnn::ClTensorDecorator::do_unmap
void do_unmap(cl::CommandQueue &q) override
Definition: ClTensorHandle.cpp:77
armnn::ClTensorDecorator::quantization
arm_compute::CLQuantization quantization() const override
Definition: ClTensorHandle.cpp:53
armnn::ClTensorDecorator::do_map
uint8_t * do_map(cl::CommandQueue &q, bool blocking) override
Definition: ClTensorHandle.cpp:68
armnn::ClTensorHandle
Definition: ClTensorHandle.hpp:28
armnn::ClTensorDecorator::map
void map(bool blocking=true)
Definition: ClTensorHandle.cpp:58
armnn::ClTensorDecorator::cl_buffer
const cl::Buffer & cl_buffer() const override
Definition: ClTensorHandle.cpp:42
ClTensorHandle.hpp
armnn::ClTensorHandle::DecorateTensorHandle
virtual std::shared_ptr< ITensorHandle > DecorateTensorHandle(const TensorInfo &tensorInfo) override
Returns a decorated version of this TensorHandle allowing us to override the TensorInfo for it.
Definition: ClTensorHandle.cpp:12
armnn
Copyright (c) 2021 ARM Limited and Contributors.
Definition: 01_00_quick_start.dox:6
ArmComputeTensorUtils.hpp
armnn::ClTensorDecorator::unmap
void unmap()
Definition: ClTensorHandle.cpp:63