mirror of
https://github.com/skeeto/w64devkit.git
synced 2026-10-23 06:08:56 +03:00
Remove llama.mak
Upstream has made some choices that make maintaining llama.mak increasingly impractical. It's not really needed now that w64devkit has cmake anyway.
This commit is contained in:
@@ -1,256 +0,0 @@
|
||||
# llama.cpp server and DLL build (CPU or Vulkan inference)
|
||||
#
|
||||
# The official llama.cpp build is CMake. This makefile is a replacement
|
||||
# build system that produces llama.dll (with the correct exports) and
|
||||
# llama-server.exe using w64dk. No source changes required.
|
||||
#
|
||||
# The DLL exports the public API and no more, and is readily usable as a
|
||||
# component in another project (game engine, etc.). The server EXE is
|
||||
# fully functional on Windows 7 or later. It is not linked against the
|
||||
# DLL because that's not useful.
|
||||
#
|
||||
# Invoke this makefile in the llama.cpp source tree:
|
||||
#
|
||||
# $ make -j$(nproc) -f path/to/w64devkit/contrib/llama.mak
|
||||
#
|
||||
# To build with Vulkan GPU support, set VULKAN_SDK:
|
||||
#
|
||||
# $ make ... VULKAN_SDK=C:/VulkanSDK/1.4.328.1
|
||||
#
|
||||
# Incremental builds are unsupported, so clean rebuild after pulling. It
|
||||
# was last tested at b8565, and an update will inevitably break it.
|
||||
|
||||
CC = gcc
|
||||
CXX = g++
|
||||
CROSS =
|
||||
CPPFLAGS = -w -O2 -march=x86-64-v3
|
||||
LDFLAGS = -s
|
||||
HOST_CXX = c++
|
||||
|
||||
.SUFFIXES: .c .cpp .o
|
||||
|
||||
# Parse GGML version from ggml/CMakeLists.txt
|
||||
ggml_major := $(shell \
|
||||
sed -n 's/^set(GGML_VERSION_MAJOR \(.*\))/\1/p' ggml/CMakeLists.txt \
|
||||
)
|
||||
ggml_minor := $(shell \
|
||||
sed -n 's/^set(GGML_VERSION_MINOR \(.*\))/\1/p' ggml/CMakeLists.txt \
|
||||
)
|
||||
ggml_patch := $(shell \
|
||||
sed -n 's/^set(GGML_VERSION_PATCH \(.*\))/\1/p' ggml/CMakeLists.txt \
|
||||
)
|
||||
ggml_version = $(ggml_major).$(ggml_minor).$(ggml_patch)
|
||||
ggml_commit := $(shell git -C ggml rev-parse --short HEAD || echo unknown)
|
||||
|
||||
def = \
|
||||
-DGGML_COMMIT='"$(ggml_commit)"' \
|
||||
-DGGML_USE_CPU \
|
||||
-DGGML_VERSION='"$(ggml_version)"' \
|
||||
-DLLAMA_BUILD_UI \
|
||||
-DLLAMA_USE_HTTPLIB
|
||||
inc = \
|
||||
-I. \
|
||||
-Icommon \
|
||||
-Iggml/include \
|
||||
-Iggml/src \
|
||||
-Iggml/src/ggml-cpu \
|
||||
-Iinclude \
|
||||
-Isrc \
|
||||
-Itools/mtmd \
|
||||
-Itools/ui \
|
||||
-Ivendor \
|
||||
-Ivendor/cpp-httplib
|
||||
lib =
|
||||
|
||||
ui_dist = build/tools/ui/dist
|
||||
ui_stamp = $(ui_dist)/.llama.mak.stamp
|
||||
ui_assets = index.html bundle.js bundle.css loading.html
|
||||
ui_url = https://huggingface.co/buckets/ggml-org/llama-ui/resolve/latest
|
||||
|
||||
vk_build_dir = vk-shaders
|
||||
vk_shaders_gen = $(vk_build_dir)/vulkan-shaders-gen.exe
|
||||
vk_shader_gen_src = $(wildcard \
|
||||
ggml/src/ggml-vulkan/vulkan-shaders/*.cpp \
|
||||
)
|
||||
vk_shader_gen_obj = $(patsubst \
|
||||
ggml/src/ggml-vulkan/vulkan-shaders/%.cpp, \
|
||||
$(vk_build_dir)/%.cpp.gen.o, \
|
||||
$(vk_shader_gen_src) \
|
||||
)
|
||||
|
||||
dll = \
|
||||
$(addsuffix .o,$(wildcard \
|
||||
ggml/src/*.c \
|
||||
ggml/src/*.cpp \
|
||||
ggml/src/ggml-cpu/*.c \
|
||||
ggml/src/ggml-cpu/*.cpp \
|
||||
ggml/src/ggml-cpu/arch/x86/*.c \
|
||||
ggml/src/ggml-cpu/arch/x86/*.cpp \
|
||||
src/*.cpp \
|
||||
src/models/*.cpp \
|
||||
))
|
||||
exe = \
|
||||
tools/mtmd/clip.cpp.o \
|
||||
tools/mtmd/mtmd-audio.cpp.o \
|
||||
tools/mtmd/mtmd-helper.cpp.o \
|
||||
tools/mtmd/mtmd-image.cpp.o \
|
||||
tools/mtmd/mtmd.cpp.o \
|
||||
tools/ui/ui.cpp.o \
|
||||
w64dk-build-info.cpp.o \
|
||||
w64dk-license.c.o \
|
||||
$(addsuffix .o,$(wildcard \
|
||||
common/*.cpp \
|
||||
common/jinja/*.cpp \
|
||||
tools/server/*.cpp \
|
||||
tools/mtmd/models/*.cpp \
|
||||
vendor/cpp-httplib/*.cpp \
|
||||
))
|
||||
|
||||
ifdef VULKAN_SDK
|
||||
GLSLC = $(VULKAN_SDK)/Bin/glslc.exe
|
||||
vk_shader_header = $(vk_build_dir)/ggml-vulkan-shaders.hpp
|
||||
vk_shaders = $(wildcard \
|
||||
ggml/src/ggml-vulkan/vulkan-shaders/*.comp \
|
||||
)
|
||||
vk_shader_objs = \
|
||||
$(patsubst %.comp,$(vk_build_dir)/%.comp.cpp.o,$(notdir $(vk_shaders)))
|
||||
|
||||
def += -DGGML_USE_VULKAN
|
||||
inc += -I$(VULKAN_SDK)/Include -I$(vk_build_dir)
|
||||
lib += -L$(VULKAN_SDK)/Lib -lvulkan-1
|
||||
dll += ggml/src/ggml-vulkan/ggml-vulkan.cpp.o $(vk_shader_objs)
|
||||
endif
|
||||
|
||||
%.c.o: %.c
|
||||
$(CROSS)$(CC) -c -o $@ $(inc) $(def) $(CPPFLAGS) $<
|
||||
%.cpp.o: %.cpp
|
||||
$(CROSS)$(CXX) -c -o $@ $(inc) $(def) $(CPPFLAGS) $<
|
||||
|
||||
all: llama.dll llama.dll.a llama-server.exe
|
||||
|
||||
llama-server.exe: $(exe) $(dll)
|
||||
$(CROSS)$(CXX) $(LDFLAGS) -o $@ $(exe) $(dll) -lws2_32 $(lib)
|
||||
|
||||
llama.dll: $(dll) llama.def
|
||||
$(CROSS)$(CXX) -shared $(LDFLAGS) -o $@ $(dll) llama.def $(lib)
|
||||
|
||||
llama.dll.a: llama.def
|
||||
$(CROSS)dlltool -l $@ -d $^
|
||||
|
||||
clean:
|
||||
rm -f $(dll) $(exe) llama.def llama.dll llama.dll.a llama-server.exe \
|
||||
tools/ui/index.html.hpp tools/ui/bundle.js.hpp \
|
||||
tools/ui/bundle.css.hpp tools/ui/loading.html.hpp \
|
||||
w64dk-build-info.cpp w64dk-license.c vulkan-shaders-gen.exe
|
||||
rm -rf $(vk_build_dir) $(ui_dist)
|
||||
|
||||
w64dk-build-info.cpp: common/build-info.cpp.in
|
||||
bnum=`git rev-list --count HEAD 2>/dev/null || printf 0`; \
|
||||
commit=`git rev-parse --short HEAD 2>/dev/null || printf unknown`; \
|
||||
compiler=`$(CC) --version 2>/dev/null | head -n1`; \
|
||||
target=`$(CC) -dumpmachine 2>/dev/null || printf unknown`; \
|
||||
sed \
|
||||
-e "s|@LLAMA_BUILD_NUMBER@|$$bnum|" \
|
||||
-e "s|@LLAMA_BUILD_COMMIT@|$$commit|" \
|
||||
-e "s|@BUILD_COMPILER@|$$compiler|" \
|
||||
-e "s|@BUILD_TARGET@|$$target|" \
|
||||
$< > $@
|
||||
|
||||
w64dk-build-info.cpp.o: w64dk-build-info.cpp
|
||||
|
||||
licenses = LICENSE $(wildcard licenses/LICENSE-*)
|
||||
w64dk-license.c: $(licenses)
|
||||
{ \
|
||||
printf 'const char *LICENSES[] = {\n'; \
|
||||
for f in $(licenses); do \
|
||||
printf ' "%s", (char[]){\n' "$${f##*-}"; \
|
||||
printf ' #embed "%s"\n' "$$f"; \
|
||||
printf ' , 0\n'; \
|
||||
printf ' },\n'; \
|
||||
done; \
|
||||
printf ' 0\n};\n'; \
|
||||
} >$@
|
||||
|
||||
$(ui_stamp): tools/ui/package.json tools/ui/package-lock.json
|
||||
mkdir -p $(ui_dist)
|
||||
if test -f $(ui_dist)/index.html \
|
||||
&& test -f $(ui_dist)/bundle.js \
|
||||
&& test -f $(ui_dist)/bundle.css \
|
||||
&& test -f $(ui_dist)/loading.html; then \
|
||||
:; \
|
||||
elif command -v npm >/dev/null 2>&1 \
|
||||
&& npm --version >/dev/null 2>&1 \
|
||||
&& (cd tools/ui && npm install && npm run build); then \
|
||||
:; \
|
||||
elif command -v wget >/dev/null 2>&1; then \
|
||||
ok=1; \
|
||||
for asset in $(ui_assets); do \
|
||||
wget -O $(ui_dist)/$$asset.tmp "$(ui_url)/$$asset?download=true" \
|
||||
&& mv $(ui_dist)/$$asset.tmp $(ui_dist)/$$asset \
|
||||
|| { ok=0; rm -f $(ui_dist)/$$asset.tmp; break; }; \
|
||||
done; \
|
||||
fi
|
||||
test -f $(ui_dist)/index.html
|
||||
test -f $(ui_dist)/bundle.js
|
||||
test -f $(ui_dist)/bundle.css
|
||||
test -f $(ui_dist)/loading.html
|
||||
touch $@
|
||||
|
||||
tools/ui/index.html.hpp: $(ui_stamp)
|
||||
cd $(ui_dist) && xxd -i index.html >../../../../tools/ui/index.html.hpp
|
||||
tools/ui/bundle.js.hpp: $(ui_stamp)
|
||||
cd $(ui_dist) && xxd -i bundle.js >../../../../tools/ui/bundle.js.hpp
|
||||
tools/ui/bundle.css.hpp: $(ui_stamp)
|
||||
cd $(ui_dist) && xxd -i bundle.css >../../../../tools/ui/bundle.css.hpp
|
||||
tools/ui/loading.html.hpp: $(ui_stamp)
|
||||
cd $(ui_dist) && xxd -i loading.html >../../../../tools/ui/loading.html.hpp
|
||||
tools/ui/ui.cpp.o: \
|
||||
tools/ui/index.html.hpp \
|
||||
tools/ui/bundle.js.hpp \
|
||||
tools/ui/bundle.css.hpp \
|
||||
tools/ui/loading.html.hpp
|
||||
|
||||
llama.def: $(dll)
|
||||
printf 'LIBRARY llama\nEXPORTS\n' >$@
|
||||
$(CROSS)nm -j $(dll) | grep '^llama_[a-z0-9_]\+$$' | sort >>$@
|
||||
|
||||
# Vulkan shader generation rules
|
||||
ifdef VULKAN_SDK
|
||||
|
||||
# vulkan-shaders-gen spawns multiple glslc processes per shader, for each
|
||||
# variant, so parallelizing it spawns hundreds of glslc processes and fails
|
||||
.NOTPARALLEL: $(vk_shader_objs)
|
||||
|
||||
$(vk_build_dir):
|
||||
mkdir -p $@
|
||||
|
||||
$(vk_build_dir)/%.cpp.gen.o: ggml/src/ggml-vulkan/vulkan-shaders/%.cpp | $(vk_build_dir)
|
||||
$(HOST_CXX) -c -o $@ -std=c++17 -O2 \
|
||||
-Iggml/src/ggml-vulkan/vulkan-shaders $<
|
||||
$(vk_shaders_gen): $(vk_shader_gen_obj)
|
||||
$(HOST_CXX) -o $@ $(vk_shader_gen_obj)
|
||||
|
||||
$(vk_shader_header): $(vk_shaders_gen) $(vk_shaders)
|
||||
mkdir -p $(vk_build_dir)/vulkan-shaders.spv
|
||||
./$(vk_shaders_gen) \
|
||||
--output-dir $(vk_build_dir)/vulkan-shaders.spv \
|
||||
--target-hpp $(vk_shader_header)
|
||||
|
||||
$(vk_build_dir)/%.comp.cpp: \
|
||||
ggml/src/ggml-vulkan/vulkan-shaders/%.comp \
|
||||
$(vk_shaders_gen) \
|
||||
$(vk_shader_header)
|
||||
./$(vk_shaders_gen) \
|
||||
--glslc $(GLSLC) \
|
||||
--source $< \
|
||||
--output-dir $(vk_build_dir)/vulkan-shaders.spv \
|
||||
--target-hpp $(vk_shader_header) \
|
||||
--target-cpp $@
|
||||
|
||||
# Pattern rule: compile each shader .cpp to .o
|
||||
$(vk_build_dir)/%.comp.cpp.o: $(vk_build_dir)/%.comp.cpp
|
||||
$(CROSS)$(CXX) -c -o $@ $(inc) $(def) $(CPPFLAGS) $<
|
||||
|
||||
ggml/src/ggml-vulkan/ggml-vulkan.cpp.o: $(vk_shader_header)
|
||||
|
||||
endif # VULKAN_SDK
|
||||
Reference in New Issue
Block a user