Skip to content

Commit 5bbe6a9

Browse files
mgroeber9110Marcus Groeber
and
Marcus Groeber
authored
ggml : portability fixes for VS 2017 (#12150)
* Add include files for std::min/max and std::toupper/tolower * win32: move _USE_MATH_DEFINES before includes to ensure M_PI is defined * Use GGML_RESTRICT instead of "restrict" keyword everywhere, and use "__restrict" in MSVC plain C mode * win32: only use __restrict in MSVC if C11/C17 support is not enabled --------- Co-authored-by: Marcus Groeber <[email protected]>
1 parent 20a9b8f commit 5bbe6a9

20 files changed

+547
-529
lines changed

Diff for: common/ngram-cache.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <cstdio>
88
#include <fstream>
99
#include <thread>
10+
#include <algorithm>
1011

1112
void common_ngram_cache_update(common_ngram_cache & ngram_cache, int ngram_min, int ngram_max,
1213
std::vector<llama_token> & inp, int nnew, bool print_progress) {

Diff for: common/sampling.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
#include <cmath>
66
#include <unordered_map>
7+
#include <algorithm>
78

89
// the ring buffer works similarly to std::deque, but with a fixed capacity
910
// TODO: deduplicate with llama-impl.h

Diff for: common/speculative.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "sampling.h"
66

77
#include <cstring>
8+
#include <algorithm>
89

910
#define SPEC_VOCAB_MAX_SIZE_DIFFERENCE 128
1011
#define SPEC_VOCAB_CHECK_START_TOKEN_ID 5

Diff for: examples/embedding/embedding.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "llama.h"
55

66
#include <ctime>
7+
#include <algorithm>
78

89
#if defined(_MSC_VER)
910
#pragma warning(disable: 4244 4267) // possible loss of data

Diff for: examples/lookahead/lookahead.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <cstdio>
88
#include <string>
99
#include <vector>
10+
#include <algorithm>
1011

1112
struct ngram_data {
1213
bool active = false;

Diff for: examples/parallel/parallel.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <string>
1313
#include <vector>
1414
#include <ctime>
15+
#include <algorithm>
1516

1617
// trim whitespace from the beginning and end of a string
1718
static std::string trim(const std::string & str) {

Diff for: examples/passkey/passkey.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <cstdio>
88
#include <string>
99
#include <vector>
10+
#include <algorithm>
1011

1112
static void print_usage(int, char ** argv) {
1213
LOG("\nexample usage:\n");

Diff for: examples/quantize/quantize.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <unordered_map>
99
#include <fstream>
1010
#include <cmath>
11+
#include <cctype>
1112

1213
struct quant_option {
1314
std::string name;

Diff for: examples/tts/tts.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1+
#define _USE_MATH_DEFINES // For M_PI on MSVC
2+
13
#include "arg.h"
24
#include "common.h"
35
#include "sampling.h"
46
#include "log.h"
57
#include "llama.h"
68
#include "json.hpp"
79

8-
#define _USE_MATH_DEFINES // For M_PI on MSVC
9-
1010
#include <algorithm>
1111
#include <cmath>
1212
#include <cstdio>

Diff for: ggml/include/ggml.h

+5-1
Original file line numberDiff line numberDiff line change
@@ -2140,7 +2140,11 @@ extern "C" {
21402140
# define GGML_RESTRICT
21412141
# endif
21422142
#else
2143-
# define GGML_RESTRICT restrict
2143+
# if defined (_MSC_VER) && (__STDC_VERSION__ < 201112L)
2144+
# define GGML_RESTRICT __restrict
2145+
# else
2146+
# define GGML_RESTRICT restrict
2147+
# endif
21442148
#endif
21452149
typedef void (*ggml_to_float_t) (const void * GGML_RESTRICT x, float * GGML_RESTRICT y, int64_t k);
21462150
typedef void (*ggml_from_float_t)(const float * GGML_RESTRICT x, void * GGML_RESTRICT y, int64_t k);

Diff for: ggml/src/ggml-backend-reg.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <string>
99
#include <type_traits>
1010
#include <vector>
11+
#include <cctype>
1112

1213
#ifdef _WIN32
1314
# define WIN32_LEAN_AND_MEAN

Diff for: ggml/src/ggml-backend.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <string.h>
2222
#include <string>
2323
#include <vector>
24+
#include <algorithm>
2425

2526
#ifdef __APPLE__
2627
#include <sys/types.h>

0 commit comments

Comments
 (0)