Skip to content

Commit bb1f981

Browse files
author
Anoop Kapoor
committed
@FIR-702 - llama.cpp: Sync with latest opensource
1 parent cc74d5b commit bb1f981

File tree

19 files changed

+3079
-11
lines changed

19 files changed

+3079
-11
lines changed

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
[submodule "kompute"]
22
path = ggml/src/ggml-kompute/kompute
33
url = https://github.com/nomic-ai/kompute.git
4+
[submodule "ggml-tsi-kernel"]
5+
path = ggml-tsi-kernel
6+
url = [email protected]:tsisw/ggml-tsi-kernel.git

CMakeLists.txt

Lines changed: 60 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,59 @@ include(CheckIncludeFileCXX)
55
#set(CMAKE_WARN_DEPRECATED YES)
66
set(CMAKE_WARN_UNUSED_CLI YES)
77

8+
if (GGML_TSAVORITE)
9+
if (NOT DEFINED GGML_TSAVORITE_TARGET)
10+
set(GGML_TSAVORITE_TARGET "posix")
11+
endif()
12+
if (NOT ${GGML_TSAVORITE_TARGET} STREQUAL fpga)
13+
set(GGML_TSAVORITE_TARGET "posix")
14+
endif()
15+
16+
if (NOT DEFINED MLIR_COMPILER_DIR)
17+
if (NOT DEFINED $ENV{MLIR_SDK_VERSION})
18+
set (MLIR_COMPILER_DIR /proj/work/rel/sw/sdk-r.0.1.0/compiler)
19+
else()
20+
set (MLIR_COMPILER_DIR $ENV{MLIR_SDK_VERSION}/compiler)
21+
endif()
22+
endif()
23+
24+
if (NOT DEFINED RUNTIME_DIR)
25+
if (NOT DEFINED $ENV{MLIR_SDK_VERSION})
26+
set (RUNTIME_DIR /proj/work/rel/sw/sdk-r.0.1.0/${GGML_TSAVORITE_TARGET}/runtime)
27+
else()
28+
set (RUNTIME_DIR $ENV{MLIR_SDK_VERSION}/${GGML_TSAVORITE_TARGET}/runtime)
29+
endif()
30+
endif()
31+
32+
if (NOT DEFINED GGML_TSI_KERNEL_DIR)
33+
set (GGML_TSI_KERNEL_DIR ${CMAKE_SOURCE_DIR}/ggml-tsi-kernel/${GGML_TSAVORITE_TARGET})
34+
endif()
35+
36+
file(GLOB TLIBS "${RUNTIME_DIR}/lib/*.so" "${GGML_TSI_KERNEL_DIR}/host/*.o")
37+
38+
if (${GGML_TSAVORITE_TARGET} STREQUAL fpga)
39+
set(CMAKE_CROSSCOMPILING ON)
40+
set(ARCH_FLAGS -march=armv8-a)
41+
message("Setting target as fpga")
42+
elseif (${GGML_TSAVORITE_TARGET} STREQUAL "posix")
43+
list(APPEND TLIBS "${MLIR_COMPILER_DIR}/lib/libFFMDeviceShim.so")
44+
message("Setting target as posix for tsavorite")
45+
endif()
46+
47+
set(GGML_TSAVORITE_TARGET "${GGML_TSAVORITE_TARGET}" CACHE STRING "Target for tsavorite")
48+
set (TSAVORITE_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/ggml/src/ggml-tsavorite/include)
49+
50+
include_directories(${TSAVORITE_INCLUDE_DIR})
51+
include_directories(${MLIR_COMPILER_DIR}/include/runtime/shim)
52+
include_directories(${RUNTIME_DIR}/include)
53+
message("tsavorite backend is enabled")
54+
endif()
55+
856
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
957

1058
if (NOT XCODE AND NOT MSVC AND NOT CMAKE_BUILD_TYPE)
11-
set(CMAKE_BUILD_TYPE Release CACHE STRING "Build type" FORCE)
59+
#set(CMAKE_BUILD_TYPE Release CACHE STRING "Build type" FORCE)
60+
set(CMAKE_BUILD_TYPE Debug CACHE STRING "Build type" FORCE)
1261
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo")
1362
endif()
1463

@@ -82,9 +131,18 @@ option(LLAMA_BUILD_EXAMPLES "llama: build examples" ${LLAMA_STANDALONE})
82131
option(LLAMA_BUILD_SERVER "llama: build server example" ${LLAMA_STANDALONE})
83132

84133
# 3rd party libs
85-
option(LLAMA_CURL "llama: use libcurl to download model from an URL" ON)
86134
option(LLAMA_LLGUIDANCE "llama-common: include LLGuidance library for structured output in common utils" OFF)
87135

136+
if (GGML_TSAVORITE)
137+
if (${GGML_TSAVORITE_TARGET} STREQUAL fpga)
138+
option(LLAMA_CURL "llama: use libcurl to download model from an URL" OFF)
139+
else()
140+
option(LLAMA_CURL "llama: use libcurl to download model from an URL" ON)
141+
endif()
142+
else()
143+
option(LLAMA_CURL "llama: use libcurl to download model from an URL" ON)
144+
endif()
145+
88146
# Required for relocatable CMake package
89147
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/build-info.cmake)
90148
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/common.cmake)

common/CMakeLists.txt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,16 @@ endif ()
145145

146146
target_include_directories(${TARGET} PUBLIC .)
147147
target_compile_features (${TARGET} PUBLIC cxx_std_17)
148-
target_link_libraries (${TARGET} PRIVATE ${LLAMA_COMMON_EXTRA_LIBS} PUBLIC llama Threads::Threads)
149148

149+
if (GGML_TSAVORITE)
150+
if (${GGML_TSAVORITE_TARGET} STREQUAL fpga)
151+
target_link_libraries (${TARGET} PRIVATE ${LLAMA_COMMON_EXTRA_LIBS} ${TLIBS} PUBLIC llama Threads::Threads)
152+
else()
153+
target_link_libraries (${TARGET} PRIVATE ${LLAMA_COMMON_EXTRA_LIBS} PUBLIC llama Threads::Threads)
154+
endif()
155+
else()
156+
target_link_libraries (${TARGET} PRIVATE ${LLAMA_COMMON_EXTRA_LIBS} PUBLIC llama Threads::Threads)
157+
endif()
150158

151159
#
152160
# copy the license files

examples/gguf-hash/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
set(TARGET llama-gguf-hash)
22
add_executable(${TARGET} gguf-hash.cpp)
3+
target_link_libraries(${TARGET} PRIVATE ${TLIBS})
34
install(TARGETS ${TARGET} RUNTIME)
45

56
# clibs dependencies

examples/gguf/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
set(TARGET llama-gguf)
22
add_executable(${TARGET} gguf.cpp)
33
install(TARGETS ${TARGET} RUNTIME)
4-
target_link_libraries(${TARGET} PRIVATE ggml ${CMAKE_THREAD_LIBS_INIT})
4+
target_link_libraries(${TARGET} PRIVATE ggml ${CMAKE_THREAD_LIBS_INIT} ${TLIBS})
55
target_compile_features(${TARGET} PRIVATE cxx_std_17)

examples/lookup/CMakeLists.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
set(TARGET llama-lookup)
22
add_executable(${TARGET} lookup.cpp)
33
install(TARGETS ${TARGET} RUNTIME)
4-
target_link_libraries(${TARGET} PRIVATE common llama ${CMAKE_THREAD_LIBS_INIT})
4+
target_link_libraries(${TARGET} PRIVATE common llama ${CMAKE_THREAD_LIBS_INIT} ${TLIBS})
55
target_compile_features(${TARGET} PRIVATE cxx_std_17)
66

77
set(TARGET llama-lookup-create)
88
add_executable(${TARGET} lookup-create.cpp)
99
install(TARGETS ${TARGET} RUNTIME)
10-
target_link_libraries(${TARGET} PRIVATE common llama ${CMAKE_THREAD_LIBS_INIT})
10+
target_link_libraries(${TARGET} PRIVATE common llama ${CMAKE_THREAD_LIBS_INIT} ${TLIBS})
1111
target_compile_features(${TARGET} PRIVATE cxx_std_17)
1212

1313
set(TARGET llama-lookup-merge)
1414
add_executable(${TARGET} lookup-merge.cpp)
1515
install(TARGETS ${TARGET} RUNTIME)
16-
target_link_libraries(${TARGET} PRIVATE common llama ${CMAKE_THREAD_LIBS_INIT})
16+
target_link_libraries(${TARGET} PRIVATE common llama ${CMAKE_THREAD_LIBS_INIT} ${TLIBS})
1717
target_compile_features(${TARGET} PRIVATE cxx_std_17)
1818

1919
set(TARGET llama-lookup-stats)
2020
add_executable(${TARGET} lookup-stats.cpp)
2121
install(TARGETS ${TARGET} RUNTIME)
22-
target_link_libraries(${TARGET} PRIVATE common llama ${CMAKE_THREAD_LIBS_INIT})
22+
target_link_libraries(${TARGET} PRIVATE common llama ${CMAKE_THREAD_LIBS_INIT} ${TLIBS})
2323
target_compile_features(${TARGET} PRIVATE cxx_std_17)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
set(TARGET llama-simple-chat)
22
add_executable(${TARGET} simple-chat.cpp)
33
install(TARGETS ${TARGET} RUNTIME)
4-
target_link_libraries(${TARGET} PRIVATE llama ${CMAKE_THREAD_LIBS_INIT})
4+
target_link_libraries(${TARGET} PRIVATE llama ${CMAKE_THREAD_LIBS_INIT} ${TLIBS})
55
target_compile_features(${TARGET} PRIVATE cxx_std_17)

examples/simple/CMakeLists.txt

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,24 @@
1+
#
2+
# simple-ctx
13
set(TARGET llama-simple)
24
add_executable(${TARGET} simple.cpp)
35
install(TARGETS ${TARGET} RUNTIME)
4-
target_link_libraries(${TARGET} PRIVATE llama ${CMAKE_THREAD_LIBS_INIT})
6+
target_link_libraries(${TARGET} PRIVATE llama ${TLIBS} ${CMAKE_THREAD_LIBS_INIT})
57
target_compile_features(${TARGET} PRIVATE cxx_std_17)
8+
9+
#
10+
if (GGML_TSAVORITE)
11+
#
12+
# tsavorite backend test cases
13+
if (${GGML_TSAVORITE_TARGET} STREQUAL fpga)
14+
file(GLOB TLIBS "${RUNTIME_DIR}/lib/*.so" "../../${GGML_TSI_KERNEL_DIR}/host/*.o")
15+
else()
16+
file(GLOB TLIBS "${RUNTIME_DIR}/lib/*.so" "${MLIR_COMPILER_DIR}/lib/libFFMDeviceShim.so" "../../${GGML_TSI_KERNEL_DIR}/host/*.o")
17+
endif()
18+
#
19+
# simple-backend-tsi
20+
21+
set(TEST_TARGET simple-backend-tsi)
22+
add_executable(${TEST_TARGET} simple-backend-tsi.cpp)
23+
target_link_libraries(${TEST_TARGET} PRIVATE ggml ${TLIBS} dl rt)
24+
endif()

0 commit comments

Comments
 (0)