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 __RECORD_MINMAX_MINMAXCOMPUTER_H__
18 #define __RECORD_MINMAX_MINMAXCOMPUTER_H__
20 #include "MinMaxVectors.h"
22 #include <luci/IR/CircleNode.h>
24 #include <unordered_map>
27 namespace record_minmax
38 virtual ~MinMaxComputer() = default;
40 // Child class must implement this
42 update_qparam(const std::unordered_map<const luci::CircleNode *, MinMaxVectors> *minmax_map) = 0;
45 class PercentileComputer : public MinMaxComputer
48 PercentileComputer(float min_percentile, float max_percentile)
49 : _min_percentile(min_percentile), _max_percentile(max_percentile)
54 update_qparam(const std::unordered_map<const luci::CircleNode *, MinMaxVectors> *minmax_map);
57 float _min_percentile = 0.0;
58 float _max_percentile = 0.0;
61 class MovingAvgComputer : public MinMaxComputer
64 MovingAvgComputer(uint32_t batch_size, float update_const)
65 : _batch_size(batch_size), _update_const(update_const)
70 update_qparam(const std::unordered_map<const luci::CircleNode *, MinMaxVectors> *minmax_map);
73 uint32_t _batch_size = 0;
74 float _update_const = 0.0;
77 std::unique_ptr<MinMaxComputer> make_percentile_computer(float min_percentile,
78 float max_percentile);
80 std::unique_ptr<MinMaxComputer> make_moving_avg_computer(uint32_t batch_size,
81 float moving_avg_const);
83 } // namespace record_minmax
85 #endif // __RECORD_MINMAX_MINMAXCOMPUTER_H__