@fugood/llama.node 0.3.2 → 0.3.4
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 +7 -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/lib/binding.ts +18 -1
- package/package.json +1 -1
- package/src/DetokenizeWorker.cpp +1 -1
- package/src/EmbeddingWorker.cpp +17 -7
- package/src/EmbeddingWorker.h +2 -1
- package/src/LlamaCompletionWorker.cpp +8 -8
- package/src/LlamaCompletionWorker.h +2 -2
- package/src/LlamaContext.cpp +89 -27
- package/src/LlamaContext.h +2 -0
- package/src/TokenizeWorker.cpp +1 -1
- package/src/common.hpp +4 -4
- package/src/llama.cpp/.github/workflows/build.yml +240 -168
- package/src/llama.cpp/.github/workflows/docker.yml +8 -8
- package/src/llama.cpp/.github/workflows/python-lint.yml +8 -1
- package/src/llama.cpp/.github/workflows/server.yml +21 -14
- package/src/llama.cpp/CMakeLists.txt +14 -6
- package/src/llama.cpp/Sources/llama/llama.h +4 -0
- package/src/llama.cpp/cmake/arm64-apple-clang.cmake +16 -0
- package/src/llama.cpp/cmake/common.cmake +33 -0
- package/src/llama.cpp/cmake/x64-windows-llvm.cmake +11 -0
- package/src/llama.cpp/common/CMakeLists.txt +6 -4
- package/src/llama.cpp/common/arg.cpp +986 -770
- package/src/llama.cpp/common/arg.h +22 -22
- package/src/llama.cpp/common/common.cpp +212 -351
- package/src/llama.cpp/common/common.h +204 -117
- 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 +163 -121
- package/src/llama.cpp/common/sampling.h +41 -20
- package/src/llama.cpp/common/speculative.cpp +274 -0
- package/src/llama.cpp/common/speculative.h +28 -0
- package/src/llama.cpp/docs/build.md +134 -161
- package/src/llama.cpp/examples/CMakeLists.txt +33 -14
- package/src/llama.cpp/examples/batched/CMakeLists.txt +1 -1
- package/src/llama.cpp/examples/batched/batched.cpp +19 -18
- package/src/llama.cpp/examples/batched-bench/CMakeLists.txt +1 -1
- package/src/llama.cpp/examples/batched-bench/batched-bench.cpp +10 -11
- package/src/llama.cpp/examples/convert-llama2c-to-ggml/CMakeLists.txt +1 -1
- package/src/llama.cpp/examples/convert-llama2c-to-ggml/convert-llama2c-to-ggml.cpp +1 -1
- package/src/llama.cpp/examples/cvector-generator/CMakeLists.txt +1 -1
- package/src/llama.cpp/examples/cvector-generator/cvector-generator.cpp +9 -9
- package/src/llama.cpp/examples/deprecation-warning/deprecation-warning.cpp +1 -1
- package/src/llama.cpp/examples/embedding/CMakeLists.txt +1 -1
- package/src/llama.cpp/examples/embedding/embedding.cpp +12 -12
- package/src/llama.cpp/examples/eval-callback/CMakeLists.txt +3 -2
- package/src/llama.cpp/examples/eval-callback/eval-callback.cpp +8 -8
- package/src/llama.cpp/examples/export-lora/CMakeLists.txt +1 -1
- package/src/llama.cpp/examples/export-lora/export-lora.cpp +5 -5
- package/src/llama.cpp/examples/gbnf-validator/CMakeLists.txt +1 -1
- package/src/llama.cpp/examples/gbnf-validator/gbnf-validator.cpp +4 -7
- package/src/llama.cpp/examples/gen-docs/CMakeLists.txt +1 -1
- package/src/llama.cpp/examples/gen-docs/gen-docs.cpp +7 -7
- package/src/llama.cpp/examples/gguf/CMakeLists.txt +1 -1
- package/src/llama.cpp/examples/gguf-hash/CMakeLists.txt +8 -1
- package/src/llama.cpp/examples/gguf-split/CMakeLists.txt +1 -1
- package/src/llama.cpp/examples/gguf-split/gguf-split.cpp +2 -2
- package/src/llama.cpp/examples/gritlm/CMakeLists.txt +1 -1
- package/src/llama.cpp/examples/gritlm/gritlm.cpp +18 -18
- package/src/llama.cpp/examples/imatrix/CMakeLists.txt +1 -1
- package/src/llama.cpp/examples/imatrix/imatrix.cpp +31 -13
- package/src/llama.cpp/examples/infill/CMakeLists.txt +1 -1
- package/src/llama.cpp/examples/infill/infill.cpp +41 -87
- package/src/llama.cpp/examples/llama-bench/CMakeLists.txt +1 -1
- package/src/llama.cpp/examples/llama-bench/llama-bench.cpp +439 -459
- package/src/llama.cpp/examples/llama.android/llama/build.gradle.kts +2 -0
- package/src/llama.cpp/examples/llama.android/llama/src/main/cpp/llama-android.cpp +11 -14
- package/src/llama.cpp/examples/llava/CMakeLists.txt +10 -3
- package/src/llama.cpp/examples/llava/clip.cpp +263 -66
- package/src/llama.cpp/examples/llava/clip.h +8 -2
- package/src/llama.cpp/examples/llava/llava-cli.cpp +23 -23
- package/src/llama.cpp/examples/llava/llava.cpp +83 -22
- package/src/llama.cpp/examples/llava/minicpmv-cli.cpp +21 -21
- package/src/llama.cpp/examples/llava/qwen2vl-cli.cpp +581 -0
- package/src/llama.cpp/examples/lookahead/CMakeLists.txt +1 -1
- package/src/llama.cpp/examples/lookahead/lookahead.cpp +26 -26
- package/src/llama.cpp/examples/lookup/CMakeLists.txt +4 -4
- 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 +16 -15
- package/src/llama.cpp/examples/lookup/lookup.cpp +30 -30
- package/src/llama.cpp/examples/main/CMakeLists.txt +1 -1
- package/src/llama.cpp/examples/main/main.cpp +73 -114
- package/src/llama.cpp/examples/main-cmake-pkg/CMakeLists.txt +1 -1
- package/src/llama.cpp/examples/parallel/CMakeLists.txt +1 -1
- package/src/llama.cpp/examples/parallel/parallel.cpp +18 -19
- package/src/llama.cpp/examples/passkey/CMakeLists.txt +1 -1
- package/src/llama.cpp/examples/passkey/passkey.cpp +14 -14
- package/src/llama.cpp/examples/perplexity/CMakeLists.txt +1 -1
- package/src/llama.cpp/examples/perplexity/perplexity.cpp +99 -120
- package/src/llama.cpp/examples/quantize/CMakeLists.txt +1 -1
- package/src/llama.cpp/examples/quantize/quantize.cpp +0 -3
- package/src/llama.cpp/examples/quantize-stats/CMakeLists.txt +1 -1
- package/src/llama.cpp/examples/quantize-stats/quantize-stats.cpp +10 -9
- package/src/llama.cpp/examples/retrieval/CMakeLists.txt +1 -1
- package/src/llama.cpp/examples/retrieval/retrieval.cpp +16 -16
- package/src/llama.cpp/examples/rpc/rpc-server.cpp +3 -1
- package/src/llama.cpp/examples/run/CMakeLists.txt +5 -0
- package/src/llama.cpp/examples/run/run.cpp +911 -0
- package/src/llama.cpp/examples/save-load-state/CMakeLists.txt +1 -1
- package/src/llama.cpp/examples/save-load-state/save-load-state.cpp +38 -21
- package/src/llama.cpp/examples/server/CMakeLists.txt +3 -16
- package/src/llama.cpp/examples/server/server.cpp +2073 -1339
- package/src/llama.cpp/examples/server/tests/requirements.txt +2 -2
- package/src/llama.cpp/examples/server/utils.hpp +354 -277
- package/src/llama.cpp/examples/simple/CMakeLists.txt +2 -2
- package/src/llama.cpp/examples/simple/simple.cpp +130 -94
- package/src/llama.cpp/examples/simple-chat/CMakeLists.txt +5 -0
- package/src/llama.cpp/examples/simple-chat/simple-chat.cpp +200 -0
- package/src/llama.cpp/examples/speculative/CMakeLists.txt +1 -1
- package/src/llama.cpp/examples/speculative/speculative.cpp +68 -64
- package/src/llama.cpp/examples/speculative-simple/CMakeLists.txt +5 -0
- package/src/llama.cpp/examples/speculative-simple/speculative-simple.cpp +265 -0
- package/src/llama.cpp/examples/tokenize/CMakeLists.txt +1 -1
- package/src/llama.cpp/examples/tokenize/tokenize.cpp +3 -3
- package/src/llama.cpp/examples/tts/CMakeLists.txt +5 -0
- package/src/llama.cpp/examples/tts/tts.cpp +932 -0
- package/src/llama.cpp/ggml/CMakeLists.txt +54 -36
- package/src/llama.cpp/ggml/include/ggml-backend.h +63 -34
- 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 +135 -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-opencl.h +26 -0
- 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 +159 -417
- package/src/llama.cpp/ggml/src/CMakeLists.txt +121 -1155
- package/src/llama.cpp/ggml/src/ggml-alloc.c +23 -28
- package/src/llama.cpp/ggml/src/ggml-backend-impl.h +57 -36
- package/src/llama.cpp/ggml/src/ggml-backend-reg.cpp +552 -0
- package/src/llama.cpp/ggml/src/ggml-backend.cpp +306 -867
- package/src/llama.cpp/ggml/src/ggml-blas/CMakeLists.txt +87 -0
- package/src/llama.cpp/ggml/src/{ggml-blas.cpp → ggml-blas/ggml-blas.cpp} +216 -65
- package/src/llama.cpp/ggml/src/ggml-cann/CMakeLists.txt +76 -0
- package/src/llama.cpp/ggml/src/ggml-cann/aclnn_ops.cpp +456 -111
- package/src/llama.cpp/ggml/src/ggml-cann/common.h +6 -3
- package/src/llama.cpp/ggml/src/{ggml-cann.cpp → ggml-cann/ggml-cann.cpp} +343 -177
- package/src/llama.cpp/ggml/src/ggml-cann/kernels/CMakeLists.txt +2 -5
- package/src/llama.cpp/ggml/src/ggml-cann/kernels/dup.cpp +22 -9
- package/src/llama.cpp/ggml/src/ggml-cann/kernels/get_row_f16.cpp +24 -13
- package/src/llama.cpp/ggml/src/ggml-cann/kernels/get_row_f32.cpp +23 -13
- package/src/llama.cpp/ggml/src/ggml-cann/kernels/get_row_q4_0.cpp +11 -0
- package/src/llama.cpp/ggml/src/ggml-cann/kernels/quantize_f16_q8_0.cpp +10 -0
- package/src/llama.cpp/ggml/src/ggml-cann/kernels/quantize_f32_q8_0.cpp +10 -0
- package/src/llama.cpp/ggml/src/ggml-cann/kernels/quantize_float_to_q4_0.cpp +17 -0
- package/src/llama.cpp/ggml/src/ggml-common.h +42 -42
- package/src/llama.cpp/ggml/src/ggml-cpu/CMakeLists.txt +336 -0
- package/src/llama.cpp/ggml/src/ggml-cpu/amx/amx.cpp +220 -0
- package/src/llama.cpp/ggml/src/ggml-cpu/amx/amx.h +8 -0
- package/src/llama.cpp/ggml/src/ggml-cpu/amx/common.h +91 -0
- package/src/llama.cpp/ggml/src/ggml-cpu/amx/mmq.cpp +2511 -0
- package/src/llama.cpp/ggml/src/ggml-cpu/amx/mmq.h +10 -0
- package/src/llama.cpp/ggml/src/ggml-cpu/cpu-feats-x86.cpp +323 -0
- package/src/llama.cpp/ggml/src/{ggml-aarch64.c → ggml-cpu/ggml-cpu-aarch64.cpp} +1299 -246
- package/src/llama.cpp/ggml/src/ggml-cpu/ggml-cpu-aarch64.h +8 -0
- package/src/llama.cpp/ggml/src/ggml-cpu/ggml-cpu-hbm.cpp +55 -0
- package/src/llama.cpp/ggml/src/ggml-cpu/ggml-cpu-hbm.h +8 -0
- package/src/llama.cpp/ggml/src/{ggml-cpu-impl.h → ggml-cpu/ggml-cpu-impl.h} +14 -242
- package/src/llama.cpp/ggml/src/ggml-cpu/ggml-cpu-quants.c +10835 -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-traits.cpp +36 -0
- package/src/llama.cpp/ggml/src/ggml-cpu/ggml-cpu-traits.h +38 -0
- package/src/llama.cpp/ggml/src/ggml-cpu/ggml-cpu.c +14123 -0
- package/src/llama.cpp/ggml/src/ggml-cpu/ggml-cpu.cpp +628 -0
- package/src/llama.cpp/ggml/src/{llamafile → ggml-cpu/llamafile}/sgemm.cpp +666 -0
- package/src/llama.cpp/ggml/src/ggml-cuda/CMakeLists.txt +152 -0
- package/src/llama.cpp/ggml/src/ggml-cuda/vendors/hip.h +8 -0
- package/src/llama.cpp/ggml/src/ggml-hip/CMakeLists.txt +104 -0
- package/src/llama.cpp/ggml/src/ggml-impl.h +393 -22
- package/src/llama.cpp/ggml/src/ggml-kompute/CMakeLists.txt +166 -0
- package/src/llama.cpp/ggml/src/{ggml-kompute.cpp → ggml-kompute/ggml-kompute.cpp} +360 -127
- package/src/llama.cpp/ggml/src/ggml-metal/CMakeLists.txt +105 -0
- package/src/llama.cpp/ggml/src/ggml-metal/ggml-metal-impl.h +288 -0
- package/src/llama.cpp/ggml/src/ggml-musa/CMakeLists.txt +107 -0
- package/src/llama.cpp/ggml/src/ggml-opencl/CMakeLists.txt +147 -0
- package/src/llama.cpp/ggml/src/ggml-opencl/ggml-opencl.cpp +4004 -0
- package/src/llama.cpp/ggml/src/ggml-opt.cpp +854 -0
- package/src/llama.cpp/ggml/src/ggml-quants.c +188 -10702
- package/src/llama.cpp/ggml/src/ggml-quants.h +78 -125
- package/src/llama.cpp/ggml/src/ggml-rpc/CMakeLists.txt +9 -0
- package/src/llama.cpp/ggml/src/{ggml-rpc.cpp → ggml-rpc/ggml-rpc.cpp} +478 -300
- package/src/llama.cpp/ggml/src/ggml-sycl/CMakeLists.txt +84 -0
- package/src/llama.cpp/ggml/src/ggml-sycl/backend.hpp +3 -0
- package/src/llama.cpp/ggml/src/ggml-sycl/common.cpp +36 -5
- package/src/llama.cpp/ggml/src/ggml-sycl/common.hpp +259 -0
- package/src/llama.cpp/ggml/src/ggml-sycl/concat.cpp +3 -2
- package/src/llama.cpp/ggml/src/ggml-sycl/convert.cpp +1 -1
- package/src/llama.cpp/ggml/src/ggml-sycl/dmmv.cpp +5 -5
- package/src/llama.cpp/ggml/src/ggml-sycl/dpct/helper.hpp +34 -35
- package/src/llama.cpp/ggml/src/ggml-sycl/element_wise.cpp +1030 -0
- package/src/llama.cpp/ggml/src/ggml-sycl/element_wise.hpp +76 -0
- package/src/llama.cpp/ggml/src/ggml-sycl/gemm.hpp +4 -4
- package/src/llama.cpp/ggml/src/{ggml-sycl.cpp → ggml-sycl/ggml-sycl.cpp} +3638 -4151
- package/src/llama.cpp/ggml/src/ggml-sycl/im2col.cpp +3 -2
- package/src/llama.cpp/ggml/src/ggml-sycl/mmq.cpp +6 -6
- package/src/llama.cpp/ggml/src/ggml-sycl/mmvq.cpp +75 -87
- package/src/llama.cpp/ggml/src/ggml-sycl/norm.cpp +7 -6
- 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/rope.cpp +4 -3
- package/src/llama.cpp/ggml/src/ggml-sycl/softmax.cpp +7 -7
- package/src/llama.cpp/ggml/src/ggml-sycl/tsembd.cpp +1 -0
- package/src/llama.cpp/ggml/src/ggml-sycl/vecdotq.hpp +4 -4
- package/src/llama.cpp/ggml/src/ggml-sycl/wkv6.cpp +141 -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 +14 -0
- package/src/llama.cpp/ggml/src/ggml-vulkan/CMakeLists.txt +92 -0
- package/src/llama.cpp/ggml/src/{ggml-vulkan.cpp → ggml-vulkan/ggml-vulkan.cpp} +2138 -887
- package/src/llama.cpp/ggml/src/{vulkan-shaders → ggml-vulkan/vulkan-shaders}/CMakeLists.txt +3 -1
- package/src/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/vulkan-shaders-gen.cpp +593 -0
- package/src/llama.cpp/ggml/src/ggml.c +4427 -20125
- package/src/llama.cpp/include/llama-cpp.h +25 -0
- package/src/llama.cpp/include/llama.h +93 -52
- package/src/llama.cpp/models/ggml-vocab-roberta-bpe.gguf.inp +112 -0
- package/src/llama.cpp/models/ggml-vocab-roberta-bpe.gguf.out +46 -0
- package/src/llama.cpp/pocs/CMakeLists.txt +3 -1
- package/src/llama.cpp/pocs/vdot/CMakeLists.txt +2 -2
- 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 +4 -8
- package/src/llama.cpp/src/llama-grammar.cpp +15 -15
- package/src/llama.cpp/src/llama-grammar.h +2 -5
- package/src/llama.cpp/src/llama-sampling.cpp +779 -194
- package/src/llama.cpp/src/llama-sampling.h +21 -2
- package/src/llama.cpp/src/llama-vocab.cpp +55 -10
- package/src/llama.cpp/src/llama-vocab.h +35 -11
- package/src/llama.cpp/src/llama.cpp +4317 -2979
- package/src/llama.cpp/src/unicode-data.cpp +2 -2
- package/src/llama.cpp/src/unicode.cpp +62 -51
- package/src/llama.cpp/src/unicode.h +9 -10
- package/src/llama.cpp/tests/CMakeLists.txt +48 -38
- package/src/llama.cpp/tests/test-arg-parser.cpp +15 -15
- package/src/llama.cpp/tests/test-backend-ops.cpp +324 -80
- package/src/llama.cpp/tests/test-barrier.cpp +1 -0
- package/src/llama.cpp/tests/test-chat-template.cpp +59 -9
- package/src/llama.cpp/tests/test-gguf.cpp +1303 -0
- package/src/llama.cpp/tests/test-grammar-integration.cpp +3 -6
- package/src/llama.cpp/tests/test-json-schema-to-grammar.cpp +17 -4
- package/src/llama.cpp/tests/test-llama-grammar.cpp +2 -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 +24 -21
- package/src/llama.cpp/tests/test-quantize-perf.cpp +16 -14
- package/src/llama.cpp/tests/test-rope.cpp +62 -20
- package/src/llama.cpp/tests/test-sampling.cpp +163 -138
- 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/.github/workflows/nix-ci-aarch64.yml +0 -72
- package/src/llama.cpp/.github/workflows/nix-ci.yml +0 -79
- package/src/llama.cpp/.github/workflows/nix-flake-update.yml +0 -22
- package/src/llama.cpp/.github/workflows/nix-publish-flake.yml +0 -36
- 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/ggml/src/ggml-aarch64.h +0 -39
- package/src/llama.cpp/ggml/src/vulkan-shaders/vulkan-shaders-gen.cpp +0 -600
- 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
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
#ifdef GGML_USE_CPU_HBM
|
|
2
|
+
|
|
3
|
+
#include "ggml-backend.h"
|
|
4
|
+
#include "ggml-backend-impl.h"
|
|
5
|
+
#include "ggml-cpu.h"
|
|
6
|
+
#include "ggml-impl.h"
|
|
7
|
+
|
|
8
|
+
#include "ggml-cpu-hbm.h"
|
|
9
|
+
|
|
10
|
+
// buffer type HBM
|
|
11
|
+
|
|
12
|
+
#include <hbwmalloc.h>
|
|
13
|
+
|
|
14
|
+
static const char * ggml_backend_cpu_hbm_buffer_type_get_name(ggml_backend_buffer_type_t buft) {
|
|
15
|
+
return "CPU_HBM";
|
|
16
|
+
|
|
17
|
+
GGML_UNUSED(buft);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
static void ggml_backend_cpu_hbm_buffer_free_buffer(ggml_backend_buffer_t buffer) {
|
|
21
|
+
hbw_free(buffer->context);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
static ggml_backend_buffer_t ggml_backend_cpu_hbm_buffer_type_alloc_buffer(ggml_backend_buffer_type_t buft,
|
|
25
|
+
size_t size) {
|
|
26
|
+
void * ptr;
|
|
27
|
+
int result = hbw_posix_memalign(&ptr, ggml_backend_cpu_buffer_type_get_alignment(buft), size);
|
|
28
|
+
if (result != 0) {
|
|
29
|
+
GGML_LOG_ERROR("failed to allocate HBM buffer of size %zu\n", size);
|
|
30
|
+
return NULL;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
ggml_backend_buffer_t buffer = ggml_backend_cpu_buffer_from_ptr(ptr, size);
|
|
34
|
+
buffer->buft = buft;
|
|
35
|
+
buffer->iface.free_buffer = ggml_backend_cpu_hbm_buffer_free_buffer;
|
|
36
|
+
|
|
37
|
+
return buffer;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
ggml_backend_buffer_type_t ggml_backend_cpu_hbm_buffer_type(void) {
|
|
41
|
+
static struct ggml_backend_buffer_type ggml_backend_cpu_buffer_type_hbm = {
|
|
42
|
+
/* .iface = */ {
|
|
43
|
+
/* .get_name = */ ggml_backend_cpu_hbm_buffer_type_get_name,
|
|
44
|
+
/* .alloc_buffer = */ ggml_backend_cpu_hbm_buffer_type_alloc_buffer,
|
|
45
|
+
/* .get_alignment = */ ggml_backend_cpu_buffer_type_get_alignment,
|
|
46
|
+
/* .get_max_size = */ nullptr, // defaults to SIZE_MAX
|
|
47
|
+
/* .get_alloc_size = */ nullptr, // defaults to ggml_nbytes
|
|
48
|
+
/* .is_host = */ ggml_backend_cpu_buffer_type_is_host,
|
|
49
|
+
},
|
|
50
|
+
/* .context = */ nullptr,
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
return &ggml_backend_cpu_buffer_type_hbm;
|
|
54
|
+
}
|
|
55
|
+
#endif
|
|
@@ -15,6 +15,18 @@
|
|
|
15
15
|
extern "C" {
|
|
16
16
|
#endif
|
|
17
17
|
|
|
18
|
+
struct ggml_compute_params {
|
|
19
|
+
// ith = thread index, nth = number of threads
|
|
20
|
+
int ith, nth;
|
|
21
|
+
|
|
22
|
+
// work buffer for all threads
|
|
23
|
+
size_t wsize;
|
|
24
|
+
void * wdata;
|
|
25
|
+
|
|
26
|
+
struct ggml_threadpool * threadpool;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
|
|
18
30
|
#if defined(_MSC_VER)
|
|
19
31
|
|
|
20
32
|
#define m512bh(p) p
|
|
@@ -27,80 +39,6 @@ extern "C" {
|
|
|
27
39
|
|
|
28
40
|
#endif
|
|
29
41
|
|
|
30
|
-
/**
|
|
31
|
-
* Converts brain16 to float32.
|
|
32
|
-
*
|
|
33
|
-
* The bfloat16 floating point format has the following structure:
|
|
34
|
-
*
|
|
35
|
-
* ┌sign
|
|
36
|
-
* │
|
|
37
|
-
* │ ┌exponent
|
|
38
|
-
* │ │
|
|
39
|
-
* │ │ ┌mantissa
|
|
40
|
-
* │ │ │
|
|
41
|
-
* │┌──┴───┐┌─┴───┐
|
|
42
|
-
* 0b0000000000000000 brain16
|
|
43
|
-
*
|
|
44
|
-
* Since bf16 has the same number of exponent bits as a 32bit float,
|
|
45
|
-
* encoding and decoding numbers becomes relatively straightforward.
|
|
46
|
-
*
|
|
47
|
-
* ┌sign
|
|
48
|
-
* │
|
|
49
|
-
* │ ┌exponent
|
|
50
|
-
* │ │
|
|
51
|
-
* │ │ ┌mantissa
|
|
52
|
-
* │ │ │
|
|
53
|
-
* │┌──┴───┐┌─┴───────────────────┐
|
|
54
|
-
* 0b00000000000000000000000000000000 IEEE binary32
|
|
55
|
-
*
|
|
56
|
-
* For comparison, the standard fp16 format has fewer exponent bits.
|
|
57
|
-
*
|
|
58
|
-
* ┌sign
|
|
59
|
-
* │
|
|
60
|
-
* │ ┌exponent
|
|
61
|
-
* │ │
|
|
62
|
-
* │ │ ┌mantissa
|
|
63
|
-
* │ │ │
|
|
64
|
-
* │┌─┴─┐┌─┴──────┐
|
|
65
|
-
* 0b0000000000000000 IEEE binary16
|
|
66
|
-
*
|
|
67
|
-
* @see IEEE 754-2008
|
|
68
|
-
*/
|
|
69
|
-
static inline float ggml_compute_bf16_to_fp32(ggml_bf16_t h) {
|
|
70
|
-
union {
|
|
71
|
-
float f;
|
|
72
|
-
uint32_t i;
|
|
73
|
-
} u;
|
|
74
|
-
u.i = (uint32_t)h.bits << 16;
|
|
75
|
-
return u.f;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* Converts float32 to brain16.
|
|
80
|
-
*
|
|
81
|
-
* This is binary identical with Google Brain float conversion.
|
|
82
|
-
* Floats shall round to nearest even, and NANs shall be quiet.
|
|
83
|
-
* Subnormals aren't flushed to zero, except perhaps when used.
|
|
84
|
-
* This code should vectorize nicely if using modern compilers.
|
|
85
|
-
*/
|
|
86
|
-
static inline ggml_bf16_t ggml_compute_fp32_to_bf16(float s) {
|
|
87
|
-
ggml_bf16_t h;
|
|
88
|
-
union {
|
|
89
|
-
float f;
|
|
90
|
-
uint32_t i;
|
|
91
|
-
} u;
|
|
92
|
-
u.f = s;
|
|
93
|
-
if ((u.i & 0x7fffffff) > 0x7f800000) { /* nan */
|
|
94
|
-
h.bits = (u.i >> 16) | 64; /* force to quiet */
|
|
95
|
-
return h;
|
|
96
|
-
}
|
|
97
|
-
h.bits = (u.i + (0x7fff + ((u.i >> 16) & 1))) >> 16;
|
|
98
|
-
return h;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
#define GGML_FP32_TO_BF16(x) ggml_compute_fp32_to_bf16(x)
|
|
102
|
-
#define GGML_BF16_TO_FP32(x) ggml_compute_bf16_to_fp32(x)
|
|
103
|
-
|
|
104
42
|
// __FMA__ and __F16C__ are not defined in MSVC, however they are implied with AVX2/AVX512
|
|
105
43
|
#if defined(_MSC_VER) && (defined(__AVX2__) || defined(__AVX512F__))
|
|
106
44
|
#ifndef __FMA__
|
|
@@ -388,28 +326,6 @@ inline static int32x4_t ggml_vdotq_s32(int32x4_t acc, int8x16_t a, int8x16_t b)
|
|
|
388
326
|
|
|
389
327
|
#endif // defined(__ARM_NEON)
|
|
390
328
|
|
|
391
|
-
#if defined(__ARM_NEON) && !defined(_MSC_VER)
|
|
392
|
-
|
|
393
|
-
#define GGML_COMPUTE_FP16_TO_FP32(x) ggml_compute_fp16_to_fp32(x)
|
|
394
|
-
#define GGML_COMPUTE_FP32_TO_FP16(x) ggml_compute_fp32_to_fp16(x)
|
|
395
|
-
|
|
396
|
-
#define GGML_FP16_TO_FP32(x) ggml_compute_fp16_to_fp32(x)
|
|
397
|
-
|
|
398
|
-
static inline float ggml_compute_fp16_to_fp32(ggml_fp16_t h) {
|
|
399
|
-
ggml_fp16_internal_t tmp;
|
|
400
|
-
memcpy(&tmp, &h, sizeof(ggml_fp16_t));
|
|
401
|
-
return (float)tmp;
|
|
402
|
-
}
|
|
403
|
-
|
|
404
|
-
static inline ggml_fp16_t ggml_compute_fp32_to_fp16(float f) {
|
|
405
|
-
ggml_fp16_t res;
|
|
406
|
-
ggml_fp16_internal_t tmp = f;
|
|
407
|
-
memcpy(&res, &tmp, sizeof(ggml_fp16_t));
|
|
408
|
-
return res;
|
|
409
|
-
}
|
|
410
|
-
|
|
411
|
-
#else
|
|
412
|
-
|
|
413
329
|
#ifdef __wasm_simd128__
|
|
414
330
|
#include <wasm_simd128.h>
|
|
415
331
|
#else
|
|
@@ -462,152 +378,8 @@ static __m256 __lasx_xvreplfr2vr_s(float val) {
|
|
|
462
378
|
}
|
|
463
379
|
#endif
|
|
464
380
|
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
#ifdef _MSC_VER
|
|
468
|
-
#define GGML_COMPUTE_FP16_TO_FP32(x) _mm_cvtss_f32(_mm_cvtph_ps(_mm_cvtsi32_si128(x)))
|
|
469
|
-
#define GGML_COMPUTE_FP32_TO_FP16(x) _mm_extract_epi16(_mm_cvtps_ph(_mm_set_ss(x), 0), 0)
|
|
470
|
-
#else
|
|
471
|
-
#define GGML_COMPUTE_FP16_TO_FP32(x) _cvtsh_ss(x)
|
|
472
|
-
#define GGML_COMPUTE_FP32_TO_FP16(x) _cvtss_sh(x, 0)
|
|
473
|
-
#endif
|
|
474
|
-
|
|
475
|
-
#elif defined(__POWER9_VECTOR__)
|
|
476
|
-
|
|
477
|
-
#define GGML_COMPUTE_FP16_TO_FP32(x) ggml_compute_fp16_to_fp32(x)
|
|
478
|
-
#define GGML_COMPUTE_FP32_TO_FP16(x) ggml_compute_fp32_to_fp16(x)
|
|
479
|
-
/* the inline asm below is about 12% faster than the lookup method */
|
|
480
|
-
#define GGML_FP16_TO_FP32(x) GGML_COMPUTE_FP16_TO_FP32(x)
|
|
481
|
-
#define GGML_FP32_TO_FP16(x) GGML_COMPUTE_FP32_TO_FP16(x)
|
|
482
|
-
|
|
483
|
-
static inline float ggml_compute_fp16_to_fp32(ggml_fp16_t h) {
|
|
484
|
-
register float f;
|
|
485
|
-
register double d;
|
|
486
|
-
__asm__(
|
|
487
|
-
"mtfprd %0,%2\n"
|
|
488
|
-
"xscvhpdp %0,%0\n"
|
|
489
|
-
"frsp %1,%0\n" :
|
|
490
|
-
/* temp */ "=d"(d),
|
|
491
|
-
/* out */ "=f"(f):
|
|
492
|
-
/* in */ "r"(h));
|
|
493
|
-
return f;
|
|
494
|
-
}
|
|
495
|
-
|
|
496
|
-
static inline ggml_fp16_t ggml_compute_fp32_to_fp16(float f) {
|
|
497
|
-
register double d;
|
|
498
|
-
register ggml_fp16_t r;
|
|
499
|
-
__asm__( /* xscvdphp can work on double or single precision */
|
|
500
|
-
"xscvdphp %0,%2\n"
|
|
501
|
-
"mffprd %1,%0\n" :
|
|
502
|
-
/* temp */ "=d"(d),
|
|
503
|
-
/* out */ "=r"(r):
|
|
504
|
-
/* in */ "f"(f));
|
|
505
|
-
return r;
|
|
506
|
-
}
|
|
507
|
-
|
|
508
|
-
#else
|
|
509
|
-
|
|
510
|
-
// FP16 <-> FP32
|
|
511
|
-
// ref: https://github.com/Maratyszcza/FP16
|
|
512
|
-
|
|
513
|
-
static inline float fp32_from_bits(uint32_t w) {
|
|
514
|
-
union {
|
|
515
|
-
uint32_t as_bits;
|
|
516
|
-
float as_value;
|
|
517
|
-
} fp32;
|
|
518
|
-
fp32.as_bits = w;
|
|
519
|
-
return fp32.as_value;
|
|
520
|
-
}
|
|
521
|
-
|
|
522
|
-
static inline uint32_t fp32_to_bits(float f) {
|
|
523
|
-
union {
|
|
524
|
-
float as_value;
|
|
525
|
-
uint32_t as_bits;
|
|
526
|
-
} fp32;
|
|
527
|
-
fp32.as_value = f;
|
|
528
|
-
return fp32.as_bits;
|
|
529
|
-
}
|
|
530
|
-
|
|
531
|
-
static inline float ggml_compute_fp16_to_fp32(ggml_fp16_t h) {
|
|
532
|
-
const uint32_t w = (uint32_t) h << 16;
|
|
533
|
-
const uint32_t sign = w & UINT32_C(0x80000000);
|
|
534
|
-
const uint32_t two_w = w + w;
|
|
535
|
-
|
|
536
|
-
const uint32_t exp_offset = UINT32_C(0xE0) << 23;
|
|
537
|
-
#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) || defined(__GNUC__) && !defined(__STRICT_ANSI__)
|
|
538
|
-
const float exp_scale = 0x1.0p-112f;
|
|
539
|
-
#else
|
|
540
|
-
const float exp_scale = fp32_from_bits(UINT32_C(0x7800000));
|
|
541
|
-
#endif
|
|
542
|
-
const float normalized_value = fp32_from_bits((two_w >> 4) + exp_offset) * exp_scale;
|
|
543
|
-
|
|
544
|
-
const uint32_t magic_mask = UINT32_C(126) << 23;
|
|
545
|
-
const float magic_bias = 0.5f;
|
|
546
|
-
const float denormalized_value = fp32_from_bits((two_w >> 17) | magic_mask) - magic_bias;
|
|
547
|
-
|
|
548
|
-
const uint32_t denormalized_cutoff = UINT32_C(1) << 27;
|
|
549
|
-
const uint32_t result = sign |
|
|
550
|
-
(two_w < denormalized_cutoff ? fp32_to_bits(denormalized_value) : fp32_to_bits(normalized_value));
|
|
551
|
-
return fp32_from_bits(result);
|
|
552
|
-
}
|
|
553
|
-
|
|
554
|
-
static inline ggml_fp16_t ggml_compute_fp32_to_fp16(float f) {
|
|
555
|
-
#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) || defined(__GNUC__) && !defined(__STRICT_ANSI__)
|
|
556
|
-
const float scale_to_inf = 0x1.0p+112f;
|
|
557
|
-
const float scale_to_zero = 0x1.0p-110f;
|
|
558
|
-
#else
|
|
559
|
-
const float scale_to_inf = fp32_from_bits(UINT32_C(0x77800000));
|
|
560
|
-
const float scale_to_zero = fp32_from_bits(UINT32_C(0x08800000));
|
|
561
|
-
#endif
|
|
562
|
-
float base = (fabsf(f) * scale_to_inf) * scale_to_zero;
|
|
563
|
-
|
|
564
|
-
const uint32_t w = fp32_to_bits(f);
|
|
565
|
-
const uint32_t shl1_w = w + w;
|
|
566
|
-
const uint32_t sign = w & UINT32_C(0x80000000);
|
|
567
|
-
uint32_t bias = shl1_w & UINT32_C(0xFF000000);
|
|
568
|
-
if (bias < UINT32_C(0x71000000)) {
|
|
569
|
-
bias = UINT32_C(0x71000000);
|
|
570
|
-
}
|
|
571
|
-
|
|
572
|
-
base = fp32_from_bits((bias >> 1) + UINT32_C(0x07800000)) + base;
|
|
573
|
-
const uint32_t bits = fp32_to_bits(base);
|
|
574
|
-
const uint32_t exp_bits = (bits >> 13) & UINT32_C(0x00007C00);
|
|
575
|
-
const uint32_t mantissa_bits = bits & UINT32_C(0x00000FFF);
|
|
576
|
-
const uint32_t nonsign = exp_bits + mantissa_bits;
|
|
577
|
-
return (sign >> 16) | (shl1_w > UINT32_C(0xFF000000) ? UINT16_C(0x7E00) : nonsign);
|
|
578
|
-
}
|
|
579
|
-
|
|
580
|
-
#define GGML_COMPUTE_FP16_TO_FP32(x) ggml_compute_fp16_to_fp32(x)
|
|
581
|
-
#define GGML_COMPUTE_FP32_TO_FP16(x) ggml_compute_fp32_to_fp16(x)
|
|
582
|
-
|
|
583
|
-
#endif // __F16C__
|
|
584
|
-
|
|
585
|
-
#endif // defined(__ARM_NEON) && (!defined(__MSC_VER)
|
|
586
|
-
|
|
587
|
-
#ifdef __ARM_FEATURE_SVE
|
|
588
|
-
#include <arm_sve.h>
|
|
589
|
-
#endif // __ARM_FEATURE_SVE
|
|
590
|
-
|
|
591
|
-
// precomputed f32 table for f16 (256 KB)
|
|
592
|
-
// defined in ggml.c, initialized in ggml_init()
|
|
593
|
-
extern float ggml_table_f32_f16[1 << 16];
|
|
594
|
-
|
|
595
|
-
// On ARM NEON, it's quicker to directly convert x -> x instead of calling into ggml_lookup_fp16_to_fp32,
|
|
596
|
-
// so we define GGML_FP16_TO_FP32 and GGML_FP32_TO_FP16 elsewhere for NEON.
|
|
597
|
-
// This is also true for POWER9.
|
|
598
|
-
#if !defined(GGML_FP16_TO_FP32)
|
|
599
|
-
inline static float ggml_lookup_fp16_to_fp32(ggml_fp16_t f) {
|
|
600
|
-
uint16_t s;
|
|
601
|
-
memcpy(&s, &f, sizeof(uint16_t));
|
|
602
|
-
return ggml_table_f32_f16[s];
|
|
603
|
-
}
|
|
604
|
-
|
|
605
|
-
#define GGML_FP16_TO_FP32(x) ggml_lookup_fp16_to_fp32(x)
|
|
606
|
-
#endif
|
|
607
|
-
|
|
608
|
-
#if !defined(GGML_FP32_TO_FP16)
|
|
609
|
-
#define GGML_FP32_TO_FP16(x) GGML_COMPUTE_FP32_TO_FP16(x)
|
|
610
|
-
#endif
|
|
381
|
+
// TODO: move to ggml-threading
|
|
382
|
+
void ggml_barrier(struct ggml_threadpool * tp);
|
|
611
383
|
|
|
612
384
|
#ifdef __cplusplus
|
|
613
385
|
}
|