Skip to content

Commit 9306367

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

File tree

9 files changed

+38
-12
lines changed

9 files changed

+38
-12
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})

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,8 +290,8 @@ ggml-tune.o: ggml-tune.c ggml.h ggml-tune.h
290290
mulmat-tune: examples/mulmat-tune/mulmat-tune.c ggml.o $(OBJS)
291291
$(CC) $(CFLAGS) $^ -o mulmat-tune $(LDFLAGS)
292292

293-
test-ggml-tune: tests/test-ggml-tune.c ggml.o $(OBJS)
294-
$(CC) $(CFLAGS) $^ -o tests/test-ggml-tune $(LDFLAGS)
293+
test-mulmat-tune: tests/test-mulmat-tune.c ggml.o $(OBJS)
294+
$(CC) $(CFLAGS) $^ -o tests/test-mulmat-tune $(LDFLAGS)
295295

296296
.PHONY: tests clean
297297
tests:

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)

examples/mulmat-tune/mulmat-tune.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,8 @@ int main(int argc, char **argv) {
301301
exit(1);
302302
}
303303

304+
ggml_mulmat_tune_free(&tune);
305+
304306
if (arg_file != NULL) {
305307
printf("result was written to %s\n", arg_file);
306308
}

ggml-tune.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,24 @@ int ggml_mulmat_tune_setup_model(struct ggml_mulmat_tune *tune,
8787
return 0;
8888
}
8989

90+
int ggml_mulmat_tune_free(struct ggml_mulmat_tune *tune) {
91+
for (int i = 0; i < tune->n_shapes; i++) {
92+
struct ggml_mulmat_tune_shape *shape = &tune->shapes[i];
93+
GGML_ASSERT(shape);
94+
GGML_ASSERT(shape->arr_m);
95+
GGML_ASSERT(shape->items);
96+
free(shape->arr_m);
97+
free(shape->items);
98+
}
99+
}
100+
90101
int ggml_mulmat_tune_validate(struct ggml_mulmat_tune *tune, const char *model,
91102
int type) {
92103
enum ggml_backend backend = ggml_auto_detect_backend();
104+
105+
GGML_ASSERT(backend > GGML_BACKEND_CPU);
106+
GGML_ASSERT(tune->backend_vendor);
107+
93108
const char *backend_vendor = ggml_get_backend_vendor();
94109

95110
int rc = 0;
@@ -100,7 +115,7 @@ int ggml_mulmat_tune_validate(struct ggml_mulmat_tune *tune, const char *model,
100115
rc = -2;
101116
} else if ((int)backend != tune->backend) {
102117
rc = -3;
103-
} else if (strcmp(backend_vendor, tune->backend_vendor) != 0) {
118+
} else if (backend_vendor == NULL || strcmp(backend_vendor, tune->backend_vendor) != 0) {
104119
rc = -4;
105120
} else {
106121
// TODO

ggml-tune.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ int ggml_mulmat_tune_validate(struct ggml_mulmat_tune *tune,
7878
int ggml_mulmat_tune_setup_model(struct ggml_mulmat_tune *tune,
7979
const char *model, int m_num);
8080

81+
int ggml_mulmat_tune_free(struct ggml_mulmat_tune *tune);
82+
8183
int ggml_mulmat_tune_write_data(const struct ggml_mulmat_tune *tune, FILE *fp);
8284

8385
int ggml_mulmat_tune_read_data(struct ggml_mulmat_tune *tune, FILE *fp);

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_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]);

tests/test-mulmat-tune

363 KB
Binary file not shown.

tests/test-mulmat-tune.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,8 @@ void test_ggml_mulmat_tune_estimate_time_non_zero_NK(void) {
165165
}
166166
}
167167

168+
ggml_mulmat_tune_free(&tune);
169+
168170
printf("%2d of %2d pass\n", n_pass, n_tests * shape->n_profiles);
169171
}
170172

@@ -314,5 +316,7 @@ void test_ggml_mulmat_tune_estimate_time_zero_NK(void) {
314316
}
315317
}
316318

319+
ggml_mulmat_tune_free(&tune);
320+
317321
printf("%2d of %2d pass\n", n_pass, n_tests * shape->n_profiles);
318322
}

0 commit comments

Comments
 (0)