Spaces:
Running
Running
Christian Kastner
commited on
Commit
·
6e460b6
1
Parent(s):
863e083
cmake: Add GGML_BACKEND_DIR option (llama/15074)
Browse files* cmake: Add GGML_BACKEND_DIR option
This can be used by distributions to specify where to look for backends
when ggml is built with GGML_BACKEND_DL=ON.
* Fix phrasing
- ggml/CMakeLists.txt +3 -2
- ggml/cmake/ggml-config.cmake.in +1 -1
- ggml/src/CMakeLists.txt +12 -1
- ggml/src/ggml-backend-reg.cpp +3 -0
ggml/CMakeLists.txt
CHANGED
|
@@ -39,8 +39,9 @@ if (WIN32)
|
|
| 39 |
set(CMAKE_SHARED_MODULE_PREFIX "")
|
| 40 |
endif()
|
| 41 |
|
| 42 |
-
option(BUILD_SHARED_LIBS
|
| 43 |
-
option(GGML_BACKEND_DL
|
|
|
|
| 44 |
|
| 45 |
#
|
| 46 |
# option list
|
|
|
|
| 39 |
set(CMAKE_SHARED_MODULE_PREFIX "")
|
| 40 |
endif()
|
| 41 |
|
| 42 |
+
option(BUILD_SHARED_LIBS "ggml: build shared libraries" ${BUILD_SHARED_LIBS_DEFAULT})
|
| 43 |
+
option(GGML_BACKEND_DL "ggml: build backends as dynamic libraries (requires BUILD_SHARED_LIBS)" OFF)
|
| 44 |
+
set(GGML_BACKEND_DIR "" CACHE PATH "ggml: directory to load dynamic backends from (requires GGML_BACKEND_DL")
|
| 45 |
|
| 46 |
#
|
| 47 |
# option list
|
ggml/cmake/ggml-config.cmake.in
CHANGED
|
@@ -106,7 +106,7 @@ if(NOT TARGET ggml::ggml)
|
|
| 106 |
|
| 107 |
find_library(GGML_LIBRARY ggml
|
| 108 |
REQUIRED
|
| 109 |
-
HINTS ${GGML_LIB_DIR}
|
| 110 |
NO_CMAKE_FIND_ROOT_PATH)
|
| 111 |
|
| 112 |
add_library(ggml::ggml UNKNOWN IMPORTED)
|
|
|
|
| 106 |
|
| 107 |
find_library(GGML_LIBRARY ggml
|
| 108 |
REQUIRED
|
| 109 |
+
HINTS ${GGML_LIB_DIR} ${GGML_BACKEND_DIR}
|
| 110 |
NO_CMAKE_FIND_ROOT_PATH)
|
| 111 |
|
| 112 |
add_library(ggml::ggml UNKNOWN IMPORTED)
|
ggml/src/CMakeLists.txt
CHANGED
|
@@ -214,6 +214,13 @@ add_library(ggml
|
|
| 214 |
ggml-backend-reg.cpp)
|
| 215 |
add_library(ggml::ggml ALIAS ggml)
|
| 216 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 217 |
target_link_libraries(ggml PUBLIC ggml-base)
|
| 218 |
|
| 219 |
if (CMAKE_SYSTEM_NAME MATCHES "Linux")
|
|
@@ -227,7 +234,11 @@ function(ggml_add_backend_library backend)
|
|
| 227 |
set_target_properties(${backend} PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
|
| 228 |
target_compile_definitions(${backend} PRIVATE GGML_BACKEND_DL)
|
| 229 |
add_dependencies(ggml ${backend})
|
| 230 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 231 |
else()
|
| 232 |
add_library(${backend} ${ARGN})
|
| 233 |
target_link_libraries(ggml PUBLIC ${backend})
|
|
|
|
| 214 |
ggml-backend-reg.cpp)
|
| 215 |
add_library(ggml::ggml ALIAS ggml)
|
| 216 |
|
| 217 |
+
if (GGML_BACKEND_DIR)
|
| 218 |
+
if (NOT GGML_BACKEND_DL)
|
| 219 |
+
message(FATAL_ERROR "GGML_BACKEND_DIR requires GGML_BACKEND_DL")
|
| 220 |
+
endif()
|
| 221 |
+
target_compile_definitions(ggml PUBLIC GGML_BACKEND_DIR="${GGML_BACKEND_DIR}")
|
| 222 |
+
endif()
|
| 223 |
+
|
| 224 |
target_link_libraries(ggml PUBLIC ggml-base)
|
| 225 |
|
| 226 |
if (CMAKE_SYSTEM_NAME MATCHES "Linux")
|
|
|
|
| 234 |
set_target_properties(${backend} PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
|
| 235 |
target_compile_definitions(${backend} PRIVATE GGML_BACKEND_DL)
|
| 236 |
add_dependencies(ggml ${backend})
|
| 237 |
+
if (GGML_BACKEND_DIR)
|
| 238 |
+
install(TARGETS ${backend} LIBRARY DESTINATION ${GGML_BACKEND_DIR})
|
| 239 |
+
else()
|
| 240 |
+
install(TARGETS ${backend} LIBRARY DESTINATION ${CMAKE_INSTALL_BINDIR})
|
| 241 |
+
endif()
|
| 242 |
else()
|
| 243 |
add_library(${backend} ${ARGN})
|
| 244 |
target_link_libraries(ggml PUBLIC ${backend})
|
ggml/src/ggml-backend-reg.cpp
CHANGED
|
@@ -498,6 +498,9 @@ static ggml_backend_reg_t ggml_backend_load_best(const char * name, bool silent,
|
|
| 498 |
|
| 499 |
std::vector<fs::path> search_paths;
|
| 500 |
if (user_search_path == nullptr) {
|
|
|
|
|
|
|
|
|
|
| 501 |
// default search paths: executable directory, current directory
|
| 502 |
search_paths.push_back(get_executable_path());
|
| 503 |
search_paths.push_back(fs::current_path());
|
|
|
|
| 498 |
|
| 499 |
std::vector<fs::path> search_paths;
|
| 500 |
if (user_search_path == nullptr) {
|
| 501 |
+
#ifdef GGML_BACKEND_DIR
|
| 502 |
+
search_paths.push_back(fs::u8path(GGML_BACKEND_DIR));
|
| 503 |
+
#endif
|
| 504 |
// default search paths: executable directory, current directory
|
| 505 |
search_paths.push_back(get_executable_path());
|
| 506 |
search_paths.push_back(fs::current_path());
|