opencoti-llamafile / patches /0097-native-elf-cmake.patch
ManniX-ITA's picture
Upload folder using huggingface_hub
b69d9d8 verified
Raw
History Blame
5.98 kB
opencoti patch 0097 β€” native-ELF CMake lane (#619, secondary artifact of #613)
Makes the vendored tree buildable as a standard Linux ELF llama-server via
plain cmake + g++/nvcc (rpath libggml-cuda.so; clean gdb/nsys), alongside the
cosmocc Makefile lane which is UNTOUCHED (BUILD.mk lists sources explicitly
and never reads CMakeLists; the new stub TU is CMake-lane-only).
- 5 CMakeLists surgical hooks: add opencoti TUs absent from upstream source
lists (ggml-turbo-quant.c, ggml-neo-pipeline.cpp, ggml-iqk-flash-attn.cpp
-> ggml-base; dca.cpp -> llama; pcie-profile.cpp -> common; ELF stubs ->
ggml-cpu) + compile the Mozilla-overlay server.cpp with -Dmain=llama_server
(upstream defines llama_server directly; the cosmo lane renames at build).
- NEW ggml/src/ggml-cpu/opencoti-elf-stubs.cpp: return-false stubs for the
cosmocc-bound llamafile/sgemm.cpp CPU fastpath dispatchers (mixmul,
mixmul_needs, mixmul_iqk, fa_* helpers) β€” every call site falls back to the
upstream generic path (same contract as fa_helpers_unsupported.cpp), so the
ELF build loses only CPU fastpaths, never correctness.
Build (bs2-proven 2026-07-05): cmake -S llama.cpp -B build-elf -DGGML_CUDA=ON
-DGGML_CUDA_FA_ALL_QUANTS=ON (REQUIRED β€” turbo/TCQ FA-VEC instances are only
globbed under this flag; cosmo lane always sets it) -DCMAKE_CUDA_ARCHITECTURES=120
-DCMAKE_BUILD_TYPE=Release -DLLAMA_CURL=OFF -DGGML_NATIVE=OFF.
Gate: A4B -ngl 99 boot, dual-ctx assistant-MTP accept 0.764, 310.2 tps decode.
--- a/llama.cpp/ggml/src/CMakeLists.txt
+++ b/llama.cpp/ggml/src/CMakeLists.txt
@@ -205,6 +205,9 @@
ggml-threading.cpp
ggml-threading.h
ggml-quants.c
+ ggml-turbo-quant.c # opencoti-hook: native-elf-cmake (#619) β€” turbo/TCQ CPU quant, in cosmo BUILD.mk but absent here
+ ggml-neo-pipeline.cpp # opencoti-hook: native-elf-cmake (#619) β€” NEO pipeline control (pure std)
+ ggml-iqk-flash-attn.cpp # opencoti-hook: native-elf-cmake (#619) β€” iqk FA enable flag (pure ggml)
ggml-quants.h
gguf.cpp)
--- a/llama.cpp/src/CMakeLists.txt
+++ b/llama.cpp/src/CMakeLists.txt
@@ -18,6 +18,7 @@
llama-context.cpp
llama-cparams.cpp
llama-grammar.cpp
+ dca.cpp # opencoti-hook: native-elf-cmake (#619) β€” DCA (matches neither llama-*.cpp list nor models/ glob)
llama-graph.cpp
llama-hparams.cpp
llama-impl.cpp
--- a/llama.cpp/common/CMakeLists.txt
+++ b/llama.cpp/common/CMakeLists.txt
@@ -66,6 +66,7 @@
chat.cpp
chat.h
common.cpp
+ pcie-profile.cpp # opencoti-hook: native-elf-cmake (#619) β€” PCIe bandwidth profile (rolling-KV)
common.h
console.cpp
console.h
--- a/llama.cpp/ggml/src/ggml-cpu/CMakeLists.txt
+++ b/llama.cpp/ggml/src/ggml-cpu/CMakeLists.txt
@@ -52,6 +52,7 @@
ggml-cpu/vec.cpp
ggml-cpu/ops.h
ggml-cpu/ops.cpp
+ ggml-cpu/opencoti-elf-stubs.cpp # opencoti-hook: native-elf-cmake (#619) β€” sgemm.cpp dispatcher stubs (cosmo lane uses real sgemm.cpp)
)
target_compile_features(${GGML_CPU_NAME} PRIVATE c_std_11 cxx_std_17)
--- a/llama.cpp/tools/server/CMakeLists.txt
+++ b/llama.cpp/tools/server/CMakeLists.txt
@@ -31,6 +31,11 @@
set(TARGET llama-server-impl)
+# opencoti-hook: native-elf-cmake (#619) β€” the Mozilla overlay's server.cpp defines
+# `int main` (the cosmocc Makefile lane renames it at compile time); upstream
+# defines `llama_server` directly. Rename here so main.cpp's wrapper links.
+set_source_files_properties(server.cpp PROPERTIES COMPILE_DEFINITIONS "main=llama_server")
+
add_library(${TARGET}
server.cpp
server-http.cpp
--- /dev/null
+++ b/llama.cpp/ggml/src/ggml-cpu/opencoti-elf-stubs.cpp
@@ -0,0 +1,57 @@
+// opencoti-hook: native-elf-cmake (#619) β€” see docs/features/llamafile_build.md
+//
+// CMake(native-ELF)-lane-ONLY stubs for the llamafile/sgemm.cpp CPU fastpath
+// dispatchers. sgemm.cpp includes <cosmo.h> (cosmocc runtime CPUID/dispatch)
+// and cannot compile under plain g++; every call site treats a false return
+// as "not handled, use the upstream ggml helper" (ggml-cpu.c:1723 mixmul_iqk,
+// ops.cpp:8519/8560 flash-attn helpers β€” same contract as Mozilla's own
+// fa_helpers_unsupported.cpp), so these stubs are behavior-safe: the native
+// ELF build loses only the iqk/tinyBLAS *CPU* fastpaths, never correctness.
+// The cosmocc Makefile lane never compiles this file (BUILD.mk lists sources
+// explicitly) and keeps the real sgemm.cpp implementations.
+
+#include <cstddef>
+#include <cstdint>
+
+struct ggml_compute_params;
+struct ggml_tensor;
+
+extern "C" {
+
+// Top-level tinyBLAS MoE mixmul (ggml-cpu.c:1592, GGML_USE_LLAMAFILE):
+// false -> generic mul_mat_id path. _needs sizes its work buffer
+// (ggml-cpu.c:3002): 0 is consistent with mixmul never running.
+bool llamafile_mixmul(const struct ggml_compute_params *,
+ const struct ggml_tensor *,
+ const struct ggml_tensor *,
+ const struct ggml_tensor *,
+ struct ggml_tensor *) {
+ return false;
+}
+
+size_t llamafile_mixmul_needs(const struct ggml_tensor *,
+ const struct ggml_tensor *,
+ const struct ggml_tensor *) {
+ return 0;
+}
+
+bool llamafile_mixmul_iqk(long, long, long, int, int,
+ const void *, const void *, float *,
+ long, long, const void *, int, int) {
+ return false;
+}
+
+bool llamafile_fa_vec_dot_f16(int, float *, const void *, const void *) {
+ return false;
+}
+
+bool llamafile_fa_fp16_to_fp32_row(const void *, float *, int64_t) {
+ return false;
+}
+
+bool llamafile_fa_simd_gemm(float *, const float *, const float *,
+ int, int, int) {
+ return false;
+}
+
+} // extern "C"