2026-10-12 17:44:56 +02:00
|
|
|
cmake_minimum_required(VERSION 3.20)
|
|
|
|
|
project(searchi_gemma_worker LANGUAGES C CXX)
|
|
|
|
|
if(NOT DEFINED LLAMA_CPP_DIR OR NOT EXISTS "${LLAMA_CPP_DIR}/include/llama.h")
|
|
|
|
|
message(FATAL_ERROR "Supply -DLLAMA_CPP_DIR=<pinned patched llama.cpp b11461 source>")
|
|
|
|
|
endif()
|
|
|
|
|
set(CMAKE_CXX_STANDARD 17)
|
2026-10-12 22:35:34 +02:00
|
|
|
# CPU-only builds remain small internal VM tools. Normal Windows x64 builds
|
|
|
|
|
# ship baseline and optimized CPU modules in the same GPU-capable package.
|
|
|
|
|
set(SEARCHI_ACCELERATION "auto" CACHE STRING "auto; explicit developer overrides: cpu, metal, vulkan, cuda")
|
|
|
|
|
set(SEARCHI_CPU_DISPATCH OFF)
|
|
|
|
|
if(WIN32 AND CMAKE_SIZEOF_VOID_P EQUAL 8 AND
|
|
|
|
|
(CMAKE_SYSTEM_PROCESSOR MATCHES "^(AMD64|amd64|x86_64|X86_64)$" OR CMAKE_GENERATOR_PLATFORM STREQUAL "x64") AND
|
|
|
|
|
NOT SEARCHI_ACCELERATION STREQUAL "cpu")
|
|
|
|
|
set(SEARCHI_CPU_DISPATCH ON)
|
2026-10-12 17:44:56 +02:00
|
|
|
endif()
|
2026-10-12 22:35:34 +02:00
|
|
|
if(MSVC)
|
|
|
|
|
# llama and ggml exchange FILE* and other CRT-owned state across DLLs.
|
|
|
|
|
# Every shared-runtime component must use the same dynamic CRT.
|
|
|
|
|
if(SEARCHI_CPU_DISPATCH)
|
|
|
|
|
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL" CACHE STRING "Shared worker CRT across runtime DLLs" FORCE)
|
|
|
|
|
else()
|
|
|
|
|
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>" CACHE STRING "Internal static worker CRT" FORCE)
|
|
|
|
|
endif()
|
|
|
|
|
endif()
|
|
|
|
|
set(BUILD_SHARED_LIBS ${SEARCHI_CPU_DISPATCH} CACHE BOOL "Shared runtime for Windows CPU dispatch" FORCE)
|
|
|
|
|
set(GGML_BACKEND_DL ${SEARCHI_CPU_DISPATCH} CACHE BOOL "Load compatible packaged CPU backend" FORCE)
|
|
|
|
|
set(GGML_CPU_ALL_VARIANTS ${SEARCHI_CPU_DISPATCH} CACHE BOOL "Baseline and optimized CPU variants" FORCE)
|
|
|
|
|
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}")
|
2026-10-12 17:44:56 +02:00
|
|
|
set(GGML_OPENMP OFF CACHE BOOL "Use bounded native llama thread pools without external OpenMP runtime" FORCE)
|
|
|
|
|
set(GGML_NATIVE OFF CACHE BOOL "Portable CPU kernels")
|
2026-10-12 21:42:31 +02:00
|
|
|
# Normal distribution builds include GPU support and CPU fallback. CPU-only
|
|
|
|
|
# configuration is explicitly reserved for development/testing in the VM.
|
2026-10-12 17:44:56 +02:00
|
|
|
set(GGML_CUDA OFF CACHE BOOL "Production CUDA backend")
|
|
|
|
|
set(GGML_VULKAN OFF CACHE BOOL "Production Vulkan backend")
|
|
|
|
|
set(GGML_METAL OFF CACHE BOOL "Production Metal backend")
|
|
|
|
|
if(SEARCHI_ACCELERATION STREQUAL "cpu")
|
|
|
|
|
set(GGML_CUDA OFF CACHE BOOL "CPU test build" FORCE)
|
|
|
|
|
set(GGML_VULKAN OFF CACHE BOOL "CPU test build" FORCE)
|
|
|
|
|
set(GGML_METAL OFF CACHE BOOL "CPU test build" FORCE)
|
|
|
|
|
elseif(SEARCHI_ACCELERATION STREQUAL "metal" OR (SEARCHI_ACCELERATION STREQUAL "auto" AND APPLE))
|
|
|
|
|
set(GGML_METAL ON CACHE BOOL "Production Metal backend" FORCE)
|
|
|
|
|
elseif(SEARCHI_ACCELERATION STREQUAL "cuda")
|
|
|
|
|
set(GGML_CUDA ON CACHE BOOL "Production CUDA backend" FORCE)
|
|
|
|
|
elseif(SEARCHI_ACCELERATION STREQUAL "vulkan")
|
|
|
|
|
set(GGML_VULKAN ON CACHE BOOL "Production Vulkan backend" FORCE)
|
|
|
|
|
elseif(SEARCHI_ACCELERATION STREQUAL "auto")
|
2026-10-12 21:42:31 +02:00
|
|
|
# A missing build SDK must not silently turn a normal release into a
|
|
|
|
|
# CPU-only artifact. End users need drivers, not this compilation SDK.
|
|
|
|
|
find_package(Vulkan COMPONENTS glslc REQUIRED)
|
|
|
|
|
set(GGML_VULKAN ON CACHE BOOL "Production GPU support with runtime CPU fallback" FORCE)
|
2026-10-12 17:44:56 +02:00
|
|
|
else()
|
|
|
|
|
message(FATAL_ERROR "Unknown SEARCHI_ACCELERATION=${SEARCHI_ACCELERATION}")
|
|
|
|
|
endif()
|
|
|
|
|
set(LLAMA_BUILD_COMMON OFF CACHE BOOL "No extra common runtime" FORCE)
|
|
|
|
|
set(LLAMA_BUILD_TOOLS OFF CACHE BOOL "No runtime tools" FORCE)
|
|
|
|
|
set(LLAMA_BUILD_SERVER OFF CACHE BOOL "No HTTP server" FORCE)
|
|
|
|
|
set(LLAMA_BUILD_EXAMPLES OFF CACHE BOOL "No examples" FORCE)
|
|
|
|
|
set(LLAMA_BUILD_TESTS OFF CACHE BOOL "No upstream tests in worker build" FORCE)
|
2026-10-12 19:16:23 +02:00
|
|
|
set(LLAMA_BUILD_MTMD ON CACHE BOOL "Google image/audio projector" FORCE)
|
|
|
|
|
set(MTMD_VIDEO OFF CACHE BOOL "Frames decoded by bounded media adapter" FORCE)
|
2026-10-12 17:44:56 +02:00
|
|
|
set(LLAMA_OPENSSL OFF CACHE BOOL "No network runtime dependencies" FORCE)
|
|
|
|
|
add_subdirectory("${LLAMA_CPP_DIR}" llama-build)
|
|
|
|
|
add_executable(searchi-gemma-worker worker.cpp)
|
|
|
|
|
target_include_directories(searchi-gemma-worker PRIVATE "${LLAMA_CPP_DIR}/vendor")
|
2026-10-12 19:16:23 +02:00
|
|
|
target_link_libraries(searchi-gemma-worker PRIVATE llama mtmd)
|
2026-10-12 22:35:34 +02:00
|
|
|
if(SEARCHI_CPU_DISPATCH)
|
|
|
|
|
target_compile_definitions(searchi-gemma-worker PRIVATE SEARCHI_CPU_DISPATCH=1)
|
|
|
|
|
endif()
|
2026-10-12 17:44:56 +02:00
|
|
|
target_compile_definitions(searchi-gemma-worker PRIVATE SEARCHI_LLAMA_TAG="b11461-no-logits-v1")
|
|
|
|
|
install(TARGETS searchi-gemma-worker RUNTIME DESTINATION bin)
|