xref: /aosp_15_r20/external/armnn/src/backends/cl/ICLTensorProxy.hpp (revision 89c4ff92f2867872bb9e2354d150bf0c8c502810)
1 //
2 // Copyright © 2022 Arm Ltd and Contributors. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 #pragma once
6 
7 #include <arm_compute/core/CL/ICLTensor.h>
8 #include <arm_compute/core/ITensorInfo.h>
9 
10 namespace armnn
11 {
12 
13 class ICLTensorProxy : public arm_compute::ICLTensor
14 {
15 public:
ICLTensorProxy(arm_compute::ICLTensor * iclTensor)16     ICLTensorProxy(arm_compute::ICLTensor* iclTensor) : m_DelegateTensor(iclTensor) {}
17     ICLTensorProxy(const ICLTensorProxy&) = delete;
18     ICLTensorProxy& operator=(const ICLTensorProxy&) = delete;
19     ICLTensorProxy(ICLTensorProxy&&) = default;
20     ICLTensorProxy& operator=(ICLTensorProxy&&) = default;
21 
set(arm_compute::ICLTensor * iclTensor)22     void set(arm_compute::ICLTensor* iclTensor)
23     {
24         if(iclTensor != nullptr)
25         {
26             m_DelegateTensor = iclTensor;
27         }
28     }
29 
30     // Inherited methods overridden:
info() const31     arm_compute::ITensorInfo* info() const
32     {
33         ARM_COMPUTE_ERROR_ON(m_DelegateTensor == nullptr);
34         return m_DelegateTensor->info();
35     }
36 
info()37     arm_compute::ITensorInfo* info()
38     {
39         ARM_COMPUTE_ERROR_ON(m_DelegateTensor == nullptr);
40         return m_DelegateTensor->info();
41     }
42 
buffer() const43     uint8_t* buffer() const
44     {
45         ARM_COMPUTE_ERROR_ON(m_DelegateTensor == nullptr);
46         return m_DelegateTensor->buffer();
47     }
48 
quantization() const49     arm_compute::CLQuantization quantization() const
50     {
51         ARM_COMPUTE_ERROR_ON(m_DelegateTensor == nullptr);
52         return m_DelegateTensor->quantization();
53     }
54 
cl_buffer() const55     const cl::Buffer& cl_buffer() const
56     {
57         ARM_COMPUTE_ERROR_ON(m_DelegateTensor == nullptr);
58         return m_DelegateTensor->cl_buffer();
59     }
60 
61 protected:
do_map(cl::CommandQueue & q,bool blocking)62     uint8_t* do_map(cl::CommandQueue& q, bool blocking)
63     {
64         ARM_COMPUTE_ERROR_ON(m_DelegateTensor == nullptr);
65         m_DelegateTensor->map(q, blocking);
66         return m_DelegateTensor->buffer();
67     }
do_unmap(cl::CommandQueue & q)68     void do_unmap(cl::CommandQueue& q)
69     {
70         ARM_COMPUTE_ERROR_ON(m_DelegateTensor == nullptr);
71         return m_DelegateTensor->unmap(q);
72     }
73 
74 private:
75     arm_compute::ICLTensor* m_DelegateTensor{ nullptr };
76 };
77 
78 } //namespace armnn