Skip to content

Commit

Permalink
[circle-mpqsolver] Refactor BisectionSolver (#11651)
Browse files Browse the repository at this point in the history
This commit moves _quantizer and read_module to parent class.

ONE-DCO-1.0-Signed-off-by: s.malakhov <[email protected]>
  • Loading branch information
stamalakhov authored Oct 5, 2023
1 parent 0f98120 commit a380292
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 16 deletions.
17 changes: 17 additions & 0 deletions compiler/circle-mpqsolver/src/MPQSolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,33 @@

#include "MPQSolver.h"

#include <luci/ImporterEx.h>
#include <iostream>

using namespace mpqsolver;

MPQSolver::MPQSolver(const std::string &input_data_path, float qerror_ratio,
const std::string &input_quantization, const std::string &output_quantization)
: _input_data_path(input_data_path), _qerror_ratio(qerror_ratio),
_input_quantization(input_quantization), _output_quantization(output_quantization)
{
_quantizer = std::make_unique<core::Quantizer>(_input_quantization, _output_quantization);
}

void MPQSolver::set_save_intermediate(const std::string &save_path)
{
_hooks = std::make_unique<core::DumpingHooks>(save_path);
}

std::unique_ptr<luci::Module> MPQSolver::read_module(const std::string &path)
{
luci::ImporterEx importerex;
auto module = importerex.importVerifyModule(path);
if (module.get() == nullptr)
{
std::cerr << "ERROR: Failed to load " << path << std::endl;
return nullptr;
}

return module;
}
7 changes: 7 additions & 0 deletions compiler/circle-mpqsolver/src/MPQSolver.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@
#ifndef __MPQSOLVER_MPQSOLEVR_SOLVER_H__
#define __MPQSOLVER_MPQSOLEVR_SOLVER_H__

#include "core/Quantizer.h"
#include <core/DumpingHooks.h>

#include <luci/IR/CircleNodes.h>

#include <memory>
#include <string>

Expand Down Expand Up @@ -47,10 +50,14 @@ class MPQSolver
*/
void set_save_intermediate(const std::string &save_path);

protected:
std::unique_ptr<luci::Module> read_module(const std::string &path);

protected:
std::string _input_data_path;
std::string _input_quantization;
std::string _output_quantization;
std::unique_ptr<core::Quantizer> _quantizer;
float _qerror_ratio = 0.f; // quantization error ratio
std::unique_ptr<core::DumpingHooks> _hooks;
};
Expand Down
14 changes: 0 additions & 14 deletions compiler/circle-mpqsolver/src/bisection/BisectionSolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,27 +72,13 @@ bool front_has_higher_error(const NodeDepthType &nodes_depth, const std::string
return error_at_input > error_at_output;
}

std::unique_ptr<luci::Module> read_module(const std::string &path)
{
luci::ImporterEx importerex;
auto module = importerex.importVerifyModule(path);
if (module.get() == nullptr)
{
std::cerr << "ERROR: Failed to load " << path << std::endl;
return nullptr;
}

return module;
}

} // namespace

BisectionSolver::BisectionSolver(const std::string &input_data_path, float qerror_ratio,
const std::string &input_quantization,
const std::string &output_quantization)
: MPQSolver(input_data_path, qerror_ratio, input_quantization, output_quantization)
{
_quantizer = std::make_unique<core::Quantizer>(_input_quantization, _output_quantization);
}

float BisectionSolver::evaluate(const core::DatasetEvaluator &evaluator,
Expand Down
2 changes: 0 additions & 2 deletions compiler/circle-mpqsolver/src/bisection/BisectionSolver.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#ifndef __MPQSOLVER_BISECTION_SOLVER_H__
#define __MPQSOLVER_BISECTION_SOLVER_H__

#include <core/Quantizer.h>
#include <core/Evaluator.h>
#include <MPQSolver.h>

Expand Down Expand Up @@ -78,7 +77,6 @@ class BisectionSolver final : public MPQSolver
private:
float _qerror = 0.f; // quantization error
Algorithm _algorithm = Algorithm::ForceQ16Front;
std::unique_ptr<core::Quantizer> _quantizer;
std::string _visq_data_path;
};

Expand Down

0 comments on commit a380292

Please sign in to comment.