Skip to content

chore: suppress warnings on Windows #2089

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion engine/cli/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "utils/file_manager_utils.h"
#include "utils/logging_utils.h"
#include "utils/system_info_utils.h"
#include "utils/widechar_conv.h"

#if defined(__APPLE__) && defined(__MACH__)
#include <libgen.h> // for dirname()
Expand Down Expand Up @@ -46,7 +47,7 @@ void SetupLogger(trantor::FileLogger& async_logger, bool verbose) {

std::filesystem::create_directories(
#if defined(_WIN32)
std::filesystem::u8path(config.logFolderPath) /
std::filesystem::path(cortex::wc::Utf8ToWstring(config.logFolderPath)) /
#else
std::filesystem::path(config.logFolderPath) /
#endif
Expand Down
3 changes: 2 additions & 1 deletion engine/common/message.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ struct Message : JsonSerializable {
std::move(root.get("object", "thread.message").asString());
message.created_at = root["created_at"].asUInt();
if (message.created_at == 0 && root["created"].asUInt64() != 0) {
message.created_at = root["created"].asUInt64() / 1000;
message.created_at =
static_cast<uint32_t>(root["created"].asUInt64() / 1000);
}
message.thread_id = std::move(root["thread_id"].asString());
message.status = StatusFromString(std::move(root["status"].asString()));
Expand Down
6 changes: 3 additions & 3 deletions engine/config/model_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ struct RemoteModelConfig {

// Load basic string fields
model = json.get("model", model).asString();
header_template =
json.get("header_template", header_template).asString();
header_template = json.get("header_template", header_template).asString();
engine = json.get("engine", engine).asString();
version = json.get("version", version).asString();
created =
Expand Down Expand Up @@ -405,7 +404,8 @@ struct ModelConfig {
oss << format_utils::print_comment("END REQUIRED");
oss << format_utils::print_comment("BEGIN OPTIONAL");

oss << format_utils::print_float("size", size);
oss << format_utils::print_kv("size", std::to_string(size),
format_utils::MAGENTA);
oss << format_utils::print_bool("stream", stream);
oss << format_utils::print_float("top_p", top_p);
oss << format_utils::print_float("temperature", temperature);
Expand Down
2 changes: 1 addition & 1 deletion engine/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ void RunServer(std::optional<std::string> host, std::optional<int> port,
// Create logs/ folder and setup log to file
std::filesystem::create_directories(
#if defined(_WIN32)
std::filesystem::u8path(config.logFolderPath) /
std::filesystem::path(cortex::wc::Utf8ToWstring(config.logFolderPath)) /
#else
std::filesystem::path(config.logFolderPath) /
#endif
Expand Down
38 changes: 37 additions & 1 deletion engine/services/hardware_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,19 @@ bool HardwareService::Restart(const std::string& host, int port) {
return false;
}

#ifdef _MSC_VER
char* value = nullptr;
size_t len = 0;
_dupenv_s(&value, &len, "CUDA_VISIBLE_DEVICES");
#else
const char* value = std::getenv("CUDA_VISIBLE_DEVICES");
#endif

if (value) {
LOG_INFO << "CUDA_VISIBLE_DEVICES is set to: " << value;
#ifdef _MSC_VER
free(value);
#endif
} else {
LOG_WARN << "CUDA_VISIBLE_DEVICES is not set.";
}
Expand All @@ -128,9 +138,18 @@ bool HardwareService::Restart(const std::string& host, int port) {
return false;
}

#ifdef _MSC_VER
char* vk_value = nullptr;
_dupenv_s(&vk_value, &len, "GGML_VK_VISIBLE_DEVICES");
#else
const char* vk_value = std::getenv("GGML_VK_VISIBLE_DEVICES");
#endif

if (vk_value) {
LOG_INFO << "GGML_VK_VISIBLE_DEVICES is set to: " << vk_value;
#ifdef _MSC_VER
free(vk_value);
#endif
} else {
LOG_WARN << "GGML_VK_VISIBLE_DEVICES is not set.";
}
Expand Down Expand Up @@ -240,7 +259,7 @@ bool HardwareService::SetActivateHardwareConfig(
auto priority = [&ahc](int software_id) -> int {
for (size_t i = 0; i < ahc.gpus.size(); i++) {
if (ahc.gpus[i] == software_id)
return i;
return static_cast<int>(i);
break;
}
return INT_MAX;
Expand Down Expand Up @@ -390,16 +409,33 @@ void HardwareService::UpdateHardwareInfos() {
#if defined(_WIN32) || defined(_WIN64) || defined(__linux__)
bool has_deactivated_gpu = a.value().size() != activated_gpu_af.size();
if (!gpus.empty() && has_deactivated_gpu) {
#ifdef _MSC_VER
char* value = nullptr;
size_t len = 0;
_dupenv_s(&value, &len, "CUDA_VISIBLE_DEVICES");
#else
const char* value = std::getenv("CUDA_VISIBLE_DEVICES");
#endif
if (value) {
LOG_INFO << "CUDA_VISIBLE_DEVICES: " << value;
#ifdef _MSC_VER
free(value);
#endif
} else {
need_restart = true;
}

#ifdef _MSC_VER
char* vk_value = nullptr;
_dupenv_s(&vk_value, &len, "GGML_VK_VISIBLE_DEVICES");
#else
const char* vk_value = std::getenv("GGML_VK_VISIBLE_DEVICES");
#endif
if (vk_value) {
LOG_INFO << "GGML_VK_VISIBLE_DEVICES: " << vk_value;
#ifdef _MSC_VER
free(vk_value);
#endif
} else {
need_restart = true;
}
Expand Down
8 changes: 4 additions & 4 deletions engine/services/model_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ cpp::result<DownloadTask, std::string> ModelService::HandleDownloadUrlAsync(

try {
std::filesystem::create_directories(local_path.parent_path());
} catch (const std::filesystem::filesystem_error& e) {
} catch (const std::filesystem::filesystem_error&) {
// if file exist, remove it
std::filesystem::remove(local_path.parent_path());
std::filesystem::create_directories(local_path.parent_path());
Expand Down Expand Up @@ -380,7 +380,7 @@ ModelService::EstimateModel(const std::string& model_handle,
auto mc = yaml_handler.GetModelConfig();
assert(hw_service_);
auto hw_info = hw_service_->GetHardwareInfo();
auto free_vram_MiB = 0u;
int64_t free_vram_MiB = 0;
for (const auto& gpu : hw_info.gpus) {
free_vram_MiB += gpu.free_vram;
}
Expand Down Expand Up @@ -444,7 +444,7 @@ cpp::result<std::string, std::string> ModelService::HandleUrl(

try {
std::filesystem::create_directories(local_path.parent_path());
} catch (const std::filesystem::filesystem_error& e) {
} catch (const std::filesystem::filesystem_error&) {
// if file exist, remove it
std::filesystem::remove(local_path.parent_path());
std::filesystem::create_directories(local_path.parent_path());
Expand Down Expand Up @@ -1326,7 +1326,7 @@ ModelService::MayFallbackToCpu(const std::string& model_path, int ngl,
}
// If in GPU acceleration mode:
// We use all visible GPUs, so only need to sum all free vram
auto free_vram_MiB = 0u;
int64_t free_vram_MiB = 0;
for (const auto& gpu : hw_info.gpus) {
free_vram_MiB += gpu.free_vram;
}
Expand Down
3 changes: 2 additions & 1 deletion engine/utils/command_executor.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ class CommandExecutor {
std::array<char, 128> buffer;
std::string result;

while (fgets(buffer.data(), buffer.size(), m_pipe.get()) != nullptr) {
while (fgets(buffer.data(), static_cast<int>(buffer.size()),
m_pipe.get()) != nullptr) {
result += buffer.data();
}

Expand Down
12 changes: 10 additions & 2 deletions engine/utils/cortex_utils.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#pragma once

#include <drogon/HttpClient.h>
#include <drogon/HttpResponse.h>
#include <sys/stat.h>
Expand Down Expand Up @@ -29,9 +30,16 @@ inline std::string logs_cli_base_name = "./logs/cortex-cli.log";
// example: Mon, 25 Nov 2024 09:57:03 GMT
inline std::string GetDateRFC1123() {
std::time_t now = std::time(nullptr);
std::tm* gmt_time = std::gmtime(&now);
std::tm gmt_time = {};
#ifdef _MSC_VER
gmtime_s(&gmt_time, &now);
std::ostringstream oss;
oss << std::put_time(&gmt_time, "%a, %d %b %Y %H:%M:%S GMT");
#else
std::tm* gmt_time_ptr = std::gmtime(&now);
std::ostringstream oss;
oss << std::put_time(gmt_time, "%a, %d %b %Y %H:%M:%S GMT");
oss << std::put_time(gmt_time_ptr, "%a, %d %b %Y %H:%M:%S GMT");
#endif
return oss.str();
}

Expand Down
46 changes: 25 additions & 21 deletions engine/utils/engine_matcher_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,52 +51,56 @@ inline std::string GetSuitableCudaVariant(
std::regex cuda_reg("cuda-(\\d+)-(\\d+)");
std::smatch match;

int requestedMajor = 0;
int requestedMinor = 0;
int requested_major = 0;
int requested_minor = 0;

if (!cuda_version.empty()) {
// Split the provided CUDA version into major and minor parts
sscanf(cuda_version.c_str(), "%d.%d", &requestedMajor, &requestedMinor);
// Split the provided CUDA version into major and minor parts
#if defined(_MSC_VER)
sscanf_s(cuda_version.c_str(), "%d.%d", &requested_major, &requested_minor);
#else
sscanf(cuda_version.c_str(), "%d.%d", &requested_major, &requested_minor);
#endif
}

std::string selectedVariant;
int bestMatchMajor = -1;
int bestMatchMinor = -1;
std::string selected_variant;
int best_match_major = -1;
int best_match_minor = -1;

for (const auto& variant : variants) {
if (std::regex_search(variant, match, cuda_reg)) {
// Found a CUDA version in the variant
int variantMajor = std::stoi(match[1]);
int variantMinor = std::stoi(match[2]);
int variant_major = std::stoi(match[1]);
int variant_minor = std::stoi(match[2]);

if (requestedMajor == variantMajor) {
if (requested_major == variant_major) {
// If the major versions match, prefer the closest minor version
if (requestedMinor >= variantMinor &&
(variantMajor > bestMatchMajor ||
(variantMajor == bestMatchMajor &&
variantMinor > bestMatchMinor))) {
selectedVariant = variant;
bestMatchMajor = variantMajor;
bestMatchMinor = variantMinor;
if (requested_minor >= variant_minor &&
(variant_major > best_match_major ||
(variant_major == best_match_major &&
variant_minor > best_match_minor))) {
selected_variant = variant;
best_match_major = variant_major;
best_match_minor = variant_minor;
}
}
}
}

// If no CUDA version is provided, select the variant without any CUDA in the name
if (selectedVariant.empty()) {
if (selected_variant.empty()) {
LOG_WARN
<< "No suitable CUDA variant found, selecting a variant without CUDA";
for (const auto& variant : variants) {
if (variant.find("cuda") == std::string::npos) {
selectedVariant = variant;
LOG_INFO << "Found variant without CUDA: " << selectedVariant << "\n";
selected_variant = variant;
LOG_INFO << "Found variant without CUDA: " << selected_variant << "\n";
break;
}
}
}

return selectedVariant;
return selected_variant;
}

inline std::string ValidateTensorrtLlm(const std::vector<std::string>& variants,
Expand Down
2 changes: 1 addition & 1 deletion engine/utils/format_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ inline std::string WriteKeyValue(const std::string& key,
strValue.pop_back();
}
out_file << strValue;
} catch (const std::exception& e) {
} catch (const std::exception&) {
out_file << value; // If not a float, write as is
}
} else {
Expand Down
2 changes: 1 addition & 1 deletion engine/utils/hardware/cpu_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ struct CpuInfo {
return CPU{};
auto cpu = res[0];
cortex::cpuid::CpuInfo inst;
float usage = GetCPUUsage();
auto usage = static_cast<float>(GetCPUUsage());
return CPU{.cores = cpu.numPhysicalCores(),
.arch = std::string(GetArch()),
.model = cpu.modelName(),
Expand Down
22 changes: 11 additions & 11 deletions engine/utils/hardware/gguf/ggml.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,21 +49,21 @@ inline float GetQuantBit(GGMLType gt) {
switch (gt) {
case GGML_TYPE_I32:
case GGML_TYPE_F32:
return 32.0;
return 32.0f;
case GGML_TYPE_I16:
case GGML_TYPE_BF16:
case GGML_TYPE_F16:
return 16.0;
return 16.0f;
case GGML_TYPE_IQ2_S:
case GGML_TYPE_IQ2_XXS:
case GGML_TYPE_IQ2_XS:
return 2.31;
return 2.31f;
case GGML_TYPE_Q2_K:
return 2.5625;
return 2.5625f;
case GGML_TYPE_IQ3_XXS:
case GGML_TYPE_IQ3_S:
case GGML_TYPE_Q3_K:
return 3.4375;
return 3.4375f;
case GGML_TYPE_Q4_0_4_4:
case GGML_TYPE_Q4_0_4_8:
case GGML_TYPE_Q4_0_8_8:
Expand All @@ -72,25 +72,25 @@ inline float GetQuantBit(GGMLType gt) {
case GGML_TYPE_Q4_0:
case GGML_TYPE_Q4_1:
case GGML_TYPE_Q4_K:
return 4.5;
return 4.5f;
case GGML_TYPE_Q5_0:
case GGML_TYPE_Q5_1:
case GGML_TYPE_Q5_K:
return 5.5;
return 5.5f;
case GGML_TYPE_Q6_K:
return 6.5625;
return 6.5625f;
case GGML_TYPE_I8:
case GGML_TYPE_Q8_0:
case GGML_TYPE_Q8_1:
case GGML_TYPE_Q8_K:
return 8.0;
return 8.0f;

case GGML_TYPE_I64:
case GGML_TYPE_F64:
return 64.0;
return 64.0f;

default:
return 8.0;
return 8.0f;
}
}

Expand Down
Loading
Loading