Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ __pycache__/

# txt
*.txt
!CMakeLists.txt

*.http

Expand Down
90 changes: 90 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
cmake_minimum_required(VERSION 3.18)
project(infinilm LANGUAGES CXX)

# ==================== Basic Configuration ====================
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# INFINI_ROOT environment variable
if(DEFINED ENV{INFINI_ROOT})
set(INFINI_ROOT "$ENV{INFINI_ROOT}")
elseif(WIN32)
set(INFINI_ROOT "$ENV{HOMEPATH}/.infini")
else()
set(INFINI_ROOT "$ENV{HOME}/.infini")
endif()

# ==================== Compilation Options ====================
option(USE_KV_CACHING "Whether to compile the path using the kv caching operator" OFF)
if(USE_KV_CACHING)
add_definitions(-DENABLE_KV_CACHING)
endif()

option(USE_CLASSIC_LLAMA "Whether to use the classic LlamaForCausalLM" OFF)
if(USE_CLASSIC_LLAMA)
add_definitions(-DUSE_CLASSIC_LLAMA)
endif()

# ==================== Third-party Headers ====================
# spdlog (third_party)
include_directories("${CMAKE_SOURCE_DIR}/third_party/spdlog/include")

# json (third_party)
include_directories("${CMAKE_SOURCE_DIR}/third_party/json/single_include/")

# Infini headers
include_directories("${INFINI_ROOT}/include")

# Local includes
include_directories("${CMAKE_SOURCE_DIR}/include")

# ==================== Find pybind11 ====================
# Method 1: Use find_package
find_package(pybind11 REQUIRED)

# Method 2: If pybind11 exists as a subdirectory
# add_subdirectory(third_party/pybind11)
# Note: If using Method 1, ensure pybind11 is installed or CMAKE_PREFIX_PATH is set

# ==================== Library Link Directories ====================
link_directories("${INFINI_ROOT}/lib")

# ==================== Build Target ====================
pybind11_add_module(_infinilm MODULE
# Source files - recursively add all files under csrc
# Alternatively, use file(GLOB) to collect files
)

# Collect source files
file(GLOB_RECURSE INFINILM_SOURCES
"${CMAKE_SOURCE_DIR}/csrc/*.cpp"
"${CMAKE_SOURCE_DIR}/csrc/*.cc"
)

# Add source files to target
target_sources(_infinilm PRIVATE ${INFINILM_SOURCES})

# ==================== Link Libraries ====================
target_link_libraries(_infinilm PRIVATE
infinicore_cpp_api
infiniop
infinirt
infiniccl
)

# ==================== Target Properties ====================
# Set output directory (corresponds to xmake's set_installdir)
set_target_properties(_infinilm PROPERTIES
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/python/infinilm/lib"
PREFIX "" # Remove lib prefix
)

# If pybind11 requires specific compile definitions
target_compile_definitions(_infinilm PRIVATE
$<$<CONFIG:Debug>:DEBUG>
)

# ==================== Python Module Installation (Optional) ====================
# install(TARGETS _infinilm
# LIBRARY DESTINATION python/infinilm/lib
# )
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,30 @@
```


- 安装 InfiniLM c++ 引擎

使用xmake编译和安装
```bash
xmake build _infinilm && xmake install _infinilm
```

使用cmake编译和安装
```bash
mkdir build && cd build

# 可能需要手动确保pybind11版本与InfiniCore的xmake一致
# 可能需要手动指定python版本
cmake .. \
-Dpybind11_DIR=/<path-to>/pybind11/share/cmake/pybind11 \
-DPYTHON_EXECUTABLE=$(which python)

cmake --build . -j$(nproc)

cd ..
```


- 安装 InfiniLM Python 包
```bash
pip install -e .
Expand Down
6 changes: 4 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@

def build_cpp_module():
"""Build and install the C++ extension module"""
subprocess.run(["xmake", "build", "_infinilm"], check=True)
subprocess.run(["xmake", "install", "_infinilm"], check=True)
return
# xmake build is now optional
# subprocess.run(["xmake", "build", "_infinilm"], check=True)
# subprocess.run(["xmake", "install", "_infinilm"], check=True)


class Build(build):
Expand Down