-
Notifications
You must be signed in to change notification settings - Fork 33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Lce benchmark and interpreter flags #717
Merged
Merged
Changes from 19 commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
b9e9e9f
add boolean flag allowing to register indirect BGEMM kernel
simonmaurer bf8ce6a
added boolean flag to LceInterpreter allowing to register indirect B…
simonmaurer e25c392
fix comment
simonmaurer 1a23b0c
added boolean flag use_xnnpack in LceInterpreter to explicitly activa…
simonmaurer 72a2ce7
lce_benchmark_model:
simonmaurer f5bdf7b
formatted code using black code style
simonmaurer c00a56b
removed uncommented code for lint checks
simonmaurer b1afcf6
reformatted code, parameter fix in LiteInterpreterWrapper
simonmaurer b275955
second parameter fix in LiteInterpreterWrapper
simonmaurer 4afb363
reformat files for proper linting
simonmaurer 060d39c
reformat code for linting
simonmaurer 33b8a78
add include of LceBenchmarkTfLiteModel for cmake build
simonmaurer cddcad1
reformat code for linting
simonmaurer 2d136ea
fix intent in lce_benchmark_tflite_mode.cc
simonmaurer 3bf5817
typo fix
simonmaurer 4be5503
format code in lce_benchmark_tflite_model.cc
simonmaurer e669c8b
buildifier check for BUILD
simonmaurer 82951a6
srcs for Makefile
simonmaurer 1c50317
removed include
simonmaurer 71d3b35
added warning when use_reference_bconv and use_indirect_bgemm are bot…
simonmaurer e43b84d
reformat code for linting
simonmaurer a2be814
adapted BUILD file to include TFLite logging header
simonmaurer 039c531
include TFLite logging header for interpreter_wrapper_lite build
simonmaurer cb2c344
typo fix: adapted BUILD file to include TFLite logging
simonmaurer 038a603
typo fix: include TFLite logging header for interpreter_wrapper_lite …
simonmaurer 7a08381
fix: remove unused header file, logging package dependency
simonmaurer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this changes the default or am I missing something? I think that's fine, but can you explain the reasoning behind it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hi @lgeiger. you're correct. following the discussion on #713 I've implemented it like this.
A) one reason to include this flag in the LceInterpreter is to make it reflect more the behavior of the benchmark binary.
B) the second reason is dynamic allocation, thus having models with
allocation_type==kTfLiteDynamic
.we had models like this and when we set
use_xnnpack=true
in the benchmark_model there will be an error thrown. this would be true for LCEInterpreter as well, as under the hood XNNPACK is "silently" applied.