-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Lce benchmark and interpreter flags (#717)
* add boolean flag allowing to register indirect BGEMM kernel * added boolean flag to LceInterpreter allowing to register indirect BGEMM kernels * added boolean flag use_xnnpack in LceInterpreter to explicitly activate/deactivate XNNPACK delegate * lce_benchmark_model: - added two cmdline flags use_reference_bconv/use_indirect_bgemm as global variables in lce_benchmark_main.cc to register respective kernels - implemented LceBenchmarkTfLiteModel as a child class of BenchmarkTfLiteModel to use builtin flags instead of manually parsing them in lce_benchmark_main.cc - modified lce_benchmark_main.cc to use LceBenchmarkTfLiteModel, the global flags are set upon calling overriden Run() method by passing them as an internal reference - added build options for lce_benchmark_tflite_model.h same as in TFLite's benchmark_tflite_model.h * add include of LceBenchmarkTfLiteModel for cmake build * srcs for Makefile * added warning when use_reference_bconv and use_indirect_bgemm are both set to true in lce_ops_register.h * adapted BUILD file to include TFLite logging header * include TFLite logging header for interpreter_wrapper_lite build
- Loading branch information
1 parent
d8193e4
commit 4cb8e72
Showing
9 changed files
with
191 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
larq_compute_engine/tflite/benchmark/lce_benchmark_tflite_model.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* Copyright 2018 The TensorFlow Authors. All Rights Reserved. | ||
Modifications copyright (C) 2022 Larq Contributors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
==============================================================================*/ | ||
|
||
#include "larq_compute_engine/tflite/benchmark/lce_benchmark_tflite_model.h" | ||
|
||
#include "tensorflow/lite/tools/logging.h" | ||
|
||
namespace tflite { | ||
namespace benchmark { | ||
|
||
BenchmarkParams LceBenchmarkTfLiteModel::DefaultParams() { | ||
BenchmarkParams default_params = BenchmarkTfLiteModel::DefaultParams(); | ||
default_params.AddParam("use_reference_bconv", | ||
BenchmarkParam::Create<bool>(false)); | ||
default_params.AddParam("use_indirect_bgemm", | ||
BenchmarkParam::Create<bool>(false)); | ||
|
||
return default_params; | ||
} | ||
|
||
LceBenchmarkTfLiteModel::LceBenchmarkTfLiteModel(BenchmarkParams params, | ||
bool& use_reference_bconv, | ||
bool& use_indirect_bgemm) | ||
: BenchmarkTfLiteModel(std::move(params)), | ||
use_reference_bconv(use_reference_bconv), | ||
use_indirect_bgemm(use_indirect_bgemm) {} | ||
|
||
std::vector<Flag> LceBenchmarkTfLiteModel::GetFlags() { | ||
std::vector<Flag> flags = BenchmarkTfLiteModel::GetFlags(); | ||
std::vector<Flag> lce_flags = { | ||
CreateFlag<bool>( | ||
"use_reference_bconv", ¶ms_, | ||
"When true, uses the reference implementation of LceBconv2d."), | ||
CreateFlag<bool>("use_indirect_bgemm", ¶ms_, | ||
"When true, uses the optimized indirect BGEMM kernel of" | ||
"LceBconv2d.")}; | ||
|
||
flags.insert(flags.end(), lce_flags.begin(), lce_flags.end()); | ||
|
||
return flags; | ||
} | ||
|
||
void LceBenchmarkTfLiteModel::LogParams() { | ||
BenchmarkTfLiteModel::LogParams(); | ||
const bool verbose = params_.Get<bool>("verbose"); | ||
LOG_BENCHMARK_PARAM(bool, "use_reference_bconv", "Use reference Bconv", | ||
verbose); | ||
LOG_BENCHMARK_PARAM(bool, "use_indirect_bgemm", "Use indirect BGEMM", | ||
verbose); | ||
} | ||
|
||
TfLiteStatus LceBenchmarkTfLiteModel::Run(int argc, char** argv) { | ||
TF_LITE_ENSURE_STATUS(ParseFlags(argc, argv)); | ||
use_reference_bconv = params_.Get<bool>("use_reference_bconv"); | ||
use_indirect_bgemm = params_.Get<bool>("use_indirect_bgemm"); | ||
|
||
return BenchmarkTfLiteModel::Run(); | ||
} | ||
|
||
} // namespace benchmark | ||
} // namespace tflite |
47 changes: 47 additions & 0 deletions
47
larq_compute_engine/tflite/benchmark/lce_benchmark_tflite_model.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* Copyright 2018 The TensorFlow Authors. All Rights Reserved. | ||
Modifications copyright (C) 2022 Larq Contributors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
==============================================================================*/ | ||
|
||
#ifndef COMPUTE_ENGINE_TFLITE_BENCHMARK_LCE_BENCHMARK_TFLITE_MODEL_H_ | ||
#define COMPUTE_ENGINE_TFLITE_BENCHMARK_LCE_BENCHMARK_TFLITE_MODEL_H_ | ||
|
||
#include "tensorflow/lite/tools/benchmark/benchmark_tflite_model.h" | ||
|
||
namespace tflite { | ||
namespace benchmark { | ||
|
||
// Benchmarks a TFLite model by running tflite interpreter. | ||
class LceBenchmarkTfLiteModel : public BenchmarkTfLiteModel { | ||
public: | ||
explicit LceBenchmarkTfLiteModel(BenchmarkParams params, | ||
bool& use_reference_bconv, | ||
bool& use_indirect_bgemm); | ||
|
||
std::vector<Flag> GetFlags() override; | ||
void LogParams() override; | ||
static BenchmarkParams DefaultParams(); | ||
|
||
using BenchmarkTfLiteModel::Run; | ||
TfLiteStatus Run(int argc, char** argv); | ||
|
||
private: | ||
bool& use_reference_bconv; | ||
bool& use_indirect_bgemm; | ||
}; | ||
|
||
} // namespace benchmark | ||
} // namespace tflite | ||
|
||
#endif // COMPUTE_ENGINE_TFLITE_BENCHMARK_LCE_BENCHMARK_TFLITE_MODEL_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters