Skip to content

Commit 2523703

Browse files
MatthiasKreiledercopybara-github
authored andcommitted
LiteRT benchmark model: Add option to enable NPU JIT compilation cache
LiteRT-PiperOrigin-RevId: 820567907
1 parent 6099208 commit 2523703

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

litert/tools/benchmark_litert_model.cc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,9 @@ litert::Expected<Environment> CreateDefaultEnvironment(
132132
params.Get<std::string>("compiler_plugin_library_path");
133133
LITERT_LOG(LITERT_INFO, "compiler_plugin_library_path: %s",
134134
compiler_plugin_library_path.c_str());
135+
auto compiler_cache_path = params.Get<std::string>("compiler_cache_path");
136+
LITERT_LOG(LITERT_INFO, "compiler_cache_path: %s",
137+
compiler_cache_path.c_str());
135138

136139
const std::vector<litert::Environment::Option> environment_options = {
137140
litert::Environment::Option{
@@ -142,6 +145,10 @@ litert::Expected<Environment> CreateDefaultEnvironment(
142145
litert::Environment::OptionTag::CompilerPluginLibraryDir,
143146
compiler_plugin_library_path.c_str(),
144147
},
148+
litert::Environment::Option{
149+
litert::Environment::OptionTag::CompilerCacheDir,
150+
compiler_cache_path.c_str(),
151+
},
145152
};
146153
return litert::Environment::Create(absl::MakeConstSpan(environment_options));
147154
}

litert/tools/benchmark_litert_model.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,8 @@ class BenchmarkLiteRtModel : public BenchmarkModel {
234234
BenchmarkParam::Create<std::string>(""));
235235
default_params.AddParam("compiler_plugin_library_path",
236236
BenchmarkParam::Create<std::string>(""));
237+
default_params.AddParam("compiler_cache_path",
238+
BenchmarkParam::Create<std::string>(""));
237239
default_params.AddParam("require_full_delegation",
238240
BenchmarkParam::Create<bool>(false));
239241
default_params.AddParam("use_profiler",
@@ -391,6 +393,9 @@ class BenchmarkLiteRtModel : public BenchmarkModel {
391393
flags.push_back(tflite::benchmark::CreateFlag<std::string>(
392394
"compiler_plugin_library_path", &params_,
393395
"Compiler plugin library path. Only for JIT compilation."));
396+
flags.push_back(tflite::benchmark::CreateFlag<std::string>(
397+
"compiler_cache_path", &params_,
398+
"Compiler plugin cache path, used to store JIT-compiled models."));
394399
flags.push_back(tflite::benchmark::CreateFlag<bool>(
395400
"require_full_delegation", &params_,
396401
"Whether to require full delegation."));

litert/tools/benchmark_litert_model_qualcomm_test.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ TEST(BenchmarkLiteRtModelQualcommTest, NPUAcceleration_JIT) {
5454
params.Set<std::string>(
5555
"compiler_plugin_library_path",
5656
"/data/local/tmp/runfiles/litert/");
57+
params.Set<std::string>(
58+
"compiler_cache_path",
59+
"/data/local/tmp/runfiles/litert/");
5760
BenchmarkLiteRtModel benchmark = BenchmarkLiteRtModel(std::move(params));
5861

5962
EXPECT_EQ(benchmark.Run(), kTfLiteOk);

0 commit comments

Comments
 (0)