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_ITENSOR_BUILDER_H__
18 #define __ONERT_BACKEND_ITENSOR_BUILDER_H__
23 #include "ir/OperandInfo.h"
24 #include "ir/Operation.h"
25 #include "ir/Layout.h"
27 #include "ITensorManager.h"
28 #include "ITensorRegistry.h"
29 #include "IDynamicTensorManager.h"
38 using IterateFunction = std::function<void(const ir::OperandIndex &)>;
40 virtual ~ITensorBuilder(void) = default;
43 * @brief Register tensor information to allocate on backend
47 * @param backend_layout Backend layout
48 * @param as_const Whether this tensor is constant
50 virtual void registerTensorInfo(const ir::OperandIndex &ind, const ir::OperandInfo &info,
51 ir::Layout backend_layout) = 0;
54 * @brief Check if the tensor has been registered with @c registerTensorInfo
56 * @return true If the tensor has been registered
57 * @return false Otherwise
59 virtual bool isRegistered(const ir::OperandIndex &) const = 0;
61 public: // methods for static tensor allocation
63 * @brief Let the tensor builder know first use(start of lifetime) of a tensor
64 * Must be called before calling @c prepare
65 * Must be run up to once for each tensor before calling @c notifyLastUse
66 * NOTE: Useful only for static models
68 virtual void notifyFirstUse(const ir::OperandIndex &) = 0;
70 * @brief Let the tensor builder know last use(end of lifetime) of a tensor
71 * Must be run up to once for each tensor after calling @c notifyFirstUse
72 * NOTE: Useful only for static models
74 virtual void notifyLastUse(const ir::OperandIndex &) = 0;
76 * @brief Prepare the tensors
77 * Before calling this, all the tensors must be registered
79 virtual void prepare(void) = 0;
81 * @brief Allocate the tensors
82 * Before calling this, @c prepare must be called
84 virtual void allocate() = 0;
86 * @brief Some actions after functions' @c IFunction::prepare method.
87 * This is called right after each function's @c IFunction::prepare function has been
90 virtual void postFunctionPrepare() = 0;
92 public: // methods for dynamic tensor allocation
94 * @brief Get dynamicTensorManager. If a backend does not support dynamic tensor, exception
97 * @return pointer of IDynamicTensorManager object
99 * @note Since it is a pointer, its life time is from the cration of TensorBuilder
100 * to the end of execution
102 virtual IDynamicTensorManager *dynamicTensorManager(void) { return nullptr; }
105 } // namespace backend
108 #endif // __ONERT_BACKEND_ITENSOR_BUILDER_H__