@@ -404,17 +404,23 @@ LiteRtStatus LiteRtCompilerPluginPartition(LiteRtCompilerPlugin compiler_plugin,
404404 LiteRtSubgraph subgraph,
405405 LiteRtOpList selected_ops) {
406406 LITERT_CHECK_STATUS_OK (SetNeuronEnvironment (soc_model));
407- absl::Cleanup dla_directory_cleanup = [] {
408- const char * dla_directory_name = std::getenv (" MTKNN_ADAPTER_DLA_DIR" );
409- if (dla_directory_name) {
410- remove_directory (dla_directory_name);
411- }
412- };
413407
414408 auto soc_and_api = CreateNeuronAdapterApi (soc_model, compiler_plugin);
415409 if (!soc_and_api) {
416410 return soc_and_api.Error ().Status ();
417411 }
412+
413+ litert::mediatek::MediatekOptions& mtk_options =
414+ compiler_plugin->GetMediatekOptions ().Value ();
415+ if (!mtk_options.GetDisableDlaDirRemoval ()) {
416+ absl::Cleanup dla_directory_cleanup = [] {
417+ const char * dla_directory_name = std::getenv (" MTKNN_ADAPTER_DLA_DIR" );
418+ if (dla_directory_name) {
419+ remove_directory (dla_directory_name);
420+ }
421+ };
422+ }
423+
418424 auto & [opt_soc_model, neuron_adapter_api] = soc_and_api.Value ();
419425
420426 litert::Subgraph graph (subgraph);
@@ -517,12 +523,22 @@ LiteRtStatus LiteRtCompilerPluginCompile(
517523 LiteRtCompilerPlugin compiler_plugin, const char * soc_model,
518524 LiteRtModel partitions, LiteRtCompiledResult* compiled_result) {
519525 LITERT_CHECK_STATUS_OK (SetNeuronEnvironment (soc_model));
520- absl::Cleanup dla_directory_cleanup = [] {
521- const char * dla_directory_name = std::getenv (" MTKNN_ADAPTER_DLA_DIR" );
522- if (dla_directory_name) {
523- remove_directory (dla_directory_name);
524- }
525- };
526+
527+ auto soc_and_api = CreateNeuronAdapterApi (soc_model, compiler_plugin);
528+ if (!soc_and_api) {
529+ return soc_and_api.Error ().Status ();
530+ }
531+
532+ litert::mediatek::MediatekOptions& mtk_options =
533+ compiler_plugin->GetMediatekOptions ().Value ();
534+ if (!mtk_options.GetDisableDlaDirRemoval ()) {
535+ absl::Cleanup dla_directory_cleanup = [] {
536+ const char * dla_directory_name = std::getenv (" MTKNN_ADAPTER_DLA_DIR" );
537+ if (dla_directory_name) {
538+ remove_directory (dla_directory_name);
539+ }
540+ };
541+ }
526542
527543 auto model = litert::ExtendedModel::CreateFromNonOwnedHandle (partitions);
528544 const auto num_partitions = model.NumSubgraphs ();
@@ -531,10 +547,6 @@ LiteRtStatus LiteRtCompilerPluginCompile(
531547 " Starting MediaTek Compilation for %d subgraphs, soc_model=%s" ,
532548 num_partitions, soc_model);
533549
534- auto soc_and_api = CreateNeuronAdapterApi (soc_model, compiler_plugin);
535- if (!soc_and_api) {
536- return soc_and_api.Error ().Status ();
537- }
538550 auto & [opt_soc_model, api] = soc_and_api.Value ();
539551
540552 auto result = std::make_unique<LiteRtCompiledResultT>();
0 commit comments