From 74063fc1cbd6ecb19ab803cc5960ddfb21f6a04f Mon Sep 17 00:00:00 2001 From: vansangpfiev Date: Mon, 26 Aug 2024 13:05:28 +0700 Subject: [PATCH] feat: pack cortex.llamacpp to cortex-cpp build --- .github/workflows/cortex-cpp-quality-gate.yml | 70 +++++++++++++++++-- cortex-cpp/CMakeLists.txt | 1 + cortex-cpp/Makefile | 8 ++- .../engines/cortex.llamacpp/engine.cmake | 58 +++++++++++++++ 4 files changed, 127 insertions(+), 10 deletions(-) create mode 100644 cortex-cpp/engines/cortex.llamacpp/engine.cmake diff --git a/.github/workflows/cortex-cpp-quality-gate.yml b/.github/workflows/cortex-cpp-quality-gate.yml index b30fb30de..ccf325d7d 100644 --- a/.github/workflows/cortex-cpp-quality-gate.yml +++ b/.github/workflows/cortex-cpp-quality-gate.yml @@ -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 diff --git a/cortex-cpp/CMakeLists.txt b/cortex-cpp/CMakeLists.txt index a53e9fa70..149a4b547 100644 --- a/cortex-cpp/CMakeLists.txt +++ b/cortex-cpp/CMakeLists.txt @@ -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) diff --git a/cortex-cpp/Makefile b/cortex-cpp/Makefile index 83c3f61f1..525216da5 100644 --- a/cortex-cpp/Makefile +++ b/cortex-cpp/Makefile @@ -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 diff --git a/cortex-cpp/engines/cortex.llamacpp/engine.cmake b/cortex-cpp/engines/cortex.llamacpp/engine.cmake new file mode 100644 index 000000000..04c05f4c9 --- /dev/null +++ b/cortex-cpp/engines/cortex.llamacpp/engine.cmake @@ -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() \ No newline at end of file