2 * Copyright (c) 2020 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_MINMAXOBSERVER_H__
18 #define __RECORD_MINMAX_MINMAXOBSERVER_H__
20 #include <luci_interpreter/Interpreter.h>
21 #include <luci_interpreter/core/Tensor.h>
23 #include "MinMaxVectors.h"
26 #include <unordered_map>
28 namespace record_minmax
34 // Record min/max of node
35 void recordMinMax(const luci::CircleNode *node, float min, float max)
37 MinMaxVectors &vectors = _minmax_map[node];
38 vectors.min_vector.push_back(min);
39 vectors.max_vector.push_back(max);
42 void appendMinMaxVector(const luci::CircleNode *node, const MinMaxVectors &minmax_vector)
44 MinMaxVectors &vectors = _minmax_map[node];
45 vectors.min_vector.insert(vectors.min_vector.end(), minmax_vector.min_vector.begin(),
46 minmax_vector.min_vector.end());
47 vectors.max_vector.insert(vectors.max_vector.end(), minmax_vector.max_vector.begin(),
48 minmax_vector.max_vector.end());
51 const std::unordered_map<const luci::CircleNode *, MinMaxVectors> *getMap() const
57 std::unordered_map<const luci::CircleNode *, MinMaxVectors> _minmax_map;
60 class MinMaxObserver : public luci_interpreter::ExecutionObserver
68 void postTensorWrite(const luci::CircleNode *node,
69 const luci_interpreter::Tensor *tensor) override;
71 // Never return nullptr
72 const MinMaxMap *minMaxData() { return &_minmax_data; }
75 MinMaxMap _minmax_data;
78 } // namespace record_minmax
80 #endif // __RECORD_MINMAX_MINMAXOBSERVER_H__