@fugood/llama.node 0.3.2 → 0.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CMakeLists.txt +2 -0
- package/bin/darwin/arm64/llama-node.node +0 -0
- package/bin/darwin/x64/llama-node.node +0 -0
- package/bin/linux/arm64/llama-node.node +0 -0
- package/bin/linux/x64/llama-node.node +0 -0
- package/bin/linux-vulkan/arm64/llama-node.node +0 -0
- package/bin/linux-vulkan/x64/llama-node.node +0 -0
- package/bin/win32/arm64/llama-node.node +0 -0
- package/bin/win32/arm64/node.lib +0 -0
- package/bin/win32/x64/llama-node.node +0 -0
- package/bin/win32/x64/node.lib +0 -0
- package/bin/win32-vulkan/arm64/llama-node.node +0 -0
- package/bin/win32-vulkan/arm64/node.lib +0 -0
- package/bin/win32-vulkan/x64/llama-node.node +0 -0
- package/bin/win32-vulkan/x64/node.lib +0 -0
- package/package.json +1 -1
- package/src/DetokenizeWorker.cpp +1 -1
- package/src/EmbeddingWorker.cpp +2 -2
- package/src/LlamaCompletionWorker.cpp +8 -8
- package/src/LlamaCompletionWorker.h +2 -2
- package/src/LlamaContext.cpp +8 -9
- package/src/TokenizeWorker.cpp +1 -1
- package/src/common.hpp +4 -4
- package/src/llama.cpp/.github/workflows/build.yml +43 -9
- package/src/llama.cpp/.github/workflows/docker.yml +3 -0
- package/src/llama.cpp/CMakeLists.txt +7 -4
- package/src/llama.cpp/cmake/arm64-apple-clang.cmake +16 -0
- package/src/llama.cpp/common/CMakeLists.txt +0 -2
- package/src/llama.cpp/common/arg.cpp +642 -607
- package/src/llama.cpp/common/arg.h +22 -22
- package/src/llama.cpp/common/common.cpp +79 -281
- package/src/llama.cpp/common/common.h +130 -100
- package/src/llama.cpp/common/json-schema-to-grammar.cpp +1 -1
- package/src/llama.cpp/common/log.cpp +50 -50
- package/src/llama.cpp/common/log.h +18 -18
- package/src/llama.cpp/common/ngram-cache.cpp +36 -36
- package/src/llama.cpp/common/ngram-cache.h +19 -19
- package/src/llama.cpp/common/sampling.cpp +116 -108
- package/src/llama.cpp/common/sampling.h +20 -20
- package/src/llama.cpp/docs/build.md +37 -17
- package/src/llama.cpp/examples/CMakeLists.txt +1 -1
- package/src/llama.cpp/examples/batched/batched.cpp +14 -14
- package/src/llama.cpp/examples/batched-bench/batched-bench.cpp +10 -11
- package/src/llama.cpp/examples/convert-llama2c-to-ggml/convert-llama2c-to-ggml.cpp +1 -1
- package/src/llama.cpp/examples/cvector-generator/cvector-generator.cpp +9 -9
- package/src/llama.cpp/examples/embedding/embedding.cpp +12 -12
- package/src/llama.cpp/examples/eval-callback/eval-callback.cpp +8 -8
- package/src/llama.cpp/examples/export-lora/export-lora.cpp +5 -5
- package/src/llama.cpp/examples/gen-docs/gen-docs.cpp +7 -7
- package/src/llama.cpp/examples/gritlm/gritlm.cpp +18 -18
- package/src/llama.cpp/examples/imatrix/imatrix.cpp +20 -11
- package/src/llama.cpp/examples/infill/infill.cpp +40 -86
- package/src/llama.cpp/examples/llama-bench/llama-bench.cpp +42 -151
- package/src/llama.cpp/examples/llama.android/llama/build.gradle.kts +1 -0
- package/src/llama.cpp/examples/llama.android/llama/src/main/cpp/llama-android.cpp +11 -14
- package/src/llama.cpp/examples/llava/clip.cpp +1 -0
- package/src/llama.cpp/examples/llava/llava-cli.cpp +23 -23
- package/src/llama.cpp/examples/llava/llava.cpp +37 -3
- package/src/llama.cpp/examples/llava/minicpmv-cli.cpp +21 -21
- package/src/llama.cpp/examples/lookahead/lookahead.cpp +26 -26
- package/src/llama.cpp/examples/lookup/lookup-create.cpp +7 -7
- package/src/llama.cpp/examples/lookup/lookup-merge.cpp +4 -4
- package/src/llama.cpp/examples/lookup/lookup-stats.cpp +14 -14
- package/src/llama.cpp/examples/lookup/lookup.cpp +29 -29
- package/src/llama.cpp/examples/main/main.cpp +64 -109
- package/src/llama.cpp/examples/parallel/parallel.cpp +18 -19
- package/src/llama.cpp/examples/passkey/passkey.cpp +14 -14
- package/src/llama.cpp/examples/perplexity/perplexity.cpp +99 -120
- package/src/llama.cpp/examples/quantize-stats/quantize-stats.cpp +10 -9
- package/src/llama.cpp/examples/retrieval/retrieval.cpp +13 -13
- package/src/llama.cpp/examples/rpc/rpc-server.cpp +3 -1
- package/src/llama.cpp/examples/save-load-state/save-load-state.cpp +34 -17
- package/src/llama.cpp/examples/server/CMakeLists.txt +4 -13
- package/src/llama.cpp/examples/server/server.cpp +553 -691
- package/src/llama.cpp/examples/server/utils.hpp +312 -25
- package/src/llama.cpp/examples/simple/CMakeLists.txt +1 -1
- package/src/llama.cpp/examples/simple/simple.cpp +128 -96
- package/src/llama.cpp/examples/simple-chat/CMakeLists.txt +5 -0
- package/src/llama.cpp/examples/simple-chat/simple-chat.cpp +197 -0
- package/src/llama.cpp/examples/speculative/speculative.cpp +54 -51
- package/src/llama.cpp/examples/tokenize/tokenize.cpp +2 -2
- package/src/llama.cpp/ggml/CMakeLists.txt +15 -9
- package/src/llama.cpp/ggml/include/ggml-amx.h +25 -0
- package/src/llama.cpp/ggml/include/ggml-backend.h +46 -33
- package/src/llama.cpp/ggml/include/ggml-blas.h +5 -3
- package/src/llama.cpp/ggml/include/ggml-cann.h +9 -7
- package/src/llama.cpp/ggml/include/ggml-cpp.h +38 -0
- package/src/llama.cpp/ggml/include/ggml-cpu.h +177 -0
- package/src/llama.cpp/ggml/include/ggml-cuda.h +12 -12
- package/src/llama.cpp/ggml/include/ggml-kompute.h +7 -3
- package/src/llama.cpp/ggml/include/ggml-metal.h +11 -7
- package/src/llama.cpp/ggml/include/ggml-opt.h +216 -0
- package/src/llama.cpp/ggml/include/ggml-rpc.h +9 -5
- package/src/llama.cpp/ggml/include/ggml-sycl.h +18 -11
- package/src/llama.cpp/ggml/include/ggml-vulkan.h +10 -8
- package/src/llama.cpp/ggml/include/ggml.h +53 -393
- package/src/llama.cpp/ggml/src/CMakeLists.txt +66 -1149
- package/src/llama.cpp/ggml/src/ggml-aarch64.c +46 -3126
- package/src/llama.cpp/ggml/src/ggml-aarch64.h +0 -20
- package/src/llama.cpp/ggml/src/ggml-alloc.c +23 -27
- package/src/llama.cpp/ggml/src/ggml-amx/CMakeLists.txt +107 -0
- package/src/llama.cpp/ggml/src/ggml-amx/common.h +94 -0
- package/src/llama.cpp/ggml/src/ggml-amx/ggml-amx.cpp +446 -0
- package/src/llama.cpp/ggml/src/ggml-amx/mmq.cpp +2510 -0
- package/src/llama.cpp/ggml/src/ggml-amx/mmq.h +17 -0
- package/src/llama.cpp/ggml/src/ggml-backend-impl.h +6 -25
- package/src/llama.cpp/ggml/src/ggml-backend-reg.cpp +195 -0
- package/src/llama.cpp/ggml/src/ggml-backend.cpp +303 -864
- package/src/llama.cpp/ggml/src/ggml-blas/CMakeLists.txt +91 -0
- package/src/llama.cpp/ggml/src/{ggml-blas.cpp → ggml-blas/ggml-blas.cpp} +213 -65
- package/src/llama.cpp/ggml/src/ggml-cann/CMakeLists.txt +46 -0
- package/src/llama.cpp/ggml/src/{ggml-cann.cpp → ggml-cann/ggml-cann.cpp} +255 -149
- package/src/llama.cpp/ggml/src/ggml-cpu/CMakeLists.txt +261 -0
- package/src/llama.cpp/ggml/src/ggml-cpu/ggml-cpu-aarch64.c +3560 -0
- package/src/llama.cpp/ggml/src/ggml-cpu/ggml-cpu-aarch64.h +30 -0
- package/src/llama.cpp/ggml/src/{ggml-cpu-impl.h → ggml-cpu/ggml-cpu-impl.h} +0 -243
- package/src/llama.cpp/ggml/src/ggml-cpu/ggml-cpu-quants.c +10822 -0
- package/src/llama.cpp/ggml/src/ggml-cpu/ggml-cpu-quants.h +63 -0
- package/src/llama.cpp/ggml/src/ggml-cpu/ggml-cpu.c +13970 -0
- package/src/llama.cpp/ggml/src/ggml-cpu/ggml-cpu.cpp +663 -0
- package/src/llama.cpp/ggml/src/{llamafile → ggml-cpu/llamafile}/sgemm.cpp +667 -1
- package/src/llama.cpp/ggml/src/ggml-cuda/CMakeLists.txt +155 -0
- package/src/llama.cpp/ggml/src/ggml-hip/CMakeLists.txt +106 -0
- package/src/llama.cpp/ggml/src/ggml-impl.h +366 -16
- package/src/llama.cpp/ggml/src/ggml-kompute/CMakeLists.txt +162 -0
- package/src/llama.cpp/ggml/src/{ggml-kompute.cpp → ggml-kompute/ggml-kompute.cpp} +238 -72
- package/src/llama.cpp/ggml/src/ggml-metal/CMakeLists.txt +108 -0
- package/src/llama.cpp/ggml/src/ggml-metal/ggml-metal-impl.h +249 -0
- package/src/llama.cpp/ggml/src/ggml-musa/CMakeLists.txt +100 -0
- package/src/llama.cpp/ggml/src/ggml-opt.cpp +867 -0
- package/src/llama.cpp/ggml/src/ggml-quants.c +187 -10692
- package/src/llama.cpp/ggml/src/ggml-quants.h +78 -125
- package/src/llama.cpp/ggml/src/ggml-rpc/CMakeLists.txt +11 -0
- package/src/llama.cpp/ggml/src/{ggml-rpc.cpp → ggml-rpc/ggml-rpc.cpp} +475 -300
- package/src/llama.cpp/ggml/src/ggml-sycl/CMakeLists.txt +81 -0
- package/src/llama.cpp/ggml/src/ggml-sycl/backend.hpp +3 -0
- package/src/llama.cpp/ggml/src/ggml-sycl/common.cpp +40 -0
- package/src/llama.cpp/ggml/src/ggml-sycl/common.hpp +258 -0
- package/src/llama.cpp/ggml/src/ggml-sycl/concat.cpp +1 -0
- package/src/llama.cpp/ggml/src/ggml-sycl/dpct/helper.hpp +2 -22
- package/src/llama.cpp/ggml/src/ggml-sycl/element_wise.cpp +1011 -0
- package/src/llama.cpp/ggml/src/ggml-sycl/element_wise.hpp +76 -0
- package/src/llama.cpp/ggml/src/{ggml-sycl.cpp → ggml-sycl/ggml-sycl.cpp} +3584 -4142
- package/src/llama.cpp/ggml/src/ggml-sycl/mmvq.cpp +69 -67
- package/src/llama.cpp/ggml/src/ggml-sycl/norm.cpp +3 -3
- package/src/llama.cpp/ggml/src/ggml-sycl/outprod.cpp +56 -0
- package/src/llama.cpp/ggml/src/ggml-sycl/outprod.hpp +11 -0
- package/src/llama.cpp/ggml/src/ggml-sycl/presets.hpp +6 -0
- package/src/llama.cpp/ggml/src/ggml-sycl/vecdotq.hpp +4 -4
- package/src/llama.cpp/ggml/src/ggml-sycl/wkv6.cpp +138 -0
- package/src/llama.cpp/ggml/src/ggml-sycl/wkv6.hpp +10 -0
- package/src/llama.cpp/ggml/src/ggml-threading.cpp +12 -0
- package/src/llama.cpp/ggml/src/ggml-threading.h +12 -0
- package/src/llama.cpp/ggml/src/ggml-vulkan/CMakeLists.txt +78 -0
- package/src/llama.cpp/ggml/src/{ggml-vulkan.cpp → ggml-vulkan/ggml-vulkan.cpp} +555 -623
- package/src/llama.cpp/ggml/src/{vulkan-shaders → ggml-vulkan/vulkan-shaders}/vulkan-shaders-gen.cpp +125 -206
- package/src/llama.cpp/ggml/src/ggml.c +4032 -19890
- package/src/llama.cpp/include/llama.h +67 -33
- package/src/llama.cpp/pocs/vdot/q8dot.cpp +4 -3
- package/src/llama.cpp/pocs/vdot/vdot.cpp +8 -7
- package/src/llama.cpp/src/CMakeLists.txt +2 -1
- package/src/llama.cpp/src/llama-sampling.cpp +745 -105
- package/src/llama.cpp/src/llama-sampling.h +21 -2
- package/src/llama.cpp/src/llama-vocab.cpp +49 -9
- package/src/llama.cpp/src/llama-vocab.h +35 -11
- package/src/llama.cpp/src/llama.cpp +2636 -2406
- package/src/llama.cpp/src/unicode-data.cpp +2 -2
- package/src/llama.cpp/tests/CMakeLists.txt +1 -2
- package/src/llama.cpp/tests/test-arg-parser.cpp +14 -14
- package/src/llama.cpp/tests/test-backend-ops.cpp +185 -60
- package/src/llama.cpp/tests/test-barrier.cpp +1 -0
- package/src/llama.cpp/tests/test-chat-template.cpp +9 -5
- package/src/llama.cpp/tests/test-json-schema-to-grammar.cpp +17 -4
- package/src/llama.cpp/tests/test-log.cpp +2 -2
- package/src/llama.cpp/tests/test-opt.cpp +853 -142
- package/src/llama.cpp/tests/test-quantize-fns.cpp +22 -19
- package/src/llama.cpp/tests/test-quantize-perf.cpp +16 -14
- package/src/llama.cpp/tests/test-rope.cpp +1 -0
- package/src/llama.cpp/tests/test-sampling.cpp +162 -137
- package/src/llama.cpp/tests/test-tokenizer-0.cpp +7 -7
- package/src/llama.cpp/tests/test-tokenizer-1-bpe.cpp +5 -5
- package/src/llama.cpp/tests/test-tokenizer-1-spm.cpp +5 -5
- package/src/llama.cpp/common/train.cpp +0 -1515
- package/src/llama.cpp/common/train.h +0 -233
- package/src/llama.cpp/examples/baby-llama/CMakeLists.txt +0 -5
- package/src/llama.cpp/examples/baby-llama/baby-llama.cpp +0 -1639
- package/src/llama.cpp/tests/test-grad0.cpp +0 -1683
- /package/src/llama.cpp/ggml/{cmake → src/ggml-cpu/cmake}/FindSIMD.cmake +0 -0
- /package/src/llama.cpp/ggml/src/{llamafile → ggml-cpu/llamafile}/sgemm.h +0 -0
- /package/src/llama.cpp/ggml/src/{vulkan-shaders → ggml-vulkan/vulkan-shaders}/CMakeLists.txt +0 -0
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
find_library(FOUNDATION_LIBRARY Foundation REQUIRED)
|
|
2
|
+
find_library(METAL_FRAMEWORK Metal REQUIRED)
|
|
3
|
+
find_library(METALKIT_FRAMEWORK MetalKit REQUIRED)
|
|
4
|
+
|
|
5
|
+
message(STATUS "Metal framework found")
|
|
6
|
+
|
|
7
|
+
add_library(ggml-metal
|
|
8
|
+
ggml-metal.m
|
|
9
|
+
)
|
|
10
|
+
|
|
11
|
+
target_link_libraries(ggml-metal PRIVATE
|
|
12
|
+
ggml-base
|
|
13
|
+
${FOUNDATION_LIBRARY}
|
|
14
|
+
${METAL_FRAMEWORK}
|
|
15
|
+
${METALKIT_FRAMEWORK}
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
target_include_directories(ggml-metal PRIVATE . ..)
|
|
19
|
+
|
|
20
|
+
if (GGML_METAL_NDEBUG)
|
|
21
|
+
add_compile_definitions(GGML_METAL_NDEBUG)
|
|
22
|
+
endif()
|
|
23
|
+
|
|
24
|
+
if (GGML_METAL_USE_BF16)
|
|
25
|
+
add_compile_definitions(GGML_METAL_USE_BF16)
|
|
26
|
+
endif()
|
|
27
|
+
|
|
28
|
+
# copy metal files to bin directory
|
|
29
|
+
configure_file(../ggml-common.h ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/ggml-common.h COPYONLY)
|
|
30
|
+
configure_file(ggml-metal.metal ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/ggml-metal.metal COPYONLY)
|
|
31
|
+
configure_file(ggml-metal-impl.h ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/ggml-metal-impl.h COPYONLY)
|
|
32
|
+
|
|
33
|
+
if (GGML_METAL_EMBED_LIBRARY)
|
|
34
|
+
enable_language(ASM)
|
|
35
|
+
|
|
36
|
+
add_compile_definitions(GGML_METAL_EMBED_LIBRARY)
|
|
37
|
+
|
|
38
|
+
set(METALLIB_COMMON "${CMAKE_CURRENT_SOURCE_DIR}/../ggml-common.h")
|
|
39
|
+
set(METALLIB_SOURCE "${CMAKE_CURRENT_SOURCE_DIR}/ggml-metal.metal")
|
|
40
|
+
set(METALLIB_IMPL "${CMAKE_CURRENT_SOURCE_DIR}/ggml-metal-impl.h")
|
|
41
|
+
|
|
42
|
+
file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/autogenerated")
|
|
43
|
+
|
|
44
|
+
# merge ggml-common.h and ggml-metal.metal into a single file
|
|
45
|
+
set(METALLIB_EMBED_ASM "${CMAKE_BINARY_DIR}/autogenerated/ggml-metal-embed.s")
|
|
46
|
+
set(METALLIB_SOURCE_EMBED "${CMAKE_BINARY_DIR}/autogenerated/ggml-metal-embed.metal")
|
|
47
|
+
set(METALLIB_SOURCE_EMBED_TMP "${CMAKE_BINARY_DIR}/autogenerated/ggml-metal-embed.metal.tmp")
|
|
48
|
+
|
|
49
|
+
add_custom_command(
|
|
50
|
+
OUTPUT ${METALLIB_EMBED_ASM}
|
|
51
|
+
COMMAND echo "Embedding Metal library"
|
|
52
|
+
COMMAND sed -e '/__embed_ggml-common.h__/r ${METALLIB_COMMON}' -e '/__embed_ggml-common.h__/d' < ${METALLIB_SOURCE} > ${METALLIB_SOURCE_EMBED_TMP}
|
|
53
|
+
COMMAND sed -e '/\#include \"ggml-metal-impl.h\"/r ${METALLIB_IMPL}' -e '/\#include \"ggml-metal-impl.h\"/d' < ${METALLIB_SOURCE_EMBED_TMP} > ${METALLIB_SOURCE_EMBED}
|
|
54
|
+
COMMAND echo ".section __DATA,__ggml_metallib" > ${METALLIB_EMBED_ASM}
|
|
55
|
+
COMMAND echo ".globl _ggml_metallib_start" >> ${METALLIB_EMBED_ASM}
|
|
56
|
+
COMMAND echo "_ggml_metallib_start:" >> ${METALLIB_EMBED_ASM}
|
|
57
|
+
COMMAND echo ".incbin \\\"${METALLIB_SOURCE_EMBED}\\\"" >> ${METALLIB_EMBED_ASM}
|
|
58
|
+
COMMAND echo ".globl _ggml_metallib_end" >> ${METALLIB_EMBED_ASM}
|
|
59
|
+
COMMAND echo "_ggml_metallib_end:" >> ${METALLIB_EMBED_ASM}
|
|
60
|
+
DEPENDS ../ggml-common.h ggml-metal.metal ggml-metal-impl.h
|
|
61
|
+
COMMENT "Generate assembly for embedded Metal library"
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
target_sources(ggml-metal PRIVATE ${METALLIB_EMBED_ASM})
|
|
65
|
+
else()
|
|
66
|
+
if (GGML_METAL_SHADER_DEBUG)
|
|
67
|
+
# custom command to do the following:
|
|
68
|
+
# xcrun -sdk macosx metal -fno-fast-math -c ggml-metal.metal -o ggml-metal.air
|
|
69
|
+
# xcrun -sdk macosx metallib ggml-metal.air -o default.metallib
|
|
70
|
+
#
|
|
71
|
+
# note: this is the only way I found to disable fast-math in Metal. it's ugly, but at least it works
|
|
72
|
+
# disabling fast math is needed in order to pass tests/test-backend-ops
|
|
73
|
+
# note: adding -fno-inline fixes the tests when using MTL_SHADER_VALIDATION=1
|
|
74
|
+
# note: unfortunately, we have to call it default.metallib instead of ggml.metallib
|
|
75
|
+
# ref: https://github.com/ggerganov/whisper.cpp/issues/1720
|
|
76
|
+
set(XC_FLAGS -fno-fast-math -fno-inline -g)
|
|
77
|
+
else()
|
|
78
|
+
set(XC_FLAGS -O3)
|
|
79
|
+
endif()
|
|
80
|
+
|
|
81
|
+
# Append macOS metal versioning flags
|
|
82
|
+
if (GGML_METAL_MACOSX_VERSION_MIN)
|
|
83
|
+
message(STATUS "Adding -mmacosx-version-min=${GGML_METAL_MACOSX_VERSION_MIN} flag to metal compilation")
|
|
84
|
+
list (APPEND XC_FLAGS -mmacosx-version-min=${GGML_METAL_MACOSX_VERSION_MIN})
|
|
85
|
+
endif()
|
|
86
|
+
|
|
87
|
+
if (GGML_METAL_STD)
|
|
88
|
+
message(STATUS "Adding -std=${GGML_METAL_STD} flag to metal compilation")
|
|
89
|
+
list (APPEND XC_FLAGS -std=${GGML_METAL_STD})
|
|
90
|
+
endif()
|
|
91
|
+
|
|
92
|
+
add_custom_command(
|
|
93
|
+
OUTPUT ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/default.metallib
|
|
94
|
+
COMMAND xcrun -sdk macosx metal ${XC_FLAGS} -c ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/ggml-metal.metal -o ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/ggml-metal.air
|
|
95
|
+
COMMAND xcrun -sdk macosx metallib ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/ggml-metal.air -o ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/default.metallib
|
|
96
|
+
COMMAND rm -f ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/ggml-metal.air
|
|
97
|
+
COMMAND rm -f ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/ggml-common.h
|
|
98
|
+
COMMAND rm -f ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/ggml-metal.metal
|
|
99
|
+
DEPENDS ggml-metal.metal ggml-common.h
|
|
100
|
+
COMMENT "Compiling Metal kernels"
|
|
101
|
+
)
|
|
102
|
+
|
|
103
|
+
# FIXME: only add to the ggml-metal target?
|
|
104
|
+
add_custom_target(
|
|
105
|
+
ggml-metal-lib ALL
|
|
106
|
+
DEPENDS ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/default.metallib
|
|
107
|
+
)
|
|
108
|
+
endif() # GGML_METAL_EMBED_LIBRARY
|
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
#ifndef GGML_METAL_IMPL
|
|
2
|
+
#define GGML_METAL_IMPL
|
|
3
|
+
|
|
4
|
+
// kernel argument structs
|
|
5
|
+
//
|
|
6
|
+
// - element counters (e.g. ne00) typically use int32_t to reduce register usage
|
|
7
|
+
// however, be careful from int overflows when using those in the kernel implementation
|
|
8
|
+
//
|
|
9
|
+
// - strides (e.g. nb00) use uint64_t
|
|
10
|
+
|
|
11
|
+
typedef struct {
|
|
12
|
+
int32_t ne00;
|
|
13
|
+
int32_t ne01;
|
|
14
|
+
int32_t ne02;
|
|
15
|
+
int32_t ne03;
|
|
16
|
+
uint64_t nb00;
|
|
17
|
+
uint64_t nb01;
|
|
18
|
+
uint64_t nb02;
|
|
19
|
+
uint64_t nb03;
|
|
20
|
+
int32_t ne10;
|
|
21
|
+
int32_t ne11;
|
|
22
|
+
int32_t ne12;
|
|
23
|
+
int32_t ne13;
|
|
24
|
+
uint64_t nb10;
|
|
25
|
+
uint64_t nb11;
|
|
26
|
+
uint64_t nb12;
|
|
27
|
+
uint64_t nb13;
|
|
28
|
+
int32_t ne0;
|
|
29
|
+
int32_t ne1;
|
|
30
|
+
int32_t ne2;
|
|
31
|
+
int32_t ne3;
|
|
32
|
+
uint64_t nb0;
|
|
33
|
+
uint64_t nb1;
|
|
34
|
+
uint64_t nb2;
|
|
35
|
+
uint64_t nb3;
|
|
36
|
+
int32_t dim;
|
|
37
|
+
} ggml_metal_kargs_concat;
|
|
38
|
+
|
|
39
|
+
typedef struct {
|
|
40
|
+
int32_t ne00;
|
|
41
|
+
int32_t ne01;
|
|
42
|
+
int32_t ne02;
|
|
43
|
+
int32_t ne03;
|
|
44
|
+
uint64_t nb00;
|
|
45
|
+
uint64_t nb01;
|
|
46
|
+
uint64_t nb02;
|
|
47
|
+
uint64_t nb03;
|
|
48
|
+
int32_t ne10;
|
|
49
|
+
int32_t ne11;
|
|
50
|
+
int32_t ne12;
|
|
51
|
+
int32_t ne13;
|
|
52
|
+
uint64_t nb10;
|
|
53
|
+
uint64_t nb11;
|
|
54
|
+
uint64_t nb12;
|
|
55
|
+
uint64_t nb13;
|
|
56
|
+
int32_t ne0;
|
|
57
|
+
int32_t ne1;
|
|
58
|
+
int32_t ne2;
|
|
59
|
+
int32_t ne3;
|
|
60
|
+
uint64_t nb0;
|
|
61
|
+
uint64_t nb1;
|
|
62
|
+
uint64_t nb2;
|
|
63
|
+
uint64_t nb3;
|
|
64
|
+
uint64_t offs;
|
|
65
|
+
} ggml_metal_kargs_bin;
|
|
66
|
+
|
|
67
|
+
typedef struct {
|
|
68
|
+
int32_t ne00;
|
|
69
|
+
int32_t ne01;
|
|
70
|
+
int32_t ne02;
|
|
71
|
+
int32_t ne03;
|
|
72
|
+
uint64_t nb00;
|
|
73
|
+
uint64_t nb01;
|
|
74
|
+
uint64_t nb02;
|
|
75
|
+
uint64_t nb03;
|
|
76
|
+
int32_t ne0;
|
|
77
|
+
int32_t ne1;
|
|
78
|
+
int32_t ne2;
|
|
79
|
+
int32_t ne3;
|
|
80
|
+
uint64_t nb0;
|
|
81
|
+
uint64_t nb1;
|
|
82
|
+
uint64_t nb2;
|
|
83
|
+
uint64_t nb3;
|
|
84
|
+
} ggml_metal_kargs_repeat;
|
|
85
|
+
|
|
86
|
+
typedef struct {
|
|
87
|
+
int64_t ne00;
|
|
88
|
+
int64_t ne01;
|
|
89
|
+
int64_t ne02;
|
|
90
|
+
int64_t ne03;
|
|
91
|
+
uint64_t nb00;
|
|
92
|
+
uint64_t nb01;
|
|
93
|
+
uint64_t nb02;
|
|
94
|
+
uint64_t nb03;
|
|
95
|
+
int64_t ne0;
|
|
96
|
+
int64_t ne1;
|
|
97
|
+
int64_t ne2;
|
|
98
|
+
int64_t ne3;
|
|
99
|
+
uint64_t nb0;
|
|
100
|
+
uint64_t nb1;
|
|
101
|
+
uint64_t nb2;
|
|
102
|
+
uint64_t nb3;
|
|
103
|
+
} ggml_metal_kargs_cpy;
|
|
104
|
+
|
|
105
|
+
typedef struct {
|
|
106
|
+
int32_t ne00;
|
|
107
|
+
int32_t ne01;
|
|
108
|
+
int32_t ne02;
|
|
109
|
+
int32_t ne03;
|
|
110
|
+
uint64_t nb00;
|
|
111
|
+
uint64_t nb01;
|
|
112
|
+
uint64_t nb02;
|
|
113
|
+
uint64_t nb03;
|
|
114
|
+
int32_t ne0;
|
|
115
|
+
int32_t ne1;
|
|
116
|
+
int32_t ne2;
|
|
117
|
+
int32_t ne3;
|
|
118
|
+
uint64_t nb0;
|
|
119
|
+
uint64_t nb1;
|
|
120
|
+
uint64_t nb2;
|
|
121
|
+
uint64_t nb3;
|
|
122
|
+
int32_t n_past;
|
|
123
|
+
int32_t n_dims;
|
|
124
|
+
int32_t n_ctx_orig;
|
|
125
|
+
float freq_base;
|
|
126
|
+
float freq_scale;
|
|
127
|
+
float ext_factor;
|
|
128
|
+
float attn_factor;
|
|
129
|
+
float beta_fast;
|
|
130
|
+
float beta_slow;
|
|
131
|
+
} ggml_metal_kargs_rope;
|
|
132
|
+
|
|
133
|
+
typedef struct {
|
|
134
|
+
int32_t ne01;
|
|
135
|
+
int32_t ne02;
|
|
136
|
+
int32_t ne03;
|
|
137
|
+
uint64_t nb01;
|
|
138
|
+
uint64_t nb02;
|
|
139
|
+
uint64_t nb03;
|
|
140
|
+
int32_t ne11;
|
|
141
|
+
int32_t ne_12_2; // assume K and V are same shape
|
|
142
|
+
int32_t ne_12_3;
|
|
143
|
+
uint64_t nb_12_1;
|
|
144
|
+
uint64_t nb_12_2;
|
|
145
|
+
uint64_t nb_12_3;
|
|
146
|
+
uint64_t nb31;
|
|
147
|
+
int32_t ne1;
|
|
148
|
+
int32_t ne2;
|
|
149
|
+
float scale;
|
|
150
|
+
float max_bias;
|
|
151
|
+
float m0;
|
|
152
|
+
float m1;
|
|
153
|
+
uint16_t n_head_log2;
|
|
154
|
+
float logit_softcap;
|
|
155
|
+
} ggml_metal_kargs_flash_attn_ext;
|
|
156
|
+
|
|
157
|
+
typedef struct {
|
|
158
|
+
int32_t ne00;
|
|
159
|
+
int32_t ne02;
|
|
160
|
+
uint64_t nb01;
|
|
161
|
+
uint64_t nb02;
|
|
162
|
+
uint64_t nb03;
|
|
163
|
+
int32_t ne12;
|
|
164
|
+
uint64_t nb10;
|
|
165
|
+
uint64_t nb11;
|
|
166
|
+
uint64_t nb12;
|
|
167
|
+
uint64_t nb13;
|
|
168
|
+
int32_t ne0;
|
|
169
|
+
int32_t ne1;
|
|
170
|
+
int16_t r2;
|
|
171
|
+
int16_t r3;
|
|
172
|
+
} ggml_metal_kargs_mul_mm;
|
|
173
|
+
|
|
174
|
+
typedef struct {
|
|
175
|
+
int32_t ne00;
|
|
176
|
+
int32_t ne01;
|
|
177
|
+
int32_t ne02;
|
|
178
|
+
uint64_t nb00;
|
|
179
|
+
uint64_t nb01;
|
|
180
|
+
uint64_t nb02;
|
|
181
|
+
uint64_t nb03;
|
|
182
|
+
int32_t ne10;
|
|
183
|
+
int32_t ne11;
|
|
184
|
+
int32_t ne12;
|
|
185
|
+
uint64_t nb10;
|
|
186
|
+
uint64_t nb11;
|
|
187
|
+
uint64_t nb12;
|
|
188
|
+
uint64_t nb13;
|
|
189
|
+
int32_t ne0;
|
|
190
|
+
int32_t ne1;
|
|
191
|
+
int16_t r2;
|
|
192
|
+
int16_t r3;
|
|
193
|
+
} ggml_metal_kargs_mul_mv;
|
|
194
|
+
|
|
195
|
+
typedef struct {
|
|
196
|
+
int32_t nei0;
|
|
197
|
+
int32_t nei1;
|
|
198
|
+
uint64_t nbi1;
|
|
199
|
+
int32_t ne00;
|
|
200
|
+
int32_t ne02;
|
|
201
|
+
uint64_t nb01;
|
|
202
|
+
uint64_t nb02;
|
|
203
|
+
int32_t ne11;
|
|
204
|
+
int32_t ne12;
|
|
205
|
+
int32_t ne13;
|
|
206
|
+
uint64_t nb10;
|
|
207
|
+
uint64_t nb11;
|
|
208
|
+
uint64_t nb12;
|
|
209
|
+
int32_t ne0;
|
|
210
|
+
int32_t ne1;
|
|
211
|
+
} ggml_metal_kargs_mul_mm_id;
|
|
212
|
+
|
|
213
|
+
typedef struct {
|
|
214
|
+
int32_t nei0;
|
|
215
|
+
int32_t nei1;
|
|
216
|
+
uint64_t nbi1;
|
|
217
|
+
int32_t ne00;
|
|
218
|
+
int32_t ne01;
|
|
219
|
+
int32_t ne02;
|
|
220
|
+
uint64_t nb00;
|
|
221
|
+
uint64_t nb01;
|
|
222
|
+
uint64_t nb02;
|
|
223
|
+
int32_t ne10;
|
|
224
|
+
int32_t ne11;
|
|
225
|
+
int32_t ne12;
|
|
226
|
+
int32_t ne13;
|
|
227
|
+
uint64_t nb10;
|
|
228
|
+
uint64_t nb11;
|
|
229
|
+
uint64_t nb12;
|
|
230
|
+
int32_t ne0;
|
|
231
|
+
int32_t ne1;
|
|
232
|
+
uint64_t nb1;
|
|
233
|
+
} ggml_metal_kargs_mul_mv_id;
|
|
234
|
+
|
|
235
|
+
typedef struct {
|
|
236
|
+
int32_t ne00;
|
|
237
|
+
int32_t ne00_4;
|
|
238
|
+
uint64_t nb01;
|
|
239
|
+
float eps;
|
|
240
|
+
} ggml_metal_kargs_norm;
|
|
241
|
+
|
|
242
|
+
typedef struct {
|
|
243
|
+
int32_t ne00;
|
|
244
|
+
int32_t ne00_4;
|
|
245
|
+
uint64_t nb01;
|
|
246
|
+
float eps;
|
|
247
|
+
} ggml_metal_kargs_rms_norm;
|
|
248
|
+
|
|
249
|
+
#endif // GGML_METAL_IMPL
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
if (NOT EXISTS $ENV{MUSA_PATH})
|
|
2
|
+
if (NOT EXISTS /opt/musa)
|
|
3
|
+
set(MUSA_PATH /usr/local/musa)
|
|
4
|
+
else()
|
|
5
|
+
set(MUSA_PATH /opt/musa)
|
|
6
|
+
endif()
|
|
7
|
+
else()
|
|
8
|
+
set(MUSA_PATH $ENV{MUSA_PATH})
|
|
9
|
+
endif()
|
|
10
|
+
|
|
11
|
+
set(CMAKE_C_COMPILER "${MUSA_PATH}/bin/clang")
|
|
12
|
+
set(CMAKE_C_EXTENSIONS OFF)
|
|
13
|
+
set(CMAKE_CXX_COMPILER "${MUSA_PATH}/bin/clang++")
|
|
14
|
+
set(CMAKE_CXX_EXTENSIONS OFF)
|
|
15
|
+
|
|
16
|
+
list(APPEND CMAKE_MODULE_PATH "${MUSA_PATH}/cmake")
|
|
17
|
+
|
|
18
|
+
find_package(MUSAToolkit)
|
|
19
|
+
|
|
20
|
+
if (MUSAToolkit_FOUND)
|
|
21
|
+
message(STATUS "MUSA Toolkit found")
|
|
22
|
+
|
|
23
|
+
file(GLOB GGML_HEADERS_MUSA "../ggml-cuda/*.cuh")
|
|
24
|
+
list(APPEND GGML_HEADERS_MUSA "../../include/ggml-cuda.h")
|
|
25
|
+
|
|
26
|
+
file(GLOB GGML_SOURCES_MUSA "../ggml-cuda/*.cu")
|
|
27
|
+
file(GLOB SRCS "../ggml-cuda/template-instances/fattn-wmma*.cu")
|
|
28
|
+
list(APPEND GGML_SOURCES_MUSA ${SRCS})
|
|
29
|
+
file(GLOB SRCS "../ggml-cuda/template-instances/mmq*.cu")
|
|
30
|
+
list(APPEND GGML_SOURCES_MUSA ${SRCS})
|
|
31
|
+
|
|
32
|
+
if (GGML_CUDA_FA_ALL_QUANTS)
|
|
33
|
+
file(GLOB SRCS "../ggml-cuda/template-instances/fattn-vec*.cu")
|
|
34
|
+
list(APPEND GGML_SOURCES_MUSA ${SRCS})
|
|
35
|
+
add_compile_definitions(GGML_CUDA_FA_ALL_QUANTS)
|
|
36
|
+
else()
|
|
37
|
+
file(GLOB SRCS "../ggml-cuda/template-instances/fattn-vec*q4_0-q4_0.cu")
|
|
38
|
+
list(APPEND GGML_SOURCES_MUSA ${SRCS})
|
|
39
|
+
file(GLOB SRCS "../ggml-cuda/template-instances/fattn-vec*q8_0-q8_0.cu")
|
|
40
|
+
list(APPEND GGML_SOURCES_MUSA ${SRCS})
|
|
41
|
+
file(GLOB SRCS "../ggml-cuda/template-instances/fattn-vec*f16-f16.cu")
|
|
42
|
+
list(APPEND GGML_SOURCES_MUSA ${SRCS})
|
|
43
|
+
endif()
|
|
44
|
+
|
|
45
|
+
set_source_files_properties(${GGML_SOURCES_MUSA} PROPERTIES LANGUAGE CXX)
|
|
46
|
+
foreach(SOURCE ${GGML_SOURCES_MUSA})
|
|
47
|
+
set_property(SOURCE ${SOURCE} PROPERTY COMPILE_FLAGS "-x musa -mtgpu --cuda-gpu-arch=mp_21 --cuda-gpu-arch=mp_22")
|
|
48
|
+
endforeach()
|
|
49
|
+
|
|
50
|
+
add_library(ggml-musa
|
|
51
|
+
${GGML_HEADERS_MUSA}
|
|
52
|
+
${GGML_SOURCES_MUSA})
|
|
53
|
+
|
|
54
|
+
target_link_libraries(ggml-musa PRIVATE ggml-base)
|
|
55
|
+
target_include_directories(ggml-musa PRIVATE . ..)
|
|
56
|
+
|
|
57
|
+
# TODO: do not use CUDA definitions for MUSA
|
|
58
|
+
target_compile_definitions(ggml PUBLIC GGML_USE_CUDA)
|
|
59
|
+
|
|
60
|
+
add_compile_definitions(GGML_USE_MUSA)
|
|
61
|
+
add_compile_definitions(GGML_CUDA_PEER_MAX_BATCH_SIZE=${GGML_CUDA_PEER_MAX_BATCH_SIZE})
|
|
62
|
+
|
|
63
|
+
if (GGML_CUDA_GRAPHS)
|
|
64
|
+
add_compile_definitions(GGML_CUDA_USE_GRAPHS)
|
|
65
|
+
endif()
|
|
66
|
+
|
|
67
|
+
if (GGML_CUDA_FORCE_MMQ)
|
|
68
|
+
add_compile_definitions(GGML_CUDA_FORCE_MMQ)
|
|
69
|
+
endif()
|
|
70
|
+
|
|
71
|
+
if (GGML_CUDA_FORCE_CUBLAS)
|
|
72
|
+
add_compile_definitions(GGML_CUDA_FORCE_CUBLAS)
|
|
73
|
+
endif()
|
|
74
|
+
|
|
75
|
+
if (GGML_CUDA_NO_VMM)
|
|
76
|
+
add_compile_definitions(GGML_CUDA_NO_VMM)
|
|
77
|
+
endif()
|
|
78
|
+
|
|
79
|
+
if (GGML_CUDA_F16 OR GGML_CUDA_DMMV_F16)
|
|
80
|
+
add_compile_definitions(GGML_CUDA_F16)
|
|
81
|
+
endif()
|
|
82
|
+
|
|
83
|
+
if (GGML_CUDA_NO_PEER_COPY)
|
|
84
|
+
add_compile_definitions(GGML_CUDA_NO_PEER_COPY)
|
|
85
|
+
endif()
|
|
86
|
+
|
|
87
|
+
if (GGML_STATIC)
|
|
88
|
+
target_link_libraries(ggml-musa PRIVATE MUSA::musart_static MUSA::mublas_static)
|
|
89
|
+
else()
|
|
90
|
+
target_link_libraries(ggml-musa PRIVATE MUSA::musart MUSA::mublas)
|
|
91
|
+
endif()
|
|
92
|
+
|
|
93
|
+
if (GGML_CUDA_NO_VMM)
|
|
94
|
+
# No VMM requested, no need to link directly with the musa driver lib (libmusa.so)
|
|
95
|
+
else()
|
|
96
|
+
target_link_libraries(ggml-musa PRIVATE MUSA::musa_driver)
|
|
97
|
+
endif()
|
|
98
|
+
else()
|
|
99
|
+
message(FATAL_ERROR "MUSA Toolkit not found")
|
|
100
|
+
endif()
|