Skip to content

Commit 33809c9

Browse files
committed
doing what i must because i can, after the mess that is ggml-org#13892
there is so much duplicate code in each cpu arch, i expect upstream will prune it eventually arch detection has no fallback if all the arches are not found, by right we should set GGML_CPU_GENERIC i should be relaxing its the weekend
1 parent f50c793 commit 33809c9

File tree

4 files changed

+64
-11
lines changed

4 files changed

+64
-11
lines changed

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,8 @@ add_library(ggml
379379
ggml/src/ggml-cpu/traits.h
380380
ggml/src/ggml-threading.cpp
381381
ggml/src/ggml-cpu/ggml-cpu.cpp
382+
ggml/src/ggml-cpu/kcpp-quantmapper.c
383+
ggml/src/ggml-cpu/kcpp-repackmapper.cpp
382384
ggml/src/ggml-cpu/repack.cpp
383385
ggml/src/ggml-cpu/repack.h
384386
ggml/src/ggml-cpu/quants.c

Makefile

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,10 @@ endif
9090
CUBLASLD_FLAGS =
9191
CUBLAS_OBJS =
9292

93-
OBJS_FULL += ggml-alloc.o ggml-cpu-traits.o ggml-quants.o ggml-cpu-quants.o ggml-cpu-repack.o unicode.o unicode-data.o ggml-threading.o ggml-cpu-cpp.o gguf.o sgemm.o common.o sampling.o kcpputils.o
94-
OBJS_SIMPLE += ggml-alloc.o ggml-cpu-traits.o ggml-quants_noavx2.o ggml-cpu-quants_noavx2.o ggml-cpu-repack_noavx2.o unicode.o unicode-data.o ggml-threading.o ggml-cpu-cpp.o gguf.o sgemm_noavx2.o common.o sampling.o kcpputils.o
95-
OBJS_SIMPLER += ggml-alloc.o ggml-cpu-traits.o ggml-quants_noavx1.o ggml-cpu-quants_noavx1.o ggml-cpu-repack_noavx1.o unicode.o unicode-data.o ggml-threading.o ggml-cpu-cpp.o gguf.o sgemm_noavx1.o common.o sampling.o kcpputils.o
96-
OBJS_FAILSAFE += ggml-alloc.o ggml-cpu-traits.o ggml-quants_failsafe.o ggml-cpu-quants_failsafe.o ggml-cpu-repack_failsafe.o unicode.o unicode-data.o ggml-threading.o ggml-cpu-cpp.o gguf.o sgemm_failsafe.o common.o sampling.o kcpputils.o
93+
OBJS_FULL += ggml-alloc.o ggml-cpu-traits.o ggml-quants.o ggml-cpu-quants.o kcpp-quantmapper.o ggml-repack.o kcpp-repackmapper.o unicode.o unicode-data.o ggml-threading.o ggml-cpu-cpp.o gguf.o sgemm.o common.o sampling.o kcpputils.o
94+
OBJS_SIMPLE += ggml-alloc.o ggml-cpu-traits.o ggml-quants_noavx2.o ggml-cpu-quants.o kcpp-quantmapper_noavx2.o ggml-repack.o kcpp-repackmapper_noavx2.o unicode.o unicode-data.o ggml-threading.o ggml-cpu-cpp.o gguf.o sgemm_noavx2.o common.o sampling.o kcpputils.o
95+
OBJS_SIMPLER += ggml-alloc.o ggml-cpu-traits.o ggml-quants_noavx1.o ggml-cpu-quants.o kcpp-quantmapper_noavx1.o ggml-repack.o kcpp-repackmapper_noavx1.o unicode.o unicode-data.o ggml-threading.o ggml-cpu-cpp.o gguf.o sgemm_noavx1.o common.o sampling.o kcpputils.o
96+
OBJS_FAILSAFE += ggml-alloc.o ggml-cpu-traits.o ggml-quants_failsafe.o ggml-cpu-quants.o kcpp-quantmapper_failsafe.o ggml-repack.o kcpp-repackmapper_failsafe.o unicode.o unicode-data.o ggml-threading.o ggml-cpu-cpp.o gguf.o sgemm_failsafe.o common.o sampling.o kcpputils.o
9797

9898
# OS specific
9999
ifeq ($(UNAME_S),Linux)
@@ -507,23 +507,29 @@ ggml-quants_noavx1.o: ggml/src/ggml-quants.c ggml/include/ggml.h ggml/src/ggml-q
507507
$(CC) $(CFLAGS) $(SIMPLERCFLAGS) -c $< -o $@
508508
ggml-quants_failsafe.o: ggml/src/ggml-quants.c ggml/include/ggml.h ggml/src/ggml-quants.h ggml/src/ggml-common.h
509509
$(CC) $(CFLAGS) $(NONECFLAGS) -c $< -o $@
510+
511+
#cpu quants
510512
ggml-cpu-quants.o: ggml/src/ggml-cpu/quants.c ggml/include/ggml.h ggml/src/ggml-cpu/quants.h ggml/src/ggml-common.h
513+
$(CC) $(CFLAGS) -c $< -o $@
514+
kcpp-quantmapper.o: ggml/src/ggml-cpu/kcpp-quantmapper.c
511515
$(CC) $(CFLAGS) $(FULLCFLAGS) -c $< -o $@
512-
ggml-cpu-quants_noavx2.o: ggml/src/ggml-cpu/quants.c ggml/include/ggml.h ggml/src/ggml-cpu/quants.h ggml/src/ggml-common.h
516+
kcpp-quantmapper_noavx2.o: ggml/src/ggml-cpu/kcpp-quantmapper.c
513517
$(CC) $(CFLAGS) $(SIMPLECFLAGS) -c $< -o $@
514-
ggml-cpu-quants_noavx1.o: ggml/src/ggml-cpu/quants.c ggml/include/ggml.h ggml/src/ggml-cpu/quants.h ggml/src/ggml-common.h
518+
kcpp-quantmapper_noavx1.o: ggml/src/ggml-cpu/kcpp-quantmapper.c
515519
$(CC) $(CFLAGS) $(SIMPLERCFLAGS) -c $< -o $@
516-
ggml-cpu-quants_failsafe.o: ggml/src/ggml-cpu/quants.c ggml/include/ggml.h ggml/src/ggml-cpu/quants.h ggml/src/ggml-common.h
520+
kcpp-quantmapper_failsafe.o: ggml/src/ggml-cpu/kcpp-quantmapper.c
517521
$(CC) $(CFLAGS) $(NONECFLAGS) -c $< -o $@
518522

519523
#aarch64 repack
520-
ggml-cpu-repack.o: ggml/src/ggml-cpu/repack.cpp ggml/include/ggml.h ggml/src/ggml-cpu/repack.h
524+
ggml-repack.o: ggml/src/ggml-cpu/repack.cpp ggml/include/ggml.h ggml/src/ggml-cpu/repack.h
525+
$(CXX) $(CXXFLAGS) -c $< -o $@
526+
kcpp-repackmapper.o: ggml/src/ggml-cpu/kcpp-repackmapper.cpp
521527
$(CXX) $(CXXFLAGS) $(FULLCFLAGS) -c $< -o $@
522-
ggml-cpu-repack_noavx2.o: ggml/src/ggml-cpu/repack.cpp ggml/include/ggml.h ggml/src/ggml-cpu/repack.h
528+
kcpp-repackmapper_noavx2.o: ggml/src/ggml-cpu/kcpp-repackmapper.cpp
523529
$(CXX) $(CXXFLAGS) $(SIMPLECFLAGS) -c $< -o $@
524-
ggml-cpu-repack_noavx1.o: ggml/src/ggml-cpu/repack.cpp ggml/include/ggml.h ggml/src/ggml-cpu/repack.h
530+
kcpp-repackmapper_noavx1.o: ggml/src/ggml-cpu/kcpp-repackmapper.cpp
525531
$(CXX) $(CXXFLAGS) $(SIMPLERCFLAGS) -c $< -o $@
526-
ggml-cpu-repack_failsafe.o: ggml/src/ggml-cpu/repack.cpp ggml/include/ggml.h ggml/src/ggml-cpu/repack.h
532+
kcpp-repackmapper_failsafe.o: ggml/src/ggml-cpu/kcpp-repackmapper.cpp
527533
$(CXX) $(CXXFLAGS) $(NONECFLAGS) -c $< -o $@
528534

529535
#sgemm
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//LCPP had to go and split up our nice all in one cpu quant handling. It's always something eh?
2+
//Now, we need to determine at compile time which subfile to load for kcpp.
3+
//priority goes X86_64 > ARM/AARCH > everything else. may god help us all.
4+
#if defined(__x86_64__) || defined(_M_X64) || defined(__i386__) || defined(_M_IX86) || defined(__amd64__) || defined(__AMD64__)
5+
#pragma message("KoboldCpp Compiling Quants for x86/x64")
6+
#include "arch/x86/quants.c"
7+
#elif defined(__aarch64__) || defined(_M_ARM64) || defined(__arm__) || defined(_M_ARM) || defined(__arm64__) || defined(__ARM64__)
8+
#pragma message("KoboldCpp Compiling Quants for ARM")
9+
#include "arch/arm/quants.c"
10+
#elif defined(__powerpc64__) || defined(__powerpc__) || defined(__ppc__) || defined(__PPC__) || defined(__ppc64le__)
11+
#pragma message("KoboldCpp Compiling Quants for PowerPC")
12+
#include "arch/powerpc/quants.c"
13+
#elif defined(__loongarch__) || defined(__loongarch64)
14+
#pragma message("KoboldCpp Compiling Quants for LoongArch")
15+
#include "arch/loongarch/quants.c"
16+
#elif defined(__riscv) && (__riscv_xlen == 64)
17+
#pragma message("KoboldCpp Compiling Quants for RISCV")
18+
#include "arch/riscv/quants.c"
19+
#elif defined(__s390x__)
20+
#pragma message("KoboldCpp Compiling Quants for S390X")
21+
#include "arch/s390/quants.c"
22+
#else
23+
#pragma message("KoboldCpp Cannot Compile Quants! Unknown Architecture!")
24+
#endif
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//LCPP had to go and split up our nice all in one cpu quant handling. It's always something eh?
2+
//Now, we need to determine at compile time which subfile to load for kcpp.
3+
//priority goes X86_64 > ARM/AARCH > everything else. may god help us all.
4+
#if defined(__x86_64__) || defined(_M_X64) || defined(__i386__) || defined(_M_IX86) || defined(__amd64__) || defined(__AMD64__)
5+
#pragma message("KoboldCpp Compiling Repack for x86/x64")
6+
#include "arch/x86/repack.cpp"
7+
#elif defined(__aarch64__) || defined(_M_ARM64) || defined(__arm__) || defined(_M_ARM) || defined(__arm64__) || defined(__ARM64__)
8+
#pragma message("KoboldCpp Compiling Repack for ARM")
9+
#include "arch/arm/repack.cpp"
10+
#elif defined(__powerpc64__) || defined(__powerpc__) || defined(__ppc__) || defined(__PPC__) || defined(__ppc64le__)
11+
#pragma message("KoboldCpp Compiling Repack for PowerPC")
12+
#elif defined(__loongarch__) || defined(__loongarch64)
13+
#pragma message("KoboldCpp Compiling Repack for LoongArch")
14+
#elif defined(__riscv) && (__riscv_xlen == 64)
15+
#pragma message("KoboldCpp Compiling Repack for RISCV")
16+
#include "arch/riscv/repack.cpp"
17+
#elif defined(__s390x__)
18+
#pragma message("KoboldCpp Compiling Repack for S390X")
19+
#else
20+
#pragma message("KoboldCpp Cannot Compile Repack! Unknown Architecture!")
21+
#endif

0 commit comments

Comments
 (0)