2024-05-18 15:55:54 +00:00
|
|
|
cmake_minimum_required(VERSION 3.14) # for add_link_options and implicit target directories.
|
2023-03-21 00:37:16 +00:00
|
|
|
project("llama.cpp" C CXX)
|
ggml : add unified SYCL backend for Intel GPUs (#2690)
* first update for migration
* update init_cublas
* add debug functio, commit all help code
* step 1
* step 2
* step3 add fp16, slower 31->28
* add GGML_LIST_DEVICE function
* step 5 format device and print
* step6, enhance error check, remove CUDA macro, enhance device id to fix none-zero id issue
* support main device is non-zero
* step7 add debug for code path, rm log
* step 8, rename all macro & func from cuda by sycl
* fix error of select non-zero device, format device list
* ren ggml-sycl.hpp -> ggml-sycl.h
* clear CMAKE to rm unused lib and options
* correct queue: rm dtct:get_queue
* add print tensor function to debug
* fix error: wrong result in 658746bb26702e50f2c59c0e4ada8e9da6010481
* summary dpct definition in one header file to replace folder:dpct
* refactor device log
* mv dpct definition from folder dpct to ggml-sycl.h
* update readme, refactor build script
* fix build with sycl
* set nthread=1 when sycl, increase performance
* add run script, comment debug code
* add ls-sycl-device tool
* add ls-sycl-device, rm unused files
* rm rear space
* dos2unix
* Update README_sycl.md
* fix return type
* remove sycl version from include path
* restore rm code to fix hang issue
* add syc and link for sycl readme
* rm original sycl code before refactor
* fix code err
* add know issue for pvc hang issue
* enable SYCL_F16 support
* align pr4766
* check for sycl blas, better performance
* cleanup 1
* remove extra endif
* add build&run script, clean CMakefile, update guide by review comments
* rename macro to intel hardware
* editor config format
* format fixes
* format fixes
* editor format fix
* Remove unused headers
* skip build sycl tool for other code path
* replace tab by space
* fix blas matmul function
* fix mac build
* restore hip dependency
* fix conflict
* ren as review comments
* mv internal function to .cpp file
* export funciton print_sycl_devices(), mv class dpct definition to source file
* update CI/action for sycl code, fix CI error of repeat/dup
* fix action ID format issue
* rm unused strategy
* enable llama_f16 in ci
* fix conflict
* fix build break on MacOS, due to CI of MacOS depend on external ggml, instead of internal ggml
* fix ci cases for unsupported data type
* revert unrelated changed in cuda cmake
remove useless nommq
fix typo of GGML_USE_CLBLAS_SYCL
* revert hip cmake changes
* fix indent
* add prefix in func name
* revert no mmq
* rm cpu blas duplicate
* fix no_new_line
* fix src1->type==F16 bug.
* pass batch offset for F16 src1
* fix batch error
* fix wrong code
* revert sycl checking in test-sampling
* pass void as arguments of ggml_backend_sycl_print_sycl_devices
* remove extra blank line in test-sampling
* revert setting n_threads in sycl
* implement std::isinf for icpx with fast math.
* Update ci/run.sh
Co-authored-by: Georgi Gerganov <ggerganov@gmail.com>
* Update examples/sycl/run-llama2.sh
Co-authored-by: Georgi Gerganov <ggerganov@gmail.com>
* Update examples/sycl/run-llama2.sh
Co-authored-by: Georgi Gerganov <ggerganov@gmail.com>
* Update CMakeLists.txt
Co-authored-by: Georgi Gerganov <ggerganov@gmail.com>
* Update CMakeLists.txt
Co-authored-by: Georgi Gerganov <ggerganov@gmail.com>
* Update CMakeLists.txt
Co-authored-by: Georgi Gerganov <ggerganov@gmail.com>
* Update CMakeLists.txt
Co-authored-by: Georgi Gerganov <ggerganov@gmail.com>
* add copyright and MIT license declare
* update the cmd example
---------
Co-authored-by: jianyuzh <jianyu.zhang@intel.com>
Co-authored-by: luoyu-intel <yu.luo@intel.com>
Co-authored-by: Meng, Hengyu <hengyu.meng@intel.com>
Co-authored-by: Georgi Gerganov <ggerganov@gmail.com>
2024-01-28 15:56:23 +00:00
|
|
|
include(CheckIncludeFileCXX)
|
2023-03-13 17:12:33 +00:00
|
|
|
|
2024-06-26 15:33:02 +00:00
|
|
|
#set(CMAKE_WARN_DEPRECATED YES)
|
|
|
|
set(CMAKE_WARN_UNUSED_CLI YES)
|
|
|
|
|
2023-03-21 15:29:41 +00:00
|
|
|
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
|
|
|
|
2023-03-13 19:22:15 +00:00
|
|
|
if (NOT XCODE AND NOT MSVC AND NOT CMAKE_BUILD_TYPE)
|
|
|
|
set(CMAKE_BUILD_TYPE Release CACHE STRING "Build type" FORCE)
|
|
|
|
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo")
|
|
|
|
endif()
|
|
|
|
|
2024-06-26 15:33:02 +00:00
|
|
|
# Add path to modules
|
|
|
|
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/")
|
|
|
|
|
2023-03-21 15:29:41 +00:00
|
|
|
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
|
|
|
|
|
2023-11-05 08:03:09 +00:00
|
|
|
if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
|
2023-03-21 15:29:41 +00:00
|
|
|
set(LLAMA_STANDALONE ON)
|
|
|
|
|
2024-06-26 15:33:02 +00:00
|
|
|
include(git-vars)
|
|
|
|
|
2023-03-21 15:29:41 +00:00
|
|
|
# configure project version
|
|
|
|
# TODO
|
|
|
|
else()
|
|
|
|
set(LLAMA_STANDALONE OFF)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if (EMSCRIPTEN)
|
|
|
|
set(BUILD_SHARED_LIBS_DEFAULT OFF)
|
|
|
|
|
|
|
|
option(LLAMA_WASM_SINGLE_FILE "llama: embed WASM inside the generated llama.js" ON)
|
|
|
|
else()
|
|
|
|
if (MINGW)
|
|
|
|
set(BUILD_SHARED_LIBS_DEFAULT OFF)
|
|
|
|
else()
|
|
|
|
set(BUILD_SHARED_LIBS_DEFAULT ON)
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
2024-06-26 15:33:02 +00:00
|
|
|
option(BUILD_SHARED_LIBS "build shared libraries" ${BUILD_SHARED_LIBS_DEFAULT})
|
2023-03-21 15:29:41 +00:00
|
|
|
|
2024-07-04 10:53:42 +00:00
|
|
|
if (WIN32)
|
|
|
|
add_compile_definitions(_CRT_SECURE_NO_WARNINGS)
|
|
|
|
endif()
|
|
|
|
|
2023-03-21 00:37:16 +00:00
|
|
|
#
|
2024-06-26 15:33:02 +00:00
|
|
|
# option list
|
2023-03-21 00:37:16 +00:00
|
|
|
#
|
2023-03-13 17:12:33 +00:00
|
|
|
|
2023-03-21 00:37:16 +00:00
|
|
|
# general
|
2024-06-26 15:33:02 +00:00
|
|
|
option(LLAMA_CCACHE "llama: use ccache if available" ON)
|
2023-03-13 17:12:33 +00:00
|
|
|
|
2023-03-21 00:37:16 +00:00
|
|
|
# debug
|
2024-06-26 15:33:02 +00:00
|
|
|
option(LLAMA_ALL_WARNINGS "llama: enable all compiler warnings" ON)
|
|
|
|
option(LLAMA_ALL_WARNINGS_3RD_PARTY "llama: enable all compiler warnings in 3rd party libs" OFF)
|
2023-03-21 00:37:16 +00:00
|
|
|
|
2024-02-17 21:03:14 +00:00
|
|
|
# build
|
2024-06-26 15:33:02 +00:00
|
|
|
option(LLAMA_FATAL_WARNINGS "llama: enable -Werror flag" OFF)
|
2024-02-17 21:03:14 +00:00
|
|
|
|
2023-03-21 00:37:16 +00:00
|
|
|
# sanitizers
|
2024-06-26 15:33:02 +00:00
|
|
|
option(LLAMA_SANITIZE_THREAD "llama: enable thread sanitizer" OFF)
|
|
|
|
option(LLAMA_SANITIZE_ADDRESS "llama: enable address sanitizer" OFF)
|
|
|
|
option(LLAMA_SANITIZE_UNDEFINED "llama: enable undefined sanitizer" OFF)
|
2023-10-03 16:53:15 +00:00
|
|
|
|
2024-06-26 15:33:02 +00:00
|
|
|
# extra artifacts
|
|
|
|
option(LLAMA_BUILD_TESTS "llama: build tests" ${LLAMA_STANDALONE})
|
|
|
|
option(LLAMA_BUILD_EXAMPLES "llama: build examples" ${LLAMA_STANDALONE})
|
|
|
|
option(LLAMA_BUILD_SERVER "llama: build server example" ${LLAMA_STANDALONE})
|
2024-01-14 08:41:44 +00:00
|
|
|
|
2023-03-21 00:37:16 +00:00
|
|
|
# 3rd party libs
|
2024-06-26 15:33:02 +00:00
|
|
|
option(LLAMA_CURL "llama: use libcurl to download model from an URL" OFF)
|
2023-03-21 15:29:41 +00:00
|
|
|
|
2023-11-27 19:25:42 +00:00
|
|
|
# Required for relocatable CMake package
|
2024-06-26 15:33:02 +00:00
|
|
|
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/build-info.cmake)
|
|
|
|
|
|
|
|
# override ggml options
|
|
|
|
set(GGML_CCACHE ${LLAMA_CCACHE})
|
|
|
|
set(GGML_SANITIZE_THREAD ${LLAMA_SANITIZE_THREAD})
|
|
|
|
set(GGML_SANITIZE_ADDRESS ${LLAMA_SANITIZE_ADDRESS})
|
|
|
|
set(GGML_SANITIZE_UNDEFINED ${LLAMA_SANITIZE_UNDEFINED})
|
|
|
|
set(GGML_ALL_WARNINGS ${LLAMA_ALL_WARNINGS})
|
|
|
|
set(GGML_FATAL_WARNINGS ${LLAMA_FATAL_WARNINGS})
|
2024-06-28 10:37:45 +00:00
|
|
|
|
|
|
|
# change the default for these ggml options
|
|
|
|
if (NOT DEFINED GGML_LLAMAFILE)
|
|
|
|
set(GGML_LLAMAFILE ON)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if (NOT DEFINED GGML_CUDA_USE_GRAPHS)
|
|
|
|
set(GGML_CUDA_USE_GRAPHS ON)
|
|
|
|
endif()
|
2024-06-26 15:33:02 +00:00
|
|
|
|
|
|
|
# transition helpers
|
|
|
|
function (llama_option_depr TYPE OLD NEW)
|
|
|
|
if (${OLD})
|
|
|
|
message(${TYPE} "${OLD} is deprecated and will be removed in the future.\nUse ${NEW} instead\n")
|
2024-06-27 18:04:39 +00:00
|
|
|
set(${NEW} ON PARENT_SCOPE)
|
2023-03-13 17:12:33 +00:00
|
|
|
endif()
|
2023-12-13 17:10:10 +00:00
|
|
|
endfunction()
|
|
|
|
|
2024-06-26 15:33:02 +00:00
|
|
|
llama_option_depr(FATAL_ERROR LLAMA_CUBLAS GGML_CUDA)
|
|
|
|
llama_option_depr(WARNING LLAMA_CUDA GGML_CUDA)
|
|
|
|
llama_option_depr(WARNING LLAMA_KOMPUTE GGML_KOMPUTE)
|
|
|
|
llama_option_depr(WARNING LLAMA_METAL GGML_METAL)
|
|
|
|
llama_option_depr(WARNING LLAMA_METAL_EMBED_LIBRARY GGML_METAL_EMBED_LIBRARY)
|
|
|
|
llama_option_depr(WARNING LLAMA_NATIVE GGML_NATIVE)
|
|
|
|
llama_option_depr(WARNING LLAMA_RPC GGML_RPC)
|
|
|
|
llama_option_depr(WARNING LLAMA_SYCL GGML_SYCL)
|
|
|
|
llama_option_depr(WARNING LLAMA_SYCL_F16 GGML_SYCL_F16)
|
2023-12-12 09:27:26 +00:00
|
|
|
|
2023-09-08 14:58:07 +00:00
|
|
|
#
|
2024-06-26 15:33:02 +00:00
|
|
|
# build the library
|
2023-09-08 14:58:07 +00:00
|
|
|
#
|
|
|
|
|
2024-06-26 15:33:02 +00:00
|
|
|
add_subdirectory(ggml)
|
|
|
|
add_subdirectory(src)
|
2023-09-14 17:04:40 +00:00
|
|
|
|
2023-08-21 20:07:43 +00:00
|
|
|
#
|
|
|
|
# install
|
|
|
|
#
|
|
|
|
|
2023-07-19 07:01:11 +00:00
|
|
|
include(GNUInstallDirs)
|
2023-09-14 17:04:40 +00:00
|
|
|
include(CMakePackageConfigHelpers)
|
|
|
|
|
2024-06-26 15:33:02 +00:00
|
|
|
set(LLAMA_BUILD_NUMBER ${BUILD_NUMBER})
|
|
|
|
set(LLAMA_BUILD_COMMIT ${BUILD_COMMIT})
|
2023-09-14 17:04:40 +00:00
|
|
|
set(LLAMA_INSTALL_VERSION 0.0.${BUILD_NUMBER})
|
2024-06-26 15:33:02 +00:00
|
|
|
|
|
|
|
set(LLAMA_INCLUDE_INSTALL_DIR ${CMAKE_INSTALL_INCLUDEDIR} CACHE PATH "Location of header files")
|
|
|
|
set(LLAMA_LIB_INSTALL_DIR ${CMAKE_INSTALL_LIBDIR} CACHE PATH "Location of library files")
|
|
|
|
set(LLAMA_BIN_INSTALL_DIR ${CMAKE_INSTALL_BINDIR} CACHE PATH "Location of binary files")
|
|
|
|
|
2023-10-02 09:51:49 +00:00
|
|
|
get_directory_property(LLAMA_TRANSIENT_DEFINES COMPILE_DEFINITIONS)
|
2023-09-14 17:04:40 +00:00
|
|
|
|
2024-06-26 15:33:02 +00:00
|
|
|
set_target_properties(llama PROPERTIES PUBLIC_HEADER ${CMAKE_CURRENT_SOURCE_DIR}/include/llama.h)
|
|
|
|
install(TARGETS llama LIBRARY PUBLIC_HEADER)
|
|
|
|
|
2023-09-14 17:04:40 +00:00
|
|
|
configure_package_config_file(
|
2024-06-26 15:33:02 +00:00
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/cmake/llama-config.cmake.in
|
|
|
|
${CMAKE_CURRENT_BINARY_DIR}/llama-config.cmake
|
|
|
|
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/llama
|
2023-09-14 17:04:40 +00:00
|
|
|
PATH_VARS LLAMA_INCLUDE_INSTALL_DIR
|
|
|
|
LLAMA_LIB_INSTALL_DIR
|
|
|
|
LLAMA_BIN_INSTALL_DIR )
|
|
|
|
|
|
|
|
write_basic_package_version_file(
|
2024-06-26 15:33:02 +00:00
|
|
|
${CMAKE_CURRENT_BINARY_DIR}/llama-version.cmake
|
2023-09-14 17:04:40 +00:00
|
|
|
VERSION ${LLAMA_INSTALL_VERSION}
|
|
|
|
COMPATIBILITY SameMajorVersion)
|
|
|
|
|
2024-06-26 15:33:02 +00:00
|
|
|
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/llama-config.cmake
|
|
|
|
${CMAKE_CURRENT_BINARY_DIR}/llama-version.cmake
|
|
|
|
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/llama)
|
2023-09-14 17:04:40 +00:00
|
|
|
|
2023-07-19 07:01:11 +00:00
|
|
|
install(
|
2024-07-02 10:05:43 +00:00
|
|
|
FILES convert_hf_to_gguf.py
|
2023-07-19 07:01:11 +00:00
|
|
|
PERMISSIONS
|
|
|
|
OWNER_READ
|
|
|
|
OWNER_WRITE
|
|
|
|
OWNER_EXECUTE
|
|
|
|
GROUP_READ
|
|
|
|
GROUP_EXECUTE
|
|
|
|
WORLD_READ
|
|
|
|
WORLD_EXECUTE
|
|
|
|
DESTINATION ${CMAKE_INSTALL_BINDIR})
|
2023-04-20 01:14:14 +00:00
|
|
|
|
2024-06-03 08:06:24 +00:00
|
|
|
configure_file(cmake/llama.pc.in
|
|
|
|
"${CMAKE_CURRENT_BINARY_DIR}/llama.pc"
|
|
|
|
@ONLY)
|
|
|
|
|
|
|
|
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/llama.pc"
|
|
|
|
DESTINATION lib/pkgconfig)
|
|
|
|
|
2023-03-21 15:29:41 +00:00
|
|
|
#
|
|
|
|
# programs, examples and tests
|
|
|
|
#
|
|
|
|
|
2023-08-21 20:07:43 +00:00
|
|
|
add_subdirectory(common)
|
|
|
|
|
2023-03-21 15:29:41 +00:00
|
|
|
if (LLAMA_BUILD_TESTS AND NOT CMAKE_JS_VERSION)
|
2023-03-30 17:56:59 +00:00
|
|
|
include(CTest)
|
2023-03-21 15:29:41 +00:00
|
|
|
add_subdirectory(tests)
|
|
|
|
endif ()
|
|
|
|
|
2023-03-25 18:26:40 +00:00
|
|
|
if (LLAMA_BUILD_EXAMPLES)
|
|
|
|
add_subdirectory(examples)
|
2023-04-18 19:00:14 +00:00
|
|
|
add_subdirectory(pocs)
|
2023-03-25 18:26:40 +00:00
|
|
|
endif()
|