From b70c44a95998ba57f4304c0bfb6821836a684a16 Mon Sep 17 00:00:00 2001 From: KMSorSMS Date: Wed, 5 Nov 2025 05:05:39 +0000 Subject: [PATCH 1/2] [build](cmake): not error if blis not found --- kt-kernel/CMakeLists.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/kt-kernel/CMakeLists.txt b/kt-kernel/CMakeLists.txt index ba044fd..bbe1a21 100644 --- a/kt-kernel/CMakeLists.txt +++ b/kt-kernel/CMakeLists.txt @@ -332,13 +332,13 @@ if(KTRANSFORMERS_CPU_MOE_AMD) ) if(NOT BLIS_INCLUDE_DIR OR NOT BLIS_LIBRARY) - message(FATAL_ERROR "BLIS not found; set BLIS_ROOT or specify BLIS_INCLUDE_DIR/BLIS_LIBRARY") + message(WARNING "BLIS not found; set BLIS_ROOT or specify BLIS_INCLUDE_DIR/BLIS_LIBRARY") else() message(STATUS "Found BLIS include at ${BLIS_INCLUDE_DIR}") message(STATUS "Found BLIS library ${BLIS_LIBRARY}") + target_include_directories(${PROJECT_NAME} PRIVATE ${BLIS_INCLUDE_DIR}) + target_link_libraries(${PROJECT_NAME} PRIVATE ${BLIS_LIBRARY}) endif() - target_include_directories(${PROJECT_NAME} PRIVATE ${BLIS_INCLUDE_DIR}) - target_link_libraries(${PROJECT_NAME} PRIVATE ${BLIS_LIBRARY}) endif() From 85abac27c86b5a2bce7bbe17568e7a2f3f7f8e4f Mon Sep 17 00:00:00 2001 From: KMSorSMS Date: Wed, 5 Nov 2025 08:04:12 +0000 Subject: [PATCH 2/2] [build](cmake): fix target include bug --- kt-kernel/CMakeLists.txt | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/kt-kernel/CMakeLists.txt b/kt-kernel/CMakeLists.txt index bbe1a21..3b34269 100644 --- a/kt-kernel/CMakeLists.txt +++ b/kt-kernel/CMakeLists.txt @@ -332,13 +332,17 @@ if(KTRANSFORMERS_CPU_MOE_AMD) ) if(NOT BLIS_INCLUDE_DIR OR NOT BLIS_LIBRARY) - message(WARNING "BLIS not found; set BLIS_ROOT or specify BLIS_INCLUDE_DIR/BLIS_LIBRARY") + message(FATAL_ERROR "BLIS not found; set BLIS_ROOT or specify BLIS_INCLUDE_DIR/BLIS_LIBRARY") else() message(STATUS "Found BLIS include at ${BLIS_INCLUDE_DIR}") message(STATUS "Found BLIS library ${BLIS_LIBRARY}") - target_include_directories(${PROJECT_NAME} PRIVATE ${BLIS_INCLUDE_DIR}) - target_link_libraries(${PROJECT_NAME} PRIVATE ${BLIS_LIBRARY}) endif() + # The Python extension target (${PROJECT_NAME}) is created later by + # pybind11_add_module(). Calling target_include_directories/target_link_libraries + # here would fail because the target doesn't exist yet. Save the discovered + # BLIS paths and apply them after the module target is created. + set(_KT_BLIS_INCLUDE_DIR ${BLIS_INCLUDE_DIR}) + set(_KT_BLIS_LIBRARY ${BLIS_LIBRARY}) endif() @@ -542,6 +546,18 @@ else() message(STATUS "LTO: disabled") endif() +# If BLIS was detected earlier, apply its include directory and library to the +# created Python extension target. We only do this after the module target +# (${PROJECT_NAME}) has been created by pybind11_add_module(). +if(DEFINED _KT_BLIS_INCLUDE_DIR AND DEFINED _KT_BLIS_LIBRARY) + if(TARGET ${PROJECT_NAME}) + target_include_directories(${PROJECT_NAME} PRIVATE ${_KT_BLIS_INCLUDE_DIR}) + target_link_libraries(${PROJECT_NAME} PRIVATE ${_KT_BLIS_LIBRARY}) + else() + message(WARNING "BLIS was detected earlier but ${PROJECT_NAME} target was not found when attempting to apply BLIS link/include settings.") + endif() +endif() + # Ensure the module target also has correct RPATH when conda is active if(TARGET ${PROJECT_NAME} AND DEFINED ENV{CONDA_PREFIX} AND EXISTS "$ENV{CONDA_PREFIX}") set_target_properties(${PROJECT_NAME} PROPERTIES