Skip to content

Commit

Permalink
[record-minmax] Remove unused code (#11424)
Browse files Browse the repository at this point in the history
This removes unused function and arguments.

ONE-DCO-1.0-Signed-off-by: Hyukjin Jeong <[email protected]>
  • Loading branch information
jinevening authored Sep 1, 2023
1 parent 3a90b84 commit 85a8fba
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 82 deletions.
10 changes: 5 additions & 5 deletions compiler/record-minmax/driver/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,11 +185,11 @@ int entry(const int argc, char **argv)
{
// Profile min/max while executing the H5 data
if (num_threads == 1)
rmm.profileData(mode, input_data_path, min_percentile, max_percentile);
rmm.profileData(input_data_path);
else
{
INFO(l) << "Using parallel recording" << std::endl;
rmm.profileDataInParallel(mode, input_data_path, min_percentile, max_percentile);
rmm.profileDataInParallel(input_data_path);
}
}
// input_data is a text file having a file path in each line.
Expand All @@ -203,13 +203,13 @@ int entry(const int argc, char **argv)
else if (input_data_format == "list" || input_data_format == "filelist")
{
// Profile min/max while executing the list of Raw data
rmm.profileRawData(mode, input_data_path, min_percentile, max_percentile);
rmm.profileRawData(input_data_path);
}
else if (input_data_format == "directory" || input_data_format == "dir")
{
// Profile min/max while executing all files under the given directory
// The contents of each file is same as the raw data in the 'list' type
rmm.profileRawDataDirectory(mode, input_data_path, min_percentile, max_percentile);
rmm.profileRawDataDirectory(input_data_path);
}
else
{
Expand All @@ -220,7 +220,7 @@ int entry(const int argc, char **argv)
else
{
// Profile min/max while executing random input data
rmm.profileDataWithRandomInputs(mode, min_percentile, max_percentile);
rmm.profileDataWithRandomInputs();
}

// Save profiled values to the model
Expand Down
16 changes: 6 additions & 10 deletions compiler/record-minmax/include/RecordMinMax.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,20 +47,16 @@ class RecordMinMax

void initialize(const std::string &input_model_path);

void profileData(const std::string &mode, const std::string &input_data_path,
float min_percentile, float max_percentile);
// TODO Refactor profile functions
void profileData(const std::string &input_data_path);

void profileDataInParallel(const std::string &mode, const std::string &input_data_path,
float min_percentile, float max_percentile);
void profileDataInParallel(const std::string &input_data_path);

void profileRawData(const std::string &mode, const std::string &input_data_path,
float min_percentile, float max_percentile);
void profileRawData(const std::string &input_data_path);

void profileRawDataDirectory(const std::string &mode, const std::string &input_data_path,
float min_percentile, float max_percentile);
void profileRawDataDirectory(const std::string &input_data_path);

void profileDataWithRandomInputs(const std::string &mode, float min_percentile,
float max_percentile);
void profileDataWithRandomInputs(void);

void saveModel(const std::string &output_model_path);

Expand Down
72 changes: 5 additions & 67 deletions compiler/record-minmax/src/RecordMinMax.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,41 +143,6 @@ void verifyTypeShape(const luci::CircleInput *input_node, const DataType &dtype,
}
}

// TODO Remove unused code
#if 0
void update_quantparam(record_minmax::MinMaxObserver *observer, const std::string &mode,
float min_percentile, float max_percentile)
{
auto minmax_map = observer->minMaxData()->getMap();
for (auto iter = minmax_map->begin(); iter != minmax_map->end(); ++iter)
{
auto node = iter->first;
auto minmax = iter->second;

float min{0.0f}, max{0.0f};
if (mode == "percentile")
{
min = record_minmax::getNthPercentile(minmax.min_vector, min_percentile);
max = record_minmax::getNthPercentile(minmax.max_vector, max_percentile);
}
else if (mode == "moving_average")
{
min = record_minmax::getMovingAverage(minmax.min_vector, 0.9, 16, true);
max = record_minmax::getMovingAverage(minmax.max_vector, 0.9, 16, false);
}
assert(mode == "percentile" || mode == "moving_average");
auto quantparam = std::make_unique<luci::CircleQuantParam>();
quantparam->min.push_back(min);
quantparam->max.push_back(max);

assert(node->quantparam() == nullptr);

auto mutable_node = const_cast<luci::CircleNode *>(node);
mutable_node->quantparam(std::move(quantparam));
}
}
#endif

} // namespace

namespace record_minmax
Expand Down Expand Up @@ -237,9 +202,7 @@ void RecordMinMax::initialize(const std::string &input_model_path)
// The directory should contain binary files each of which is a raw data,
// ready to be consumed by the input circle model without any modification
// TODO reduce duplicate codes with profileRawData
void RecordMinMax::profileRawDataDirectory(const std::string &mode,
const std::string &input_data_path, float min_percentile,
float max_percentile)
void RecordMinMax::profileRawDataDirectory(const std::string &input_data_path)
{
struct dirent *entry = nullptr;
DIR *dp = nullptr;
Expand Down Expand Up @@ -300,10 +263,6 @@ void RecordMinMax::profileRawDataDirectory(const std::string &mode,
std::cout << "Recording finished. Number of recorded data: " << num_records << std::endl;

_minmax_computer->update_qparam(getObserver());
// TODO Remove redundant arguments
(void)mode;
(void)min_percentile;
(void)max_percentile;
}

// input_data_path is a text file which specifies the representative data
Expand All @@ -312,8 +271,7 @@ void RecordMinMax::profileRawDataDirectory(const std::string &mode,
// ready to be consumed by the input circle model without any modification
// NOTE If a model has multiple inputs, the binary file should have inputs concatenated in the same
// order with the input index of the circle model.
void RecordMinMax::profileRawData(const std::string &mode, const std::string &input_data_path,
float min_percentile, float max_percentile)
void RecordMinMax::profileRawData(const std::string &input_data_path)
{
std::ifstream input_file(input_data_path);
if (input_file.fail())
Expand Down Expand Up @@ -364,10 +322,6 @@ void RecordMinMax::profileRawData(const std::string &mode, const std::string &in
std::cout << "Recording finished. Number of recorded data: " << num_records << std::endl;

_minmax_computer->update_qparam(getObserver());
// TODO Remove redundant arguments
(void)mode;
(void)min_percentile;
(void)max_percentile;
}

WholeOutput RecordMinMax::importH5Data(const std::string &input_data_path)
Expand Down Expand Up @@ -428,8 +382,7 @@ WholeOutput RecordMinMax::importH5Data(const std::string &input_data_path)
}
}

void RecordMinMax::profileData(const std::string &mode, const std::string &input_data_path,
float min_percentile, float max_percentile)
void RecordMinMax::profileData(const std::string &input_data_path)
{
try
{
Expand Down Expand Up @@ -492,15 +445,9 @@ void RecordMinMax::profileData(const std::string &mode, const std::string &input
}

_minmax_computer->update_qparam(getObserver());
// TODO Remove redundant arguments
(void)mode;
(void)min_percentile;
(void)max_percentile;
}

void RecordMinMax::profileDataInParallel(const std::string &mode,
const std::string &input_data_path, float min_percentile,
float max_percentile)
void RecordMinMax::profileDataInParallel(const std::string &input_data_path)
{
LOGGER(l);

Expand Down Expand Up @@ -585,14 +532,9 @@ void RecordMinMax::profileDataInParallel(const std::string &mode,
std::cout << "Recording finished. Number of recorded data: " << num_records << std::endl;

_minmax_computer->update_qparam(observer.get());
// TODO Remove redundant arguments
(void)mode;
(void)min_percentile;
(void)max_percentile;
}

void RecordMinMax::profileDataWithRandomInputs(const std::string &mode, float min_percentile,
float max_percentile)
void RecordMinMax::profileDataWithRandomInputs(void)
{
// We use three randomly-generated records
const uint32_t num_records = 3;
Expand Down Expand Up @@ -661,10 +603,6 @@ void RecordMinMax::profileDataWithRandomInputs(const std::string &mode, float mi
std::cout << "Recording finished. Number of recorded data: " << num_records << std::endl;

_minmax_computer->update_qparam(getObserver());
// TODO Remove redundant arguments
(void)mode;
(void)min_percentile;
(void)max_percentile;
}

void RecordMinMax::saveModel(const std::string &output_model_path)
Expand Down

0 comments on commit 85a8fba

Please sign in to comment.