Skip to content

Commit 1701eeb

Browse files
committed
try fix Windows CMake build errors; fix ubuntu build error: undefined reference to 'sqrtf'
1 parent 3f5893e commit 1701eeb

File tree

4 files changed

+17
-10
lines changed

4 files changed

+17
-10
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ if (LLAMA_BLAS)
158158
endif()
159159
set(BLA_VENDOR ${LLAMA_BLAS_VENDOR})
160160
find_package(BLAS)
161-
if (BLAS_FOUND)
161+
if (BLAS_FOUND)
162162
message(STATUS "BLAS found, Libraries: ${BLAS_LIBRARIES}")
163163

164164
add_compile_options(${BLAS_LINKER_FLAGS})

examples/mulmat-tune/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
set(TARGET mulmat-tune)
22
add_executable(${TARGET} mulmat-tune.c)
3-
target_link_libraries(${TARGET} PRIVATE ggml ${CMAKE_THREAD_LIBS_INIT})
3+
target_link_libraries(${TARGET} PRIVATE ggml m ${CMAKE_THREAD_LIBS_INIT})
44
target_compile_features(${TARGET} PRIVATE c_std_11)
55
if(TARGET BUILD_INFO)
66
add_dependencies(${TARGET} BUILD_INFO)

ggml-tune.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@ int ggml_mulmat_tune_setup_model(struct ggml_mulmat_tune *tune,
9090
int ggml_mulmat_tune_validate(struct ggml_mulmat_tune *tune, const char *model,
9191
int type) {
9292
enum ggml_backend backend = ggml_auto_detect_backend();
93+
94+
GGML_ASSERT(backend > GGML_BACKEND_CPU);
95+
GGML_ASSERT(tune->backend_vendor);
96+
9397
const char *backend_vendor = ggml_get_backend_vendor();
9498

9599
int rc = 0;
@@ -100,7 +104,7 @@ int ggml_mulmat_tune_validate(struct ggml_mulmat_tune *tune, const char *model,
100104
rc = -2;
101105
} else if ((int)backend != tune->backend) {
102106
rc = -3;
103-
} else if (strcmp(backend_vendor, tune->backend_vendor) != 0) {
107+
} else if (backend_vendor == NULL || strcmp(backend_vendor, tune->backend_vendor) != 0) {
104108
rc = -4;
105109
} else {
106110
// TODO

ggml.c

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434

3535
typedef volatile LONG atomic_int;
3636
typedef atomic_int atomic_bool;
37-
typedef atomic_int atomic_flag;
37+
typedef LONG atomic_int atomic_flag;
3838

3939
static void atomic_store(atomic_int* ptr, LONG val) {
4040
InterlockedExchange(ptr, val);
@@ -49,10 +49,10 @@ static LONG atomic_fetch_sub(atomic_int* ptr, LONG dec) {
4949
return atomic_fetch_add(ptr, -(dec));
5050
}
5151

52-
static inline LONG atomic_flag_test_and_set(atomic_flag* ptr) {
52+
static inline LONG atomic_flag_test_and_set(volatile atomic_flag* ptr) {
5353
return InterlockedCompareExchange(ptr, 1, 0);
5454
}
55-
static inline LONG atomic_flag_clear(atomic_flag* ptr) {
55+
static inline LONG atomic_flag_clear(volatile atomic_flag* ptr) {
5656
return InterlockedExchange(ptr, 0);
5757
}
5858

@@ -14361,7 +14361,7 @@ void ggml_graph_compute_mul_mat_set_task_profile(struct ggml_cgraph *cgraph) {
1436114361

1436214362
const int mm_cache_len = 16;
1436314363
struct mm_cache_element mm_cache[mm_cache_len];
14364-
memset(mm_cache, 0, sizeof(mm_cache));
14364+
memset(mm_cache, 0, sizeof(struct mm_cache_element) * mm_cache_len);
1436514365

1436614366
// TODO: optimize if we are sure that the M is a fixed value.
1436714367

@@ -14489,8 +14489,6 @@ void ggml_graph_compute(struct ggml_context * ctx, struct ggml_cgraph * cgraph)
1448914489
if (n_threads > 1) {
1449014490
state_shared = (struct ggml_compute_state_shared){
1449114491
.spin = { 0 },
14492-
.mutex = PTHREAD_MUTEX_INITIALIZER,
14493-
.cond = PTHREAD_COND_INITIALIZER,
1449414492
.n_tasks = 0,
1449514493
.n_waiting = 0,
1449614494
.wait_now = false,
@@ -14500,13 +14498,18 @@ void ggml_graph_compute(struct ggml_context * ctx, struct ggml_cgraph * cgraph)
1450014498
.stop = false,
1450114499
};
1450214500

14501+
int rc;
14502+
rc = pthread_mutex_init(&state_shared.mutex, NULL);
14503+
GGML_ASSERT(rc == 0);
14504+
rc = pthread_cond_init(&state_shared.cond, NULL);
14505+
GGML_ASSERT(rc == 0);
14506+
1450314507
size_t sz_workers = sizeof(struct ggml_compute_state) * (n_threads - 1);
1450414508
workers = alloca(sz_workers);
1450514509
GGML_ASSERT(workers);
1450614510
memset(workers, 0, sz_workers);
1450714511

1450814512
// NOTE: we could delay creating workers.
14509-
int rc;
1451014513
for (int j = 0; j < n_threads - 1; j++) {
1451114514
workers[j].shared = &state_shared;
1451214515
rc = ggml_thread_create(&workers[j].thrd, NULL, ggml_graph_compute_thread, &workers[j]);

0 commit comments

Comments
 (0)