@@ -137,19 +137,23 @@ InferResult InferenceService::LoadModel(
137137 }
138138 };
139139
140- if (IsEngineLoaded (kLlamaRepo ) && ne == kTrtLlmRepo ) {
141- // Remove llamacpp dll directory
142- if (!RemoveDllDirectory (engines_[kLlamaRepo ].cookie )) {
143- LOG_WARN << " Could not remove dll directory: " << kLlamaRepo ;
140+ if (bool should_use_dll_search_path = !(getenv (" ENGINE_PATH" ));
141+ should_use_dll_search_path) {
142+ if (IsEngineLoaded (kLlamaRepo ) && ne == kTrtLlmRepo &&
143+ should_use_dll_search_path) {
144+ // Remove llamacpp dll directory
145+ if (!RemoveDllDirectory (engines_[kLlamaRepo ].cookie )) {
146+ LOG_WARN << " Could not remove dll directory: " << kLlamaRepo ;
147+ } else {
148+ LOG_INFO << " Removed dll directory: " << kLlamaRepo ;
149+ }
150+
151+ add_dll (ne, abs_path);
152+ } else if (IsEngineLoaded (kTrtLlmRepo ) && ne == kLlamaRepo ) {
153+ // Do nothing
144154 } else {
145- LOG_INFO << " Removed dll directory: " << kLlamaRepo ;
155+ add_dll (ne, abs_path) ;
146156 }
147-
148- add_dll (ne, abs_path);
149- } else if (IsEngineLoaded (kTrtLlmRepo ) && ne == kLlamaRepo ) {
150- // Do nothing
151- } else {
152- add_dll (ne, abs_path);
153157 }
154158#endif
155159 engines_[ne].dl = std::make_unique<cortex_cpp::dylib>(abs_path, " engine" );
@@ -366,10 +370,13 @@ InferResult InferenceService::UnloadEngine(
366370 EngineI* e = std::get<EngineI*>(engines_[ne].engine );
367371 delete e;
368372#if defined(_WIN32)
369- if (!RemoveDllDirectory (engines_[ne].cookie )) {
370- LOG_WARN << " Could not remove dll directory: " << ne;
371- } else {
372- LOG_INFO << " Removed dll directory: " << ne;
373+ if (bool should_use_dll_search_path = !(getenv (" ENGINE_PATH" ));
374+ should_use_dll_search_path) {
375+ if (!RemoveDllDirectory (engines_[ne].cookie )) {
376+ LOG_WARN << " Could not remove dll directory: " << ne;
377+ } else {
378+ LOG_INFO << " Removed dll directory: " << ne;
379+ }
373380 }
374381#endif
375382 engines_.erase (ne);
0 commit comments