Skip to content

Commit fa96cae

Browse files
peter277mglambda
authored andcommitted
common, examples, ggml : fix MSYS2 GCC compiler errors and warnings when building with LLAMA_CURL=ON and GGML_OPENCL=ON (ggml-org#11013)
In common/common.cpp: * Convert usage of stat() function call to check if file exists to standard library function std::filesystem::exists (error unable to match to correct function signature) * Additional conditions to check if PATH_MAX is already defined in WIN32 environment (warning it is already defined in MSYS2) In examples/run/run.cpp: * Add io.h header inclusion (error cannot find function _get_osfhandle) * Change initialisers for OVERLAPPED to empty struct (warning about uninitialised members) * Add initialiser for hFile (warning it may be uninitialised) * Add cast for curl_off_t percentage value to long int in generate_progress_prefix function (warning that curl_off_t is long long int) In ggml/src/ggml-opencl/ggml-opencl.cpp: * Initialise certain declared cl_mem variables to nullptr for greater safety (warning about B_d variable possibly used unassigned)
1 parent f5d1932 commit fa96cae

File tree

3 files changed

+16
-13
lines changed

3 files changed

+16
-13
lines changed

common/common.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <cstdarg>
1919
#include <cstring>
2020
#include <ctime>
21+
#include <filesystem>
2122
#include <fstream>
2223
#include <iostream>
2324
#include <iterator>
@@ -62,7 +63,9 @@
6263
#ifdef __linux__
6364
#include <linux/limits.h>
6465
#elif defined(_WIN32)
65-
#define PATH_MAX MAX_PATH
66+
# if !defined(PATH_MAX)
67+
# define PATH_MAX MAX_PATH
68+
# endif
6669
#else
6770
#include <sys/syslimits.h>
6871
#endif
@@ -1148,8 +1151,7 @@ static bool common_download_file(const std::string & url, const std::string & pa
11481151
#endif
11491152

11501153
// Check if the file already exists locally
1151-
struct stat model_file_info;
1152-
auto file_exists = (stat(path.c_str(), &model_file_info) == 0);
1154+
auto file_exists = std::filesystem::exists(path);
11531155

11541156
// If the file exists, check its JSON metadata companion file.
11551157
std::string metadata_path = path + ".json";

examples/run/run.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#if defined(_WIN32)
22
# include <windows.h>
3+
# include <io.h>
34
#else
45
# include <sys/file.h>
56
# include <sys/ioctl.h>
@@ -253,7 +254,7 @@ class File {
253254
return 1;
254255
}
255256

256-
OVERLAPPED overlapped = { 0 };
257+
OVERLAPPED overlapped = {};
257258
if (!LockFileEx(hFile, LOCKFILE_EXCLUSIVE_LOCK | LOCKFILE_FAIL_IMMEDIATELY, 0, MAXDWORD, MAXDWORD,
258259
&overlapped)) {
259260
fd = -1;
@@ -277,7 +278,7 @@ class File {
277278
if (fd >= 0) {
278279
# ifdef _WIN32
279280
if (hFile != INVALID_HANDLE_VALUE) {
280-
OVERLAPPED overlapped = { 0 };
281+
OVERLAPPED overlapped = {};
281282
UnlockFileEx(hFile, 0, MAXDWORD, MAXDWORD, &overlapped);
282283
}
283284
# else
@@ -293,7 +294,7 @@ class File {
293294
private:
294295
int fd = -1;
295296
# ifdef _WIN32
296-
HANDLE hFile;
297+
HANDLE hFile = nullptr;
297298
# endif
298299
};
299300

@@ -464,7 +465,7 @@ class HttpClient {
464465
return (now_downloaded_plus_file_size * 100) / total_to_download;
465466
}
466467

467-
static std::string generate_progress_prefix(curl_off_t percentage) { return fmt("%3ld%% |", percentage); }
468+
static std::string generate_progress_prefix(curl_off_t percentage) { return fmt("%3ld%% |", static_cast<long int>(percentage)); }
468469

469470
static double calculate_speed(curl_off_t now_downloaded, const std::chrono::steady_clock::time_point & start_time) {
470471
const auto now = std::chrono::steady_clock::now();

ggml/src/ggml-opencl/ggml-opencl.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2744,13 +2744,13 @@ static void ggml_cl_mul_mat(ggml_backend_t backend, const ggml_tensor * src0, co
27442744
cl_image_format img_fmt_1d;
27452745
cl_image_desc img_desc_1d;
27462746
cl_buffer_region region;
2747-
cl_mem A_image1d;
2748-
cl_mem B_image1d;
2749-
cl_mem B_sub_buffer;
2750-
cl_mem C_d;
2747+
cl_mem A_image1d = nullptr;
2748+
cl_mem B_image1d = nullptr;
2749+
cl_mem B_sub_buffer = nullptr;
2750+
cl_mem C_d = nullptr;
27512751
// for B transpose
2752-
cl_mem B_d;
2753-
cl_mem B_d_input_image;
2752+
cl_mem B_d = nullptr;
2753+
cl_mem B_d_input_image = nullptr;
27542754
// <--------------------------------------------> //
27552755

27562756
// define matrix dimensions

0 commit comments

Comments
 (0)