Skip to content

Commit

Permalink
feat: pack cortex.llamacpp to cortex-cpp build
Browse files Browse the repository at this point in the history
  • Loading branch information
vansangpfiev committed Aug 26, 2024
1 parent ab128f5 commit 74063fc
Show file tree
Hide file tree
Showing 4 changed files with 127 additions and 10 deletions.
70 changes: 63 additions & 7 deletions .github/workflows/cortex-cpp-quality-gate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,29 +22,85 @@ jobs:
matrix:
include:
- os: "linux"
name: "amd64"
name: "amd64-noavx"
runs-on: "ubuntu-20-04"
cmake-flags: "-DCORTEX_CPP_VERSION=${{github.event.pull_request.head.sha}}"
cmake-flags: "-DLLAMA_NATIVE=OFF"
build-deps-cmake-flags: ""
run-e2e: false
ccache-dir: ''

- os: "linux"
name: "amd64-vulkan"
runs-on: "ubuntu-20-04-cuda-11-7"
cmake-flags: "-DLLAMA_VULKAN=ON -DLLAMA_NATIVE=OFF"
build-deps-cmake-flags: ""
run-e2e: false
ccache-dir: ''

- os: "linux"
name: "amd64-noavx-cuda-11-7"
runs-on: "ubuntu-20-04-cuda-11-7"
cmake-flags: "-DCUDA_11_7=ON -DLLAMA_NATIVE=OFF -DLLAMA_CUDA=ON"
build-deps-cmake-flags: ""
run-e2e: false
ccache-dir: ''

- os: "linux"
name: "amd64-noavx-cuda-12-0"
runs-on: "ubuntu-20-04-cuda-12-0"
cmake-flags: "-DCUDA_12_0=ON -DLLAMA_NATIVE=OFF -DLLAMA_CUDA=ON"
build-deps-cmake-flags: ""
run-e2e: false
ccache-dir: ''

- os: "mac"
name: "amd64"
runs-on: "macos-13"
cmake-flags: "-DCORTEX_CPP_VERSION=${{github.event.pull_request.head.sha}}"
cmake-flags: ""
build-deps-cmake-flags: ""
run-e2e: false
ccache-dir: ''

- os: "mac"
name: "arm64"
runs-on: "mac-silicon"
cmake-flags: "-DCORTEX_CPP_VERSION=${{github.event.pull_request.head.sha}} -DMAC_ARM64=ON"
cmake-flags: "-DMAC_ARM64=ON"
build-deps-cmake-flags: ""
run-e2e: false
ccache-dir: ''

- os: "windows"
name: "amd64"
name: "amd64-noavx"
runs-on: "windows-cuda-11-7"
cmake-flags: "-DLLAMA_NATIVE=OFF -DLLAMA_BUILD_SERVER=ON -DLLAMA_BLAS=ON -DBUILD_SHARED_LIBS=OFF -DCMAKE_BUILD_TYPE=RELEASE -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CUDA_COMPILER_LAUNCHER=ccache -GNinja"
build-deps-cmake-flags: "-DCMAKE_BUILD_TYPE=RELEASE -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CUDA_COMPILER_LAUNCHER=ccache -GNinja"
run-e2e: false
ccache-dir: 'C:\Users\ContainerAdministrator\AppData\Local\ccache'

- os: "windows"
name: "amd64-vulkan"
runs-on: "windows-cuda-12-0"
cmake-flags: "-DLLAMA_VULKAN=ON -DLLAMA_NATIVE=OFF -DLLAMA_BUILD_SERVER=ON -DBUILD_SHARED_LIBS=OFF -DCMAKE_BUILD_TYPE=RELEASE -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CUDA_COMPILER_LAUNCHER=ccache -GNinja"
build-deps-cmake-flags: "-DCMAKE_BUILD_TYPE=RELEASE -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CUDA_COMPILER_LAUNCHER=ccache -GNinja"
run-e2e: false
ccache-dir: 'C:\Users\ContainerAdministrator\AppData\Local\ccache'

- os: "windows"
name: "amd64-noavx-cuda-12-0"
runs-on: "windows-cuda-12-0"
cmake-flags: "-DCORTEX_CPP_VERSION=${{github.event.pull_request.head.sha}} -DBUILD_SHARED_LIBS=OFF -DCMAKE_BUILD_TYPE=RELEASE -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CUDA_COMPILER_LAUNCHER=ccache -GNinja"
cmake-flags: "-DLLAMA_NATIVE=OFF -DCUDA_12_0=ON -DLLAMA_BUILD_SERVER=ON -DLLAMA_CUDA=ON -DBUILD_SHARED_LIBS=OFF -DCMAKE_BUILD_TYPE=RELEASE -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CUDA_COMPILER_LAUNCHER=ccache -GNinja"
build-deps-cmake-flags: "-DCMAKE_BUILD_TYPE=RELEASE -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CUDA_COMPILER_LAUNCHER=ccache -GNinja"
ccache-dir: 'C:\Users\ContainerAdministrator\AppData\Local\ccache'
run-e2e: false
ccache-dir: 'C:\Users\ContainerAdministrator\AppData\Local\ccache'

- os: "windows"
name: "amd64-noavx-cuda-11-7"
runs-on: "windows-cuda-11-7"
cmake-flags: "-DLLAMA_NATIVE=OFF -DCUDA_11_7=ON -DLLAMA_BUILD_SERVER=ON -DLLAMA_CUDA=ON -DBUILD_SHARED_LIBS=OFF -DCMAKE_BUILD_TYPE=RELEASE -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CUDA_COMPILER_LAUNCHER=ccache -GNinja"
build-deps-cmake-flags: "-DCMAKE_BUILD_TYPE=RELEASE -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CUDA_COMPILER_LAUNCHER=ccache -GNinja"
run-e2e: false
ccache-dir: 'C:\Users\ContainerAdministrator\AppData\Local\ccache'

steps:
- name: Clone
id: checkout
Expand Down
1 change: 1 addition & 0 deletions cortex-cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
cmake_minimum_required(VERSION 3.5)

project(cortex-cpp C CXX)
include(engines/cortex.llamacpp/engine.cmake)

# Build using CMAKE-JS
if(DEFINED CMAKE_JS_INC)
Expand Down
8 changes: 5 additions & 3 deletions cortex-cpp/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,18 @@ endif

pre-package:
ifeq ($(OS),Windows_NT)
@powershell -Command "mkdir -p cortex-cpp;"
@powershell -Command "mkdir -p cortex-cpp\engines\cortex.llamacpp\; cp build\engines\cortex.llamacpp\engine.dll cortex-cpp\engines\cortex.llamacpp\;"
@powershell -Command "cp build\cortex-cpp.exe .\cortex-cpp\;"
@powershell -Command "cp ..\.github\patches\windows\msvcp140.dll .\cortex-cpp\;"
@powershell -Command "cp ..\.github\patches\windows\vcruntime140_1.dll .\cortex-cpp\;"
@powershell -Command "cp ..\.github\patches\windows\vcruntime140.dll .\cortex-cpp\;"
else ifeq ($(shell uname -s),Linux)
@mkdir -p cortex-cpp; \
@mkdir -p cortex-cpp/engines/cortex.llamacpp; \
cp build/engines/cortex.llamacpp/libengine.so cortex-cpp/engines/cortex.llamacpp/; \
cp build/cortex-cpp cortex-cpp/;
else
@mkdir -p cortex-cpp; \
@mkdir -p cortex-cpp/engines/cortex.llamacpp; \
cp build/engines/cortex.llamacpp/libengine.dylib cortex-cpp/engines/cortex.llamacpp/; \
cp build/cortex-cpp cortex-cpp/;
endif

Expand Down
58 changes: 58 additions & 0 deletions cortex-cpp/engines/cortex.llamacpp/engine.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# cortex.llamacpp release version
set(VERSION 0.1.25)

set(ENGINE_VERSION v${VERSION})
add_compile_definitions(CORTEX_LLAMACPP_VERSION="${VERSION}")

# MESSAGE("ENGINE_VERSION=" ${ENGINE_VERSION})

# Download library based on instructions
if(UNIX AND NOT APPLE)
if(CUDA_12_0)
set(LIBRARY_NAME cortex.llamacpp-${VERSION}-linux-amd64-noavx-cuda-12-0.tar.gz)
elseif(CUDA_11_7)
set(LIBRARY_NAME cortex.llamacpp-${VERSION}-linux-amd64-noavx-cuda-11-7.tar.gz)
elseif(LLAMA_VULKAN)
set(LIBRARY_NAME cortex.llamacpp-${VERSION}-linux-amd64-vulkan.tar.gz)
set(ENGINE_VERSION v${VERSION})
else()
set(LIBRARY_NAME cortex.llamacpp-${VERSION}-linux-amd64-noavx.tar.gz)
endif()
elseif(UNIX)
if(MAC_ARM64)
set(LIBRARY_NAME cortex.llamacpp-${VERSION}-mac-arm64.tar.gz)
else()
set(LIBRARY_NAME cortex.llamacpp-${VERSION}-mac-amd64.tar.gz)
endif()
else()
if(CUDA_12_0)
set(LIBRARY_NAME cortex.llamacpp-${VERSION}-windows-amd64-noavx-cuda-12-0.tar.gz)
elseif(CUDA_11_7)
set(LIBRARY_NAME cortex.llamacpp-${VERSION}-windows-amd64-noavx-cuda-11-7.tar.gz)
elseif(LLAMA_VULKAN)
set(LIBRARY_NAME cortex.llamacpp-${VERSION}-windows-amd64-vulkan.tar.gz)
set(ENGINE_VERSION v${VERSION})
else()
set(LIBRARY_NAME cortex.llamacpp-${VERSION}-windows-amd64-noavx.tar.gz)
endif()
endif()


set(LIBLLAMA_ENGINE_URL https://github.com/janhq/cortex.llamacpp/releases/download/${ENGINE_VERSION}/${LIBRARY_NAME})
# MESSAGE("LIBLLAMA_ENGINE_URL="${LIBLLAMA_ENGINE_URL})
# MESSAGE("LIBARRY_NAME=" ${LIBRARY_NAME})

set(LIBLLAMA_ENGINE_PATH ${CMAKE_BINARY_DIR}/engines/${LIBRARY_NAME})

# MESSAGE("CMAKE_BINARY_DIR = " ${CMAKE_BINARY_DIR})

file(DOWNLOAD ${LIBLLAMA_ENGINE_URL} ${LIBLLAMA_ENGINE_PATH} STATUS LIBLLAMA_ENGINE_DOWNLOAD_STATUS)
list(GET LIBLLAMA_ENGINE_DOWNLOAD_STATUS 0 LIBLLAMA_ENGINE_DOWNLOAD_STATUS_NO)
# MESSAGE("file = " ${CMAKE_BINARY_DIR}/engines/${LIBRARY_NAME})

if(LIBLLAMA_ENGINE_DOWNLOAD_STATUS_NO)
message(STATUS "Pre-built library not downloaded. (${LIBLLAMA_ENGINE_DOWNLOAD_STATUS})")
else()
message(STATUS "Linking downloaded pre-built library.")
file(ARCHIVE_EXTRACT INPUT ${CMAKE_BINARY_DIR}/engines/${LIBRARY_NAME} DESTINATION ${CMAKE_BINARY_DIR}/engines/)
endif()

0 comments on commit 74063fc

Please sign in to comment.