-
Notifications
You must be signed in to change notification settings - Fork 65
feat: native llama.cpp integration in cortex-daemon replacing ollama process #766
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Ishant5436
wants to merge
6
commits into
cxlinux-ai:main
Choose a base branch
from
Ishant5436:feat/native-cortex-inference
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
4b12fd5
feat: native llama.cpp integration in cortex-daemon replacing ollama …
Ishant5436 9455d88
chore: remove build dir and address CMake review feedback
Ishant5436 00e3d03
Address CodeRabbit feedback: handle NUL bytes, string allocations, ge…
Ishant5436 101c81e
Fix minor review feedback from CodeRabbit
Ishant5436 ffe6c18
chore: remove unused n_vocab variable
Ishant5436 03a46da
fix: resolve AI feedback on cortex-daemon bridging
Ishant5436 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,113 @@ | ||
| cmake_minimum_required(VERSION 3.20) | ||
| project(cortex-daemon VERSION 1.0.0 LANGUAGES C CXX) | ||
|
|
||
| set(CMAKE_CXX_STANDARD 17) | ||
| set(CMAKE_CXX_STANDARD_REQUIRED ON) | ||
| set(CMAKE_C_STANDARD 11) | ||
|
|
||
| # Build options | ||
| option(CORTEX_STATIC_LINK "Link llama.cpp statically" ON) | ||
| option(CORTEX_METAL "Enable Apple Metal GPU (macOS)" OFF) | ||
| option(CORTEX_CUDA "Enable NVIDIA CUDA GPU" OFF) | ||
| option(CORTEX_VULKAN "Enable Vulkan GPU" OFF) | ||
| option(CORTEX_AVX2 "Enable AVX2 SIMD (x86_64)" OFF) | ||
|
|
||
| # Detect architecture | ||
| if(CMAKE_SYSTEM_PROCESSOR MATCHES "arm64|aarch64") | ||
| set(ARCH_ARM64 TRUE) | ||
| message(STATUS "Target: ARM64") | ||
| elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64|amd64|AMD64") | ||
| set(ARCH_X86_64 TRUE) | ||
| message(STATUS "Target: x86_64") | ||
| else() | ||
| message(FATAL_ERROR "Unsupported architecture: ${CMAKE_SYSTEM_PROCESSOR}") | ||
| endif() | ||
|
|
||
| # ── llama.cpp submodule ────────────────────────────────────────────────────── | ||
| set(LLAMA_CPP_DIR "${CMAKE_SOURCE_DIR}/vendor/llama.cpp") | ||
|
|
||
| if(NOT EXISTS "${LLAMA_CPP_DIR}/CMakeLists.txt") | ||
| message(FATAL_ERROR | ||
| "llama.cpp submodule not found. Run:\n" | ||
| " git submodule update --init --recursive") | ||
| endif() | ||
|
|
||
| # Forward GPU options into llama.cpp's own build | ||
| set(LLAMA_METAL ${CORTEX_METAL} CACHE BOOL "" FORCE) | ||
| set(LLAMA_CUDA ${CORTEX_CUDA} CACHE BOOL "" FORCE) | ||
| set(LLAMA_VULKAN ${CORTEX_VULKAN} CACHE BOOL "" FORCE) | ||
|
|
||
| # Build llama.cpp as a library only (no CLI executables) | ||
| set(LLAMA_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE) | ||
| set(LLAMA_BUILD_TESTS OFF CACHE BOOL "" FORCE) | ||
| set(LLAMA_BUILD_SERVER OFF CACHE BOOL "" FORCE) | ||
|
|
||
| add_subdirectory(${LLAMA_CPP_DIR} llama_cpp_build) | ||
|
|
||
| # ── Cortex inference library ───────────────────────────────────────────────── | ||
| set(INFERENCE_SOURCES | ||
| src/inference/llama_engine.cpp | ||
| src/inference/inference_manager.cpp | ||
| src/bindings/llama_c_bridge.cpp | ||
| src/models/model_registry.cpp | ||
| ) | ||
|
|
||
| if(CORTEX_STATIC_LINK) | ||
| add_library(cortex_inference STATIC ${INFERENCE_SOURCES}) | ||
| else() | ||
| add_library(cortex_inference SHARED ${INFERENCE_SOURCES}) | ||
| set_target_properties(cortex_inference PROPERTIES | ||
| VERSION ${PROJECT_VERSION} | ||
| SOVERSION 1 | ||
| ) | ||
| endif() | ||
|
|
||
| target_include_directories(cortex_inference | ||
| PUBLIC | ||
| $<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/src> | ||
| $<INSTALL_INTERFACE:include/cortex> | ||
| PRIVATE | ||
| ${LLAMA_CPP_DIR} | ||
| ${LLAMA_CPP_DIR}/common | ||
| ) | ||
|
|
||
| # Use portable Threads package | ||
| find_package(Threads REQUIRED) | ||
|
|
||
| target_link_libraries(cortex_inference | ||
| PUBLIC llama Threads::Threads | ||
| PRIVATE $<$<PLATFORM_ID:Linux>:dl> | ||
| ) | ||
|
Comment on lines
+77
to
+80
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hardcoding |
||
|
|
||
| # Conditional compiler flags for non-MSVC | ||
| if(NOT MSVC) | ||
| target_compile_options(cortex_inference PRIVATE | ||
| -O3 | ||
| -ffast-math | ||
| -fvisibility=hidden | ||
| $<$<CXX_COMPILER_ID:GNU,Clang>:-Wall -Wextra -Wpedantic> | ||
| ) | ||
|
|
||
| # Restrict ARM64 flags to non-Apple to prevent macOS build failures | ||
| if(ARCH_ARM64) | ||
| if(NOT APPLE) | ||
| target_compile_options(cortex_inference PRIVATE -mcpu=native) | ||
| endif() | ||
| elseif(ARCH_X86_64) | ||
| # Avoid -march=native by default to ensure binary portability | ||
| target_compile_options(cortex_inference PRIVATE | ||
| $<$<BOOL:${CORTEX_AVX2}>:-mavx2 -mfma> | ||
| ) | ||
| endif() | ||
| endif() | ||
|
|
||
| # ── Cortex daemon executable ───────────────────────────────────────────────── | ||
| add_executable(cortexd src/main.cpp) | ||
| target_link_libraries(cortexd PRIVATE cortex_inference) | ||
|
|
||
| # ── Tests ──────────────────────────────────────────────────────────────────── | ||
| # Guard enable_testing() to prevent affecting parent projects | ||
| if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME) | ||
| enable_testing() | ||
| add_subdirectory(tests) | ||
| endif() | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To support portable thread linking, we should find the
Threadspackage usingfind_package(Threads REQUIRED).