Skip to content

Commit 85cf8bb

Browse files
authored
Merge branch 'ggerganov:master' into master
2 parents f6ff41b + d583cd0 commit 85cf8bb

File tree

107 files changed

+3969
-2939
lines changed

Some content is hidden

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

107 files changed

+3969
-2939
lines changed

.github/workflows/build.yml

Lines changed: 61 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -552,35 +552,44 @@ jobs:
552552
-DCMAKE_XCODE_ATTRIBUTE_DEVELOPMENT_TEAM=ggml
553553
cmake --build . --config Release -j $(sysctl -n hw.logicalcpu) -- CODE_SIGNING_ALLOWED=NO
554554
555-
# TODO: tmp disabled. see for possible re-enable:
556-
# https://github.com/ggerganov/llama.cpp/pull/10525
557-
# macOS-latest-swift:
558-
# runs-on: macos-latest
559-
#
560-
# strategy:
561-
# matrix:
562-
# destination: ['generic/platform=macOS', 'generic/platform=iOS', 'generic/platform=tvOS']
563-
#
564-
# steps:
565-
# - name: Clone
566-
# id: checkout
567-
# uses: actions/checkout@v4
568-
#
569-
# - name: Dependencies
570-
# id: depends
571-
# continue-on-error: true
572-
# run: |
573-
# brew update
574-
#
575-
# - name: xcodebuild for swift package
576-
# id: xcodebuild
577-
# run: |
578-
# xcodebuild -scheme llama -destination "${{ matrix.destination }}"
579-
#
580-
# - name: Build Swift Example
581-
# id: make_build_swift_example
582-
# run: |
583-
# make swift
555+
macOS-latest-swift:
556+
runs-on: macos-latest
557+
558+
strategy:
559+
matrix:
560+
destination: ['generic/platform=macOS', 'generic/platform=iOS', 'generic/platform=tvOS']
561+
562+
steps:
563+
- name: Clone
564+
id: checkout
565+
uses: actions/checkout@v4
566+
567+
- name: Dependencies
568+
id: depends
569+
continue-on-error: true
570+
run: |
571+
brew update
572+
573+
- name: Build llama.cpp with CMake
574+
id: cmake_build
575+
run: |
576+
sysctl -a
577+
mkdir build
578+
cd build
579+
cmake -G Xcode .. \
580+
-DGGML_METAL_USE_BF16=ON \
581+
-DGGML_METAL_EMBED_LIBRARY=ON \
582+
-DLLAMA_BUILD_EXAMPLES=OFF \
583+
-DLLAMA_BUILD_TESTS=OFF \
584+
-DLLAMA_BUILD_SERVER=OFF \
585+
-DCMAKE_OSX_ARCHITECTURES="arm64;x86_64"
586+
cmake --build . --config Release -j $(sysctl -n hw.logicalcpu)
587+
sudo cmake --install . --config Release
588+
589+
- name: xcodebuild for swift package
590+
id: xcodebuild
591+
run: |
592+
xcodebuild -scheme llama-Package -destination "${{ matrix.destination }}"
584593
585594
windows-msys2:
586595
runs-on: windows-latest
@@ -1104,6 +1113,29 @@ jobs:
11041113
- name: Checkout code
11051114
uses: actions/checkout@v4
11061115

1116+
- name: Build
1117+
id: cmake_build
1118+
run: |
1119+
sysctl -a
1120+
mkdir build
1121+
cd build
1122+
cmake -G Xcode .. \
1123+
-DGGML_METAL_USE_BF16=ON \
1124+
-DGGML_METAL_EMBED_LIBRARY=ON \
1125+
-DLLAMA_BUILD_EXAMPLES=OFF \
1126+
-DLLAMA_BUILD_TESTS=OFF \
1127+
-DLLAMA_BUILD_SERVER=OFF \
1128+
-DCMAKE_SYSTEM_NAME=iOS \
1129+
-DCMAKE_OSX_DEPLOYMENT_TARGET=14.0 \
1130+
-DCMAKE_XCODE_ATTRIBUTE_DEVELOPMENT_TEAM=ggml
1131+
cmake --build . --config Release -j $(sysctl -n hw.logicalcpu) -- CODE_SIGNING_ALLOWED=NO
1132+
sudo cmake --install . --config Release
1133+
1134+
- name: xcodebuild for swift package
1135+
id: xcodebuild
1136+
run: |
1137+
xcodebuild -scheme llama-Package -destination 'generic/platform=iOS'
1138+
11071139
- name: Build Xcode project
11081140
run: xcodebuild -project examples/llama.swiftui/llama.swiftui.xcodeproj -scheme llama.swiftui -sdk iphoneos CODE_SIGNING_REQUIRED=NO CODE_SIGN_IDENTITY= -destination 'generic/platform=iOS' build
11091141

@@ -1131,23 +1163,6 @@ jobs:
11311163
11321164
./gradlew build --no-daemon
11331165
1134-
# freeBSD-latest:
1135-
# runs-on: macos-12
1136-
# steps:
1137-
# - name: Clone
1138-
# uses: actions/checkout@v4
1139-
#
1140-
# - name: Build
1141-
# uses: cross-platform-actions/action@v0.19.0
1142-
# with:
1143-
# operating_system: freebsd
1144-
# version: '13.2'
1145-
# hypervisor: 'qemu'
1146-
# run: |
1147-
# sudo pkg update
1148-
# sudo pkg install -y gmake automake autoconf pkgconf llvm15 openblas
1149-
# gmake CC=/usr/local/bin/clang15 CXX=/usr/local/bin/clang++15 -j `sysctl -n hw.ncpu`
1150-
11511166
release:
11521167
if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/master' ) || github.event.inputs.create_release == 'true' }}
11531168

.github/workflows/server.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ jobs:
7979
# Setup nodejs (to be used for verifying bundled index.html)
8080
- uses: actions/setup-node@v4
8181
with:
82-
node-version: 22
82+
node-version: '22.11.0'
8383

8484
- name: Verify bundled index.html
8585
id: verify_server_index_html

CMakeLists.txt

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,9 @@ if (WIN32)
4646
add_compile_definitions(_CRT_SECURE_NO_WARNINGS)
4747
endif()
4848

49-
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
50-
add_compile_options("$<$<COMPILE_LANGUAGE:C>:/source-charset:utf-8>")
51-
add_compile_options("$<$<COMPILE_LANGUAGE:CXX>:/source-charset:utf-8>")
52-
add_compile_options("$<$<COMPILE_LANGUAGE:C>:/execution-charset:utf-8>")
53-
add_compile_options("$<$<COMPILE_LANGUAGE:CXX>:/execution-charset:utf-8>")
49+
if (MSVC)
50+
add_compile_options("$<$<COMPILE_LANGUAGE:C>:/utf-8>")
51+
add_compile_options("$<$<COMPILE_LANGUAGE:CXX>:/utf-8>")
5452
endif()
5553

5654
#

CMakePresets.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,13 @@
3131
{ "name": "sycl_f16", "hidden": true, "cacheVariables": { "GGML_SYCL_F16": "ON" } },
3232
{ "name": "vulkan", "hidden": true, "cacheVariables": { "GGML_VULKAN": "ON" } },
3333

34+
{
35+
"name": "x64-windows-llvm", "hidden": true,
36+
"cacheVariables": {
37+
"CMAKE_TOOLCHAIN_FILE": "${sourceDir}/cmake/x64-windows-llvm.cmake"
38+
}
39+
},
40+
3441
{
3542
"name": "arm64-windows-msvc", "hidden": true,
3643
"architecture": { "value": "arm64", "strategy": "external" },
@@ -70,6 +77,11 @@
7077
{ "name": "arm64-windows-msvc-release", "inherits": [ "base", "arm64-windows-msvc", "reldbg" ] },
7178
{ "name": "arm64-windows-msvc+static-release", "inherits": [ "base", "arm64-windows-msvc", "reldbg", "static" ] },
7279

80+
{ "name": "x64-windows-llvm-debug", "inherits": [ "base", "x64-windows-llvm", "debug" ] },
81+
{ "name": "x64-windows-llvm-release", "inherits": [ "base", "x64-windows-llvm", "release" ] },
82+
{ "name": "x64-windows-llvm-reldbg", "inherits": [ "base", "x64-windows-llvm", "reldbg" ] },
83+
{ "name": "x64-windows-llvm+static-release", "inherits": [ "base", "x64-windows-llvm", "reldbg", "static" ] },
84+
7385
{ "name": "x64-windows-msvc-debug", "inherits": [ "base", "debug" ] },
7486
{ "name": "x64-windows-msvc-release", "inherits": [ "base", "reldbg" ] },
7587
{ "name": "x64-windows-msvc+static-release", "inherits": [ "base", "reldbg", "static" ] },

CODEOWNERS

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
# collaborators can optionally add themselves here to indicate their availability for reviewing related PRs
22

3-
ci/ @ggerganov
3+
/ci/ @ggerganov
4+
/.devops/ @ngxson
5+
/examples/server/ @ngxson

Makefile

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,10 @@ ifeq ($(UNAME_M),$(filter $(UNAME_M),x86_64 i686 amd64))
445445
MK_CFLAGS += -march=native -mtune=native
446446
HOST_CXXFLAGS += -march=native -mtune=native
447447

448+
# Usage AMX build test
449+
#MK_CFLAGS += -march=graniterapids -mtune=graniterapids
450+
#HOST_CXXFLAGS += -march=graniterapids -mtune=graniterapids
451+
448452
# Usage AVX-only
449453
#MK_CFLAGS += -mfma -mf16c -mavx
450454
#MK_CXXFLAGS += -mfma -mf16c -mavx
@@ -948,17 +952,18 @@ DIR_COMMON = common
948952

949953
OBJ_GGML = \
950954
$(DIR_GGML)/src/ggml.o \
951-
$(DIR_GGML)/src/ggml-aarch64.o \
952955
$(DIR_GGML)/src/ggml-alloc.o \
953956
$(DIR_GGML)/src/ggml-backend.o \
954957
$(DIR_GGML)/src/ggml-backend-reg.o \
955958
$(DIR_GGML)/src/ggml-opt.o \
956959
$(DIR_GGML)/src/ggml-quants.o \
957960
$(DIR_GGML)/src/ggml-threading.o \
958961
$(DIR_GGML)/src/ggml-cpu/ggml-cpu.o \
959-
$(DIR_GGML)/src/ggml-cpu/ggml-cpu-cpp.o \
962+
$(DIR_GGML)/src/ggml-cpu/ggml-cpu_cpp.o \
960963
$(DIR_GGML)/src/ggml-cpu/ggml-cpu-aarch64.o \
964+
$(DIR_GGML)/src/ggml-cpu/ggml-cpu-hbm.o \
961965
$(DIR_GGML)/src/ggml-cpu/ggml-cpu-quants.o \
966+
$(DIR_GGML)/src/ggml-cpu/ggml-cpu-traits.o \
962967
$(OBJ_GGML_EXT)
963968

964969
OBJ_LLAMA = \
@@ -1098,17 +1103,10 @@ DEP_FILES = $(OBJ_GGML:.o=.d) $(OBJ_LLAMA:.o=.d) $(OBJ_COMMON:.o=.d)
10981103
# Default target
10991104
all: $(BUILD_TARGETS)
11001105

1106+
# force c++ build for source file that have same name as c file
11011107
# Note: need this exception because `ggml-cpu.c` and `ggml-cpu.cpp` both produce the same obj/dep files
1102-
# g++ -M -I ./ggml/include/ -I ./ggml/src ggml/src/ggml-cpu/ggml-cpu.cpp | grep ggml
1103-
$(DIR_GGML)/src/ggml-cpu/ggml-cpu-cpp.o: \
1104-
ggml/src/ggml-cpu/ggml-cpu.cpp \
1105-
ggml/include/ggml-backend.h \
1106-
ggml/include/ggml.h \
1107-
ggml/include/ggml-alloc.h \
1108-
ggml/src/ggml-backend-impl.h \
1109-
ggml/include/ggml-cpu.h \
1110-
ggml/src/ggml-impl.h
1111-
$(CXX) $(CXXFLAGS) -c $< -o $@
1108+
$(DIR_GGML)/%_cpp.o: $(DIR_GGML)/%.cpp
1109+
$(CXX) $(CXXFLAGS) -MMD -c $< -o $@
11121110

11131111
# Rules for building object files
11141112
$(DIR_GGML)/%.o: $(DIR_GGML)/%.c

Package.swift

Lines changed: 2 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -2,59 +2,6 @@
22

33
import PackageDescription
44

5-
var sources = [
6-
"src/llama.cpp",
7-
"src/llama-vocab.cpp",
8-
"src/llama-grammar.cpp",
9-
"src/llama-sampling.cpp",
10-
"src/unicode.cpp",
11-
"src/unicode-data.cpp",
12-
"ggml/src/ggml.c",
13-
"ggml/src/ggml-aarch64.c",
14-
"ggml/src/ggml-alloc.c",
15-
"ggml/src/ggml-backend.cpp",
16-
"ggml/src/ggml-backend-reg.cpp",
17-
"ggml/src/ggml-cpu/ggml-cpu.c",
18-
"ggml/src/ggml-cpu/ggml-cpu.cpp",
19-
"ggml/src/ggml-cpu/ggml-cpu-aarch64.c",
20-
"ggml/src/ggml-cpu/ggml-cpu-quants.c",
21-
"ggml/src/ggml-threading.cpp",
22-
"ggml/src/ggml-quants.c",
23-
]
24-
25-
var resources: [Resource] = []
26-
var linkerSettings: [LinkerSetting] = []
27-
var cSettings: [CSetting] = [
28-
.unsafeFlags(["-Wno-shorten-64-to-32", "-O3", "-DNDEBUG"]),
29-
.unsafeFlags(["-fno-objc-arc"]),
30-
.headerSearchPath("ggml/src"),
31-
.headerSearchPath("ggml/src/ggml-cpu"),
32-
// NOTE: NEW_LAPACK will required iOS version 16.4+
33-
// We should consider add this in the future when we drop support for iOS 14
34-
// (ref: ref: https://developer.apple.com/documentation/accelerate/1513264-cblas_sgemm?language=objc)
35-
// .define("ACCELERATE_NEW_LAPACK"),
36-
// .define("ACCELERATE_LAPACK_ILP64")
37-
.define("GGML_USE_CPU"),
38-
]
39-
40-
41-
#if canImport(Darwin)
42-
sources.append("ggml/src/ggml-common.h")
43-
sources.append("ggml/src/ggml-metal/ggml-metal.m")
44-
resources.append(.process("ggml/src/ggml-metal/ggml-metal.metal"))
45-
linkerSettings.append(.linkedFramework("Accelerate"))
46-
cSettings.append(
47-
contentsOf: [
48-
.define("GGML_USE_ACCELERATE"),
49-
.define("GGML_USE_METAL"),
50-
]
51-
)
52-
#endif
53-
54-
#if os(Linux)
55-
cSettings.append(.define("_GNU_SOURCE"))
56-
#endif
57-
585
let package = Package(
596
name: "llama",
607
platforms: [
@@ -67,26 +14,6 @@ let package = Package(
6714
.library(name: "llama", targets: ["llama"]),
6815
],
6916
targets: [
70-
.target(
71-
name: "llama",
72-
path: ".",
73-
exclude: [
74-
"build",
75-
"cmake",
76-
"examples",
77-
"scripts",
78-
"models",
79-
"tests",
80-
"CMakeLists.txt",
81-
"Makefile",
82-
"ggml/src/ggml-metal-embed.metal"
83-
],
84-
sources: sources,
85-
resources: resources,
86-
publicHeadersPath: "spm-headers",
87-
cSettings: cSettings,
88-
linkerSettings: linkerSettings
89-
)
90-
],
91-
cxxLanguageStandard: .cxx17
17+
.systemLibrary(name: "llama", pkgConfig: "llama"),
18+
]
9219
)

Sources/llama/llama.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#pragma once
2+
3+
#include <llama.h>
4+

Sources/llama/module.modulemap

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module llama [system] {
2+
header "llama.h"
3+
link "llama"
4+
export *
5+
}

cmake/llama.pc.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ includedir=${prefix}/include
66
Name: llama
77
Description: Port of Facebook's LLaMA model in C/C++
88
Version: @PROJECT_VERSION@
9-
Libs: -L${libdir} -lllama
9+
Libs: -L${libdir} -lggml -lggml-base -lllama
1010
Cflags: -I${includedir}

cmake/x64-windows-llvm.cmake

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
set( CMAKE_SYSTEM_NAME Windows )
2+
set( CMAKE_SYSTEM_PROCESSOR x86_64 )
3+
4+
set( CMAKE_C_COMPILER clang )
5+
set( CMAKE_CXX_COMPILER clang++ )
6+
7+
set( arch_c_flags "-march=native" )
8+
9+
set( CMAKE_C_FLAGS_INIT "${arch_c_flags}" )
10+
set( CMAKE_CXX_FLAGS_INIT "${arch_c_flags}" )
11+

0 commit comments

Comments
 (0)