Skip to content

Commit

Permalink
Upgrade to Cosmopolitan v3.8.0
Browse files Browse the repository at this point in the history
The latest cosmocc allows us to use Clang for compilation which improves
build latency for this project by 3x.
  • Loading branch information
jart committed Aug 31, 2024
1 parent c7c4d65 commit ea39f26
Show file tree
Hide file tree
Showing 14 changed files with 22 additions and 26 deletions.
8 changes: 4 additions & 4 deletions build/config.mk
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#── vi: set noet ft=make ts=8 sw=8 fenc=utf-8 :vi ────────────────────┘

PREFIX = /usr/local
COSMOCC = .cosmocc/3.7.1
COSMOCC = .cosmocc/3.8.0
TOOLCHAIN = $(COSMOCC)/bin/cosmo

CC = $(TOOLCHAIN)cc
Expand All @@ -14,7 +14,7 @@ INSTALL = install

ARFLAGS = rcsD
CXXFLAGS = -frtti -std=gnu++23
CCFLAGS = -O2 -fexceptions -fsignaling-nans -ffunction-sections -fdata-sections
CCFLAGS = -O2 -g -fexceptions -ffunction-sections -fdata-sections -mclang
CPPFLAGS_ = -iquote. -mcosmo -DGGML_MULTIPLATFORM -Wno-attributes -DLLAMAFILE_DEBUG
TARGET_ARCH = -Xx86_64-mtune=znver4

Expand Down Expand Up @@ -52,5 +52,5 @@ clean:; rm -rf o
.PHONY: distclean
distclean:; rm -rf o .cosmocc

.cosmocc/3.7.1:
build/download-cosmocc.sh $@ 3.7.1 13b65b0e659b493bd82f3d0a319d0265d66f849839e484aa2a54191024711e85
.cosmocc/3.8.0:
build/download-cosmocc.sh $@ 3.8.0 813c6b2f95062d2e0a845307a79505424cb98cb038e8013334f8a22e3b92a474
5 changes: 4 additions & 1 deletion llama.cpp/BUILD.mk
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ o/$(MODE)/llama.cpp/ggml-vector-amd-f16c.o \
o/$(MODE)/llama.cpp/ggml-vector-amd-fma.o \
o/$(MODE)/llama.cpp/ggml-vector-arm80.o \
o/$(MODE)/llama.cpp/ggml-vector-arm82.o: \
private CCFLAGS += -O3
private CCFLAGS += -O3 -mgcc

o/$(MODE)/llama.cpp/ggml-alloc.o \
o/$(MODE)/llama.cpp/ggml-backend.o \
Expand All @@ -60,6 +60,9 @@ o/$(MODE)/llama.cpp/ggml-alloc.o \
o/$(MODE)/llama.cpp/common.o: \
private CCFLAGS += -Os

o/$(MODE)/llama.cpp/unicode-data.o: \
private CCFLAGS += -mgcc

o/$(MODE)/llama.cpp/ggml-quants.o: private CXXFLAGS += -Os
o/$(MODE)/llama.cpp/ggml-quants-amd-k8.o: private TARGET_ARCH += -Xx86_64-mtune=k8
o/$(MODE)/llama.cpp/ggml-quants-amd-ssse3.o: private TARGET_ARCH += -Xx86_64-mtune=core2 -Xx86_64-mssse3
Expand Down
2 changes: 1 addition & 1 deletion llama.cpp/ggml-backend.c
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ GGML_CALL static void ggml_backend_registry_init(void) {

// add forward decls here to avoid including the backend headers
/* #ifdef GGML_USE_CUDA [jart] */
/* extern GGML_CALL void ggml_backend_cuda_reg_devices(void); */
extern GGML_CALL void ggml_backend_cuda_reg_devices(void);
ggml_backend_cuda_reg_devices();
/* #endif */

Expand Down
11 changes: 4 additions & 7 deletions llama.cpp/ggml.c
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,10 @@ inline static void * ggml_aligned_malloc(size_t size) {
if (result != 0) {
// Handle allocation failure
const char *error_desc = "unknown allocation error";
switch (result) {
case EINVAL:
error_desc = "invalid alignment value";
break;
case ENOMEM:
error_desc = "insufficient memory";
break;
if (result == EINVAL) {
error_desc = "invalid alignment value";
} else if (result == ENOMEM) {
error_desc = "insufficient memory";
}
GGML_PRINT("%s: %s (attempted to allocate %6.2f MB)\n", __func__, error_desc, size/(1024.0*1024.0));
GGML_ABORT("fatal error");
Expand Down
2 changes: 1 addition & 1 deletion llama.cpp/llama-bench/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include <string>
#include <unistd.h>
#include <vector>
#include <tool/args/args.h>
#include <cosmo.h>
#include <stdatomic.h>
#include <third_party/nsync/futex.internal.h>

Expand Down
2 changes: 0 additions & 2 deletions llama.cpp/llava/BUILD.mk
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ LLAMA_CPP_LLAVA_HDRS = $(filter %.h,$(LLAMA_CPP_LLAVA_FILES))
LLAMA_CPP_LLAVA_SRCS = $(filter %.cpp,$(LLAMA_CPP_LLAVA_FILES))
LLAMA_CPP_LLAVA_OBJS = $(LLAMA_CPP_LLAVA_SRCS:%.cpp=o/$(MODE)/%.o)

.PHONY: tool/args/args.h

o/$(MODE)/llama.cpp/llava/llava.a: \
$(LLAMA_CPP_LLAVA_OBJS)

Expand Down
2 changes: 1 addition & 1 deletion llama.cpp/main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include <string>
#include <unistd.h>
#include <vector>
#include <tool/args/args.h>
#include <cosmo.h>

#include "llamafile/version.h"
#include "llama.cpp/llama.h"
Expand Down
3 changes: 1 addition & 2 deletions llama.cpp/server/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@
#include <condition_variable>
#include <atomic>
#include <signal.h>
#include <libc/calls/pledge.h>
#include <tool/args/args.h>
#include <cosmo.h>
#include <libc/dce.h>

double g_prompt_per_second_jart;
Expand Down
2 changes: 1 addition & 1 deletion llamafile/BUILD.mk
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ o/$(MODE)/llamafile/tinyblas_cpu_sgemm_amd_fma.o \
o/$(MODE)/llamafile/tinyblas_cpu_sgemm_amd_zen4.o \
o/$(MODE)/llamafile/tinyblas_cpu_sgemm_arm80.o \
o/$(MODE)/llamafile/tinyblas_cpu_sgemm_arm82.o: \
private CCFLAGS += -O3 -fopenmp
private CCFLAGS += -O3 -fopenmp -mgcc

################################################################################
# testing
Expand Down
4 changes: 2 additions & 2 deletions llamafile/ansiblas.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace ansiBLAS {

static constexpr int KN = 8;

alignas(64) union Vector {
union alignas(64) Vector {
double v[KN];
};

Expand Down Expand Up @@ -94,7 +94,7 @@ struct ansiBLAS {
}

template <int RM, int RN>
__target_clones("avx512f,fma") void gemm(int m0, int m, int n0, int n) {
void gemm(int m0, int m, int n0, int n) {
int ytiles = (m - m0) / RM;
int xtiles = (n - n0) / RN;
int tiles = xtiles * ytiles;
Expand Down
2 changes: 1 addition & 1 deletion llamafile/debug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ static void on_sigfpe(int sig, siginfo_t *si, void *arg) {
}
if (!once) {
struct StackFrame sf = {.next = (struct StackFrame *)ctx->uc_mcontext.BP,
.addr = ctx->uc_mcontext.PC};
.addr = (intptr_t)ctx->uc_mcontext.PC};
ShowBacktrace(2, &sf);
const struct ggml_cgraph *g;
if ((g = llamafile_debug_graph)) {
Expand Down
2 changes: 1 addition & 1 deletion llamafile/server/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
// limitations under the License.

#include <assert.h>
#include <tool/args/args.h>
#include <cosmo.h>

#include "llama.cpp/llama.h"
#include "llamafile/llamafile.h"
Expand Down
2 changes: 1 addition & 1 deletion llamafile/tokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
#include "llamafile.h"
#include "version.h"

#include <cosmo.h>
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <tool/args/args.h>

#include "llama.cpp/llama.h"

Expand Down
1 change: 0 additions & 1 deletion whisper.cpp/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include "llama.cpp/json.h"

#include <cosmo.h>
#include <tool/args/args.h>
#include <cmath>
#include <fstream>
#include <cstdio>
Expand Down

0 comments on commit ea39f26

Please sign in to comment.