From eb96ed4e7a8577ec9667c6098fd468f9d25130d3 Mon Sep 17 00:00:00 2001 From: James Date: Tue, 5 Nov 2024 10:12:25 +0700 Subject: [PATCH] update ld_library_path --- engine/cli/commands/server_start_cmd.cc | 8 ++------ engine/cli/main.cc | 11 ++++++++--- engine/services/engine_service.cc | 12 +++++------- engine/utils/file_manager_utils.h | 13 +++++++++++++ 4 files changed, 28 insertions(+), 16 deletions(-) diff --git a/engine/cli/commands/server_start_cmd.cc b/engine/cli/commands/server_start_cmd.cc index ca5363fa6..47a8cf320 100644 --- a/engine/cli/commands/server_start_cmd.cc +++ b/engine/cli/commands/server_start_cmd.cc @@ -97,12 +97,8 @@ bool ServerStartCmd::Exec(const std::string& host, int port) { v += g; } CTL_INF("LD_LIBRARY_PATH: " << v); - auto data_path = file_manager_utils::GetEnginesContainerPath(); - auto llamacpp_path = data_path / "cortex.llamacpp/"; - auto trt_path = data_path / "cortex.tensorrt-llm/"; - if (!std::filesystem::exists(llamacpp_path)) { - std::filesystem::create_directory(llamacpp_path); - } + auto llamacpp_path = file_manager_utils::GetCudaToolkitPath(kLlamaRepo); + auto trt_path = file_manager_utils::GetCudaToolkitPath(kTrtLlmRepo); auto new_v = trt_path.string() + ":" + llamacpp_path.string() + ":" + v; setenv(name, new_v.c_str(), true); diff --git a/engine/cli/main.cc b/engine/cli/main.cc index 52c1ce457..62a88eb38 100644 --- a/engine/cli/main.cc +++ b/engine/cli/main.cc @@ -48,7 +48,7 @@ void SetupLogger(trantor::FileLogger& async_logger, bool verbose) { std::filesystem::path(config.logFolderPath) / std::filesystem::path(cortex_utils::logs_folder)); async_logger.setFileName(config.logFolderPath + "/" + - cortex_utils::logs_cli_base_name); + cortex_utils::logs_cli_base_name); async_logger.setMaxLines(config.maxLogLines); // Keep last 100000 lines async_logger.startLogging(); trantor::Logger::setOutputFunction( @@ -96,7 +96,12 @@ int main(int argc, char* argv[]) { } } - { file_manager_utils::CreateConfigFileIfNotExist(); } + { + auto result = file_manager_utils::CreateConfigFileIfNotExist(); + if (result.has_error()) { + CTL_ERR("Error creating config file: " << result.error()); + } + } RemoveBinaryTempFileIfExists(); @@ -104,7 +109,7 @@ int main(int argc, char* argv[]) { SetupLogger(async_file_logger, verbose); if (should_install_server) { - InstallServer(); + InstallServer(); return 0; } diff --git a/engine/services/engine_service.cc b/engine/services/engine_service.cc index 4468476f3..0780e65ec 100644 --- a/engine/services/engine_service.cc +++ b/engine/services/engine_service.cc @@ -76,8 +76,6 @@ cpp::result EngineService::InstallEngineAsyncV2( CTL_INF("InstallEngineAsyncV2: " << ne << ", " << version << ", " << variant_name.value_or("")); auto os = hw_inf_.sys_inf->os; - CTL_INF("os: " << os); - CTL_INF("kMacOs: " << kMacOs); if (os == kMacOs && (ne == kOnnxRepo || ne == kTrtLlmRepo)) { return cpp::fail("Engine " + ne + " is not supported on macOS"); } @@ -88,9 +86,9 @@ cpp::result EngineService::InstallEngineAsyncV2( auto result = DownloadEngineV2(ne, version, variant_name); if (result.has_error()) { - return result; + return cpp::fail(result.error()); } - auto cuda_res = DownloadCuda(ne, true /*async*/); + auto cuda_res = DownloadCuda(ne, true); if (cuda_res.has_error()) { return cpp::fail(cuda_res.error()); } @@ -451,12 +449,12 @@ cpp::result EngineService::DownloadCuda( auto cuda_toolkit_url = url_parser::FromUrl(url_obj); - LOG_DEBUG << "Cuda toolkit download url: " << cuda_toolkit_url; + CTL_DBG("Cuda toolkit download url: " << cuda_toolkit_url); auto cuda_toolkit_local_path = file_manager_utils::GetContainerFolderPath( file_manager_utils::DownloadTypeToString(DownloadType::CudaToolkit)) / cuda_toolkit_file_name; - LOG_DEBUG << "Download to: " << cuda_toolkit_local_path.string(); + CTL_DBG("Download to: " << cuda_toolkit_local_path.string()); auto downloadCudaToolkitTask{DownloadTask{ .id = download_id, .type = DownloadType::CudaToolkit, @@ -466,7 +464,7 @@ cpp::result EngineService::DownloadCuda( }}; auto on_finished = [engine](const DownloadTask& finishedTask) { - auto engine_path = file_manager_utils::GetEnginesContainerPath() / engine; + auto engine_path = file_manager_utils::GetCudaToolkitPath(engine); archive_utils::ExtractArchive(finishedTask.items[0].localPath.string(), engine_path.string()); diff --git a/engine/utils/file_manager_utils.h b/engine/utils/file_manager_utils.h index fb28d02da..b6d1f1c5a 100644 --- a/engine/utils/file_manager_utils.h +++ b/engine/utils/file_manager_utils.h @@ -272,6 +272,19 @@ inline std::filesystem::path GetModelsContainerPath() { return models_container_path; } +inline std::filesystem::path GetCudaToolkitPath(const std::string& engine) { + auto engine_path = getenv("ENGINE_PATH") + ? std::filesystem::path(getenv("ENGINE_PATH")) + : GetCortexDataPath(); + + auto cuda_path = engine_path / "engines" / engine / "deps"; + if (!std::filesystem::exists(cuda_path)) { + std::filesystem::create_directories(cuda_path); + } + + return cuda_path; +} + inline std::filesystem::path GetEnginesContainerPath() { auto cortex_path = getenv("ENGINE_PATH") ? std::filesystem::path(getenv("ENGINE_PATH"))