frontend/strata_context.cpp replaces tools/server/server-context.cpp. The other seven server files (server-http, -queue, -task, -common, -chat, -schema, -stream) compile unmodified from the submodule into the static library strata_llama_server; frontend/ui_stub/ supplies the empty web-UI asset table that server-http.cpp references. The context runs one slot: the engine is a child process spoken to over its line protocol (docs/BACKENDS.md), a vocab-only llama_model provides tokenizing, the chat template and the reasoning and tool-call parsers, and the server's own task and result types carry the OpenAI JSON, SSE framing and client-disconnect cancel. Routes kept: /health, /v1/models, /v1/chat/completions, /tokenize, /detokenize. The strata engine's 8-token reserve is kept out of max_new. A supervisor thread ends the process with exit code 1 when the engine dies, for a unit with Restart=on-failure. frontend/engine.hpp is the child adapter: fork+exec, READY/INFO, GEN/GENI, T/PP/RESUME/DONE/ERR/FATAL, STOP with drain to DONE, non-blocking reap. quit() and the supervisor's reap_exit() share the pid through an atomic that quit() takes over by exchange, and only a positive local copy ever reaches kill(). The first draft kept a plain pid_t and the supervisor set it to -1 on reaping, so a SIGTERM during shutdown raced into kill(-1, SIGKILL), which killed every process of the user; it did so twice on 2026-10-17. Build: STRATA_FRONTEND (default on) gates the llama.cpp libraries and the front end, not CUDA, so they build on a machine without a GPU. Makefile: unbiased-strata joins `make build`; `make frontend` builds it alone without CUDA into build-frontend/; `make test` builds engine_test there and runs it and frontend/tests/e2e.sh against a fake engine (frontend/tests/fake-engine.py). The nvcc probes run only when there is an nvcc and only the build and configure goals demand one. UPSTREAM.md records all of it. Verified on macOS arm64 without CUDA: `make frontend` and `make test` pass. engine_test, 7 cases: READY, a request, STOP mid-request with drain and a clean next request, a 100k-token burst the caller abandons, ERR leaves the adapter usable, the engine dying mid-request is diagnosed, a DONE with the wrong prompt size is visible. e2e.sh, 12 checks: /health, /v1/models, a non-streaming chat with content, finish and usage, a stream whose deltas join to the content and end with finish_reason and [DONE], a client that disconnects mid-stream (the server logs the cancel and the next request completes), an oversize prompt refused with 400, a tokenize/detokenize round trip. Zero new patch lines to llama.cpp, so the step-4 gate of PLAN.md section 5 passes and design C stands. Not yet run against a real engine. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
83 lines
5.4 KiB
Makefile
83 lines
5.4 KiB
Makefile
# UnbiasedStrata 2 build. Needs CMake 3.24+, a C++20 compiler, a C compiler and a CUDA 12.x toolkit with its driver.
|
|
# Nothing is downloaded: ggml, llama, common and mtmd come from the third_party/llama.cpp submodule.
|
|
#
|
|
# git clone <repo> && cd <repo>
|
|
# git submodule update --init
|
|
# make build # build/bin/{strata,strata-poly,libstrata_kq.so,unbiased-strata}
|
|
# make test # the front end against a fake engine; no GPU needed
|
|
#
|
|
BUILD_DIR ?= build
|
|
# CUDA archs: GTX 10 (61), RTX 20 / GTX 16 (75), RTX 30 (86), RTX 40 (89). Any arch below 75 turns on upstream's
|
|
# STRATA_EXPERIMENTAL_SM60, which needs a CUDA 12.x toolkit (13 dropped sm_61). `make build CUDA_ARCHS=86` builds for
|
|
# one card and is several times faster. An arch the installed nvcc cannot compile is dropped with a note.
|
|
CUDA_ARCHS ?= 61;75;86;89
|
|
# nvcc: on PATH, else the toolkit's usual place (RunPod images and distro packages differ). NVCC=/path overrides.
|
|
NVCC ?= $(or $(shell command -v nvcc 2>/dev/null),$(wildcard /usr/local/cuda/bin/nvcc))
|
|
ifeq ($(NVCC),)
|
|
ifneq ($(filter build configure,$(MAKECMDGOALS)),)
|
|
$(error nvcc not found on PATH or in /usr/local/cuda/bin; install a CUDA 12.x toolkit or set NVCC=/path/to/nvcc)
|
|
endif
|
|
endif
|
|
# Everything below that runs nvcc is skipped when there is none (a laptop running `make frontend` or `make test`).
|
|
ifneq ($(NVCC),)
|
|
NVCC_ARCHS := $(shell $(NVCC) --list-gpu-arch 2>/dev/null | sed 's/compute_//' | tr '\n' ' ')
|
|
ifneq ($(NVCC_ARCHS),)
|
|
CUDA_ARCHS_DROPPED := $(strip $(foreach a,$(subst ;, ,$(CUDA_ARCHS)),$(if $(filter $(firstword $(subst -, ,$(a))),$(NVCC_ARCHS)),,$(a))))
|
|
ifneq ($(CUDA_ARCHS_DROPPED),)
|
|
$(info make: nvcc cannot compile CUDA arch(s) $(CUDA_ARCHS_DROPPED); building without them)
|
|
CUDA_ARCHS := $(subst $(eval) ,;,$(strip $(foreach a,$(subst ;, ,$(CUDA_ARCHS)),$(if $(filter $(firstword $(subst -, ,$(a))),$(NVCC_ARCHS)),$(a),))))
|
|
endif
|
|
endif
|
|
SM60 := $(shell echo "$(CUDA_ARCHS)" | tr ';' '\n' | sed 's/-.*//' | grep -E '^[0-9]+$$' | awk '$$1 < 75 { print "ON"; exit }')
|
|
SM60_FLAG := $(if $(SM60),-DSTRATA_EXPERIMENTAL_SM60=ON,)
|
|
# PORTABLE=1: an AVX2 baseline for the CPU expert kernels instead of -march=native (build on one box, run on another).
|
|
PORTABLE_FLAG := $(if $(PORTABLE),-DSTRATA_PORTABLE=ON,)
|
|
# One compiler for the C, C++ and CUDA host sides. nvcc accepts GCC only up to a version (CUDA 12.4: 13); when the
|
|
# C++ files are compiled by a newer g++ and nvcc falls back to an older one, two libstdc++ generations meet at the link
|
|
# and it fails on __cxa_call_terminate (upstream #1645). The probe tries the versioned compilers newest first and hands
|
|
# CMake absolute paths, so `g++` resolving to a version nvcc rejects cannot slip through. HOSTCXX=/usr/bin/g++-13
|
|
# overrides it.
|
|
HOSTCXX ?= $(shell for c in g++-15 g++-14 g++-13 g++-12 g++-11 g++; do p=$$(command -v $$c 2>/dev/null) || continue; \
|
|
t=$$(mktemp /tmp/strata-hc-XXXXXX.cu) && printf 'int main(){return 0;}\n' > $$t && \
|
|
if $(NVCC) -ccbin $$p -c $$t -o /dev/null >/dev/null 2>&1; then rm -f $$t; echo $$p; break; fi; rm -f $$t; done)
|
|
HOSTCC := $(subst g++,gcc,$(HOSTCXX))
|
|
endif
|
|
COMPILER_FLAGS := $(if $(HOSTCXX),-DCMAKE_C_COMPILER=$(HOSTCC) -DCMAKE_CXX_COMPILER=$(HOSTCXX) -DCMAKE_CUDA_HOST_COMPILER=$(HOSTCXX),)
|
|
# capped: inside a container nproc reports the host's CPUs, not the container's quota
|
|
JOBS ?= $(shell n=$$(nproc 2>/dev/null || echo 4); [ $$n -gt 16 ] && n=16; echo $$n)
|
|
# what `make build` produces; upstream's `all` also builds about 70 parity and bench programs
|
|
TARGETS := strata strata-poly strata_kq unbiased-strata
|
|
|
|
.PHONY: build configure clean test
|
|
|
|
configure:
|
|
@test -f third_party/llama.cpp/ggml/CMakeLists.txt || \
|
|
{ echo "third_party/llama.cpp is empty: run 'git submodule update --init' first"; exit 1; }
|
|
cmake -S . -B $(BUILD_DIR) -DCMAKE_BUILD_TYPE=Release -DSTRATA_ENABLE_CUDA=ON -DSTRATA_NATIVE_EXPERTS=ON \
|
|
-DSTRATA_MMQ_KQUANTS=ON -DSTRATA_Q6K_EXPERTS=ON -DSTRATA_BUILD_TESTS=OFF \
|
|
"-DCMAKE_CUDA_ARCHITECTURES=$(CUDA_ARCHS)" $(SM60_FLAG) $(PORTABLE_FLAG) $(COMPILER_FLAGS) -DCMAKE_CUDA_COMPILER=$(NVCC) \
|
|
-DCMAKE_RUNTIME_OUTPUT_DIRECTORY=$(abspath $(BUILD_DIR))/bin \
|
|
-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=$(abspath $(BUILD_DIR))/bin $(CMAKE_EXTRA)
|
|
|
|
build: configure
|
|
cmake --build $(BUILD_DIR) -j $(JOBS) --target $(TARGETS)
|
|
@echo "built:"; ls -1 $(BUILD_DIR)/bin/strata $(BUILD_DIR)/bin/strata-poly $(BUILD_DIR)/bin/libstrata_kq.so $(BUILD_DIR)/bin/unbiased-strata
|
|
|
|
# The front end alone, without CUDA: for a laptop or a CI box. Needs only a C++20 compiler and CMake.
|
|
.PHONY: frontend
|
|
frontend:
|
|
cmake -S . -B $(BUILD_DIR)-frontend -DCMAKE_BUILD_TYPE=Release -DSTRATA_ENABLE_CUDA=OFF -DSTRATA_BUILD_TESTS=OFF \
|
|
-DCMAKE_RUNTIME_OUTPUT_DIRECTORY=$(abspath $(BUILD_DIR))-frontend/bin $(CMAKE_EXTRA)
|
|
cmake --build $(BUILD_DIR)-frontend -j $(JOBS) --target unbiased-strata
|
|
|
|
# The front end's tests, against a fake engine (frontend/tests/fake-engine.py): the adapter's cases (cancel, drain,
|
|
# backpressure, child exit, ERR) and the HTTP surface a coding agent touches (frontend/tests/e2e.sh). Needs python3
|
|
# and curl; no GPU and no model. Runs in the CUDA-free build directory, so it works on the build box and on a laptop.
|
|
test: frontend
|
|
cmake --build $(BUILD_DIR)-frontend -j $(JOBS) --target engine_test
|
|
$(BUILD_DIR)-frontend/engine_test frontend/tests/fake-engine.py
|
|
frontend/tests/e2e.sh $(BUILD_DIR)-frontend/bin/unbiased-strata
|
|
|
|
clean:
|
|
rm -rf $(BUILD_DIR)
|