aboutsummaryrefslogtreecommitdiff
path: root/src/backends/cl/ICLTensorProxy.hpp
blob: fff9c53d3184c3abc32172e87256a47087f4525d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
//
// Copyright © 2022 Arm Ltd and Contributors. All rights reserved.
// SPDX-License-Identifier: MIT
//
#pragma once

#include <arm_compute/core/CL/ICLTensor.h>
#include <arm_compute/core/ITensorInfo.h>

namespace armnn
{

class ICLTensorProxy : public arm_compute::ICLTensor
{
public:
    ICLTensorProxy(arm_compute::ICLTensor* iclTensor) : m_DelegateTensor(iclTensor) {}
    ICLTensorProxy(const ICLTensorProxy&) = delete;
    ICLTensorProxy& operator=(const ICLTensorProxy&) = delete;
    ICLTensorProxy(ICLTensorProxy&&) = default;
    ICLTensorProxy& operator=(ICLTensorProxy&&) = default;

    void set(arm_compute::ICLTensor* iclTensor)
    {
        if(iclTensor != nullptr)
        {
            m_DelegateTensor = iclTensor;
        }
    }

    // Inherited methods overridden:
    arm_compute::ITensorInfo* info() const
    {
        ARM_COMPUTE_ERROR_ON(m_DelegateTensor == nullptr);
        return m_DelegateTensor->info();
    }

    arm_compute::ITensorInfo* info()
    {
        ARM_COMPUTE_ERROR_ON(m_DelegateTensor == nullptr);
        return m_DelegateTensor->info();
    }

    uint8_t* buffer() const
    {
        ARM_COMPUTE_ERROR_ON(m_DelegateTensor == nullptr);
        return m_DelegateTensor->buffer();
    }

    arm_compute::CLQuantization quantization() const
    {
        ARM_COMPUTE_ERROR_ON(m_DelegateTensor == nullptr);
        return m_DelegateTensor->quantization();
    }

    const cl::Buffer& cl_buffer() const
    {
        ARM_COMPUTE_ERROR_ON(m_DelegateTensor == nullptr);
        return m_DelegateTensor->cl_buffer();
    }

protected:
    uint8_t* do_map(cl::CommandQueue& q, bool blocking)
    {
        ARM_COMPUTE_ERROR_ON(m_DelegateTensor == nullptr);
        m_DelegateTensor->map(q, blocking);
        return m_DelegateTensor->buffer();
    }
    void do_unmap(cl::CommandQueue& q)
    {
        ARM_COMPUTE_ERROR_ON(m_DelegateTensor == nullptr);
        return m_DelegateTensor->unmap(q);
    }

private:
    arm_compute::ICLTensor* m_DelegateTensor{ nullptr };
};

} //namespace armnn