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

Commit 07509ef

Browse files
sangjanainamchuai
authored andcommitted
fix linux
1 parent 68b92f8 commit 07509ef

File tree

7 files changed

+31
-37
lines changed

7 files changed

+31
-37
lines changed

engine/cli/command_line_parser.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,7 @@ void CommandLineParser::SetupEngineCommands() {
471471
list_engines_cmd->callback([this]() {
472472
if (std::exchange(executed_, true))
473473
return;
474-
commands::EngineListCmd command;
474+
auto command = commands::EngineListCmd(engine_service_);
475475
command.Exec(cml_data_.config.apiServerHost,
476476
std::stoi(cml_data_.config.apiServerPort));
477477
});

engine/cli/commands/engine_list_cmd.cc

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
// clang-format on
1414

1515
namespace commands {
16-
1716
bool EngineListCmd::Exec(const std::string& host, int port) {
1817
// Start server if server is not started yet
1918
if (!commands::IsServerAlive(host, port)) {
@@ -38,15 +37,10 @@ bool EngineListCmd::Exec(const std::string& host, int port) {
3837
return false;
3938
}
4039

41-
std::vector<std::string> engines = {
42-
kLlamaEngine,
43-
kOnnxEngine,
44-
kTrtLlmEngine,
45-
};
46-
4740
std::unordered_map<std::string, std::vector<EngineVariantResponse>>
4841
engine_map;
4942

43+
auto engines = engine_service_->GetSupportedEngineNames().value();
5044
for (const auto& engine : engines) {
5145
auto installed_variants = result.value()[engine];
5246
for (const auto& variant : installed_variants) {
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
#pragma once
22

33
#include <string>
4+
#include "services/engine_service.h"
45

56
namespace commands {
67
class EngineListCmd {
78
public:
9+
explicit EngineListCmd(std::shared_ptr<EngineService> engine_service)
10+
: engine_service_{engine_service} {}
11+
812
bool Exec(const std::string& host, int port);
13+
14+
private:
15+
std::shared_ptr<EngineService> engine_service_;
916
};
1017

1118
} // namespace commands

engine/controllers/engines.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ void Engines::ListEngine(
2424
const HttpRequestPtr& req,
2525
std::function<void(const HttpResponsePtr&)>&& callback) const {
2626
Json::Value ret;
27-
for (const auto& engine :
28-
engine_service_->GetSupportedEngineNames().value()) {
27+
auto engines = engine_service_->GetSupportedEngineNames().value();
28+
for (const auto& engine : engines) {
2929
auto installed_engines =
3030
engine_service_->GetInstalledEngineVariants(engine);
3131
if (installed_engines.has_error()) {
@@ -37,6 +37,7 @@ void Engines::ListEngine(
3737
}
3838
ret[engine] = variants;
3939
}
40+
4041
// Add remote engine
4142
auto remote_engines = engine_service_->GetEngines();
4243
if (remote_engines.has_value()) {
@@ -49,7 +50,6 @@ void Engines::ListEngine(
4950
}
5051
}
5152
}
52-
5353
auto resp = cortex_utils::CreateCortexHttpJsonResponse(ret);
5454
resp->setStatusCode(k200OK);
5555
callback(resp);

engine/cortex-common/EngineI.h

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,11 @@
88
#include "trantor/utils/Logger.h"
99
class EngineI {
1010
public:
11-
struct RegisterLibraryOption {
12-
std::vector<std::filesystem::path> paths;
13-
};
14-
1511
struct EngineLoadOption {
1612
// engine
1713
std::filesystem::path engine_path;
18-
std::filesystem::path cuda_path;
19-
bool custom_engine_path;
14+
std::filesystem::path deps_path;
15+
bool is_custom_engine_path;
2016

2117
// logging
2218
std::filesystem::path log_path;
@@ -25,16 +21,11 @@ class EngineI {
2521
};
2622

2723
struct EngineUnloadOption {
28-
bool unload_dll;
24+
// place holder for now
2925
};
3026

3127
virtual ~EngineI() {}
3228

33-
/**
34-
* Being called before starting process to register dependencies search paths.
35-
*/
36-
virtual void RegisterLibraryPath(RegisterLibraryOption opts) = 0;
37-
3829
virtual void Load(EngineLoadOption opts) = 0;
3930

4031
virtual void Unload(EngineUnloadOption opts) = 0;

engine/services/engine_service.cc

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -713,6 +713,7 @@ cpp::result<void, std::string> EngineService::LoadEngine(
713713
try {
714714
auto cuda_path = file_manager_utils::GetCudaToolkitPath(ne);
715715

716+
#if defined(_WIN32) || defined(_WIN64)
716717
// register deps
717718
std::vector<std::filesystem::path> paths{};
718719
paths.push_back(std::move(cuda_path));
@@ -730,24 +731,22 @@ cpp::result<void, std::string> EngineService::LoadEngine(
730731
} else {
731732
CTL_DBG("Registered lib paths for: " << ne);
732733
}
734+
#endif
733735

734736
auto dylib =
735737
std::make_unique<cortex_cpp::dylib>(engine_dir_path.string(), "engine");
736738

737739
auto config = file_manager_utils::GetCortexConfig();
738-
739-
auto log_path =
740-
std::filesystem::path(config.logFolderPath) /
741-
std::filesystem::path(
742-
config.logLlamaCppPath); // for now seems like we use same log path
740+
auto log_path = std::filesystem::path(config.logFolderPath) /
741+
std::filesystem::path(config.logLlamaCppPath);
743742

744743
// init
745744
auto func = dylib->get_function<EngineI*()>("get_engine");
746745
auto engine_obj = func();
747746
auto load_opts = EngineI::EngineLoadOption{
748747
.engine_path = engine_dir_path,
749-
.cuda_path = file_manager_utils::GetCudaToolkitPath(ne),
750-
.custom_engine_path = custom_engine_path,
748+
.deps_path = cuda_path,
749+
.is_custom_engine_path = custom_engine_path,
751750
.log_path = log_path,
752751
.max_log_lines = config.maxLogLines,
753752
.log_level = logging_utils_helper::global_log_level,
@@ -773,7 +772,7 @@ void EngineService::RegisterEngineLibPath() {
773772
try {
774773
auto engine_dir_path_res = GetEngineDirPath(engine);
775774
if (engine_dir_path_res.has_error()) {
776-
CTL_ERR(
775+
CTL_WRN(
777776
"Could not get engine dir path: " << engine_dir_path_res.error());
778777
continue;
779778
}
@@ -794,8 +793,9 @@ void EngineService::RegisterEngineLibPath() {
794793

795794
auto reg_result = dylib_path_manager_->RegisterPath(ne, paths);
796795
if (reg_result.has_error()) {
796+
CTL_WRN("Failed register lib path for " << engine);
797797
} else {
798-
CTL_DBG("Register lib path for: " << engine);
798+
CTL_DBG("Registered lib path for " << engine);
799799
}
800800

801801
} catch (const std::exception& e) {
@@ -863,9 +863,7 @@ cpp::result<void, std::string> EngineService::UnloadEngine(
863863
CTL_DBG("Unregistered lib paths for: " << ne);
864864
}
865865
auto* e = std::get<EngineI*>(engines_[ne].engine);
866-
auto unload_opts = EngineI::EngineUnloadOption{
867-
.unload_dll = true,
868-
};
866+
auto unload_opts = EngineI::EngineUnloadOption{};
869867
e->Unload(unload_opts);
870868
delete e;
871869
engines_.erase(ne);

engine/utils/dylib_path_manager.cc

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ cpp::result<void, std::string> DylibPathManager::RegisterPath(
4949
// Get current LD_LIBRARY_PATH
5050
const char* current_path = getenv(kLdLibraryPath);
5151
std::string current_paths = current_path ? current_path : "";
52+
CTL_DBG("Current paths: " << current_paths);
5253

5354
// Add new paths
5455
for (const auto& path : paths) {
@@ -64,12 +65,15 @@ cpp::result<void, std::string> DylibPathManager::RegisterPath(
6465
if (!current_paths.empty()) {
6566
new_path << ":" << current_paths;
6667
}
67-
68+
CTL_DBG("New paths: " << new_path.str());
6869
// Set the new LD_LIBRARY_PATH
6970
if (setenv(kLdLibraryPath, new_path.str().c_str(), 1) != 0) {
71+
CTL_ERR("Failed to set path!!!");
7072
return cpp::fail("Failed to set " + std::string(kLdLibraryPath));
7173
}
7274

75+
CTL_DBG("After set path: " << getenv(kLdLibraryPath));
76+
7377
dylib_map_[key] = std::move(dylib_paths);
7478
#endif
7579

@@ -92,7 +96,7 @@ cpp::result<void, std::string> DylibPathManager::Unregister(
9296
}
9397
}
9498

95-
#else
99+
#elif defined(__linux__)
96100
// For Linux, we need to rebuild LD_LIBRARY_PATH without the removed paths
97101
const char* current_path = getenv(kLdLibraryPath);
98102
if (current_path) {

0 commit comments

Comments
 (0)