2 * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #ifndef __ONERT_BACKEND_OPERAND_I_TENSOR_H__
18 #define __ONERT_BACKEND_OPERAND_I_TENSOR_H__
24 #include "ir/DataType.h"
25 #include "ir/Layout.h"
27 #include "ir/Coordinates.h"
28 #include "util/Utils.h"
35 struct IDynamicTensorManager;
40 virtual ~ITensor() = default;
43 virtual uint8_t *buffer() const = 0;
44 virtual size_t total_size() const = 0;
45 virtual size_t dimension(size_t index) const = 0;
46 virtual size_t num_dimensions() const = 0;
47 virtual size_t calcOffset(const ir::Coordinates &coords) const = 0;
48 virtual ir::Layout layout() const = 0;
49 virtual ir::DataType data_type() const = 0;
50 virtual float data_scale() const = 0;
51 virtual int32_t data_offset() const = 0;
52 virtual bool has_padding() const = 0;
53 virtual void access(const std::function<void(ITensor &tensor)> &fn) = 0;
56 * @brief Return the dynamic tensor manager
58 * If dynamic tensors are not supported, it returns @c nullptr .
60 * @return IDynamicTensorManager* DynamicTensorManager
62 virtual IDynamicTensorManager *dynamic_tensor_manager() { return nullptr; }
65 * @brief Return true if the tensor is constant
67 virtual bool is_constant() const
69 throw std::runtime_error("This backend does not support checking constant");
73 * @brief Return true if the tensor needs dynamic allocation, meaning that during compile-time
74 * the outpus shape cannot be known and the output shape is calculated during
75 * kernel execution-time.
77 virtual bool is_dynamic() const = 0;
79 /// @brief set this tensor dynamic
80 virtual void set_dynamic()
82 throw std::runtime_error("This backend does not support dynamic tensor");
86 * @brief Set the shape of tenser to new_shape
87 * @note Higer dimension will be placed on front.
89 virtual void setShape(const ir::Shape &new_shape)
91 UNUSED_RELEASE(new_shape);
92 throw std::runtime_error("This backend does not support dynamic setShape");
96 * @brief Get ir::Shape of tensor
97 * @note Higer dimension will be placed on front.
99 virtual ir::Shape getShape() const;
102 } // namespace backend
105 #endif // __ONERT_BACKEND_OPERAND_I_TENSOR_H__