mirror of
				https://github.com/ggml-org/llama.cpp.git
				synced 2025-10-31 08:51:55 +00:00 
			
		
		
		
	common, examples, ggml : fix MSYS2 GCC compiler errors and warnings when building with LLAMA_CURL=ON and GGML_OPENCL=ON (#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)
This commit is contained in:
		| @@ -18,6 +18,7 @@ | |||||||
| #include <cstdarg> | #include <cstdarg> | ||||||
| #include <cstring> | #include <cstring> | ||||||
| #include <ctime> | #include <ctime> | ||||||
|  | #include <filesystem> | ||||||
| #include <fstream> | #include <fstream> | ||||||
| #include <iostream> | #include <iostream> | ||||||
| #include <iterator> | #include <iterator> | ||||||
| @@ -62,7 +63,9 @@ | |||||||
| #ifdef __linux__ | #ifdef __linux__ | ||||||
| #include <linux/limits.h> | #include <linux/limits.h> | ||||||
| #elif defined(_WIN32) | #elif defined(_WIN32) | ||||||
| #define PATH_MAX MAX_PATH | #   if !defined(PATH_MAX) | ||||||
|  | #   define PATH_MAX MAX_PATH | ||||||
|  | #   endif | ||||||
| #else | #else | ||||||
| #include <sys/syslimits.h> | #include <sys/syslimits.h> | ||||||
| #endif | #endif | ||||||
| @@ -1148,8 +1151,7 @@ static bool common_download_file(const std::string & url, const std::string & pa | |||||||
| #endif | #endif | ||||||
|  |  | ||||||
|     // Check if the file already exists locally |     // Check if the file already exists locally | ||||||
|     struct stat model_file_info; |     auto file_exists = std::filesystem::exists(path); | ||||||
|     auto file_exists = (stat(path.c_str(), &model_file_info) == 0); |  | ||||||
|  |  | ||||||
|     // If the file exists, check its JSON metadata companion file. |     // If the file exists, check its JSON metadata companion file. | ||||||
|     std::string metadata_path = path + ".json"; |     std::string metadata_path = path + ".json"; | ||||||
|   | |||||||
| @@ -1,5 +1,6 @@ | |||||||
| #if defined(_WIN32) | #if defined(_WIN32) | ||||||
| #    include <windows.h> | #    include <windows.h> | ||||||
|  | #    include <io.h> | ||||||
| #else | #else | ||||||
| #    include <sys/file.h> | #    include <sys/file.h> | ||||||
| #    include <sys/ioctl.h> | #    include <sys/ioctl.h> | ||||||
| @@ -253,7 +254,7 @@ class File { | |||||||
|                 return 1; |                 return 1; | ||||||
|             } |             } | ||||||
|  |  | ||||||
|             OVERLAPPED overlapped = { 0 }; |             OVERLAPPED overlapped = {}; | ||||||
|             if (!LockFileEx(hFile, LOCKFILE_EXCLUSIVE_LOCK | LOCKFILE_FAIL_IMMEDIATELY, 0, MAXDWORD, MAXDWORD, |             if (!LockFileEx(hFile, LOCKFILE_EXCLUSIVE_LOCK | LOCKFILE_FAIL_IMMEDIATELY, 0, MAXDWORD, MAXDWORD, | ||||||
|                             &overlapped)) { |                             &overlapped)) { | ||||||
|                 fd = -1; |                 fd = -1; | ||||||
| @@ -277,7 +278,7 @@ class File { | |||||||
|         if (fd >= 0) { |         if (fd >= 0) { | ||||||
| #    ifdef _WIN32 | #    ifdef _WIN32 | ||||||
|             if (hFile != INVALID_HANDLE_VALUE) { |             if (hFile != INVALID_HANDLE_VALUE) { | ||||||
|                 OVERLAPPED overlapped = { 0 }; |                 OVERLAPPED overlapped = {}; | ||||||
|                 UnlockFileEx(hFile, 0, MAXDWORD, MAXDWORD, &overlapped); |                 UnlockFileEx(hFile, 0, MAXDWORD, MAXDWORD, &overlapped); | ||||||
|             } |             } | ||||||
| #    else | #    else | ||||||
| @@ -293,7 +294,7 @@ class File { | |||||||
|   private: |   private: | ||||||
|     int fd = -1; |     int fd = -1; | ||||||
| #    ifdef _WIN32 | #    ifdef _WIN32 | ||||||
|     HANDLE hFile; |     HANDLE hFile = nullptr; | ||||||
| #    endif | #    endif | ||||||
| }; | }; | ||||||
|  |  | ||||||
| @@ -464,7 +465,7 @@ class HttpClient { | |||||||
|         return (now_downloaded_plus_file_size * 100) / total_to_download; |         return (now_downloaded_plus_file_size * 100) / total_to_download; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     static std::string generate_progress_prefix(curl_off_t percentage) { return fmt("%3ld%% |", percentage); } |     static std::string generate_progress_prefix(curl_off_t percentage) { return fmt("%3ld%% |", static_cast<long int>(percentage)); } | ||||||
|  |  | ||||||
|     static double calculate_speed(curl_off_t now_downloaded, const std::chrono::steady_clock::time_point & start_time) { |     static double calculate_speed(curl_off_t now_downloaded, const std::chrono::steady_clock::time_point & start_time) { | ||||||
|         const auto                          now             = std::chrono::steady_clock::now(); |         const auto                          now             = std::chrono::steady_clock::now(); | ||||||
|   | |||||||
| @@ -2744,13 +2744,13 @@ static void ggml_cl_mul_mat(ggml_backend_t backend, const ggml_tensor * src0, co | |||||||
|     cl_image_format     img_fmt_1d; |     cl_image_format     img_fmt_1d; | ||||||
|     cl_image_desc       img_desc_1d; |     cl_image_desc       img_desc_1d; | ||||||
|     cl_buffer_region    region; |     cl_buffer_region    region; | ||||||
|     cl_mem              A_image1d; |     cl_mem              A_image1d = nullptr; | ||||||
|     cl_mem              B_image1d; |     cl_mem              B_image1d = nullptr; | ||||||
|     cl_mem              B_sub_buffer; |     cl_mem              B_sub_buffer = nullptr; | ||||||
|     cl_mem              C_d; |     cl_mem              C_d = nullptr; | ||||||
|     // for B transpose |     // for B transpose | ||||||
|     cl_mem B_d; |     cl_mem B_d = nullptr; | ||||||
|     cl_mem B_d_input_image; |     cl_mem B_d_input_image = nullptr; | ||||||
|     // <--------------------------------------------> // |     // <--------------------------------------------> // | ||||||
|  |  | ||||||
|     // define matrix dimensions |     // define matrix dimensions | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Peter
					Peter