mirror of
https://github.com/ggerganov/llama.cpp.git
synced 2025-01-10 18:51:45 +00:00
metal : fix build and swift package (#10279)
Some checks are pending
flake8 Lint / Lint (push) Waiting to run
Some checks are pending
flake8 Lint / Lint (push) Waiting to run
ggml-ci
This commit is contained in:
parent
dd49f08852
commit
42eb364db5
4
Makefile
4
Makefile
@ -903,12 +903,12 @@ ggml/src/ggml-metal-embed.o: \
|
|||||||
ggml/src/ggml-metal/ggml-metal.metal \
|
ggml/src/ggml-metal/ggml-metal.metal \
|
||||||
ggml/src/ggml-common.h
|
ggml/src/ggml-common.h
|
||||||
@echo "Embedding Metal library"
|
@echo "Embedding Metal library"
|
||||||
@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
|
@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
|
||||||
$(eval TEMP_ASSEMBLY=$(shell mktemp -d))
|
$(eval TEMP_ASSEMBLY=$(shell mktemp -d))
|
||||||
@echo ".section __DATA, __ggml_metallib" > $(TEMP_ASSEMBLY)/ggml-metal-embed.s
|
@echo ".section __DATA, __ggml_metallib" > $(TEMP_ASSEMBLY)/ggml-metal-embed.s
|
||||||
@echo ".globl _ggml_metallib_start" >> $(TEMP_ASSEMBLY)/ggml-metal-embed.s
|
@echo ".globl _ggml_metallib_start" >> $(TEMP_ASSEMBLY)/ggml-metal-embed.s
|
||||||
@echo "_ggml_metallib_start:" >> $(TEMP_ASSEMBLY)/ggml-metal-embed.s
|
@echo "_ggml_metallib_start:" >> $(TEMP_ASSEMBLY)/ggml-metal-embed.s
|
||||||
@echo ".incbin \"ggml/src/ggml-metal-embed.metal\"" >> $(TEMP_ASSEMBLY)/ggml-metal-embed.s
|
@echo ".incbin \"ggml/src/ggml-metal/ggml-metal-embed.metal\"" >> $(TEMP_ASSEMBLY)/ggml-metal-embed.s
|
||||||
@echo ".globl _ggml_metallib_end" >> $(TEMP_ASSEMBLY)/ggml-metal-embed.s
|
@echo ".globl _ggml_metallib_end" >> $(TEMP_ASSEMBLY)/ggml-metal-embed.s
|
||||||
@echo "_ggml_metallib_end:" >> $(TEMP_ASSEMBLY)/ggml-metal-embed.s
|
@echo "_ggml_metallib_end:" >> $(TEMP_ASSEMBLY)/ggml-metal-embed.s
|
||||||
$(CC) $(CFLAGS) -c $(TEMP_ASSEMBLY)/ggml-metal-embed.s -o $@
|
$(CC) $(CFLAGS) -c $(TEMP_ASSEMBLY)/ggml-metal-embed.s -o $@
|
||||||
|
@ -10,11 +10,16 @@ var sources = [
|
|||||||
"src/unicode.cpp",
|
"src/unicode.cpp",
|
||||||
"src/unicode-data.cpp",
|
"src/unicode-data.cpp",
|
||||||
"ggml/src/ggml.c",
|
"ggml/src/ggml.c",
|
||||||
"ggml/src/ggml-cpu.c",
|
"ggml/src/ggml-aarch64.c",
|
||||||
"ggml/src/ggml-alloc.c",
|
"ggml/src/ggml-alloc.c",
|
||||||
"ggml/src/ggml-backend.cpp",
|
"ggml/src/ggml-backend.cpp",
|
||||||
|
"ggml/src/ggml-backend-reg.cpp",
|
||||||
|
"ggml/src/ggml-cpu/ggml-cpu.c",
|
||||||
|
"ggml/src/ggml-cpu/ggml-cpu.cpp",
|
||||||
|
"ggml/src/ggml-cpu/ggml-cpu-aarch64.c",
|
||||||
|
"ggml/src/ggml-cpu/ggml-cpu-quants.c",
|
||||||
|
"ggml/src/ggml-threading.cpp",
|
||||||
"ggml/src/ggml-quants.c",
|
"ggml/src/ggml-quants.c",
|
||||||
"ggml/src/ggml-aarch64.c",
|
|
||||||
]
|
]
|
||||||
|
|
||||||
var resources: [Resource] = []
|
var resources: [Resource] = []
|
||||||
@ -22,6 +27,7 @@ var linkerSettings: [LinkerSetting] = []
|
|||||||
var cSettings: [CSetting] = [
|
var cSettings: [CSetting] = [
|
||||||
.unsafeFlags(["-Wno-shorten-64-to-32", "-O3", "-DNDEBUG"]),
|
.unsafeFlags(["-Wno-shorten-64-to-32", "-O3", "-DNDEBUG"]),
|
||||||
.unsafeFlags(["-fno-objc-arc"]),
|
.unsafeFlags(["-fno-objc-arc"]),
|
||||||
|
.headerSearchPath("ggml/src"),
|
||||||
// NOTE: NEW_LAPACK will required iOS version 16.4+
|
// NOTE: NEW_LAPACK will required iOS version 16.4+
|
||||||
// We should consider add this in the future when we drop support for iOS 14
|
// We should consider add this in the future when we drop support for iOS 14
|
||||||
// (ref: ref: https://developer.apple.com/documentation/accelerate/1513264-cblas_sgemm?language=objc)
|
// (ref: ref: https://developer.apple.com/documentation/accelerate/1513264-cblas_sgemm?language=objc)
|
||||||
@ -30,6 +36,7 @@ var cSettings: [CSetting] = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
#if canImport(Darwin)
|
#if canImport(Darwin)
|
||||||
|
sources.append("ggml/src/ggml-common.h")
|
||||||
sources.append("ggml/src/ggml-metal/ggml-metal.m")
|
sources.append("ggml/src/ggml-metal/ggml-metal.m")
|
||||||
resources.append(.process("ggml/src/ggml-metal/ggml-metal.metal"))
|
resources.append(.process("ggml/src/ggml-metal/ggml-metal.metal"))
|
||||||
linkerSettings.append(.linkedFramework("Accelerate"))
|
linkerSettings.append(.linkedFramework("Accelerate"))
|
||||||
|
@ -46,7 +46,7 @@ if (GGML_METAL_EMBED_LIBRARY)
|
|||||||
add_custom_command(
|
add_custom_command(
|
||||||
OUTPUT ${METALLIB_EMBED_ASM}
|
OUTPUT ${METALLIB_EMBED_ASM}
|
||||||
COMMAND echo "Embedding Metal library"
|
COMMAND echo "Embedding Metal library"
|
||||||
COMMAND sed -e '/\#include \"ggml-common.h\"/r ${METALLIB_COMMON}' -e '/\#include \"ggml-common.h\"/d' < ${METALLIB_SOURCE} > ${METALLIB_SOURCE_EMBED}
|
COMMAND sed -e '/__embed_ggml-common.h__/r ${METALLIB_COMMON}' -e '/__embed_ggml-common.h__/d' < ${METALLIB_SOURCE} > ${METALLIB_SOURCE_EMBED}
|
||||||
COMMAND echo ".section __DATA,__ggml_metallib" > ${METALLIB_EMBED_ASM}
|
COMMAND echo ".section __DATA,__ggml_metallib" > ${METALLIB_EMBED_ASM}
|
||||||
COMMAND echo ".globl _ggml_metallib_start" >> ${METALLIB_EMBED_ASM}
|
COMMAND echo ".globl _ggml_metallib_start" >> ${METALLIB_EMBED_ASM}
|
||||||
COMMAND echo "_ggml_metallib_start:" >> ${METALLIB_EMBED_ASM}
|
COMMAND echo "_ggml_metallib_start:" >> ${METALLIB_EMBED_ASM}
|
||||||
|
@ -516,6 +516,10 @@ static struct ggml_backend_metal_context * ggml_metal_init(ggml_backend_dev_t de
|
|||||||
[prep setObject:@"1" forKey:@"GGML_METAL_USE_BF16"];
|
[prep setObject:@"1" forKey:@"GGML_METAL_USE_BF16"];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if GGML_METAL_EMBED_LIBRARY
|
||||||
|
[prep setObject:@"1" forKey:@"GGML_METAL_EMBED_LIBRARY"];
|
||||||
|
#endif
|
||||||
|
|
||||||
MTLCompileOptions * options = [MTLCompileOptions new];
|
MTLCompileOptions * options = [MTLCompileOptions new];
|
||||||
options.preprocessorMacros = prep;
|
options.preprocessorMacros = prep;
|
||||||
|
|
||||||
|
@ -1,6 +1,11 @@
|
|||||||
#define GGML_COMMON_DECL_METAL
|
#define GGML_COMMON_DECL_METAL
|
||||||
#define GGML_COMMON_IMPL_METAL
|
#define GGML_COMMON_IMPL_METAL
|
||||||
#include "ggml-common.h"
|
#if defined(GGML_METAL_EMBED_LIBRARY)
|
||||||
|
__embed_ggml-common.h__
|
||||||
|
#else
|
||||||
|
// TODO: this should not be a relative path, but can't figure out how to set Metal include paths in Package.swift
|
||||||
|
#include "../ggml-common.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <metal_stdlib>
|
#include <metal_stdlib>
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user