Skip to content

Fix: ensure bitnet-lut-kernels.h prepared before llama.cpp build#449

Open
shivansh31414 wants to merge 1 commit intomicrosoft:mainfrom
shivansh31414:fix-cmake-header
Open

Fix: ensure bitnet-lut-kernels.h prepared before llama.cpp build#449
shivansh31414 wants to merge 1 commit intomicrosoft:mainfrom
shivansh31414:fix-cmake-header

Conversation

@shivansh31414
Copy link

Title: Fix CMake build: ensure bitnet-lut-kernels.h prepared before llama.cpp

Summary
The CMake build currently fails because include/bitnet-lut-kernels.h is required at configure time but is not tracked in the source tree. This header is produced by setup scripts (setup_env.py, codegen utilities) and not by CMake itself, which breaks a clean cmake .. && make workflow.

Problem

  • bitnet-lut-kernels.h is missing during CMake configure.
  • ggml’s CMakeLists expects the header before add_subdirectory(3rdparty/llama.cpp).
  • Contributors running plain CMake builds hit a fatal error without running setup scripts first.

Fix Implemented
fixes: #378

  • Updated top‑level CMakeLists.txt to ensure include/bitnet-lut-kernels.h exists before llama.cpp is added.
  • Added two cache variables:
    • BITNET_PRESET_KERNEL_MODEL (default: bitnet_b1_58-3B)
    • BITNET_LUT_KERNELS_FILE (optional explicit header path)
  • Behavior:
    • If header already exists → leave untouched.
    • If BITNET_LUT_KERNELS_FILE is set → copy that file.
    • Else → auto‑copy from preset_kernels/<model>/bitnet-lut-kernels-{tl1|tl2}.h based on architecture.
    • If nothing valid is found → clear fatal error with guidance.

Copilot AI review requested due to automatic review settings March 13, 2026 10:59
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes clean CMake configure/build failures by ensuring include/bitnet-lut-kernels.h is present before 3rdparty/llama.cpp / ggml is configured, using either a user-provided header path or a preset-kernel header selected by model + architecture.

Changes:

  • Adds CMake cache variables BITNET_PRESET_KERNEL_MODEL and BITNET_LUT_KERNELS_FILE to control how bitnet-lut-kernels.h is prepared.
  • Implements configure-time logic to copy a provided header or a preset header into include/bitnet-lut-kernels.h before adding llama.cpp.
  • Adds a clearer fatal error when no suitable preset header can be found.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment on lines +41 to +50
set(BITNET_LUT_KERNELS_DST "${CMAKE_CURRENT_SOURCE_DIR}/include/bitnet-lut-kernels.h")
if (NOT EXISTS "${BITNET_LUT_KERNELS_DST}")
file(MAKE_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/include")

if (BITNET_LUT_KERNELS_FILE)
if (NOT EXISTS "${BITNET_LUT_KERNELS_FILE}")
message(FATAL_ERROR "BITNET_LUT_KERNELS_FILE does not exist: ${BITNET_LUT_KERNELS_FILE}")
endif()
configure_file("${BITNET_LUT_KERNELS_FILE}" "${BITNET_LUT_KERNELS_DST}" COPYONLY)
message(STATUS "Prepared bitnet-lut-kernels.h from BITNET_LUT_KERNELS_FILE=${BITNET_LUT_KERNELS_FILE}")
add_compile_options(-fpermissive)
endif()

set(BITNET_LUT_KERNELS_DST "${CMAKE_CURRENT_SOURCE_DIR}/include/bitnet-lut-kernels.h")
set(BITNET_LUT_KERNEL_VARIANT "tl1")
elseif (GGML_BITNET_X86_TL2)
set(BITNET_LUT_KERNEL_VARIANT "tl2")
elseif (CMAKE_SYSTEM_PROCESSOR MATCHES "^(aarch64|arm64)")
@shivansh31414
Copy link
Author

@microsoft-github-policy-service agree

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CMake build fails due to missing bitnet-lut-kernels.h

2 participants