2 * Copyright (c) 2023 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_EXEC_TRAIN_TRAINABLE_EXECUTORS_H__
18 #define __ONERT_EXEC_TRAIN_TRAINABLE_EXECUTORS_H__
20 #include "TrainableExecutor.h"
21 #include "exec/IExecutors.h"
32 * @brief Class to gather executor set for trainable model NN package
34 class TrainableExecutors : public IExecutors
38 * @brief Construct a new TrainableExecutors object
40 TrainableExecutors(void) = default;
41 TrainableExecutors(const TrainableExecutors &) = delete;
42 TrainableExecutors(TrainableExecutors &&) = default;
45 * @brief Destroy the TrainableExecutors object
47 ~TrainableExecutors() = default;
50 TrainableExecutors &operator=(const TrainableExecutors &) = delete;
51 TrainableExecutors &operator=(TrainableExecutors &&) = default;
54 void emplace(const ir::ModelIndex &model_index, const ir::SubgraphIndex &subg_index,
55 std::unique_ptr<IExecutor> exec) override;
57 TrainableExecutor *at(const ir::ModelIndex &model_index,
58 const ir::SubgraphIndex &subg_index) const override;
60 TrainableExecutor *entryExecutor() const { return at(ir::ModelIndex{0}, ir::SubgraphIndex{0}); }
62 uint32_t inputSize() const override;
64 uint32_t outputSize() const override;
66 const ir::OperandInfo &inputInfo(const ir::IOIndex &index) const override;
68 const ir::OperandInfo &outputInfo(const ir::IOIndex &index) const override;
70 void execute(const IODescription &desc) override;
75 * @param desc IO information
76 * @param training_step The number of iterations of an training process.
77 * In other words, the number of gradient update.
79 void train(const IODescription &desc, uint32_t training_step);
81 float getLoss(const ir::IOIndex &index) const;
84 // TODO Append model index to ModelIndex
85 std::unordered_map<ir::SubgraphIndex, std::unique_ptr<TrainableExecutor>> _executors;
92 #endif // __ONERT_EXEC_TRAIN_TRAINABLE_EXECUTORS_H__