Skip to content

Commit cb13ef8

Browse files
authored
remove CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS (#10797)
other windows build fixes
1 parent 4064c0e commit cb13ef8

File tree

14 files changed

+80
-69
lines changed

14 files changed

+80
-69
lines changed

examples/CMakeLists.txt

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,12 @@ else()
2020
add_subdirectory(batched)
2121
add_subdirectory(embedding)
2222
add_subdirectory(eval-callback)
23-
add_subdirectory(gbnf-validator)
23+
24+
if (NOT WIN32)
25+
# disabled on Windows because it uses internal functions not exported with LLAMA_API
26+
add_subdirectory(gbnf-validator)
27+
endif()
28+
2429
add_subdirectory(gguf-hash)
2530
add_subdirectory(gguf-split)
2631
add_subdirectory(gguf)
@@ -51,7 +56,10 @@ else()
5156
add_subdirectory(convert-llama2c-to-ggml)
5257
add_subdirectory(cvector-generator)
5358
add_subdirectory(export-lora)
54-
add_subdirectory(quantize-stats)
59+
if (NOT WIN32)
60+
# disabled on Windows because it uses internal functions not exported with LLAMA_API
61+
add_subdirectory(quantize-stats)
62+
endif()
5563
add_subdirectory(llava)
5664
if (GGML_RPC)
5765
add_subdirectory(rpc)

examples/gguf-split/gguf-split.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ struct split_strategy {
287287
}
288288

289289
void print_info() {
290-
printf("n_split: %ld\n", ctx_outs.size());
290+
printf("n_split: %zu\n", ctx_outs.size());
291291
int i_split = 0;
292292
for (auto & ctx_out : ctx_outs) {
293293
// re-calculate the real gguf size for each split (= metadata size + total size of all tensors)
@@ -297,7 +297,7 @@ struct split_strategy {
297297
total_size += ggml_nbytes(t);
298298
}
299299
total_size = total_size / 1000 / 1000; // convert to megabytes
300-
printf("split %05d: n_tensors = %d, total_size = %ldM\n", i_split + 1, gguf_get_n_tensors(ctx_out), total_size);
300+
printf("split %05d: n_tensors = %d, total_size = %zuM\n", i_split + 1, gguf_get_n_tensors(ctx_out), total_size);
301301
i_split++;
302302
}
303303
}

examples/llama-bench/llama-bench.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1521,7 +1521,7 @@ int main(int argc, char ** argv) {
15211521
for (const auto & inst : params_instances) {
15221522
params_idx++;
15231523
if (params.progress) {
1524-
fprintf(stderr, "llama-bench: benchmark %d/%ld: starting\n", params_idx, params_count);
1524+
fprintf(stderr, "llama-bench: benchmark %d/%zu: starting\n", params_idx, params_count);
15251525
}
15261526
// keep the same model between tests when possible
15271527
if (!lmodel || !prev_inst || !inst.equal_mparams(*prev_inst)) {
@@ -1573,14 +1573,14 @@ int main(int argc, char ** argv) {
15731573
// warmup run
15741574
if (t.n_prompt > 0) {
15751575
if (params.progress) {
1576-
fprintf(stderr, "llama-bench: benchmark %d/%ld: warmup prompt run\n", params_idx, params_count);
1576+
fprintf(stderr, "llama-bench: benchmark %d/%zu: warmup prompt run\n", params_idx, params_count);
15771577
}
15781578
//test_prompt(ctx, std::min(t.n_batch, std::min(t.n_prompt, 32)), 0, t.n_batch, t.n_threads);
15791579
test_prompt(ctx, t.n_prompt, t.n_batch, t.n_threads);
15801580
}
15811581
if (t.n_gen > 0) {
15821582
if (params.progress) {
1583-
fprintf(stderr, "llama-bench: benchmark %d/%ld: warmup generation run\n", params_idx, params_count);
1583+
fprintf(stderr, "llama-bench: benchmark %d/%zu: warmup generation run\n", params_idx, params_count);
15841584
}
15851585
test_gen(ctx, 1, t.n_threads);
15861586
}
@@ -1592,14 +1592,14 @@ int main(int argc, char ** argv) {
15921592

15931593
if (t.n_prompt > 0) {
15941594
if (params.progress) {
1595-
fprintf(stderr, "llama-bench: benchmark %d/%ld: prompt run %d/%d\n", params_idx, params_count,
1595+
fprintf(stderr, "llama-bench: benchmark %d/%zu: prompt run %d/%d\n", params_idx, params_count,
15961596
i + 1, params.reps);
15971597
}
15981598
test_prompt(ctx, t.n_prompt, t.n_batch, t.n_threads);
15991599
}
16001600
if (t.n_gen > 0) {
16011601
if (params.progress) {
1602-
fprintf(stderr, "llama-bench: benchmark %d/%ld: generation run %d/%d\n", params_idx, params_count,
1602+
fprintf(stderr, "llama-bench: benchmark %d/%zu: generation run %d/%d\n", params_idx, params_count,
16031603
i + 1, params.reps);
16041604
}
16051605
test_gen(ctx, t.n_gen, t.n_threads);

examples/retrieval/retrieval.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ int main(int argc, char ** argv) {
143143
std::vector<chunk> file_chunk = chunk_file(context_file, params.chunk_size, params.chunk_separator);
144144
chunks.insert(chunks.end(), file_chunk.begin(), file_chunk.end());
145145
}
146-
LOG_INF("Number of chunks: %ld\n", chunks.size());
146+
LOG_INF("Number of chunks: %zu\n", chunks.size());
147147

148148
llama_backend_init();
149149
llama_numa_init(params.numa);

examples/tokenize/tokenize.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ int main(int raw_argc, char ** raw_argv) {
394394
}
395395

396396
if (show_token_count) {
397-
printf("Total number of tokens: %ld\n", tokens.size());
397+
printf("Total number of tokens: %zu\n", tokens.size());
398398
}
399399
// silence valgrind
400400
llama_free(ctx);

ggml/CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,13 @@ else()
3232
endif()
3333
endif()
3434

35+
# remove the lib prefix on win32 mingw
36+
if (WIN32)
37+
set(CMAKE_STATIC_LIBRARY_PREFIX "")
38+
set(CMAKE_SHARED_LIBRARY_PREFIX "")
39+
set(CMAKE_SHARED_MODULE_PREFIX "")
40+
endif()
41+
3542
option(BUILD_SHARED_LIBS "ggml: build shared libraries" ${BUILD_SHARED_LIBS_DEFAULT})
3643
option(GGML_BACKEND_DL "ggml: build backends as dynamic libraries (requires BUILD_SHARED_LIBS)" OFF)
3744

ggml/src/CMakeLists.txt

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -194,11 +194,6 @@ endif()
194194

195195
if (WIN32)
196196
add_compile_definitions(_CRT_SECURE_NO_WARNINGS)
197-
198-
if (BUILD_SHARED_LIBS)
199-
# TODO: should not use this
200-
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
201-
endif()
202197
endif()
203198

204199
# ggml

ggml/src/ggml-cpu/amx/amx.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ static const char * ggml_backend_amx_buffer_type_get_name(ggml_backend_buffer_ty
122122
}
123123

124124
static ggml_backend_buffer_t ggml_backend_amx_buffer_type_alloc_buffer(ggml_backend_buffer_type_t buft, size_t size) {
125-
void * data = aligned_alloc(TENSOR_ALIGNMENT, size);
125+
void * data = ggml_aligned_malloc(size);
126126
if (data == NULL) {
127127
fprintf(stderr, "%s: failed to allocate buffer of size %zu\n", __func__, size);
128128
return NULL;

ggml/src/ggml-cpu/ggml-cpu.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,7 @@ struct ggml_arm_arch_features_type {
126126
#endif
127127
#include <windows.h>
128128

129-
130-
#if !defined(__clang__)
129+
#if defined(_MSC_VER) && !defined(__clang__)
131130
#define GGML_CACHE_ALIGN __declspec(align(GGML_CACHE_LINE))
132131

133132
typedef volatile LONG atomic_int;
@@ -12945,7 +12944,7 @@ static thread_ret_t ggml_graph_compute_secondary_thread(void* data);
1294512944
#include "windows.h"
1294612945

1294712946
// TODO: support > 64 CPUs
12948-
bool ggml_thread_apply_affinity(bool * mask) {
12947+
static bool ggml_thread_apply_affinity(bool * mask) {
1294912948
HANDLE h = GetCurrentThread();
1295012949
uint64_t bitmask = 0ULL;
1295112950

ggml/src/ggml-impl.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ static inline int ggml_up(int n, int m) {
7474
//
7575

7676
GGML_ATTRIBUTE_FORMAT(2, 3)
77-
void ggml_log_internal (enum ggml_log_level level, const char * format, ...);
78-
void ggml_log_callback_default(enum ggml_log_level level, const char * text, void * user_data);
77+
GGML_API void ggml_log_internal (enum ggml_log_level level, const char * format, ...);
78+
GGML_API void ggml_log_callback_default(enum ggml_log_level level, const char * text, void * user_data);
7979

8080
#define GGML_LOG(...) ggml_log_internal(GGML_LOG_LEVEL_NONE , __VA_ARGS__)
8181
#define GGML_LOG_INFO(...) ggml_log_internal(GGML_LOG_LEVEL_INFO , __VA_ARGS__)
@@ -304,8 +304,8 @@ struct ggml_cgraph ggml_graph_view(struct ggml_cgraph * cgraph, int i0, int i1);
304304

305305
// Memory allocation
306306

307-
void * ggml_aligned_malloc(size_t size);
308-
void ggml_aligned_free(void * ptr, size_t size);
307+
GGML_API void * ggml_aligned_malloc(size_t size);
308+
GGML_API void ggml_aligned_free(void * ptr, size_t size);
309309

310310
// FP16 to FP32 conversion
311311

ggml/src/ggml-threading.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
#pragma once
22

3+
#include "ggml.h"
4+
35
#ifdef __cplusplus
46
extern "C" {
57
#endif
68

7-
void ggml_critical_section_start(void);
8-
void ggml_critical_section_end(void);
9+
GGML_API void ggml_critical_section_start(void);
10+
GGML_API void ggml_critical_section_end(void);
911

1012
#ifdef __cplusplus
1113
}

src/CMakeLists.txt

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,3 @@
1-
# TODO: should not use this
2-
if (WIN32)
3-
if (BUILD_SHARED_LIBS)
4-
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
5-
endif()
6-
endif()
7-
81
llama_add_compile_flags()
92

103
#

src/llama.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1794,7 +1794,7 @@ struct llama_file {
17941794
DWORD bufLen = FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
17951795
NULL, error_code, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPSTR)&lpMsgBuf, 0, NULL);
17961796
if (!bufLen) {
1797-
ret = format("Win32 error code: %s", error_code);
1797+
ret = format("Win32 error code: %lx", error_code);
17981798
} else {
17991799
ret = lpMsgBuf;
18001800
LocalFree(lpMsgBuf);
@@ -2132,7 +2132,7 @@ struct llama_mmap {
21322132
HMODULE hKernel32 = GetModuleHandleW(L"kernel32.dll");
21332133

21342134
// may fail on pre-Windows 8 systems
2135-
pPrefetchVirtualMemory = reinterpret_cast<decltype(pPrefetchVirtualMemory)> (GetProcAddress(hKernel32, "PrefetchVirtualMemory"));
2135+
pPrefetchVirtualMemory = (decltype(pPrefetchVirtualMemory))(void *) GetProcAddress(hKernel32, "PrefetchVirtualMemory");
21362136

21372137
if (pPrefetchVirtualMemory) {
21382138
// advise the kernel to preload the mapped memory
@@ -21577,7 +21577,7 @@ float * llama_get_embeddings_ith(struct llama_context * ctx, int32_t i) {
2157721577
throw std::runtime_error(format("negative index out of range [0, %d)", ctx->n_outputs));
2157821578
}
2157921579
} else if ((size_t) i >= ctx->output_ids.size()) {
21580-
throw std::runtime_error(format("out of range [0, %lu)", ctx->output_ids.size()));
21580+
throw std::runtime_error(format("out of range [0, %zu)", ctx->output_ids.size()));
2158121581
} else {
2158221582
j = ctx->output_ids[i];
2158321583
}

tests/CMakeLists.txt

Lines changed: 40 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -84,38 +84,50 @@ llama_test(test-tokenizer-0 NAME test-tokenizer-0-qwen2 ARGS ${CMAKE
8484
llama_test(test-tokenizer-0 NAME test-tokenizer-0-refact ARGS ${CMAKE_CURRENT_SOURCE_DIR}/../models/ggml-vocab-refact.gguf)
8585
llama_test(test-tokenizer-0 NAME test-tokenizer-0-starcoder ARGS ${CMAKE_CURRENT_SOURCE_DIR}/../models/ggml-vocab-starcoder.gguf)
8686

87-
# build test-tokenizer-1-bpe target once and add many tests
88-
add_executable(test-tokenizer-1-bpe test-tokenizer-1-bpe.cpp)
89-
target_link_libraries(test-tokenizer-1-bpe PRIVATE common)
90-
install(TARGETS test-tokenizer-1-bpe RUNTIME)
91-
92-
# TODO: disabled due to slowness
93-
#llama_test(test-tokenizer-1-bpe NAME test-tokenizer-1-aquila ARGS ${CMAKE_CURRENT_SOURCE_DIR}/../models/ggml-vocab-aquila.gguf)
94-
#llama_test(test-tokenizer-1-bpe NAME test-tokenizer-1-falcon ARGS ${CMAKE_CURRENT_SOURCE_DIR}/../models/ggml-vocab-falcon.gguf)
95-
#llama_test(test-tokenizer-1-bpe NAME test-tokenizer-1-gpt-2 ARGS ${CMAKE_CURRENT_SOURCE_DIR}/../models/ggml-vocab-gpt-2.gguf)
96-
#llama_test(test-tokenizer-1-bpe NAME test-tokenizer-1-gpt-neox ARGS ${CMAKE_CURRENT_SOURCE_DIR}/../models/ggml-vocab-gpt-neox.gguf)
97-
#llama_test(test-tokenizer-1-bpe NAME test-tokenizer-1-llama-bpe ARGS ${CMAKE_CURRENT_SOURCE_DIR}/../models/ggml-vocab-llama-bpe.gguf --ignore-merges)
98-
#llama_test(test-tokenizer-1-bpe NAME test-tokenizer-1-mpt ARGS ${CMAKE_CURRENT_SOURCE_DIR}/../models/ggml-vocab-mpt.gguf)
99-
#llama_test(test-tokenizer-1-bpe NAME test-tokenizer-1-refact ARGS ${CMAKE_CURRENT_SOURCE_DIR}/../models/ggml-vocab-refact.gguf)
100-
#llama_test(test-tokenizer-1-bpe NAME test-tokenizer-1-starcoder ARGS ${CMAKE_CURRENT_SOURCE_DIR}/../models/ggml-vocab-starcoder.gguf)
101-
102-
# build test-tokenizer-1-spm target once and add many tests
103-
add_executable(test-tokenizer-1-spm test-tokenizer-1-spm.cpp)
104-
target_link_libraries(test-tokenizer-1-spm PRIVATE common)
105-
install(TARGETS test-tokenizer-1-spm RUNTIME)
106-
107-
llama_test(test-tokenizer-1-spm NAME test-tokenizer-1-llama-spm ARGS ${CMAKE_CURRENT_SOURCE_DIR}/../models/ggml-vocab-llama-spm.gguf)
108-
#llama_test(test-tokenizer-1-spm NAME test-tokenizer-1-baichuan ARGS ${CMAKE_CURRENT_SOURCE_DIR}/../models/ggml-vocab-baichuan.gguf)
109-
110-
# llama_target_and_test(test-double-float.cpp) # SLOW
87+
88+
if (NOT WIN32)
89+
# these tests are disabled on Windows because they use internal functions not exported with LLAMA_API
90+
llama_target_and_test(test-sampling.cpp)
91+
llama_target_and_test(test-grammar-parser.cpp)
92+
llama_target_and_test(test-grammar-integration.cpp)
93+
llama_target_and_test(test-llama-grammar.cpp)
94+
# TODO: disabled on loongarch64 because the ggml-ci node lacks Python 3.8
95+
if (NOT ${CMAKE_SYSTEM_PROCESSOR} MATCHES "loongarch64")
96+
llama_target_and_test(test-json-schema-to-grammar.cpp WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/..)
97+
target_include_directories(test-json-schema-to-grammar PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../examples/server)
98+
endif()
99+
100+
101+
# build test-tokenizer-1-bpe target once and add many tests
102+
add_executable(test-tokenizer-1-bpe test-tokenizer-1-bpe.cpp)
103+
target_link_libraries(test-tokenizer-1-bpe PRIVATE common)
104+
install(TARGETS test-tokenizer-1-bpe RUNTIME)
105+
106+
# TODO: disabled due to slowness
107+
#llama_test(test-tokenizer-1-bpe NAME test-tokenizer-1-aquila ARGS ${CMAKE_CURRENT_SOURCE_DIR}/../models/ggml-vocab-aquila.gguf)
108+
#llama_test(test-tokenizer-1-bpe NAME test-tokenizer-1-falcon ARGS ${CMAKE_CURRENT_SOURCE_DIR}/../models/ggml-vocab-falcon.gguf)
109+
#llama_test(test-tokenizer-1-bpe NAME test-tokenizer-1-gpt-2 ARGS ${CMAKE_CURRENT_SOURCE_DIR}/../models/ggml-vocab-gpt-2.gguf)
110+
#llama_test(test-tokenizer-1-bpe NAME test-tokenizer-1-gpt-neox ARGS ${CMAKE_CURRENT_SOURCE_DIR}/../models/ggml-vocab-gpt-neox.gguf)
111+
#llama_test(test-tokenizer-1-bpe NAME test-tokenizer-1-llama-bpe ARGS ${CMAKE_CURRENT_SOURCE_DIR}/../models/ggml-vocab-llama-bpe.gguf --ignore-merges)
112+
#llama_test(test-tokenizer-1-bpe NAME test-tokenizer-1-mpt ARGS ${CMAKE_CURRENT_SOURCE_DIR}/../models/ggml-vocab-mpt.gguf)
113+
#llama_test(test-tokenizer-1-bpe NAME test-tokenizer-1-refact ARGS ${CMAKE_CURRENT_SOURCE_DIR}/../models/ggml-vocab-refact.gguf)
114+
#llama_test(test-tokenizer-1-bpe NAME test-tokenizer-1-starcoder ARGS ${CMAKE_CURRENT_SOURCE_DIR}/../models/ggml-vocab-starcoder.gguf)
115+
116+
# build test-tokenizer-1-spm target once and add many tests
117+
add_executable(test-tokenizer-1-spm test-tokenizer-1-spm.cpp)
118+
target_link_libraries(test-tokenizer-1-spm PRIVATE common)
119+
install(TARGETS test-tokenizer-1-spm RUNTIME)
120+
121+
llama_test(test-tokenizer-1-spm NAME test-tokenizer-1-llama-spm ARGS ${CMAKE_CURRENT_SOURCE_DIR}/../models/ggml-vocab-llama-spm.gguf)
122+
#llama_test(test-tokenizer-1-spm NAME test-tokenizer-1-baichuan ARGS ${CMAKE_CURRENT_SOURCE_DIR}/../models/ggml-vocab-baichuan.gguf)
123+
124+
# llama_target_and_test(test-double-float.cpp) # SLOW
125+
endif()
126+
111127
llama_target_and_test(test-log.cpp)
112128
llama_target_and_test(test-arg-parser.cpp)
113-
llama_target_and_test(test-sampling.cpp)
114129
llama_target_and_test(test-chat-template.cpp)
115130

116-
llama_target_and_test(test-grammar-parser.cpp)
117-
llama_target_and_test(test-grammar-integration.cpp)
118-
llama_target_and_test(test-llama-grammar.cpp)
119131
# llama_target_and_test(test-opt.cpp) # SLOW
120132
llama_target_and_test(test-backend-ops.cpp)
121133

@@ -130,11 +142,6 @@ if (NOT GGML_BACKEND_DL)
130142
llama_target_and_test(test-rope.cpp)
131143
endif()
132144

133-
# TODO: disabled on loongarch64 because the ggml-ci node lacks Python 3.8
134-
if (NOT ${CMAKE_SYSTEM_PROCESSOR} MATCHES "loongarch64")
135-
llama_target_and_test(test-json-schema-to-grammar.cpp WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/..)
136-
target_include_directories(test-json-schema-to-grammar PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../examples/server)
137-
endif()
138145

139146
# dummy executable - not installed
140147
get_filename_component(TEST_TARGET test-c.c NAME_WE)

0 commit comments

Comments
 (0)