Imported Upstream version 1.7.0
[platform/core/ml/nnfw.git] / runtime / onert / backend / acl_common / IACLTensor.h
1 /*
2  * Copyright (c) 2019 Samsung Electronics Co., Ltd. All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #ifndef __ONERT_BACKEND_ACL_COMMON_I_ACL_TENSOR_H__
18 #define __ONERT_BACKEND_ACL_COMMON_I_ACL_TENSOR_H__
19
20 #include <backend/ITensor.h>
21 #include <arm_compute/core/ITensor.h>
22
23 namespace onert
24 {
25 namespace backend
26 {
27 namespace acl_common
28 {
29
30 /**
31  * @brief Class representing Tensor for ACL
32  * @todo Override is_dynamic() method. We don't support dynamic tensor for ACL yet as of Apr, 2020.
33  *       FYI, ACL ITensorInfo has is_dynamic() method, which seems currently not used.
34  *       Maybe for ACL, this method can be implemented using ITensorInfo::is_dynamic() in future.
35  */
36 class IACLTensor : public ITensor
37 {
38 public:
39   IACLTensor() = default;
40   IACLTensor(const IACLTensor &) = delete;
41   IACLTensor &operator=(const IACLTensor &) = delete;
42   IACLTensor(IACLTensor &&) = default;
43   IACLTensor &operator=(IACLTensor &&) = default;
44
45 public:
46   uint8_t *buffer() const final { return handle()->buffer(); }
47   size_t total_size() const final { return info()->total_size(); }
48   size_t dimension(size_t index) const final;
49   size_t calcOffset(const ir::Coordinates &coords) const final;
50   ir::Layout layout() const final;
51   ir::DataType data_type() const final;
52   float data_scale() const override;
53   int32_t data_offset() const override;
54   bool has_padding() const override { return info()->has_padding(); }
55   bool is_dynamic() const override { return false; }
56
57 public:
58   virtual const arm_compute::ITensor *handle() const = 0;
59   virtual arm_compute::ITensor *handle() = 0;
60
61   const arm_compute::ITensorInfo *info() const { return handle()->info(); }
62   arm_compute::ITensorInfo *info() { return handle()->info(); }
63 };
64
65 } // namespace acl_common
66 } // namespace backend
67 } // namespace onert
68
69 #endif //__ONERT_BACKEND_ACL_COMMON_I_ACL_TENSOR_H__