ONE - On-device Neural Engine
Loading...
Searching...
No Matches
Quantizer.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2022 Samsung Electronics Co., Ltd. All Rights Reserved
3 *
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
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
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.
15 */
16
17#ifndef __MPQSOLVER_CORE_QUANTIZER_H__
18#define __MPQSOLVER_CORE_QUANTIZER_H__
19
20#include <luci/IR/Module.h>
22
23#include <string>
24#include <vector>
25#include <memory>
26
27namespace mpqsolver
28{
29namespace core
30{
31
33using LayerParams = std::vector<std::shared_ptr<LayerParam>>;
34
36{
41 virtual void onQuantized(luci::Module *module) const = 0;
42};
43
45{
46public:
47 struct Context
48 {
49 std::string output_model_dtype = "uint8";
50 std::string granularity = "channel";
51 std::string input_type = "uint8";
52 std::string output_type = "uint8";
53 bool TF_style_maxpool = false;
54 bool save_min_max = false;
55 // TODO Support layer info
56 };
57
58public:
59 Quantizer(const Context &ctx) : _ctx(ctx) {}
60
64 void setHook(const QuantizerHook *callback);
65
70 bool quantize(luci::Module *module, const std::string &quant_dtype, LayerParams &layer_params);
71
76 bool quantize(luci::Module *module, LayerParams &layer_params);
77
82 bool fakeQuantize(luci::Module *module, const std::string &quant_dtype,
83 LayerParams &layer_params);
84
85 const Context &getContext() const { return _ctx; }
86
87private:
88 Context _ctx;
89 const QuantizerHook *_hook = nullptr;
90};
91
92} // namespace core
93} // namespace mpqsolver
94
95#endif //__MPQSOLVER_CORE_QUANTIZER_H__
luci::CircleQuantizer::Options::LayerParams LayerParams
Collection of 'loco::Graph's.
Definition Module.h:33
bool quantize(luci::Module *module, const std::string &quant_dtype, LayerParams &layer_params)
quantize recorded module (min/max initialized) with specified parameters returns true on success
Definition Quantizer.cpp:58
bool fakeQuantize(luci::Module *module, const std::string &quant_dtype, LayerParams &layer_params)
fake_quantize recorded module (min/max initialized) with specified parameters returns true on success
Quantizer(const Context &ctx)
Definition Quantizer.h:59
void setHook(const QuantizerHook *callback)
set hook on the end of quantization event
Definition Quantizer.cpp:52
const Context & getContext() const
Definition Quantizer.h:85
std::vector< std::shared_ptr< LayerParam > > LayerParams
Definition Dumper.h:31
virtual void onQuantized(luci::Module *module) const =0
called on successfull quantization