Skip to content

Commit 551edce

Browse files
committed
metal : fix build and swift package
ggml-ci
1 parent dd49f08 commit 551edce

File tree

5 files changed

+28
-12
lines changed

5 files changed

+28
-12
lines changed

Makefile

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -887,7 +887,7 @@ ifdef GGML_METAL_NDEBUG
887887
endif
888888
ifdef GGML_METAL_EMBED_LIBRARY
889889
MK_CPPFLAGS += -DGGML_METAL_EMBED_LIBRARY
890-
OBJ_GGML += ggml/src/ggml-metal-embed.o
890+
OBJ_GGML += ggml/src/ggml-metal-embed.o
891891
endif
892892
endif # GGML_METAL
893893

@@ -903,14 +903,14 @@ ggml/src/ggml-metal-embed.o: \
903903
ggml/src/ggml-metal/ggml-metal.metal \
904904
ggml/src/ggml-common.h
905905
@echo "Embedding Metal library"
906-
@sed -e '/#include "ggml-common.h"/r ggml/src/ggml-common.h' -e '/#include "ggml-common.h"/d' < ggml/src/ggml-metal/ggml-metal.metal > ggml/src/ggml-metal/ggml-metal-embed.metal
906+
@sed -e '/__embed_ggml-common.h__/r ggml/src/ggml-common.h' -e '/__embed_ggml-common.h__/d' < ggml/src/ggml-metal/ggml-metal.metal > ggml/src/ggml-metal/ggml-metal-embed.metal
907907
$(eval TEMP_ASSEMBLY=$(shell mktemp -d))
908-
@echo ".section __DATA, __ggml_metallib" > $(TEMP_ASSEMBLY)/ggml-metal-embed.s
909-
@echo ".globl _ggml_metallib_start" >> $(TEMP_ASSEMBLY)/ggml-metal-embed.s
910-
@echo "_ggml_metallib_start:" >> $(TEMP_ASSEMBLY)/ggml-metal-embed.s
911-
@echo ".incbin \"ggml/src/ggml-metal-embed.metal\"" >> $(TEMP_ASSEMBLY)/ggml-metal-embed.s
912-
@echo ".globl _ggml_metallib_end" >> $(TEMP_ASSEMBLY)/ggml-metal-embed.s
913-
@echo "_ggml_metallib_end:" >> $(TEMP_ASSEMBLY)/ggml-metal-embed.s
908+
@echo ".section __DATA, __ggml_metallib" > $(TEMP_ASSEMBLY)/ggml-metal-embed.s
909+
@echo ".globl _ggml_metallib_start" >> $(TEMP_ASSEMBLY)/ggml-metal-embed.s
910+
@echo "_ggml_metallib_start:" >> $(TEMP_ASSEMBLY)/ggml-metal-embed.s
911+
@echo ".incbin \"ggml/src/ggml-metal/ggml-metal-embed.metal\"" >> $(TEMP_ASSEMBLY)/ggml-metal-embed.s
912+
@echo ".globl _ggml_metallib_end" >> $(TEMP_ASSEMBLY)/ggml-metal-embed.s
913+
@echo "_ggml_metallib_end:" >> $(TEMP_ASSEMBLY)/ggml-metal-embed.s
914914
$(CC) $(CFLAGS) -c $(TEMP_ASSEMBLY)/ggml-metal-embed.s -o $@
915915
@rm -f ${TEMP_ASSEMBLY}/ggml-metal-embed.s
916916
@rmdir ${TEMP_ASSEMBLY}

Package.swift

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,24 @@ var sources = [
1010
"src/unicode.cpp",
1111
"src/unicode-data.cpp",
1212
"ggml/src/ggml.c",
13-
"ggml/src/ggml-cpu.c",
13+
"ggml/src/ggml-aarch64.c",
1414
"ggml/src/ggml-alloc.c",
1515
"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",
1622
"ggml/src/ggml-quants.c",
17-
"ggml/src/ggml-aarch64.c",
1823
]
1924

2025
var resources: [Resource] = []
2126
var linkerSettings: [LinkerSetting] = []
2227
var cSettings: [CSetting] = [
2328
.unsafeFlags(["-Wno-shorten-64-to-32", "-O3", "-DNDEBUG"]),
2429
.unsafeFlags(["-fno-objc-arc"]),
30+
.headerSearchPath("ggml/src"),
2531
// NOTE: NEW_LAPACK will required iOS version 16.4+
2632
// We should consider add this in the future when we drop support for iOS 14
2733
// (ref: ref: https://developer.apple.com/documentation/accelerate/1513264-cblas_sgemm?language=objc)
@@ -30,6 +36,7 @@ var cSettings: [CSetting] = [
3036
]
3137

3238
#if canImport(Darwin)
39+
sources.append("ggml/src/ggml-common.h")
3340
sources.append("ggml/src/ggml-metal/ggml-metal.m")
3441
resources.append(.process("ggml/src/ggml-metal/ggml-metal.metal"))
3542
linkerSettings.append(.linkedFramework("Accelerate"))

ggml/src/ggml-metal/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ if (GGML_METAL_EMBED_LIBRARY)
4646
add_custom_command(
4747
OUTPUT ${METALLIB_EMBED_ASM}
4848
COMMAND echo "Embedding Metal library"
49-
COMMAND sed -e '/\#include \"ggml-common.h\"/r ${METALLIB_COMMON}' -e '/\#include \"ggml-common.h\"/d' < ${METALLIB_SOURCE} > ${METALLIB_SOURCE_EMBED}
49+
COMMAND sed -e '/__embed_ggml-common.h__/r ${METALLIB_COMMON}' -e '/__embed_ggml-common.h__/d' < ${METALLIB_SOURCE} > ${METALLIB_SOURCE_EMBED}
5050
COMMAND echo ".section __DATA,__ggml_metallib" > ${METALLIB_EMBED_ASM}
5151
COMMAND echo ".globl _ggml_metallib_start" >> ${METALLIB_EMBED_ASM}
5252
COMMAND echo "_ggml_metallib_start:" >> ${METALLIB_EMBED_ASM}

ggml/src/ggml-metal/ggml-metal.m

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,10 @@ @implementation GGMLMetalClass
516516
[prep setObject:@"1" forKey:@"GGML_METAL_USE_BF16"];
517517
}
518518

519+
#if GGML_METAL_EMBED_LIBRARY
520+
[prep setObject:@"1" forKey:@"GGML_METAL_EMBED_LIBRARY"];
521+
#endif
522+
519523
MTLCompileOptions * options = [MTLCompileOptions new];
520524
options.preprocessorMacros = prep;
521525

ggml/src/ggml-metal/ggml-metal.metal

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
#define GGML_COMMON_DECL_METAL
22
#define GGML_COMMON_IMPL_METAL
3-
#include "ggml-common.h"
3+
#if defined(GGML_METAL_EMBED_LIBRARY)
4+
__embed_ggml-common.h__
5+
#else
6+
// TODO: this should not be a relative path, but can't figure out how to set Metal include paths in Package.swift
7+
#include "../ggml-common.h"
8+
#endif
49

510
#include <metal_stdlib>
611

0 commit comments

Comments
 (0)