Skip to content

Distribute and run LLMs with a single file.

Fix code compatibility issues

Justine Tunney867c7524afaf
diff --git a/llama.cpp/ggml-vector.cpp b/llama.cpp/ggml-vector.cpp
index f5e6332d..60d9d034 100644
--- a/llama.cpp/ggml-vector.cpp
+++ b/llama.cpp/ggml-vector.cpp
@@ -1,6 +1,7 @@
#include <cosmo.h>
#include <sys/auxv.h>
#include <libc/sysv/consts/hwcap.h>
+#define restrict
#include "ggml-vector.h"
extern "C" void ggml_fp16_to_fp32_row_amd_avx512bf16(const ggml_fp16_t * x, float * y, int64_t n);
diff --git a/llama.cpp/main/main.cpp b/llama.cpp/main/main.cpp
index 6f8a3657..81af6bc1 100644
--- a/llama.cpp/main/main.cpp
+++ b/llama.cpp/main/main.cpp
@@ -16,8 +16,6 @@
#include <unistd.h>
#include <vector>
#include <tool/args/args.h>
-#include <stdatomic.h>
-#include <third_party/nsync/futex.internal.h>
#include "llamafile/version.h"
#include "llama.cpp/llama.h"
@@ -36,6 +34,9 @@ static std::ostringstream * g_output_ss;
static std::vector<llama_token> * g_output_tokens;
static bool is_interacting = false;
+extern "C" int nsync_futex_wake_(int *, int, char);
+extern "C" int nsync_futex_wait_(int *, int, char, const struct timespec *);
+
static bool file_exists(const std::string &path) {
std::ifstream f(path.c_str());
return f.good();
@@ -92,7 +93,7 @@ static void write_logfile(
fclose(logfile);
}
-static atomic_int is_killed;
+static int is_killed;
static void *safe_sigint_handler(void *arg) {
while (!is_killed)
diff --git a/llamafile/debug.cpp b/llamafile/debug.cpp
index eb3acd69..2448e617 100644
--- a/llamafile/debug.cpp
+++ b/llamafile/debug.cpp
@@ -23,6 +23,7 @@
#include <fenv.h>
#include <libc/calls/struct/aarch64.internal.h>
#include <libc/calls/struct/ucontext.internal.h>
+#include <pthread.h>
#include <signal.h>
#include <termios.h>
#include <ucontext.h>
@@ -204,12 +205,12 @@ static void setup_sigfpe(void) {
}
int llamafile_trapping_enabled(int delta) {
- static _Atomic(uint32_t) once;
+ static pthread_once_t once = PTHREAD_ONCE_INIT;
bool was_enabled = g_enabled > 0;
bool is_enabled = (g_enabled += delta) > 0;
feclearexcept(FE_ALL_EXCEPT);
if (is_enabled && !was_enabled) {
- cosmo_once(&once, setup_sigfpe);
+ pthread_once(&once, setup_sigfpe);
feenableexcept(TRAPS);
}
if (!is_enabled && was_enabled) {