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

Commit ae5bfa8

Browse files
authored
chore: suppress warnings on Windows (#2089)
* chore: suppress warnings on Windows * chore: msvc * chore: remove c-style cast
1 parent dbaf4f8 commit ae5bfa8

File tree

16 files changed

+133
-75
lines changed

16 files changed

+133
-75
lines changed

engine/cli/main.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "utils/file_manager_utils.h"
99
#include "utils/logging_utils.h"
1010
#include "utils/system_info_utils.h"
11+
#include "utils/widechar_conv.h"
1112

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

4748
std::filesystem::create_directories(
4849
#if defined(_WIN32)
49-
std::filesystem::u8path(config.logFolderPath) /
50+
std::filesystem::path(cortex::wc::Utf8ToWstring(config.logFolderPath)) /
5051
#else
5152
std::filesystem::path(config.logFolderPath) /
5253
#endif

engine/common/message.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,8 @@ struct Message : JsonSerializable {
107107
std::move(root.get("object", "thread.message").asString());
108108
message.created_at = root["created_at"].asUInt();
109109
if (message.created_at == 0 && root["created"].asUInt64() != 0) {
110-
message.created_at = root["created"].asUInt64() / 1000;
110+
message.created_at =
111+
static_cast<uint32_t>(root["created"].asUInt64() / 1000);
111112
}
112113
message.thread_id = std::move(root["thread_id"].asString());
113114
message.status = StatusFromString(std::move(root["status"].asString()));

engine/config/model_config.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ struct RemoteModelConfig {
3535

3636
// Load basic string fields
3737
model = json.get("model", model).asString();
38-
header_template =
39-
json.get("header_template", header_template).asString();
38+
header_template = json.get("header_template", header_template).asString();
4039
engine = json.get("engine", engine).asString();
4140
version = json.get("version", version).asString();
4241
created =
@@ -405,7 +404,8 @@ struct ModelConfig {
405404
oss << format_utils::print_comment("END REQUIRED");
406405
oss << format_utils::print_comment("BEGIN OPTIONAL");
407406

408-
oss << format_utils::print_float("size", size);
407+
oss << format_utils::print_kv("size", std::to_string(size),
408+
format_utils::MAGENTA);
409409
oss << format_utils::print_bool("stream", stream);
410410
oss << format_utils::print_float("top_p", top_p);
411411
oss << format_utils::print_float("temperature", temperature);

engine/main.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ void RunServer(std::optional<std::string> host, std::optional<int> port,
105105
// Create logs/ folder and setup log to file
106106
std::filesystem::create_directories(
107107
#if defined(_WIN32)
108-
std::filesystem::u8path(config.logFolderPath) /
108+
std::filesystem::path(cortex::wc::Utf8ToWstring(config.logFolderPath)) /
109109
#else
110110
std::filesystem::path(config.logFolderPath) /
111111
#endif

engine/services/hardware_service.cc

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,19 @@ bool HardwareService::Restart(const std::string& host, int port) {
106106
return false;
107107
}
108108

109+
#ifdef _MSC_VER
110+
char* value = nullptr;
111+
size_t len = 0;
112+
_dupenv_s(&value, &len, "CUDA_VISIBLE_DEVICES");
113+
#else
109114
const char* value = std::getenv("CUDA_VISIBLE_DEVICES");
115+
#endif
116+
110117
if (value) {
111118
LOG_INFO << "CUDA_VISIBLE_DEVICES is set to: " << value;
119+
#ifdef _MSC_VER
120+
free(value);
121+
#endif
112122
} else {
113123
LOG_WARN << "CUDA_VISIBLE_DEVICES is not set.";
114124
}
@@ -128,9 +138,18 @@ bool HardwareService::Restart(const std::string& host, int port) {
128138
return false;
129139
}
130140

141+
#ifdef _MSC_VER
142+
char* vk_value = nullptr;
143+
_dupenv_s(&vk_value, &len, "GGML_VK_VISIBLE_DEVICES");
144+
#else
131145
const char* vk_value = std::getenv("GGML_VK_VISIBLE_DEVICES");
146+
#endif
147+
132148
if (vk_value) {
133149
LOG_INFO << "GGML_VK_VISIBLE_DEVICES is set to: " << vk_value;
150+
#ifdef _MSC_VER
151+
free(vk_value);
152+
#endif
134153
} else {
135154
LOG_WARN << "GGML_VK_VISIBLE_DEVICES is not set.";
136155
}
@@ -240,7 +259,7 @@ bool HardwareService::SetActivateHardwareConfig(
240259
auto priority = [&ahc](int software_id) -> int {
241260
for (size_t i = 0; i < ahc.gpus.size(); i++) {
242261
if (ahc.gpus[i] == software_id)
243-
return i;
262+
return static_cast<int>(i);
244263
break;
245264
}
246265
return INT_MAX;
@@ -390,16 +409,33 @@ void HardwareService::UpdateHardwareInfos() {
390409
#if defined(_WIN32) || defined(_WIN64) || defined(__linux__)
391410
bool has_deactivated_gpu = a.value().size() != activated_gpu_af.size();
392411
if (!gpus.empty() && has_deactivated_gpu) {
412+
#ifdef _MSC_VER
413+
char* value = nullptr;
414+
size_t len = 0;
415+
_dupenv_s(&value, &len, "CUDA_VISIBLE_DEVICES");
416+
#else
393417
const char* value = std::getenv("CUDA_VISIBLE_DEVICES");
418+
#endif
394419
if (value) {
395420
LOG_INFO << "CUDA_VISIBLE_DEVICES: " << value;
421+
#ifdef _MSC_VER
422+
free(value);
423+
#endif
396424
} else {
397425
need_restart = true;
398426
}
399427

428+
#ifdef _MSC_VER
429+
char* vk_value = nullptr;
430+
_dupenv_s(&vk_value, &len, "GGML_VK_VISIBLE_DEVICES");
431+
#else
400432
const char* vk_value = std::getenv("GGML_VK_VISIBLE_DEVICES");
433+
#endif
401434
if (vk_value) {
402435
LOG_INFO << "GGML_VK_VISIBLE_DEVICES: " << vk_value;
436+
#ifdef _MSC_VER
437+
free(vk_value);
438+
#endif
403439
} else {
404440
need_restart = true;
405441
}

engine/services/model_service.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ cpp::result<DownloadTask, std::string> ModelService::HandleDownloadUrlAsync(
315315

316316
try {
317317
std::filesystem::create_directories(local_path.parent_path());
318-
} catch (const std::filesystem::filesystem_error& e) {
318+
} catch (const std::filesystem::filesystem_error&) {
319319
// if file exist, remove it
320320
std::filesystem::remove(local_path.parent_path());
321321
std::filesystem::create_directories(local_path.parent_path());
@@ -380,7 +380,7 @@ ModelService::EstimateModel(const std::string& model_handle,
380380
auto mc = yaml_handler.GetModelConfig();
381381
assert(hw_service_);
382382
auto hw_info = hw_service_->GetHardwareInfo();
383-
auto free_vram_MiB = 0u;
383+
int64_t free_vram_MiB = 0;
384384
for (const auto& gpu : hw_info.gpus) {
385385
free_vram_MiB += gpu.free_vram;
386386
}
@@ -444,7 +444,7 @@ cpp::result<std::string, std::string> ModelService::HandleUrl(
444444

445445
try {
446446
std::filesystem::create_directories(local_path.parent_path());
447-
} catch (const std::filesystem::filesystem_error& e) {
447+
} catch (const std::filesystem::filesystem_error&) {
448448
// if file exist, remove it
449449
std::filesystem::remove(local_path.parent_path());
450450
std::filesystem::create_directories(local_path.parent_path());
@@ -1326,7 +1326,7 @@ ModelService::MayFallbackToCpu(const std::string& model_path, int ngl,
13261326
}
13271327
// If in GPU acceleration mode:
13281328
// We use all visible GPUs, so only need to sum all free vram
1329-
auto free_vram_MiB = 0u;
1329+
int64_t free_vram_MiB = 0;
13301330
for (const auto& gpu : hw_info.gpus) {
13311331
free_vram_MiB += gpu.free_vram;
13321332
}

engine/utils/command_executor.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ class CommandExecutor {
3737
std::array<char, 128> buffer;
3838
std::string result;
3939

40-
while (fgets(buffer.data(), buffer.size(), m_pipe.get()) != nullptr) {
40+
while (fgets(buffer.data(), static_cast<int>(buffer.size()),
41+
m_pipe.get()) != nullptr) {
4142
result += buffer.data();
4243
}
4344

engine/utils/cortex_utils.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#pragma once
2+
23
#include <drogon/HttpClient.h>
34
#include <drogon/HttpResponse.h>
45
#include <sys/stat.h>
@@ -29,9 +30,16 @@ inline std::string logs_cli_base_name = "./logs/cortex-cli.log";
2930
// example: Mon, 25 Nov 2024 09:57:03 GMT
3031
inline std::string GetDateRFC1123() {
3132
std::time_t now = std::time(nullptr);
32-
std::tm* gmt_time = std::gmtime(&now);
33+
std::tm gmt_time = {};
34+
#ifdef _MSC_VER
35+
gmtime_s(&gmt_time, &now);
36+
std::ostringstream oss;
37+
oss << std::put_time(&gmt_time, "%a, %d %b %Y %H:%M:%S GMT");
38+
#else
39+
std::tm* gmt_time_ptr = std::gmtime(&now);
3340
std::ostringstream oss;
34-
oss << std::put_time(gmt_time, "%a, %d %b %Y %H:%M:%S GMT");
41+
oss << std::put_time(gmt_time_ptr, "%a, %d %b %Y %H:%M:%S GMT");
42+
#endif
3543
return oss.str();
3644
}
3745

engine/utils/engine_matcher_utils.h

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -51,52 +51,56 @@ inline std::string GetSuitableCudaVariant(
5151
std::regex cuda_reg("cuda-(\\d+)-(\\d+)");
5252
std::smatch match;
5353

54-
int requestedMajor = 0;
55-
int requestedMinor = 0;
54+
int requested_major = 0;
55+
int requested_minor = 0;
5656

5757
if (!cuda_version.empty()) {
58-
// Split the provided CUDA version into major and minor parts
59-
sscanf(cuda_version.c_str(), "%d.%d", &requestedMajor, &requestedMinor);
58+
// Split the provided CUDA version into major and minor parts
59+
#if defined(_MSC_VER)
60+
sscanf_s(cuda_version.c_str(), "%d.%d", &requested_major, &requested_minor);
61+
#else
62+
sscanf(cuda_version.c_str(), "%d.%d", &requested_major, &requested_minor);
63+
#endif
6064
}
6165

62-
std::string selectedVariant;
63-
int bestMatchMajor = -1;
64-
int bestMatchMinor = -1;
66+
std::string selected_variant;
67+
int best_match_major = -1;
68+
int best_match_minor = -1;
6569

6670
for (const auto& variant : variants) {
6771
if (std::regex_search(variant, match, cuda_reg)) {
6872
// Found a CUDA version in the variant
69-
int variantMajor = std::stoi(match[1]);
70-
int variantMinor = std::stoi(match[2]);
73+
int variant_major = std::stoi(match[1]);
74+
int variant_minor = std::stoi(match[2]);
7175

72-
if (requestedMajor == variantMajor) {
76+
if (requested_major == variant_major) {
7377
// If the major versions match, prefer the closest minor version
74-
if (requestedMinor >= variantMinor &&
75-
(variantMajor > bestMatchMajor ||
76-
(variantMajor == bestMatchMajor &&
77-
variantMinor > bestMatchMinor))) {
78-
selectedVariant = variant;
79-
bestMatchMajor = variantMajor;
80-
bestMatchMinor = variantMinor;
78+
if (requested_minor >= variant_minor &&
79+
(variant_major > best_match_major ||
80+
(variant_major == best_match_major &&
81+
variant_minor > best_match_minor))) {
82+
selected_variant = variant;
83+
best_match_major = variant_major;
84+
best_match_minor = variant_minor;
8185
}
8286
}
8387
}
8488
}
8589

8690
// If no CUDA version is provided, select the variant without any CUDA in the name
87-
if (selectedVariant.empty()) {
91+
if (selected_variant.empty()) {
8892
LOG_WARN
8993
<< "No suitable CUDA variant found, selecting a variant without CUDA";
9094
for (const auto& variant : variants) {
9195
if (variant.find("cuda") == std::string::npos) {
92-
selectedVariant = variant;
93-
LOG_INFO << "Found variant without CUDA: " << selectedVariant << "\n";
96+
selected_variant = variant;
97+
LOG_INFO << "Found variant without CUDA: " << selected_variant << "\n";
9498
break;
9599
}
96100
}
97101
}
98102

99-
return selectedVariant;
103+
return selected_variant;
100104
}
101105

102106
inline std::string ValidateTensorrtLlm(const std::vector<std::string>& variants,

engine/utils/format_utils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ inline std::string WriteKeyValue(const std::string& key,
6767
strValue.pop_back();
6868
}
6969
out_file << strValue;
70-
} catch (const std::exception& e) {
70+
} catch (const std::exception&) {
7171
out_file << value; // If not a float, write as is
7272
}
7373
} else {

0 commit comments

Comments
 (0)