ref(upstream): FULL TREE — Deep-Spark xllm (1470) + ds_vllm csrc/models (703)

Replaces cherry-picked upstream_ref with complete source trees.

xllm/ — Iluvatar official C++ inference engine (15MB, 1470 files)
  Complete: kernels → layers → models → runtime → scheduler → api
  Excluded: .git, binary images, third_party submodule checkouts

ds_vllm/ — Iluvatar official vllm fork (8MB, 703 files)
  Included: csrc/ (ALL CUDA kernels), fused_moe/, qwen3_5 model, _custom_ops
  Excluded: tests, benchmarks, docs, examples (not needed for reference)

Critical call chains now fully traceable:
  MoE: moe_topk_softmax_kernels.cuh → ixformer.h → fused_moe.cpp → layer
  GDN: qwen3_gated_delta_net_base.cpp → qwen3_5_gated_delta_net.cpp
  Attention: ixformer.h → xllm_paged_attention → attention.cpp
This commit is contained in:
EX Engine
2026-08-10 02:53:54 +00:00
parent 9e4fb3712f
commit 002f9879b2
2179 changed files with 494021 additions and 79 deletions

View File

@@ -0,0 +1,17 @@
# Try to find the compiler
find_program(CMAKE_MUSA_COMPILER
NAMES mcc
DOC "MUSA compiler"
)
set(CMAKE_MUSA_COMPILER_ENV_VAR "MUSA")
# Check if compiler was found
if(CMAKE_MUSA_COMPILER)
set(CMAKE_MUSA_COMPILER_LOADED 1)
message(STATUS "Found MUSA compiler: ${CMAKE_MUSA_COMPILER}")
else()
message(FATAL_ERROR "MUSA compiler not found")
endif()
configure_file(${CMAKE_CURRENT_LIST_DIR}/CMakeMUSACompiler.cmake.in
${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/${CMAKE_VERSION}/CMakeMUSACompiler.cmake IMMEDIATE @ONLY)

View File

@@ -0,0 +1,25 @@
# ported from https://github.com/Devolutions/CMakeRust
if(NOT CMAKE_Rust_COMPILER)
find_package(Rust)
if(RUST_FOUND)
set(CMAKE_Rust_COMPILER "${RUSTC_EXECUTABLE}")
set(CMAKE_Rust_COMPILER_ID "Rust")
set(CMAKE_Rust_COMPILER_VERSION "${RUST_VERSION}")
set(CMAKE_Rust_PLATFORM_ID "Rust")
endif()
endif()
message(STATUS "Cargo Home: ${CARGO_HOME}")
message(STATUS "Rust Compiler Version: ${RUSTC_VERSION}")
mark_as_advanced(CMAKE_Rust_COMPILER)
if(CMAKE_Rust_COMPILER)
set(CMAKE_Rust_COMPILER_LOADED 1)
endif(CMAKE_Rust_COMPILER)
configure_file(${CMAKE_CURRENT_LIST_DIR}/CMakeRustCompiler.cmake.in
${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/${CMAKE_VERSION}/CMakeRustCompiler.cmake IMMEDIATE @ONLY)
set(CMAKE_Rust_COMPILER_ENV_VAR "RUSTC")

View File

@@ -0,0 +1,18 @@
set(CMAKE_MUSA_SOURCE_FILE_EXTENSIONS mu;cu)
if(UNIX)
set(CMAKE_MUSA_OUTPUT_EXTENSION .o)
else()
set(CMAKE_MUSA_OUTPUT_EXTENSION .obj)
endif()
set(CMAKE_INCLUDE_FLAG_MUSA "-I")
set(CMAKE_MUSA_COMPILE_OBJECT
"<CMAKE_MUSA_COMPILER> <DEFINES> <INCLUDES> <FLAGS> -mtgpu -c <SOURCE> -o <OBJECT>"
)
set(CMAKE_MUSA_LINK_EXECUTABLE
"<CMAKE_MUSA_COMPILER> <FLAGS> <LINK_FLAGS> <OBJECTS> -lmusa -lmusart -o <TARGET> <LINK_LIBRARIES>"
)
set(CMAKE_MUSA_INFORMATION_LOADED 1)

View File

@@ -0,0 +1,12 @@
# ported from https://github.com/Devolutions/CMakeRust
set(CMAKE_Rust_COMPILER "@CMAKE_Rust_COMPILER@")
set(CMAKE_Rust_COMPILER_ID "@CMAKE_Rust_COMPILER_ID@")
set(CMAKE_Rust_COMPILER_VERSION "@CMAKE_Rust_COMPILER_VERSION@")
set(CMAKE_Rust_COMPILER_LOADED @CMAKE_Rust_COMPILER_LOADED@)
set(CMAKE_Rust_PLATFORM_ID "@CMAKE_Rust_PLATFORM_ID@")
SET(CMAKE_Rust_SOURCE_FILE_EXTENSIONS rs)
SET(CMAKE_Rust_LINKER_PREFERENCE 40)
set(CMAKE_Rust_COMPILER_ENV_VAR "RUSTC")

View File

@@ -0,0 +1,106 @@
# ported from https://github.com/Devolutions/CMakeRust
#
# Usage: rustc [OPTIONS] INPUT
#
# Options:
# -h --help Display this message
# --cfg SPEC Configure the compilation environment
# -L [KIND=]PATH Add a directory to the library search path. The
# optional KIND can be one of dependency, crate, native,
# framework or all (the default).
# -l [KIND=]NAME Link the generated crate(s) to the specified native
# library NAME. The optional KIND can be one of static,
# dylib, or framework. If omitted, dylib is assumed.
# --crate-type [bin|lib|rlib|dylib|cdylib|staticlib|metadata]
# Comma separated list of types of crates for the
# compiler to emit
# --crate-name NAME Specify the name of the crate being built
# --emit [asm|llvm-bc|llvm-ir|obj|link|dep-info]
# Comma separated list of types of output for the
# compiler to emit
# --print [crate-name|file-names|sysroot|cfg|target-list|target-cpus|target-features|relocation-models|code-models]
# Comma separated list of compiler information to print
# on stdout
# -g Equivalent to -C debuginfo=2
# -O Equivalent to -C opt-level=2
# -o FILENAME Write output to <filename>
# --out-dir DIR Write output to compiler-chosen filename in <dir>
# --explain OPT Provide a detailed explanation of an error message
# --test Build a test harness
# --target TARGET Target triple for which the code is compiled
# -W --warn OPT Set lint warnings
# -A --allow OPT Set lint allowed
# -D --deny OPT Set lint denied
# -F --forbid OPT Set lint forbidden
# --cap-lints LEVEL Set the most restrictive lint level. More restrictive
# lints are capped at this level
# -C --codegen OPT[=VALUE]
# Set a codegen option
# -V --version Print version info and exit
# -v --verbose Use verbose output
#
# Additional help:
# -C help Print codegen options
# -W help Print 'lint' options and default settings
# -Z help Print internal options for debugging rustc
# --help -v Print the full set of options rustc accepts
#
# <TARGET> <TARGET_BASE> <OBJECT> <OBJECTS> <LINK_LIBRARIES> <FLAGS> <LINK_FLAGS> <SOURCE> <SOURCES>
include(CMakeLanguageInformation)
if(UNIX)
set(CMAKE_Rust_OUTPUT_EXTENSION .o)
else()
set(CMAKE_Rust_OUTPUT_EXTENSION .obj)
endif()
set(CMAKE_Rust_ECHO_ALL "echo \"TARGET: <TARGET> TARGET_BASE: <TARGET_BASE> ")
set(CMAKE_Rust_ECHO_ALL "${CMAKE_Rust_ECHO_ALL} OBJECT: <OBJECT> OBJECTS: <OBJECTS> OBJECT_DIR: <OBJECT_DIR> SOURCE: <SOURCE> SOURCES: <SOURCES> ")
set(CMAKE_Rust_ECHO_ALL "${CMAKE_Rust_ECHO_ALL} LINK_LIBRARIES: <LINK_LIBRARIES> FLAGS: <FLAGS> LINK_FLAGS: <LINK_FLAGS> \"")
if(NOT CMAKE_Rust_CREATE_SHARED_LIBRARY)
set(CMAKE_Rust_CREATE_SHARED_LIBRARY
"echo \"CMAKE_Rust_CREATE_SHARED_LIBRARY\""
"${CMAKE_Rust_ECHO_ALL}"
)
endif()
if(NOT CMAKE_Rust_CREATE_SHARED_MODULE)
set(CMAKE_Rust_CREATE_SHARED_MODULE
"echo \"CMAKE_Rust_CREATE_SHARED_MODULE\""
"${CMAKE_Rust_ECHO_ALL}"
)
endif()
if(NOT CMAKE_Rust_CREATE_STATIC_LIBRARY)
set(CMAKE_Rust_CREATE_STATIC_LIBRARY
"echo \"CMAKE_Rust_CREATE_STATIC_LIBRARY\""
"${CMAKE_Rust_ECHO_ALL}"
)
endif()
if(NOT CMAKE_Rust_COMPILE_OBJECT)
set(CMAKE_Rust_COMPILE_OBJECT
"echo \"CMAKE_Rust_COMPILE_OBJECT\""
"${CMAKE_Rust_ECHO_ALL}"
"${CMAKE_Rust_COMPILER} --emit obj <SOURCE> -o <OBJECT>")
endif()
if(NOT CMAKE_Rust_LINK_EXECUTABLE)
set(CMAKE_Rust_LINK_EXECUTABLE
"echo \"CMAKE_Rust_LINK_EXECUTABLE\""
"${CMAKE_Rust_ECHO_ALL}"
)
endif()
mark_as_advanced(
CMAKE_Rust_FLAGS
CMAKE_Rust_FLAGS_DEBUG
CMAKE_Rust_FLAGS_MINSIZEREL
CMAKE_Rust_FLAGS_RELEASE
CMAKE_Rust_FLAGS_RELWITHDEBINFO)
set(CMAKE_Rust_INFORMATION_LOADED 1)

View File

@@ -0,0 +1 @@
set(CMAKE_Rust_COMPILER_WORKS 1 CACHE INTERNAL "")

View File

@@ -0,0 +1,73 @@
# ported from https://github.com/Devolutions/CMakeRust
set(_CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ${CMAKE_FIND_ROOT_PATH_MODE_PROGRAM})
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM BOTH)
set(_CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ${CMAKE_FIND_ROOT_PATH_MODE_INCLUDE})
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE BOTH)
if(CMAKE_HOST_WIN32)
set(USER_HOME "$ENV{USERPROFILE}")
else()
set(USER_HOME "$ENV{HOME}")
endif()
if(NOT DEFINED CARGO_HOME)
if("$ENV{CARGO_HOME}" STREQUAL "")
set(CARGO_HOME "${USER_HOME}/.cargo")
else()
set(CARGO_HOME "$ENV{CARGO_HOME}")
endif()
endif()
# Find cargo executable
find_program(CARGO_EXECUTABLE cargo
HINTS "${CARGO_HOME}"
PATH_SUFFIXES "bin")
mark_as_advanced(CARGO_EXECUTABLE)
# Find rustc executable
find_program(RUSTC_EXECUTABLE rustc
HINTS "${CARGO_HOME}"
PATH_SUFFIXES "bin")
mark_as_advanced(RUSTC_EXECUTABLE)
# Find rustdoc executable
find_program(RUSTDOC_EXECUTABLE rustdoc
HINTS "${CARGO_HOME}"
PATH_SUFFIXES "bin")
mark_as_advanced(RUSTDOC_EXECUTABLE)
# Find rust-gdb executable
find_program(RUST_GDB_EXECUTABLE rust-gdb
HINTS "${CARGO_HOME}"
PATH_SUFFIXES "bin")
mark_as_advanced(RUST_GDB_EXECUTABLE)
# Find rust-lldb executable
find_program(RUST_LLDB_EXECUTABLE rust-lldb
HINTS "${CARGO_HOME}"
PATH_SUFFIXES "bin")
mark_as_advanced(RUST_LLDB_EXECUTABLE)
# Find rustup executable
find_program(RUSTUP_EXECUTABLE rustup
HINTS "${CARGO_HOME}"
PATH_SUFFIXES "bin")
mark_as_advanced(RUSTUP_EXECUTABLE)
set(RUST_FOUND FALSE CACHE INTERNAL "")
if(CARGO_EXECUTABLE AND RUSTC_EXECUTABLE AND RUSTDOC_EXECUTABLE)
set(RUST_FOUND TRUE CACHE INTERNAL "")
set(CARGO_HOME "${CARGO_HOME}" CACHE PATH "Rust Cargo Home")
execute_process(COMMAND ${RUSTC_EXECUTABLE} --version OUTPUT_VARIABLE RUSTC_VERSION OUTPUT_STRIP_TRAILING_WHITESPACE)
string(REGEX REPLACE "rustc ([^ ]+) .*" "\\1" RUSTC_VERSION "${RUSTC_VERSION}")
endif()
if(NOT RUST_FOUND)
message(FATAL_ERROR "Could not find Rust!")
endif()
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ${_CMAKE_FIND_ROOT_PATH_MODE_PROGRAM})
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ${_CMAKE_FIND_ROOT_PATH_MODE_INCLUDE})

View File

@@ -0,0 +1,94 @@
include(CMakeParseArguments)
# inspired by https://github.com/abseil/abseil-cpp
# cc_library()
# CMake function to imitate Bazel's cc_library rule.
function(cargo_library)
cmake_parse_arguments(
CARGO # prefix
"" # options
"NAME" # one value args
"HDRS" # multi value args
${ARGN}
)
string(REPLACE "-" "_" LIB_NAME ${CARGO_NAME})
# set(CARGO_TARGET_DIR ${CMAKE_CURRENT_BINARY_DIR})
# figure out the target triple
if(WIN32)
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(LIB_TARGET "x86_64-pc-windows-msvc")
else()
set(LIB_TARGET "i686-pc-windows-msvc")
endif()
elseif(ANDROID)
if(ANDROID_SYSROOT_ABI STREQUAL "x86")
set(LIB_TARGET "i686-linux-android")
elseif(ANDROID_SYSROOT_ABI STREQUAL "x86_64")
set(LIB_TARGET "x86_64-linux-android")
elseif(ANDROID_SYSROOT_ABI STREQUAL "arm")
set(LIB_TARGET "arm-linux-androideabi")
elseif(ANDROID_SYSROOT_ABI STREQUAL "arm64")
set(LIB_TARGET "aarch64-linux-android")
endif()
elseif(IOS)
set(LIB_TARGET "universal")
elseif(CMAKE_SYSTEM_NAME STREQUAL Darwin)
set(LIB_TARGET "x86_64-apple-darwin")
else()
if(CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64")
set(LIB_TARGET "aarch64-unknown-linux-gnu")
elseif(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(LIB_TARGET "x86_64-unknown-linux-gnu")
else()
set(LIB_TARGET "i686-unknown-linux-gnu")
endif()
endif()
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
set(LIB_BUILD_TYPE "debug")
else()
set(LIB_BUILD_TYPE "release")
endif()
if(IOS)
set(CARGO_ARGS "lipo")
else()
set(CARGO_ARGS "build")
list(APPEND CARGO_ARGS "--target" ${LIB_TARGET})
endif()
if(${LIB_BUILD_TYPE} STREQUAL "release")
list(APPEND CARGO_ARGS "--release")
endif()
file(GLOB_RECURSE LIB_SOURCES "*.rs")
set(CARGO_ENV_COMMAND ${CMAKE_COMMAND} -E env "CARGO_TARGET_DIR=${CMAKE_CURRENT_BINARY_DIR}")
# build the library target with cargo
set(STATIC_LIB_NAME
"${CMAKE_STATIC_LIBRARY_PREFIX}${LIB_NAME}${CMAKE_STATIC_LIBRARY_SUFFIX}")
set(LIB_FILE
"${CMAKE_CURRENT_BINARY_DIR}/${LIB_TARGET}/${LIB_BUILD_TYPE}/${STATIC_LIB_NAME}")
message(STATUS "running: ${CARGO_ENV_COMMAND} ${CARGO_EXECUTABLE} ARGS ${CARGO_ARGS}")
add_custom_command(
OUTPUT ${LIB_FILE}
COMMAND ${CARGO_ENV_COMMAND} ${CARGO_EXECUTABLE} ARGS ${CARGO_ARGS}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
DEPENDS ${LIB_SOURCES}
COMMENT "Building cargo library ${LIB_FILE}"
)
add_custom_target(${CARGO_NAME}_target ALL DEPENDS ${LIB_FILE})
# add the library target
add_library(${CARGO_NAME} STATIC IMPORTED GLOBAL)
add_dependencies(${CARGO_NAME} ${CARGO_NAME}_target)
set_target_properties(${CARGO_NAME} PROPERTIES
IMPORTED_LOCATION ${LIB_FILE}
)
target_sources(${CARGO_NAME} INTERFACE ${CARGO_HDRS})
endfunction()

View File

@@ -0,0 +1,93 @@
include(CMakeParseArguments)
# inspired by https://github.com/abseil/abseil-cpp
# cc_library()
# CMake function to imitate Bazel's cc_library rule.
function(cargo_shared_library)
cmake_parse_arguments(
CARGO # prefix
"" # options
"NAME" # one value args
"HDRS" # multi value args
${ARGN}
)
string(REPLACE "-" "_" LIB_NAME ${CARGO_NAME})
# set(CARGO_TARGET_DIR ${CMAKE_CURRENT_BINARY_DIR})
# figure out the target triple
if(WIN32)
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(LIB_TARGET "x86_64-pc-windows-msvc")
else()
set(LIB_TARGET "i686-pc-windows-msvc")
endif()
elseif(ANDROID)
if(ANDROID_SYSROOT_ABI STREQUAL "x86")
set(LIB_TARGET "i686-linux-android")
elseif(ANDROID_SYSROOT_ABI STREQUAL "x86_64")
set(LIB_TARGET "x86_64-linux-android")
elseif(ANDROID_SYSROOT_ABI STREQUAL "arm")
set(LIB_TARGET "arm-linux-androideabi")
elseif(ANDROID_SYSROOT_ABI STREQUAL "arm64")
set(LIB_TARGET "aarch64-linux-android")
endif()
elseif(IOS)
set(LIB_TARGET "universal")
elseif(CMAKE_SYSTEM_NAME STREQUAL Darwin)
set(LIB_TARGET "x86_64-apple-darwin")
else()
if(CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64")
set(LIB_TARGET "aarch64-unknown-linux-gnu")
elseif(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(LIB_TARGET "x86_64-unknown-linux-gnu")
else()
set(LIB_TARGET "i686-unknown-linux-gnu")
endif()
endif()
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
set(LIB_BUILD_TYPE "debug")
else()
set(LIB_BUILD_TYPE "release")
endif()
if(IOS)
set(CARGO_ARGS "lipo")
else()
set(CARGO_ARGS "build")
list(APPEND CARGO_ARGS "--target" ${LIB_TARGET})
endif()
if(${LIB_BUILD_TYPE} STREQUAL "release")
list(APPEND CARGO_ARGS "--release")
endif()
file(GLOB_RECURSE LIB_SOURCES "*.rs")
set(CARGO_ENV_COMMAND ${CMAKE_COMMAND} -E env "CARGO_TARGET_DIR=${CMAKE_CURRENT_BINARY_DIR}")
# build the library target with cargo
set(SHARED_LIB_NAME
"${CMAKE_SHARED_LIBRARY_PREFIX}${LIB_NAME}${CMAKE_SHARED_LIBRARY_SUFFIX}")
set(LIB_FILE
"${CMAKE_CURRENT_BINARY_DIR}/${LIB_TARGET}/${LIB_BUILD_TYPE}/${SHARED_LIB_NAME}")
add_custom_command(
OUTPUT ${LIB_FILE}
COMMAND ${CARGO_ENV_COMMAND} ${CARGO_EXECUTABLE} ARGS ${CARGO_ARGS}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
DEPENDS ${LIB_SOURCES}
COMMENT "Building cargo library ${LIB_FILE}"
)
add_custom_target(${CARGO_NAME}_target ALL DEPENDS ${LIB_FILE})
# add the library target
add_library(${CARGO_NAME} SHARED IMPORTED GLOBAL)
add_dependencies(${CARGO_NAME} ${CARGO_NAME}_target)
set_target_properties(${CARGO_NAME} PROPERTIES
IMPORTED_LOCATION ${LIB_FILE}
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_CURRENT_SOURCE_DIR}
IMPORTED_NO_SONAME TRUE
)
endfunction()

View File

@@ -0,0 +1,60 @@
include(CMakeParseArguments)
# inspired by https://github.com/abseil/abseil-cpp
# cc_binary()
# CMake function to imitate Bazel's cc_binary rule.
#
# Parameters:
# NAME: name of target
# HDRS: List of public header files for the library
# SRCS: List of source files for the library
# COPTS: List of private compile options
# DEFINES: List of public defines
# LINKOPTS: List of link options
# DEPS: List of other libraries to be linked in to the binary targets
#
# cc_library(
# NAME
# awesome
# HDRS
# "a.h"
# SRCS
# "a.cc"
# )
# cc_binary(
# NAME
# fantastic
# SRCS
# "b.cc"
# DEPS
# :awesome
# )
#
function(cc_binary)
cmake_parse_arguments(
CC_BINARY # prefix
"" # options
"NAME" # one value args
"HDRS;SRCS;COPTS;DEFINES;LINKOPTS;DEPS" # multi value args
${ARGN}
)
add_executable(${CC_BINARY_NAME} "")
target_sources(${CC_BINARY_NAME}
PRIVATE ${CC_BINARY_SRCS} ${CC_BINARY_HDRS}
)
target_link_libraries(${CC_BINARY_NAME}
PUBLIC
${CC_BINARY_DEPS}
PRIVATE
${CC_BINARY_LINKOPTS}
)
target_include_directories(${CC_BINARY_NAME}
PUBLIC
"$<BUILD_INTERFACE:${COMMON_INCLUDE_DIRS}>"
)
target_compile_options(${CC_BINARY_NAME} PRIVATE ${CC_BINARY_COPTS})
target_compile_definitions(${CC_BINARY_NAME} PUBLIC ${CC_BINARY_DEFINES})
add_executable(:${CC_BINARY_NAME} ALIAS ${CC_BINARY_NAME})
endfunction()

View File

@@ -0,0 +1,92 @@
include(CMakeParseArguments)
# inspired by https://github.com/abseil/abseil-cpp
# cc_library()
# CMake function to imitate Bazel's cc_library rule.
#
# Parameters:
# NAME: name of target
# HDRS: List of public header files for the library
# SRCS: List of source files for the library
# DEPS: List of other libraries to be linked in to the binary targets
# COPTS: List of private compile options
# DEFINES: List of public defines
# LINKOPTS: List of link options
#
# cc_library(
# NAME
# awesome
# HDRS
# "a.h"
# SRCS
# "a.cc"
# )
# cc_library(
# NAME
# fantastic_lib
# SRCS
# "b.cc"
# DEPS
# :awesome
# )
#
function(cc_library)
cmake_parse_arguments(
CC_LIB # prefix
"TESTONLY" # options
"NAME" # one value args
"HDRS;SRCS;COPTS;DEFINES;LINKOPTS;DEPS;INCLUDES" # multi value args
${ARGN}
)
if(CC_LIB_TESTONLY AND (NOT BUILD_TESTING))
return()
endif()
# Check if this is a header only library
set(_CC_SRCS "${CC_LIB_SRCS}")
foreach(src_file IN LISTS _CC_SRCS)
if(${src_file} MATCHES ".*\\.(h|inc)")
list(REMOVE_ITEM _CC_SRCS "${src_file}")
endif()
endforeach()
if(_CC_SRCS STREQUAL "")
set(CC_LIB_IS_INTERFACE 1)
else()
set(CC_LIB_IS_INTERFACE 0)
endif()
if(NOT CC_LIB_IS_INTERFACE)
add_library(${CC_LIB_NAME} STATIC)
target_sources(${CC_LIB_NAME}
PRIVATE ${CC_LIB_SRCS} ${CC_LIB_HDRS})
target_link_libraries(${CC_LIB_NAME}
PUBLIC ${CC_LIB_DEPS}
PRIVATE ${CC_LIB_LINKOPTS}
)
target_include_directories(${CC_LIB_NAME}
PUBLIC
"$<BUILD_INTERFACE:${COMMON_INCLUDE_DIRS}>"
${CC_LIB_INCLUDES}
)
target_compile_options(${CC_LIB_NAME} PRIVATE ${CC_LIB_COPTS})
target_compile_definitions(${CC_LIB_NAME} PUBLIC ${CC_LIB_DEFINES})
else()
# Generating header only library
add_library(${CC_LIB_NAME} INTERFACE)
target_include_directories(${CC_LIB_NAME}
INTERFACE
"$<BUILD_INTERFACE:${COMMON_INCLUDE_DIRS}>"
${CC_LIB_INCLUDES}
)
target_link_libraries(${CC_LIB_NAME}
INTERFACE ${CC_LIB_DEPS} ${CC_LIB_LINKOPTS}
)
target_compile_definitions(${CC_LIB_NAME} INTERFACE ${CC_LIB_DEFINES})
endif()
# add alias for the library target
add_library(:${CC_LIB_NAME} ALIAS ${CC_LIB_NAME})
endfunction()

View File

@@ -0,0 +1,104 @@
include(CMakeParseArguments)
# inspired by https://github.com/abseil/abseil-cpp
# cc_shared_library()
# CMake function to imitate Bazel's cc_shared_library rule.
#
# Parameters:
# NAME: name of target
# HDRS: List of public header files for the library
# SRCS: List of source files for the library
# DEPS: List of other libraries to be linked in to the binary targets
# COPTS: List of private compile options
# DEFINES: List of public defines
# LINKOPTS: List of link options
#
# cc_library(
# NAME
# awesome
# HDRS
# "a.h"
# SRCS
# "a.cc"
# )
# cc_shared_library(
# NAME
# fantastic_lib
# SRCS
# "b.cc"
# DEPS
# :awesome
# )
#
function(cc_shared_library)
cmake_parse_arguments(
CC_LIB # prefix
"TESTONLY" # options
"NAME" # one value args
"HDRS;SRCS;COPTS;DEFINES;LINKOPTS;DEPS;INCLUDES" # multi value args
${ARGN}
)
if(CC_LIB_TESTONLY AND (NOT BUILD_TESTING))
return()
endif()
# Check if this is a header only library
set(_CC_SRCS "${CC_LIB_SRCS}")
foreach(src_file IN LISTS _CC_SRCS)
if(${src_file} MATCHES ".*\\.(h|inc)")
list(REMOVE_ITEM _CC_SRCS "${src_file}")
endif()
endforeach()
if(_CC_SRCS STREQUAL "")
set(CC_LIB_IS_INTERFACE 1)
else()
set(CC_LIB_IS_INTERFACE 0)
endif()
if(NOT CC_LIB_IS_INTERFACE)
add_library(${CC_LIB_NAME} SHARED)
target_sources(${CC_LIB_NAME}
PRIVATE ${CC_LIB_SRCS} ${CC_LIB_HDRS})
target_compile_options(${CC_LIB_NAME} PRIVATE
-fvisibility=hidden
-fvisibility-inlines-hidden
)
target_link_options(${CC_LIB_NAME} PRIVATE
-Wl,--exclude-libs,ALL
-Wl,--no-undefined
)
target_link_options(${CC_LIB_NAME} PRIVATE -Wl,--whole-archive)
target_link_libraries(${CC_LIB_NAME}
PUBLIC ${CC_LIB_DEPS}
PRIVATE ${CC_LIB_LINKOPTS}
)
target_link_options(${CC_LIB_NAME} PRIVATE -Wl,--no-whole-archive)
target_include_directories(${CC_LIB_NAME}
PUBLIC
"$<BUILD_INTERFACE:${COMMON_INCLUDE_DIRS}>"
${CC_LIB_INCLUDES}
)
target_compile_options(${CC_LIB_NAME} PRIVATE ${CC_LIB_COPTS})
target_compile_definitions(${CC_LIB_NAME} PUBLIC ${CC_LIB_DEFINES})
else()
# Generating header only library
add_library(${CC_LIB_NAME} INTERFACE)
target_include_directories(${CC_LIB_NAME}
INTERFACE
"$<BUILD_INTERFACE:${COMMON_INCLUDE_DIRS}>"
${CC_LIB_INCLUDES}
)
target_link_libraries(${CC_LIB_NAME}
INTERFACE ${CC_LIB_DEPS} ${CC_LIB_LINKOPTS}
)
target_compile_definitions(${CC_LIB_NAME} INTERFACE ${CC_LIB_DEFINES})
endif()
# add alias for the library target
add_library(:${CC_LIB_NAME} ALIAS ${CC_LIB_NAME})
endfunction()

View File

@@ -0,0 +1,127 @@
include(CMakeParseArguments)
# inspired by https://github.com/abseil/abseil-cpp
# cc_test()
# CMake function to imitate Bazel's cc_test rule.
#
# Parameters:
# NAME: name of target (see Usage below)
# SRCS: List of source files for the binary
# DEPS: List of other libraries to be linked in to the binary targets
# COPTS: List of private compile options
# LINKOPTS: List of link options
# ARGS: Command line arguments to test case
#
# Usage:
# cc_library(
# NAME
# awesome
# HDRS
# "a.h"
# SRCS
# "a.cc"
# )
#
# cc_test(
# NAME
# awesome_test
# SRCS
# "awesome_test.cc"
# DEPS
# :awesome
# GTest::gmock
# )
#
function(cc_test)
if(NOT BUILD_TESTING)
return()
endif()
cmake_parse_arguments(
CC_TEST # prefix
"" # options
"NAME" # one value args
"SRCS;COPTS;LINKOPTS;DEPS;INCLUDES;ARGS;DATA" # multi value args
${ARGN}
)
# place test data in build directory
if(CC_TEST_DATA)
foreach(data ${CC_TEST_DATA})
configure_file(${data} ${CMAKE_CURRENT_BINARY_DIR}/${data} COPYONLY)
endforeach()
endif()
set(_CC_TEST_SRCS "")
set(_CC_TEST_INCLUDE_DIRS ${CC_TEST_INCLUDES})
list(APPEND _CC_TEST_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR})
# xllm test sources live under tests and often include private headers
# from the mirrored production source directory.
if(DEFINED XLLM_TESTS_DIR)
list(APPEND _CC_TEST_INCLUDE_DIRS
${PROJECT_SOURCE_DIR}/xllm
${XLLM_TESTS_DIR}
${XLLM_TESTS_DIR}/core
)
endif()
foreach(src IN LISTS CC_TEST_SRCS)
if(IS_ABSOLUTE "${src}")
list(APPEND _CC_TEST_SRCS "${src}")
get_filename_component(src_dir "${src}" DIRECTORY)
list(APPEND _CC_TEST_INCLUDE_DIRS "${src_dir}")
continue()
endif()
set(src_path "${CMAKE_CURRENT_SOURCE_DIR}/${src}")
if(EXISTS "${src_path}")
list(APPEND _CC_TEST_SRCS "${src}")
get_filename_component(src_dir "${src_path}" DIRECTORY)
list(APPEND _CC_TEST_INCLUDE_DIRS "${src_dir}")
if(DEFINED XLLM_TESTS_DIR)
file(RELATIVE_PATH xllm_test_src_dir "${XLLM_TESTS_DIR}" "${src_dir}")
if(NOT xllm_test_src_dir MATCHES "^\\.\\.")
list(APPEND _CC_TEST_INCLUDE_DIRS
"${PROJECT_SOURCE_DIR}/xllm/${xllm_test_src_dir}"
)
endif()
endif()
continue()
endif()
list(APPEND _CC_TEST_SRCS "${src}")
endforeach()
list(REMOVE_DUPLICATES _CC_TEST_INCLUDE_DIRS)
add_executable(${CC_TEST_NAME})
target_sources(${CC_TEST_NAME} PRIVATE ${_CC_TEST_SRCS})
target_include_directories(${CC_TEST_NAME}
PUBLIC
"$<BUILD_INTERFACE:${COMMON_INCLUDE_DIRS}>"
${_CC_TEST_INCLUDE_DIRS}
)
target_compile_options(${CC_TEST_NAME}
PRIVATE ${CC_TEST_COPTS}
)
target_link_libraries(${CC_TEST_NAME}
PUBLIC ${CC_TEST_DEPS}
PRIVATE ${CC_TEST_LINKOPTS}
)
if(USE_NPU)
set(COMMON_LIBS Python::Python torch_npu torch_python)
target_link_libraries(${CC_TEST_NAME} PRIVATE ${COMMON_LIBS})
endif()
add_dependencies(all_tests ${CC_TEST_NAME})
gtest_add_tests(
TARGET ${CC_TEST_NAME}
EXTRA_ARGS ${CC_TEST_ARGS}
)
#add_test(NAME ${CC_TEST_NAME} COMMAND ${CC_TEST_NAME} ${CC_TEST_ARGS})
endfunction()

View File

@@ -0,0 +1,69 @@
include(CMakeParseArguments)
include(CMakePrintHelpers)
# inspired by https://github.com/abseil/abseil-cpp
# proto_library()
# CMake function to imitate Bazel's proto_library rule.
#
# Parameters:
# NAME: name of target
# SRCS: List of proto source files for the library
# DEPS: List of other libraries to be linked in to the binary targets
# COPTS: List of private compile options
# DEFINES: List of public defines
# LINKOPTS: List of link options
#
# cc_library(
# NAME
# awesome
# HDRS
# "a.h"
# SRCS
# "a.cc"
# )
# proto_library(
# NAME
# proto_lib
# SRCS
# "b.proto"
# DEPS
# :awesome
# )
#
function(proto_library)
# parse arguments and set variables
cmake_parse_arguments(
PROTO_LIB # prefix
"" # options
"NAME" # one value args
"SRCS;COPTS;DEFINES;LINKOPTS;DEPS" # multi value args
${ARGN}
)
# generate cpp and hpp files from proto files using protoc compiler
protobuf_generate_cpp(PROTO_SRCS PROTO_HDRS ${PROTO_LIB_SRCS})
add_library(${PROTO_LIB_NAME} STATIC)
target_sources(${PROTO_LIB_NAME}
PRIVATE ${PROTO_SRCS} ${PROTO_HDRS}
)
target_link_libraries(${PROTO_LIB_NAME}
PUBLIC protobuf::libprotobuf
)
target_include_directories(${PROTO_LIB_NAME}
PUBLIC
${Protobuf_INCLUDE_DIRS}
${CMAKE_CURRENT_BINARY_DIR}
)
target_compile_options(${PROTO_LIB_NAME}
PRIVATE
${PROTO_LIB_COPTS}
-Wno-unused-parameter
)
target_compile_definitions(${PROTO_LIB_NAME}
PUBLIC
${PROTO_LIB_DEFINES}
)
add_library(proto::${PROTO_LIB_NAME} ALIAS ${PROTO_LIB_NAME})
endfunction()

View File

@@ -0,0 +1,103 @@
include(CMakeParseArguments)
# pybind_extension()
#
# Parameters:
# NAME: name of module
# HDRS: List of public header files for the library
# SRCS: List of source files for the library
# DEPS: List of other libraries to be linked in to the binary targets
# COPTS: List of private compile options
# DEFINES: List of public defines
# LINKOPTS: List of link options
#
# pybind_extension(
# NAME
# awesome
# HDRS
# "a.h"
# SRCS
# "a.cc"
# )
#
if(NOT DEFINED PYTHON_MODULE_EXTENSION OR NOT DEFINED PYTHON_MODULE_DEBUG_POSTFIX)
execute_process(
COMMAND
"${Python_EXECUTABLE}" "-c"
"import sys, importlib; s = importlib.import_module('distutils.sysconfig' if sys.version_info < (3, 10) else 'sysconfig'); print(s.get_config_var('EXT_SUFFIX') or s.get_config_var('SO'))"
OUTPUT_VARIABLE _PYTHON_MODULE_EXT_SUFFIX
ERROR_VARIABLE _PYTHON_MODULE_EXT_SUFFIX_ERR
OUTPUT_STRIP_TRAILING_WHITESPACE)
if(_PYTHON_MODULE_EXT_SUFFIX STREQUAL "")
message(
FATAL_ERROR "pybind11 could not query the module file extension, likely the 'distutils'"
"package is not installed. Full error message:\n${_PYTHON_MODULE_EXT_SUFFIX_ERR}"
)
endif()
# This needs to be available for the pybind11_extension function
if(NOT DEFINED PYTHON_MODULE_DEBUG_POSTFIX)
get_filename_component(_PYTHON_MODULE_DEBUG_POSTFIX "${_PYTHON_MODULE_EXT_SUFFIX}" NAME_WE)
set(PYTHON_MODULE_DEBUG_POSTFIX
"${_PYTHON_MODULE_DEBUG_POSTFIX}"
CACHE INTERNAL "")
endif()
if(NOT DEFINED PYTHON_MODULE_EXTENSION)
get_filename_component(_PYTHON_MODULE_EXTENSION "${_PYTHON_MODULE_EXT_SUFFIX}" EXT)
set(PYTHON_MODULE_EXTENSION
"${_PYTHON_MODULE_EXTENSION}"
CACHE INTERNAL "")
endif()
endif()
function(pybind_extension)
cmake_parse_arguments(
PY # prefix
"TESTONLY" # options
"NAME" # one value args
"HDRS;SRCS;COPTS;DEFINES;LINKOPTS;LINKDIRS;DEPS" # multi value args
${ARGN}
)
if(PY_TESTONLY AND (NOT BUILD_TESTING))
return()
endif()
add_dependencies(export_module ${PY_NAME})
add_library(${PY_NAME} SHARED)
target_sources(${PY_NAME}
PRIVATE ${PY_SRCS} ${PY_HDRS}
)
target_link_libraries(${PY_NAME}
PUBLIC ${PY_DEPS}
PRIVATE ${PY_LINKOPTS}
)
# search directories for libraries
target_link_directories(${PY_NAME}
PUBLIC ${PY_LINKDIRS}
)
target_compile_options(${PY_NAME} PRIVATE ${PY_COPTS})
target_compile_definitions(${PY_NAME} PUBLIC ${PY_DEFINES})
# -fvisibility=hidden is required to allow multiple modules compiled against
# different pybind versions to work properly, and for some features (e.g.
# py::module_local).
if(NOT DEFINED CMAKE_CXX_VISIBILITY_PRESET)
set_target_properties(${PY_NAME} PROPERTIES CXX_VISIBILITY_PRESET "hidden")
endif()
if(NOT DEFINED CMAKE_CUDA_VISIBILITY_PRESET)
set_target_properties(${PY_NAME} PROPERTIES CUDA_VISIBILITY_PRESET "hidden")
endif()
set_target_properties(
${PY_NAME}
PROPERTIES PREFIX ""
DEBUG_POSTFIX "${PYTHON_MODULE_DEBUG_POSTFIX}"
SUFFIX "${PYTHON_MODULE_EXTENSION}")
endfunction()