Skip to content

Commit

Permalink
try fix Windows CMake build errors; fix ubuntu build error: undefined…
Browse files Browse the repository at this point in the history
… reference to 'sqrtf'
  • Loading branch information
mqy committed May 29, 2023
1 parent 3f5893e commit 1701eeb
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 10 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ if (LLAMA_BLAS)
endif()
set(BLA_VENDOR ${LLAMA_BLAS_VENDOR})
find_package(BLAS)
if (BLAS_FOUND)
if (BLAS_FOUND)
message(STATUS "BLAS found, Libraries: ${BLAS_LIBRARIES}")

add_compile_options(${BLAS_LINKER_FLAGS})
Expand Down
2 changes: 1 addition & 1 deletion examples/mulmat-tune/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
set(TARGET mulmat-tune)
add_executable(${TARGET} mulmat-tune.c)
target_link_libraries(${TARGET} PRIVATE ggml ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries(${TARGET} PRIVATE ggml m ${CMAKE_THREAD_LIBS_INIT})
target_compile_features(${TARGET} PRIVATE c_std_11)
if(TARGET BUILD_INFO)
add_dependencies(${TARGET} BUILD_INFO)
Expand Down
6 changes: 5 additions & 1 deletion ggml-tune.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ int ggml_mulmat_tune_setup_model(struct ggml_mulmat_tune *tune,
int ggml_mulmat_tune_validate(struct ggml_mulmat_tune *tune, const char *model,
int type) {
enum ggml_backend backend = ggml_auto_detect_backend();

GGML_ASSERT(backend > GGML_BACKEND_CPU);
GGML_ASSERT(tune->backend_vendor);

const char *backend_vendor = ggml_get_backend_vendor();

int rc = 0;
Expand All @@ -100,7 +104,7 @@ int ggml_mulmat_tune_validate(struct ggml_mulmat_tune *tune, const char *model,
rc = -2;
} else if ((int)backend != tune->backend) {
rc = -3;
} else if (strcmp(backend_vendor, tune->backend_vendor) != 0) {
} else if (backend_vendor == NULL || strcmp(backend_vendor, tune->backend_vendor) != 0) {
rc = -4;
} else {
// TODO
Expand Down
17 changes: 10 additions & 7 deletions ggml.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

typedef volatile LONG atomic_int;
typedef atomic_int atomic_bool;
typedef atomic_int atomic_flag;
typedef LONG atomic_int atomic_flag;

static void atomic_store(atomic_int* ptr, LONG val) {
InterlockedExchange(ptr, val);
Expand All @@ -49,10 +49,10 @@ static LONG atomic_fetch_sub(atomic_int* ptr, LONG dec) {
return atomic_fetch_add(ptr, -(dec));
}

static inline LONG atomic_flag_test_and_set(atomic_flag* ptr) {
static inline LONG atomic_flag_test_and_set(volatile atomic_flag* ptr) {
return InterlockedCompareExchange(ptr, 1, 0);
}
static inline LONG atomic_flag_clear(atomic_flag* ptr) {
static inline LONG atomic_flag_clear(volatile atomic_flag* ptr) {
return InterlockedExchange(ptr, 0);
}

Expand Down Expand Up @@ -14361,7 +14361,7 @@ void ggml_graph_compute_mul_mat_set_task_profile(struct ggml_cgraph *cgraph) {

const int mm_cache_len = 16;
struct mm_cache_element mm_cache[mm_cache_len];
memset(mm_cache, 0, sizeof(mm_cache));
memset(mm_cache, 0, sizeof(struct mm_cache_element) * mm_cache_len);

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

Expand Down Expand Up @@ -14489,8 +14489,6 @@ void ggml_graph_compute(struct ggml_context * ctx, struct ggml_cgraph * cgraph)
if (n_threads > 1) {
state_shared = (struct ggml_compute_state_shared){
.spin = { 0 },
.mutex = PTHREAD_MUTEX_INITIALIZER,
.cond = PTHREAD_COND_INITIALIZER,
.n_tasks = 0,
.n_waiting = 0,
.wait_now = false,
Expand All @@ -14500,13 +14498,18 @@ void ggml_graph_compute(struct ggml_context * ctx, struct ggml_cgraph * cgraph)
.stop = false,
};

int rc;
rc = pthread_mutex_init(&state_shared.mutex, NULL);
GGML_ASSERT(rc == 0);
rc = pthread_cond_init(&state_shared.cond, NULL);
GGML_ASSERT(rc == 0);

size_t sz_workers = sizeof(struct ggml_compute_state) * (n_threads - 1);
workers = alloca(sz_workers);
GGML_ASSERT(workers);
memset(workers, 0, sz_workers);

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

0 comments on commit 1701eeb

Please sign in to comment.