From 8a8859ced414960149cd19871bd0fdf5a198e208 Mon Sep 17 00:00:00 2001 From: mike dupont Date: Thu, 23 Nov 2023 15:16:41 -0500 Subject: [PATCH] update --- ggml-internal.hpp | 93 +++++++++++++++++++++++++++++++++++++++++++++++ ggml.cpp | 93 ++--------------------------------------------- print.hpp | 9 ----- 3 files changed, 97 insertions(+), 98 deletions(-) create mode 100644 ggml-internal.hpp diff --git a/ggml-internal.hpp b/ggml-internal.hpp new file mode 100644 index 000000000..b44826a37 --- /dev/null +++ b/ggml-internal.hpp @@ -0,0 +1,93 @@ +struct ggml_context { + size_t mem_size; + void * mem_buffer; + bool mem_buffer_owned; + bool no_alloc; + bool no_alloc_save; // this is used to save the no_alloc state when using scratch buffers + + int n_objects; + + struct ggml_object * objects_begin; + struct ggml_object * objects_end; + + struct ggml_scratch scratch; + struct ggml_scratch scratch_save; + + ggml_context(): + mem_size(0), + mem_buffer(0), + mem_buffer_owned(0), + no_alloc(0), + no_alloc_save(0), + n_objects(0), + objects_begin(0), + objects_end(0), + scratch(), + scratch_save() + { + + } +}; + +struct ggml_context_container { + bool used; + + struct ggml_context context; + + ggml_context_container(): used(0),context(){ + + } +}; +typedef int ggml_lock_t; +typedef pthread_t ggml_thread_t; +typedef int ggml_lock_t; +typedef pthread_t ggml_thread_t; +typedef volatile LONG atomic_int; +typedef atomic_int atomic_bool; +typedef HANDLE pthread_t; + +typedef DWORD thread_ret_t; +typedef void * thread_ret_t; +typedef double ggml_float; + +#define ggml_lock_init(x) UNUSED(x) +#define ggml_lock_destroy(x) UNUSED(x) +#define ggml_lock_lock(x) UNUSED(x) +#define ggml_lock_unlock(x) UNUSED(x) + +#define GGML_LOCK_INITIALIZER 0 + + + +#define ggml_thread_create pthread_create +#define ggml_thread_join pthread_join + + + +//typedef pthread_spinlock_t ggml_lock_t; + +//#define ggml_lock_init(x) pthread_spin_init(x, PTHREAD_PROCESS_PRIVATE) +//#define ggml_lock_destroy pthread_spin_destroy +//#define ggml_lock_lock pthread_spin_lock +//#define ggml_lock_unlock pthread_spin_unlock + + + +#define ggml_lock_init(x) UNUSED(x) +#define ggml_lock_destroy(x) UNUSED(x) +#if defined(__x86_64__) || (defined(_MSC_VER) && defined(_M_AMD64)) +#define ggml_lock_lock(x) _mm_pause() +#else +#define ggml_lock_lock(x) UNUSED(x) +#endif +#define ggml_lock_unlock(x) UNUSED(x) + +#define GGML_LOCK_INITIALIZER 0 + + + +#define ggml_thread_create pthread_create +#define ggml_thread_join pthread_join + + + diff --git a/ggml.cpp b/ggml.cpp index 27f078ca1..65b0d11c3 100644 --- a/ggml.cpp +++ b/ggml.cpp @@ -48,8 +48,6 @@ #include -typedef volatile LONG atomic_int; -typedef atomic_int atomic_bool; static void atomic_store(atomic_int * ptr, LONG val) { InterlockedExchange(ptr, val); @@ -64,9 +62,6 @@ static LONG atomic_fetch_sub(atomic_int * ptr, LONG dec) { return atomic_fetch_add(ptr, -(dec)); } -typedef HANDLE pthread_t; - -typedef DWORD thread_ret_t; static int pthread_create(pthread_t * out, void * unused, thread_ret_t(*func)(void *), void * arg) { (void) unused; HANDLE handle = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) func, arg, 0, NULL); @@ -100,7 +95,7 @@ using namespace std; #include #endif -typedef void * thread_ret_t; + #include #include @@ -112,6 +107,8 @@ typedef void * thread_ret_t; #include #endif +#include "ggml-internal.hpp" + #if defined(__APPLE__) #include #endif @@ -281,7 +278,7 @@ inline static void * ggml_aligned_malloc(size_t size) { #endif // floating point type used to accumulate sums -typedef double ggml_float; + #undef MIN #undef MAX @@ -1621,46 +1618,6 @@ static void ggml_setup_op_has_task_pass(void) { // ggml context // -struct ggml_context { - size_t mem_size; - void * mem_buffer; - bool mem_buffer_owned; - bool no_alloc; - bool no_alloc_save; // this is used to save the no_alloc state when using scratch buffers - - int n_objects; - - struct ggml_object * objects_begin; - struct ggml_object * objects_end; - - struct ggml_scratch scratch; - struct ggml_scratch scratch_save; - - ggml_context(): - mem_size(0), - mem_buffer(0), - mem_buffer_owned(0), - no_alloc(0), - no_alloc_save(0), - n_objects(0), - objects_begin(0), - objects_end(0), - scratch(), - scratch_save() - { - - } -}; - -struct ggml_context_container { - bool used; - - struct ggml_context context; - - ggml_context_container(): used(0),context(){ - - } -}; // // NUMA support @@ -15766,48 +15723,6 @@ void ggml_graph_clear(struct ggml_cgraph * cgraph) { // //#define GGML_LOCK_INITIALIZER OS_UNFAIR_LOCK_INIT -typedef int ggml_lock_t; - -#define ggml_lock_init(x) UNUSED(x) -#define ggml_lock_destroy(x) UNUSED(x) -#define ggml_lock_lock(x) UNUSED(x) -#define ggml_lock_unlock(x) UNUSED(x) - -#define GGML_LOCK_INITIALIZER 0 - -typedef pthread_t ggml_thread_t; - -#define ggml_thread_create pthread_create -#define ggml_thread_join pthread_join - -#else - -//typedef pthread_spinlock_t ggml_lock_t; - -//#define ggml_lock_init(x) pthread_spin_init(x, PTHREAD_PROCESS_PRIVATE) -//#define ggml_lock_destroy pthread_spin_destroy -//#define ggml_lock_lock pthread_spin_lock -//#define ggml_lock_unlock pthread_spin_unlock - -typedef int ggml_lock_t; - -#define ggml_lock_init(x) UNUSED(x) -#define ggml_lock_destroy(x) UNUSED(x) -#if defined(__x86_64__) || (defined(_MSC_VER) && defined(_M_AMD64)) -#define ggml_lock_lock(x) _mm_pause() -#else -#define ggml_lock_lock(x) UNUSED(x) -#endif -#define ggml_lock_unlock(x) UNUSED(x) - -#define GGML_LOCK_INITIALIZER 0 - -typedef pthread_t ggml_thread_t; - -#define ggml_thread_create pthread_create -#define ggml_thread_join pthread_join - -#endif // Android's libc implementation "bionic" does not support setting affinity #if defined(__linux__) && !defined(__BIONIC__) diff --git a/print.hpp b/print.hpp index 5961a0c28..83ae1e10b 100644 --- a/print.hpp +++ b/print.hpp @@ -141,9 +141,6 @@ REFL_TYPE(ggml_opt_context) REFL_FIELD(ctx) REFL_END -//REFL_TYPE(gguf_context) -//REFL_END - REFL_TYPE(gguf_init_params) REFL_END @@ -151,12 +148,6 @@ REFL_TYPE(ggml_something) REFL_FIELD(type_name) REFL_END - -//REFL_TYPE() -// REFL_FIELD(d) -//REFL_TYPE() - -// incomplete ttype // REFL_TYPE(ggml_context) // REFL_FIELD(mem_size) // REFL_FIELD(mem_buffer)