Skip to content
This repository was archived by the owner on Jul 4, 2025. It is now read-only.

Commit 8a6387f

Browse files
authored
fix: only set dll search path if don't use ENGINE_PATH (#1557)
1 parent 113ea98 commit 8a6387f

File tree

2 files changed

+26
-16
lines changed

2 files changed

+26
-16
lines changed

engine/controllers/server.cc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ namespace inferences {
1313
server::server(std::shared_ptr<services::InferenceService> inference_service)
1414
: inference_svc_(inference_service) {
1515
#if defined(_WIN32)
16-
SetDefaultDllDirectories(LOAD_LIBRARY_SEARCH_DEFAULT_DIRS);
16+
if (bool should_use_dll_search_path = !(getenv("ENGINE_PATH"));
17+
should_use_dll_search_path) {
18+
SetDefaultDllDirectories(LOAD_LIBRARY_SEARCH_DEFAULT_DIRS);
19+
}
1720
#endif
1821
};
1922

engine/services/inference_service.cc

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)