diff --git a/CMakeLists.txt b/CMakeLists.txt index 24ae538a..2f93ed48 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -114,6 +114,10 @@ set(ONEBIT_SERVE_TEST_GGUF "" CACHE FILEPATH "GGUF the serve_e2e tests load") # --device cpu the same build with no GPU layers. The build has no Vulkan or ROCm backend # (RFC #213 stage 3): what HRX does not run, Lemonade serves with its own llamacpp backends. option(ONEBIT_HRX "Build the HRX llama-server and wire it into Lemonade" OFF) +set(ONEBIT_GPU_PRIVATE "" CACHE PATH "A gpu-kernels checkout whose addons/hip-hrx HIP kernels are built into the HRX llama.cpp (needs ONEBIT_HRX)") +if(ONEBIT_GPU_PRIVATE AND NOT ONEBIT_HRX) + message(FATAL_ERROR "ONEBIT_GPU_PRIVATE needs ONEBIT_HRX=ON") +endif() if(ONEBIT_HRX) include(cmake/hrx.cmake) add_dependencies(onebit llama_hrx) diff --git a/cmake/hrx.cmake b/cmake/hrx.cmake index b330658c..06c48891 100644 --- a/cmake/hrx.cmake +++ b/cmake/hrx.cmake @@ -51,6 +51,25 @@ endif() set(ONEBIT_HRX_LIBHSA "${_hrx_libhsa_first}" CACHE FILEPATH "TheRock HSA runtime HRX loads (IREE_HAL_AMDGPU_LIBHSA_PATH)") message(STATUS "ONEBIT_HRX: HSA runtime ${ONEBIT_HRX_LIBHSA}") +# Private GPU kernels (docs/hrx.md, "Private HIP kernels"): a checkout of the private gpu-kernels +# repository whose addons/hip-hrx is built into the HRX llama.cpp (its GGML_HRX_HIP_ADDON_DIR hook). +set(_hrx_gpu_private_args) +if(ONEBIT_GPU_PRIVATE) + if(NOT IS_DIRECTORY "${ONEBIT_GPU_PRIVATE}/addons/hip-hrx/kernels") + message(FATAL_ERROR "ONEBIT_GPU_PRIVATE=${ONEBIT_GPU_PRIVATE} has no addons/hip-hrx/kernels") + endif() + set(_hrx_hip_cmake "${CMAKE_SOURCE_DIR}/third_party/llama.cpp/ggml/src/ggml-hrx/hip/ggml-hrx-hip.cmake") + set(_hrx_addon_hook) + if(EXISTS "${_hrx_hip_cmake}") + file(STRINGS "${_hrx_hip_cmake}" _hrx_addon_hook REGEX "GGML_HRX_HIP_ADDON_DIR") + endif() + if(NOT _hrx_addon_hook) + message(FATAL_ERROR "ONEBIT_GPU_PRIVATE: third_party/llama.cpp has no GGML_HRX_HIP_ADDON_DIR hook (needs the HIP plumbing)") + endif() + list(APPEND _hrx_gpu_private_args "-DGGML_HRX_HIP_ADDON_DIR=${ONEBIT_GPU_PRIVATE}/addons/hip-hrx") + message(STATUS "ONEBIT_HRX: private HIP kernels from ${ONEBIT_GPU_PRIVATE}/addons/hip-hrx") +endif() + set(ONEBIT_HRX_SERVER "${CMAKE_BINARY_DIR}/hrx/llama/bin/llama-server") ExternalProject_Add(llama_hrx SOURCE_DIR ${CMAKE_SOURCE_DIR}/third_party/llama.cpp @@ -63,6 +82,7 @@ ExternalProject_Add(llama_hrx -DHRX_SOURCE_DIR=${CMAKE_SOURCE_DIR}/third_party/hrx-system -DGGML_HRX=ON -DGGML_VULKAN=OFF -DGGML_CUDA=OFF -DGGML_HIP=OFF -DGGML_NATIVE=ON -DGGML_CPU=ON -DLLAMA_BUILD_SERVER=ON -DLLAMA_CURL=OFF + ${_hrx_gpu_private_args} BUILD_COMMAND ${CMAKE_COMMAND} --build --target llama-server llama-bench INSTALL_COMMAND "" BUILD_ALWAYS ON diff --git a/docs/hrx.md b/docs/hrx.md index a623dee0..5f170aa2 100644 --- a/docs/hrx.md +++ b/docs/hrx.md @@ -507,6 +507,16 @@ cmake --build build --target onebit build path it searches `/opt/rocm-therock`. To run llama-server or llama-bench by hand, export that variable yourself. +### Private HIP kernels + +Our own HIP kernels for HRX are closed source, like the NPU kernels: they live in the private +`1bit-MONSTER/gpu-kernels` repository (`addons/hip-hrx`). The llama.cpp fork keeps only the +public HIP-through-HRX plumbing (`ggml/src/ggml-hrx/hip/`). `-DONEBIT_GPU_PRIVATE=` +(with `-DONEBIT_HRX=ON`) passes `GGML_HRX_HIP_ADDON_DIR=/addons/hip-hrx` to the HRX +llama.cpp build, which compiles those kernels and matchers in; it needs a llama.cpp pin with +that hook. Without the option the build is unchanged. To drop the add-on from an existing +build directory, delete `build/hrx/llama` (its CMake cache keeps the setting). + ## Verified (2026-09-23, llama.cpp `f1a0aca`, hrx-system `51b1739`) `ctest` passed, re-run after the first daily bump (#13). At the time the check