Skip to content

Commit e75889a

Browse files
committed
Merge branch 'master' into cuda-cublas-opts
ggml-ci
2 parents 66a8dd3 + c6c4fc0 commit e75889a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+9728
-2132
lines changed

.editorconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ indent_size = 4
1515
[Makefile]
1616
indent_style = tab
1717

18+
[scripts/*.mk]
19+
indent_style = tab
20+
1821
[prompts/*.txt]
1922
insert_final_newline = unset
2023

.github/workflows/build.yml

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,9 @@ jobs:
143143
cd build
144144
ctest --verbose
145145
146+
# TODO: build with LLAMA_NO_METAL because test-backend-ops fail on "Apple Paravirtual device" and I don't know
147+
# how to debug it.
148+
# ref: https://github.com/ggerganov/llama.cpp/actions/runs/7131777249/job/19420981052#step:5:1124
146149
macOS-latest-make:
147150
runs-on: macos-latest
148151

@@ -160,14 +163,18 @@ jobs:
160163
- name: Build
161164
id: make_build
162165
run: |
163-
make -j $(sysctl -n hw.logicalcpu)
166+
LLAMA_NO_METAL=1 make -j $(sysctl -n hw.logicalcpu)
164167
165168
- name: Test
166169
id: make_test
167170
run: |
168-
make tests -j $(sysctl -n hw.logicalcpu)
169-
make test -j $(sysctl -n hw.logicalcpu)
171+
LLAMA_NO_METAL=1 make tests -j $(sysctl -n hw.logicalcpu)
172+
LLAMA_NO_METAL=1 make test -j $(sysctl -n hw.logicalcpu)
170173
174+
# TODO: build with LLAMA_METAL=OFF because test-backend-ops fail on "Apple Paravirtual device" and I don't know
175+
# how to debug it.
176+
# ref: https://github.com/ggerganov/llama.cpp/actions/runs/7132125951/job/19422043567?pr=4359#step:5:6584
177+
# would be great if we fix these
171178
macOS-latest-cmake:
172179
runs-on: macos-latest
173180

@@ -188,7 +195,7 @@ jobs:
188195
sysctl -a
189196
mkdir build
190197
cd build
191-
cmake ..
198+
cmake -DLLAMA_METAL=OFF ..
192199
cmake --build . --config Release -j $(sysctl -n hw.logicalcpu)
193200
194201
- name: Test

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,3 +101,4 @@ poetry.toml
101101
/tests/test-tokenizer-1-llama
102102
/tests/test-tokenizer-1-bpe
103103
/tests/test-rope
104+
/tests/test-backend-ops

CMakeLists.txt

Lines changed: 98 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,9 @@ option(LLAMA_METAL_NDEBUG "llama: disable Metal debugging"
9797
option(LLAMA_MPI "llama: use MPI" OFF)
9898
option(LLAMA_QKK_64 "llama: use super-block size of 64 for k-quants" OFF)
9999

100-
option(LLAMA_BUILD_TESTS "llama: build tests" ${LLAMA_STANDALONE})
101-
option(LLAMA_BUILD_EXAMPLES "llama: build examples" ${LLAMA_STANDALONE})
102-
option(LLAMA_BUILD_SERVER "llama: build server example" ON)
100+
option(LLAMA_BUILD_TESTS "llama: build tests" ${LLAMA_STANDALONE})
101+
option(LLAMA_BUILD_EXAMPLES "llama: build examples" ${LLAMA_STANDALONE})
102+
option(LLAMA_BUILD_SERVER "llama: build server example" ON)
103103

104104
# Required for relocatable CMake package
105105
include(${CMAKE_CURRENT_SOURCE_DIR}/scripts/build-info.cmake)
@@ -397,57 +397,102 @@ if (LLAMA_HIPBLAS)
397397
endif()
398398
endif()
399399

400+
function(get_flags CCID CCVER)
401+
set(C_FLAGS "")
402+
set(CXX_FLAGS "")
403+
404+
if (CCID MATCHES "Clang")
405+
set(C_FLAGS -Wunreachable-code-break -Wunreachable-code-return)
406+
set(CXX_FLAGS -Wunreachable-code-break -Wunreachable-code-return -Wmissing-prototypes -Wextra-semi)
407+
408+
if (
409+
(CCID STREQUAL "Clang" AND CCVER VERSION_GREATER_EQUAL 3.8.0) OR
410+
(CCID STREQUAL "AppleClang" AND CCVER VERSION_GREATER_EQUAL 7.3.0)
411+
)
412+
set(C_FLAGS ${C_FLAGS} -Wdouble-promotion)
413+
endif()
414+
elseif (CCID STREQUAL "GNU")
415+
set(C_FLAGS -Wdouble-promotion)
416+
set(CXX_FLAGS -Wno-array-bounds)
417+
418+
if (CCVER VERSION_GREATER_EQUAL 7.1.0)
419+
set(CXX_FLAGS ${CXX_FLAGS} -Wno-format-truncation)
420+
endif()
421+
if (CCVER VERSION_GREATER_EQUAL 8.1.0)
422+
set(CXX_FLAGS ${CXX_FLAGS} -Wextra-semi)
423+
endif()
424+
endif()
425+
426+
set(GF_C_FLAGS ${C_FLAGS} PARENT_SCOPE)
427+
set(GF_CXX_FLAGS ${CXX_FLAGS} PARENT_SCOPE)
428+
endfunction()
429+
400430
if (LLAMA_ALL_WARNINGS)
401431
if (NOT MSVC)
402-
set(warning_flags -Wall -Wextra -Wpedantic -Wcast-qual -Wno-unused-function)
403-
set(c_flags -Wshadow -Wstrict-prototypes -Wpointer-arith -Wmissing-prototypes -Werror=implicit-int -Werror=implicit-function-declaration)
404-
set(cxx_flags -Wmissing-declarations -Wmissing-noreturn)
405-
set(host_cxx_flags "")
406-
407-
if (CMAKE_C_COMPILER_ID MATCHES "Clang")
408-
set(warning_flags ${warning_flags} -Wunreachable-code-break -Wunreachable-code-return)
409-
set(host_cxx_flags ${host_cxx_flags} -Wmissing-prototypes -Wextra-semi)
410-
411-
if (
412-
(CMAKE_C_COMPILER_ID STREQUAL "Clang" AND CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 3.8.0) OR
413-
(CMAKE_C_COMPILER_ID STREQUAL "AppleClang" AND CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 7.3.0)
414-
)
415-
set(c_flags ${c_flags} -Wdouble-promotion)
416-
endif()
417-
elseif (CMAKE_C_COMPILER_ID STREQUAL "GNU")
418-
set(c_flags ${c_flags} -Wdouble-promotion)
419-
set(host_cxx_flags ${host_cxx_flags} -Wno-array-bounds)
432+
set(WARNING_FLAGS -Wall -Wextra -Wpedantic -Wcast-qual -Wno-unused-function)
433+
set(C_FLAGS -Wshadow -Wstrict-prototypes -Wpointer-arith -Wmissing-prototypes
434+
-Werror=implicit-int -Werror=implicit-function-declaration)
435+
set(CXX_FLAGS -Wmissing-declarations -Wmissing-noreturn)
420436

421-
if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 7.1.0)
422-
set(host_cxx_flags ${host_cxx_flags} -Wno-format-truncation)
423-
endif()
424-
if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 8.1.0)
425-
set(host_cxx_flags ${host_cxx_flags} -Wextra-semi)
426-
endif()
427-
endif()
437+
set(C_FLAGS ${WARNING_FLAGS} ${C_FLAGS})
438+
set(CXX_FLAGS ${WARNING_FLAGS} ${CXX_FLAGS})
439+
440+
get_flags(${CMAKE_CXX_COMPILER_ID} ${CMAKE_CXX_COMPILER_VERSION})
441+
442+
add_compile_options("$<$<COMPILE_LANGUAGE:C>:${C_FLAGS};${GF_C_FLAGS}>"
443+
"$<$<COMPILE_LANGUAGE:CXX>:${CXX_FLAGS};${GF_CXX_FLAGS}>")
428444
else()
429445
# todo : msvc
446+
set(C_FLAGS "")
447+
set(CXX_FLAGS "")
430448
endif()
449+
endif()
431450

432-
set(c_flags ${c_flags} ${warning_flags})
433-
set(cxx_flags ${cxx_flags} ${warning_flags})
434-
add_compile_options("$<$<COMPILE_LANGUAGE:C>:${c_flags}>"
435-
"$<$<COMPILE_LANGUAGE:CXX>:${cxx_flags}>"
436-
"$<$<COMPILE_LANGUAGE:CXX>:${host_cxx_flags}>")
451+
if (LLAMA_CUBLAS)
452+
set(CUDA_FLAGS ${CXX_FLAGS} -use_fast_math)
453+
if (NOT MSVC)
454+
set(CUDA_FLAGS ${CUDA_FLAGS} -Wno-pedantic)
455+
endif()
437456

438-
endif()
457+
if (LLAMA_ALL_WARNINGS AND NOT MSVC)
458+
set(NVCC_CMD ${CMAKE_CUDA_COMPILER} .c)
459+
if (NOT CMAKE_CUDA_HOST_COMPILER STREQUAL "")
460+
set(NVCC_CMD ${NVCC_CMD} -ccbin ${CMAKE_CUDA_HOST_COMPILER})
461+
endif()
439462

440-
if (NOT MSVC)
441-
set(cuda_flags -Wno-pedantic)
442-
endif()
443-
set(cuda_flags ${cxx_flags} -use_fast_math ${cuda_flags})
463+
execute_process(
464+
COMMAND ${NVCC_CMD} -Xcompiler --version
465+
OUTPUT_VARIABLE CUDA_CCFULLVER
466+
ERROR_QUIET
467+
)
444468

445-
list(JOIN host_cxx_flags " " cuda_host_flags) # pass host compiler flags as a single argument
446-
if (NOT cuda_host_flags STREQUAL "")
447-
set(cuda_flags ${cuda_flags} -Xcompiler ${cuda_host_flags})
448-
endif()
469+
if (NOT CUDA_CCFULLVER MATCHES clang)
470+
set(CUDA_CCID "GNU")
471+
execute_process(
472+
COMMAND ${NVCC_CMD} -Xcompiler "-dumpfullversion -dumpversion"
473+
OUTPUT_VARIABLE CUDA_CCVER
474+
ERROR_QUIET
475+
)
476+
else()
477+
if (CUDA_CCFULLVER MATCHES Apple)
478+
set(CUDA_CCID "AppleClang")
479+
else()
480+
set(CUDA_CCID "Clang")
481+
endif()
482+
string(REGEX REPLACE "^.* version ([0-9.]*).*$" "\\1" CUDA_CCVER ${CUDA_CCFULLVER})
483+
endif()
484+
485+
message("-- CUDA host compiler is ${CUDA_CCID} ${CUDA_CCVER}")
449486

450-
add_compile_options("$<$<COMPILE_LANGUAGE:CUDA>:${cuda_flags}>")
487+
get_flags(${CUDA_CCID} ${CUDA_CCVER})
488+
list(JOIN GF_CXX_FLAGS " " CUDA_CXX_FLAGS) # pass host compiler flags as a single argument
489+
if (NOT CUDA_CXX_FLAGS STREQUAL "")
490+
set(CUDA_FLAGS ${CUDA_FLAGS} -Xcompiler ${CUDA_CXX_FLAGS})
491+
endif()
492+
endif()
493+
494+
add_compile_options("$<$<COMPILE_LANGUAGE:CUDA>:${CUDA_FLAGS}>")
495+
endif()
451496

452497
if (WIN32)
453498
add_compile_definitions(_CRT_SECURE_NO_WARNINGS)
@@ -471,6 +516,7 @@ endif()
471516
execute_process(
472517
COMMAND ${CMAKE_C_COMPILER} ${CMAKE_EXE_LINKER_FLAGS} -Wl,-v
473518
ERROR_VARIABLE output
519+
OUTPUT_QUIET
474520
)
475521
if (output MATCHES "dyld-1015\.7")
476522
add_compile_definitions(HAVE_BUGGY_APPLE_LINKER)
@@ -593,6 +639,11 @@ else()
593639
message(STATUS "Unknown architecture")
594640
endif()
595641

642+
if (MINGW)
643+
# Target Windows 8 for PrefetchVirtualMemory
644+
add_compile_definitions(_WIN32_WINNT=0x602)
645+
endif()
646+
596647
#
597648
# POSIX conformance
598649
#
@@ -662,11 +713,11 @@ add_library(ggml OBJECT
662713
ggml-backend.h
663714
ggml-quants.c
664715
ggml-quants.h
665-
${GGML_SOURCES_CUDA} ${GGML_HEADERS_CUDA}
716+
${GGML_SOURCES_CUDA} ${GGML_HEADERS_CUDA}
666717
${GGML_SOURCES_OPENCL} ${GGML_HEADERS_OPENCL}
667-
${GGML_SOURCES_METAL} ${GGML_HEADERS_METAL}
668-
${GGML_SOURCES_MPI} ${GGML_HEADERS_MPI}
669-
${GGML_SOURCES_EXTRA} ${GGML_HEADERS_EXTRA}
718+
${GGML_SOURCES_METAL} ${GGML_HEADERS_METAL}
719+
${GGML_SOURCES_MPI} ${GGML_HEADERS_MPI}
720+
${GGML_SOURCES_EXTRA} ${GGML_HEADERS_EXTRA}
670721
)
671722

672723
target_include_directories(ggml PUBLIC . ${LLAMA_EXTRA_INCLUDES})

0 commit comments

Comments
 (0)