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.
19 * @brief This file contains OperandInfo class
21 #ifndef __ONERT_IR_OPERAND_INFO_H__
22 #define __ONERT_IR_OPERAND_INFO_H__
25 #include "ir/TypeInfo.h"
26 #include "ir/Layout.h"
34 * @brief enum class indicating when the memory for a tensor is allocated
36 enum class MemAllocType
39 * @brief At compile time, shape for a tensor is known, thus requried memory capacity can be
45 * @brief At kernel execution time, shape for a tensor is known, thus requried memory capacity
52 * @brief Class to save tensor's shape and type
58 * @brief Construct a new OperandInfo object (deleted)
60 OperandInfo() = delete;
63 * @brief Construct a new OperandInfo object
64 * @param[in] shape Tensor shape
65 * @param[in] typeInfo Tensor data type
66 * @param[in] alloc_type When the thesor needs memory allocation
68 OperandInfo(const Shape &shape, const TypeInfo &typeInfo, MemAllocType alloc_type,
69 bool is_const = false)
70 : _shape(shape), _typeInfo(typeInfo), _alloc_type(alloc_type), _const(is_const)
75 * @brief Construct a new OperandInfo object
76 * @param[in] origin info for copy
78 OperandInfo(const OperandInfo &origin) = default;
81 * @brief Create a static OperandInfo object
83 static OperandInfo createStaticInfo(const Shape &shape, const TypeInfo &typeInfo)
85 return OperandInfo(shape, typeInfo, MemAllocType::STATIC);
90 * @brief Return tensor shape
91 * @return Tensor shape
93 const Shape &shape() const { return _shape; }
95 * @brief Return mutable tensor shape
96 * @return Tensor shape
98 Shape &shape() { return _shape; }
102 void shape(const ir::Shape &new_shape) { _shape = new_shape; }
104 * @brief Return tensor data type info
105 * @return Tensor data type
107 const TypeInfo &typeInfo() const { return _typeInfo; }
109 * @brief Set tensor data type
111 void type(const DataType type) { _typeInfo.type(type); }
113 * @brief Return size of tensor (bytes)
114 * @return Tensor size
116 size_t total_size() const { return _shape.num_elements() * sizeOfDataType(_typeInfo.type()); }
118 MemAllocType memAllocType() const { return _alloc_type; }
119 void setAsConstant() { _const = true; }
120 bool isConstant() const
122 // Impossible case: constant and dynamic operand
123 assert(!(isDynamic() && _const));
126 bool isDynamic() const { return _alloc_type == MemAllocType::DYNAMIC; }
127 void setDynamic() { _alloc_type = MemAllocType::DYNAMIC; }
133 MemAllocType _alloc_type;
140 #endif // __ONERT_IR_OPERAND_INFO_H__