8000 Integrate the compiler flags into the tooling · linux-on-ibm-z/tensorflow@988ab99 · GitHub
[go: up one dir, main page]

Skip to content

Commit 988ab99

Browse files
LukeBoyertensorflower-gardener
authored andcommitted
Integrate the compiler flags into the tooling
PiperOrigin-RevId: 730644395
1 parent f84cf9d commit 988ab99

File tree

4 files changed

+36
-6
lines changed

4 files changed

+36
-6
lines changed

tensorflow/lite/experimental/litert/tools/BUILD

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ cc_library(
3434
"//tensorflow/lite/experimental/litert/cc:litert_expected",
3535
"//tensorflow/lite/experimental/litert/cc:litert_macros",
3636
"//tensorflow/lite/experimental/litert/cc:litert_model",
37+
"//tensorflow/lite/experimental/litert/compiler/plugin:compiler_flags",
3738
"//tensorflow/lite/experimental/litert/compiler/plugin:compiler_plugin",
3839
"//tensorflow/lite/experimental/litert/core/model:model_serialize",
3940
"//tensorflow/lite/experimental/litert/core/util:flatbuffer_tools",
@@ -96,7 +97,9 @@ litert_cc_bin_with_qnn(
9697
deps = [
9798
":apply_plugin",
9899
":outstream",
100+
"//tensorflow/lite/experimental/litert/compiler/plugin:compiler_flags",
99101
"//tensorflow/lite/experimental/litert/core:build_stamp",
102+
"@com_google_absl//absl/strings",
100103
"@com_google_absl//absl/strings:str_format",
101104
"@com_google_absl//absl/strings:string_view",
102105
"@llvm-project//llvm:Support",
@@ -121,7 +124,8 @@ cc_binary(
121124
deps = [
122125
":apply_plugin",
123126
":outstream",
124-
"//tensorflow/lite/experimental/litert/core:build_stamp",
127+
"//tensorflow/lite/experimental/litert/compiler/plugin:compiler_flags",
128+
"@com_google_absl//absl/strings",
125129
"@com_google_absl//absl/strings:str_format",
126130
"@llvm-project//llvm:Support",
127131
],

tensorflow/lite/experimental/litert/tools/apply_plugin.cc

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include "tensorflow/lite/experimental/litert/cc/litert_expected.h"
3535
#include "tensorflow/lite/experimental/litert/cc/litert_macros.h"
3636
#include "tensorflow/lite/experimental/litert/cc/litert_model.h"
37+
#include "tensorflow/lite/experimental/litert/compiler/plugin/compiler_flags.h"
3738
#include "tensorflow/lite/experimental/litert/compiler/plugin/compiler_plugin.h"
3839
#include "tensorflow/lite/experimental/litert/core/model/model_serialize.h"
3940
#include "tensorflow/lite/experimental/litert/core/util/flatbuffer_tools.h"
@@ -43,6 +44,7 @@
4344
namespace litert::tools {
4445

4546
using ::litert::BufferRef;
47+
using ::litert::internal::CompilerFlags;
4648
using ::litert::internal::CompilerPlugin;
4749
using ::litert::internal::Dump;
4850
using ::litert::internal::PartitionResult;
@@ -87,6 +89,8 @@ class Context {
8789
return run_->outs.at(out_ind);
8890
}
8991

92+
const CompilerFlags& Flags() const { return run_->compiler_flags; }
93+
9094
OutStream SwapOut(OutStream out) {
9195
ABSL_CHECK_EQ(run_->outs.size(), 1);
9296
auto res = run_->outs.front();
@@ -118,10 +122,12 @@ void DumpSubgraphs(ToolDisplay& display, absl::string_view label,
118122
}
119123

120124
void DumpCompilationRequest(ToolDisplay& display, absl::string_view soc_model,
121-
size_t num_subgraphs) {
125+
size_t num_subgraphs, const CompilerFlags& flags) {
122126
display.Labeled() << absl::StreamFormat(
123-
"Requesting compilation for target `%s` on %lu partitions\n", soc_model,
124-
num_subgraphs);
127+
"Requesting compilation for target `%s` on %lu "
128+
"partitions with flags: ",
129+
soc_model, num_subgraphs)
130+
<< flags << "\n";
125131
}
126132

127133
void DumpCompilationResult(ToolDisplay& display, size_t byte_code_size,
@@ -360,8 +366,9 @@ LiteRtStatus Compile(Context& ctx) {
360366
}
361367

362368
ctx.Dump().Start("Compiling");
363-
DumpCompilationRequest(ctx.Dump(), ctx.SocModelTarget(),
364-
model.NumSubgraphs());
369+
DumpCompilationRequest(ctx.Dump(), ctx.SocModelTarget(), model.NumSubgraphs(),
370+
ctx.Flags());
371+
plugin->SetFlags(ctx.Flags());
365372
auto compilation_result = plugin->Compile(&model, ctx.SocModelTarget());
366373
if (!compilation_result) {
367374
ctx.Dump().Fail();
@@ -425,6 +432,7 @@ LiteRtStatus Apply(Context& ctx) {
425432
}
426433

427434
ctx.Dump().Start("Applying plugin");
435+
plugin->SetFlags(ctx.Flags());
428436
if (auto status =
429437
litert::internal::ApplyPlugin(*plugin, model, ctx.SocModelTarget());
430438
!status) {

tensorflow/lite/experimental/litert/tools/apply_plugin.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,13 @@
2222

2323
#include "absl/strings/string_view.h"
2424
#include "tensorflow/lite/experimental/litert/c/litert_common.h"
25+
#include "tensorflow/lite/experimental/litert/compiler/plugin/compiler_flags.h"
2526
#include "tensorflow/lite/experimental/litert/tools/outstream.h"
2627

2728
namespace litert::tools {
2829

30+
using ::litert::internal::CompilerFlags;
31+
2932
struct ApplyPluginRun {
3033
// NOTE: All StrFlagT are expected to have static storage duration.
3134
using Ptr = std::unique_ptr<ApplyPluginRun>;
@@ -138,6 +141,10 @@ struct ApplyPluginRun {
138141
// "silent" behavior and should only be used when this tool is part of a
139142
// larger pipeline like an end2end test.
140143
UserStream dump_out;
144+
145+
// Compiler flags to pass to the plugin. Only relevant for "APPLY" and
146+
// "COMPILE" commands.
147+
CompilerFlags compiler_flags;
141148
};
142149

143150
LiteRtStatus ApplyPlugin(ApplyPluginRun::Ptr run);

tensorflow/lite/experimental/litert/tools/apply_plugin_main.cc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "absl/strings/str_format.h"
2121
#include "llvm/ADT/ArrayRef.h"
2222
#include "llvm/Support/CommandLine.h"
23+
#include "tensorflow/lite/experimental/litert/compiler/plugin/compiler_flags.h"
2324
#include "tensorflow/lite/experimental/litert/tools/apply_plugin.h"
2425
#include "tensorflow/lite/experimental/litert/tools/outstream.h"
2526

@@ -75,13 +76,23 @@ static llvm::cl::opt<std::string> err(
7576
"\"--\" for standard err, \"none\" for null stream."),
7677
llvm::cl::init("--"));
7778

79+
// NOLINTNEXTLINE
80+
static llvm::cl::opt<std::string> compiler_flags(
81+
"compiler-flags",
82+
llvm::cl::desc("List of comma separated (no space) compiler flags. Flags "
83+
"may be key-value pairs "
84+
"in the format of \"key=value\", or just \"key\". E.g. "
85+
"\"--compiler-flags=key1=value1,key2\""));
86+
7887
ApplyPluginRun::Ptr ParseFlags() {
7988
auto res = std::make_unique<ApplyPluginRun>();
8089

8190
if (!model.empty()) {
8291
res->model = model;
8392
}
8493

94+
res->compiler_flags = *litert::internal::ParseCompilerFlags(compiler_flags);
95+
8596
res->soc_manufacturer = soc_manufacturer;
8697
res->soc_models.push_back(soc_model);
8798

0 commit comments

Comments
 (0)
0