@novastera-oss/llamarn 0.2.7 → 0.3.0
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/android/src/main/cpp/include/llama.h +8 -3
- package/android/src/main/jniLibs/arm64-v8a/libggml-base.so +0 -0
- package/android/src/main/jniLibs/arm64-v8a/libggml-cpu.so +0 -0
- package/android/src/main/jniLibs/arm64-v8a/libggml.so +0 -0
- package/android/src/main/jniLibs/arm64-v8a/libllama.so +0 -0
- package/android/src/main/jniLibs/armeabi-v7a/libggml-base.so +0 -0
- package/android/src/main/jniLibs/armeabi-v7a/libggml-cpu.so +0 -0
- package/android/src/main/jniLibs/armeabi-v7a/libggml.so +0 -0
- package/android/src/main/jniLibs/armeabi-v7a/libllama.so +0 -0
- package/android/src/main/jniLibs/x86/libggml-base.so +0 -0
- package/android/src/main/jniLibs/x86/libggml-cpu.so +0 -0
- package/android/src/main/jniLibs/x86/libggml.so +0 -0
- package/android/src/main/jniLibs/x86/libllama.so +0 -0
- package/android/src/main/jniLibs/x86_64/libggml-base.so +0 -0
- package/android/src/main/jniLibs/x86_64/libggml-cpu.so +0 -0
- package/android/src/main/jniLibs/x86_64/libggml.so +0 -0
- package/android/src/main/jniLibs/x86_64/libllama.so +0 -0
- package/cpp/LlamaCppModel.cpp +56 -22
- package/cpp/build-info.cpp +2 -2
- package/cpp/llama.cpp/CMakeLists.txt +1 -2
- package/cpp/llama.cpp/README.md +4 -5
- package/cpp/llama.cpp/build-xcframework.sh +1 -1
- package/cpp/llama.cpp/common/CMakeLists.txt +4 -5
- package/cpp/llama.cpp/common/arg.cpp +24 -0
- package/cpp/llama.cpp/common/chat.cpp +37 -20
- package/cpp/llama.cpp/common/chat.h +2 -0
- package/cpp/llama.cpp/common/common.cpp +3 -0
- package/cpp/llama.cpp/common/common.h +5 -0
- package/cpp/llama.cpp/common/json-schema-to-grammar.cpp +3 -46
- package/cpp/llama.cpp/convert_hf_to_gguf.py +860 -23
- package/cpp/llama.cpp/convert_hf_to_gguf_update.py +9 -0
- package/cpp/llama.cpp/ggml/CMakeLists.txt +8 -2
- package/cpp/llama.cpp/ggml/include/ggml-backend.h +1 -1
- package/cpp/llama.cpp/ggml/include/ggml-cpu.h +2 -0
- package/cpp/llama.cpp/ggml/include/ggml.h +206 -10
- package/cpp/llama.cpp/ggml/src/CMakeLists.txt +17 -1
- package/cpp/llama.cpp/ggml/src/ggml-backend-reg.cpp +0 -8
- package/cpp/llama.cpp/ggml/src/ggml-backend.cpp +36 -18
- package/cpp/llama.cpp/ggml/src/ggml-cann/aclnn_ops.cpp +68 -5
- package/cpp/llama.cpp/ggml/src/ggml-cann/common.h +1 -1
- package/cpp/llama.cpp/ggml/src/ggml-cann/ggml-cann.cpp +16 -2
- package/cpp/llama.cpp/ggml/src/ggml-cpu/CMakeLists.txt +37 -3
- package/cpp/llama.cpp/ggml/src/ggml-cpu/amx/mmq.cpp +10 -9
- package/cpp/llama.cpp/ggml/src/ggml-cpu/arch/arm/quants.c +109 -108
- package/cpp/llama.cpp/ggml/src/ggml-cpu/arch/arm/repack.cpp +1027 -1038
- package/cpp/llama.cpp/ggml/src/ggml-cpu/arch/loongarch/quants.c +53 -52
- package/cpp/llama.cpp/ggml/src/ggml-cpu/arch/powerpc/cpu-feats.cpp +82 -0
- package/cpp/llama.cpp/ggml/src/ggml-cpu/arch/powerpc/quants.c +56 -55
- package/cpp/llama.cpp/ggml/src/ggml-cpu/arch/riscv/quants.c +42 -41
- package/cpp/llama.cpp/ggml/src/ggml-cpu/arch/riscv/repack.cpp +24 -23
- package/cpp/llama.cpp/ggml/src/ggml-cpu/arch/s390/quants.c +29 -28
- package/cpp/llama.cpp/ggml/src/ggml-cpu/arch/wasm/quants.c +30 -29
- package/cpp/llama.cpp/ggml/src/ggml-cpu/arch/x86/quants.c +83 -82
- package/cpp/llama.cpp/ggml/src/ggml-cpu/arch/x86/repack.cpp +20 -19
- package/cpp/llama.cpp/ggml/src/ggml-cpu/common.h +3 -2
- package/cpp/llama.cpp/ggml/src/ggml-cpu/ggml-cpu-impl.h +9 -3
- package/cpp/llama.cpp/ggml/src/ggml-cpu/ggml-cpu.c +111 -103
- package/cpp/llama.cpp/ggml/src/ggml-cpu/ggml-cpu.cpp +4 -0
- package/cpp/llama.cpp/ggml/src/ggml-cpu/llamafile/sgemm.cpp +3 -2
- package/cpp/llama.cpp/ggml/src/ggml-cpu/ops.cpp +1405 -240
- package/cpp/llama.cpp/ggml/src/ggml-cpu/ops.h +8 -0
- package/cpp/llama.cpp/ggml/src/ggml-cpu/quants.c +25 -24
- package/cpp/llama.cpp/ggml/src/ggml-cpu/repack.cpp +56 -40
- package/cpp/llama.cpp/ggml/src/ggml-cpu/simd-mappings.h +212 -34
- package/cpp/llama.cpp/ggml/src/ggml-cpu/vec.cpp +35 -11
- package/cpp/llama.cpp/ggml/src/ggml-cpu/vec.h +187 -54
- package/cpp/llama.cpp/ggml/src/ggml-cuda/common.cuh +71 -29
- package/cpp/llama.cpp/ggml/src/ggml-cuda/conv2d-dw.cu +161 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/conv2d-dw.cuh +5 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/conv2d-transpose.cu +91 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/conv2d-transpose.cuh +4 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/convert.cu +22 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/convert.cuh +5 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/cross-entropy-loss.cu +2 -14
- package/cpp/llama.cpp/ggml/src/ggml-cuda/fattn-common.cuh +4 -1
- package/cpp/llama.cpp/ggml/src/ggml-cuda/fattn-mma-f16.cuh +8 -4
- package/cpp/llama.cpp/ggml/src/ggml-cuda/fattn-tile-f16.cu +6 -4
- package/cpp/llama.cpp/ggml/src/ggml-cuda/fattn-tile-f32.cu +14 -12
- package/cpp/llama.cpp/ggml/src/ggml-cuda/fattn-vec-f16.cuh +5 -3
- package/cpp/llama.cpp/ggml/src/ggml-cuda/fattn-vec-f32.cuh +15 -10
- package/cpp/llama.cpp/ggml/src/ggml-cuda/fattn-wmma-f16.cu +12 -6
- package/cpp/llama.cpp/ggml/src/ggml-cuda/getrows.cu +8 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/ggml-cuda.cu +269 -110
- package/cpp/llama.cpp/ggml/src/ggml-cuda/mean.cu +19 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/mean.cuh +3 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/mmq.cuh +2 -8
- package/cpp/llama.cpp/ggml/src/ggml-cuda/mmv.cu +257 -87
- package/cpp/llama.cpp/ggml/src/ggml-cuda/mmv.cuh +2 -3
- package/cpp/llama.cpp/ggml/src/ggml-cuda/rope.cu +21 -27
- package/cpp/llama.cpp/ggml/src/ggml-cuda/scale.cu +8 -6
- package/cpp/llama.cpp/ggml/src/ggml-cuda/softmax.cu +119 -58
- package/cpp/llama.cpp/ggml/src/ggml-cuda/ssm-conv.cu +10 -2
- package/cpp/llama.cpp/ggml/src/ggml-cuda/ssm-scan.cu +192 -52
- package/cpp/llama.cpp/ggml/src/ggml-cuda/sumrows.cu +5 -18
- package/cpp/llama.cpp/ggml/src/ggml-cuda/sumrows.cuh +0 -1
- package/cpp/llama.cpp/ggml/src/ggml-cuda/unary.cu +97 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/unary.cuh +11 -0
- package/cpp/llama.cpp/ggml/src/ggml-cuda/upscale.cu +92 -6
- package/cpp/llama.cpp/ggml/src/ggml-cuda/vendors/hip.h +14 -5
- package/cpp/llama.cpp/ggml/src/ggml-impl.h +125 -183
- package/cpp/llama.cpp/ggml/src/ggml-metal/CMakeLists.txt +4 -2
- package/cpp/llama.cpp/ggml/src/ggml-metal/ggml-metal-impl.h +51 -9
- package/cpp/llama.cpp/ggml/src/ggml-metal/ggml-metal.m +394 -80
- package/cpp/llama.cpp/ggml/src/ggml-metal/ggml-metal.metal +616 -239
- package/cpp/llama.cpp/ggml/src/ggml-musa/mudnn.cuh +2 -2
- package/cpp/llama.cpp/ggml/src/ggml-opencl/CMakeLists.txt +3 -0
- package/cpp/llama.cpp/ggml/src/ggml-opencl/ggml-opencl.cpp +741 -571
- package/cpp/llama.cpp/ggml/src/ggml-opencl/kernels/gelu.cl +27 -0
- package/cpp/llama.cpp/ggml/src/ggml-opencl/kernels/glu.cl +337 -0
- package/cpp/llama.cpp/ggml/src/ggml-opencl/kernels/mul_mat_f16_f32.cl +130 -0
- package/cpp/llama.cpp/ggml/src/ggml-opencl/kernels/scale.cl +3 -2
- package/cpp/llama.cpp/ggml/src/ggml-opencl/kernels/set_rows.cl +95 -0
- package/cpp/llama.cpp/ggml/src/ggml-opencl/kernels/softmax_4_f16.cl +24 -11
- package/cpp/llama.cpp/ggml/src/ggml-opencl/kernels/softmax_4_f32.cl +24 -11
- package/cpp/llama.cpp/ggml/src/ggml-opencl/kernels/softmax_f16.cl +24 -11
- package/cpp/llama.cpp/ggml/src/ggml-opencl/kernels/softmax_f32.cl +24 -11
- package/cpp/llama.cpp/ggml/src/ggml-opencl/kernels/upscale.cl +2 -3
- package/cpp/llama.cpp/ggml/src/ggml-quants.c +6 -6
- package/cpp/llama.cpp/ggml/src/ggml-sycl/backend.hpp +1 -0
- package/cpp/llama.cpp/ggml/src/ggml-sycl/binbcast.cpp +5 -6
- package/cpp/llama.cpp/ggml/src/ggml-sycl/common.hpp +1 -24
- package/cpp/llama.cpp/ggml/src/ggml-sycl/concat.cpp +28 -41
- package/cpp/llama.cpp/ggml/src/ggml-sycl/conv.cpp +4 -10
- package/cpp/llama.cpp/ggml/src/ggml-sycl/convert.cpp +99 -166
- package/cpp/llama.cpp/ggml/src/ggml-sycl/cpy.cpp +94 -72
- package/cpp/llama.cpp/ggml/src/ggml-sycl/dmmv.cpp +49 -67
- package/cpp/llama.cpp/ggml/src/ggml-sycl/dpct/helper.hpp +31 -1
- package/cpp/llama.cpp/ggml/src/ggml-sycl/element_wise.cpp +697 -1098
- package/cpp/llama.cpp/ggml/src/ggml-sycl/element_wise.hpp +18 -9
- package/cpp/llama.cpp/ggml/src/ggml-sycl/getrows.cpp +6 -9
- package/cpp/llama.cpp/ggml/src/ggml-sycl/ggml-sycl.cpp +104 -62
- package/cpp/llama.cpp/ggml/src/ggml-sycl/gla.cpp +2 -2
- package/cpp/llama.cpp/ggml/src/ggml-sycl/im2col.cpp +1 -1
- package/cpp/llama.cpp/ggml/src/ggml-sycl/mmq.cpp +60 -80
- package/cpp/llama.cpp/ggml/src/ggml-sycl/mmvq.cpp +132 -201
- package/cpp/llama.cpp/ggml/src/ggml-sycl/norm.cpp +55 -74
- package/cpp/llama.cpp/ggml/src/ggml-sycl/rope.cpp +39 -38
- package/cpp/llama.cpp/ggml/src/ggml-sycl/set_rows.cpp +131 -0
- package/cpp/llama.cpp/ggml/src/ggml-sycl/set_rows.hpp +8 -0
- package/cpp/llama.cpp/ggml/src/ggml-sycl/softmax.cpp +3 -3
- package/cpp/llama.cpp/ggml/src/ggml-sycl/sycl_hw.cpp +3 -1
- package/cpp/llama.cpp/ggml/src/ggml-sycl/sycl_hw.hpp +3 -0
- package/cpp/llama.cpp/ggml/src/ggml-sycl/tsembd.cpp +3 -8
- package/cpp/llama.cpp/ggml/src/ggml-sycl/wkv.cpp +12 -16
- package/cpp/llama.cpp/ggml/src/ggml-vulkan/CMakeLists.txt +12 -1
- package/cpp/llama.cpp/ggml/src/ggml-vulkan/ggml-vulkan.cpp +767 -292
- package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/CMakeLists.txt +4 -0
- package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/copy_to_quant.comp +58 -7
- package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/flash_attn.comp +28 -23
- package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/flash_attn_base.comp +14 -9
- package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/flash_attn_cm1.comp +38 -32
- package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/flash_attn_cm2.comp +32 -27
- package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/flash_attn_split_k_reduce.comp +44 -12
- package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/geglu.comp +13 -0
- package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/geglu_erf.comp +27 -0
- package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/geglu_quick.comp +11 -0
- package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/gelu_erf.comp +39 -0
- package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/glu_head.comp +15 -0
- package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/glu_main.comp +29 -0
- package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/mul_mm.comp +128 -72
- package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/mul_mm_cm2.comp +38 -9
- package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/reglu.comp +9 -0
- package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/rms_norm.comp +12 -3
- package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/roll.comp +46 -0
- package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/rope_multi.comp +7 -9
- package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/rope_neox.comp +7 -9
- package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/rope_norm.comp +7 -9
- package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/scale.comp +1 -1
- package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/soft_max.comp +20 -4
- package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/swiglu.comp +9 -0
- package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/upscale.comp +69 -5
- package/cpp/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/vulkan-shaders-gen.cpp +23 -3
- package/cpp/llama.cpp/ggml/src/ggml.c +449 -72
- package/cpp/llama.cpp/ggml/src/gguf.cpp +13 -2
- package/cpp/llama.cpp/gguf-py/gguf/constants.py +285 -0
- package/cpp/llama.cpp/gguf-py/gguf/gguf_writer.py +27 -0
- package/cpp/llama.cpp/gguf-py/gguf/tensor_mapping.py +137 -21
- package/cpp/llama.cpp/gguf-py/gguf/vocab.py +109 -7
- package/cpp/llama.cpp/gguf-py/pyproject.toml +2 -2
- package/cpp/llama.cpp/include/llama.h +8 -43
- package/cpp/llama.cpp/models/templates/Mistral-Small-3.2-24B-Instruct-2506.jinja +124 -0
- package/cpp/llama.cpp/src/llama-arch.cpp +265 -3
- package/cpp/llama.cpp/src/llama-arch.h +36 -1
- package/cpp/llama.cpp/src/llama-batch.cpp +596 -359
- package/cpp/llama.cpp/src/llama-batch.h +105 -70
- package/cpp/llama.cpp/src/llama-chat.cpp +26 -6
- package/cpp/llama.cpp/src/llama-chat.h +1 -0
- package/cpp/llama.cpp/src/llama-context.cpp +101 -107
- package/cpp/llama.cpp/src/llama-context.h +13 -13
- package/cpp/llama.cpp/src/llama-graph.cpp +286 -404
- package/cpp/llama.cpp/src/llama-graph.h +78 -79
- package/cpp/llama.cpp/src/llama-hparams.cpp +11 -1
- package/cpp/llama.cpp/src/llama-hparams.h +11 -0
- package/cpp/llama.cpp/src/llama-kv-cache-unified-iswa.cpp +74 -66
- package/cpp/llama.cpp/src/llama-kv-cache-unified-iswa.h +23 -26
- package/cpp/llama.cpp/src/llama-kv-cache-unified.cpp +312 -157
- package/cpp/llama.cpp/src/llama-kv-cache-unified.h +79 -46
- package/cpp/llama.cpp/src/llama-kv-cells.h +97 -21
- package/cpp/llama.cpp/src/llama-memory-hybrid.cpp +73 -69
- package/cpp/llama.cpp/src/llama-memory-hybrid.h +19 -22
- package/cpp/llama.cpp/src/llama-memory-recurrent.cpp +88 -77
- package/cpp/llama.cpp/src/llama-memory-recurrent.h +15 -20
- package/cpp/llama.cpp/src/llama-memory.cpp +17 -0
- package/cpp/llama.cpp/src/llama-memory.h +21 -22
- package/cpp/llama.cpp/src/llama-model-saver.cpp +1 -0
- package/cpp/llama.cpp/src/llama-model.cpp +5301 -2922
- package/cpp/llama.cpp/src/llama-model.h +40 -0
- package/cpp/llama.cpp/src/llama-quant.cpp +88 -5
- package/cpp/llama.cpp/src/llama-vocab.cpp +37 -3
- package/cpp/llama.cpp/src/llama-vocab.h +42 -0
- package/cpp/rn-utils.h +3 -0
- package/ios/include/chat.h +2 -0
- package/ios/include/common.h +5 -0
- package/ios/include/llama.h +8 -43
- package/ios/libs/llama.xcframework/Info.plist +19 -19
- package/ios/libs/llama.xcframework/ios-arm64/dSYMs/llama.dSYM/Contents/Resources/DWARF/llama +0 -0
- package/ios/libs/llama.xcframework/ios-arm64/dSYMs/llama.dSYM/Contents/Resources/Relocations/aarch64/llama.yml +5059 -4863
- package/ios/libs/llama.xcframework/ios-arm64/llama.framework/Headers/ggml-backend.h +1 -1
- package/ios/libs/llama.xcframework/ios-arm64/llama.framework/Headers/ggml-cpu.h +2 -0
- package/ios/libs/llama.xcframework/ios-arm64/llama.framework/Headers/ggml.h +206 -10
- package/ios/libs/llama.xcframework/ios-arm64/llama.framework/Headers/llama.h +8 -43
- package/ios/libs/llama.xcframework/ios-arm64/llama.framework/llama +0 -0
- package/ios/libs/llama.xcframework/ios-arm64_x86_64-simulator/dSYMs/llama.dSYM/Contents/Resources/DWARF/llama +0 -0
- package/ios/libs/llama.xcframework/ios-arm64_x86_64-simulator/dSYMs/llama.dSYM/Contents/Resources/Relocations/aarch64/llama.yml +5030 -4834
- package/ios/libs/llama.xcframework/ios-arm64_x86_64-simulator/dSYMs/llama.dSYM/Contents/Resources/Relocations/x86_64/llama.yml +3889 -3742
- package/ios/libs/llama.xcframework/ios-arm64_x86_64-simulator/llama.framework/Headers/ggml-backend.h +1 -1
- package/ios/libs/llama.xcframework/ios-arm64_x86_64-simulator/llama.framework/Headers/ggml-cpu.h +2 -0
- package/ios/libs/llama.xcframework/ios-arm64_x86_64-simulator/llama.framework/Headers/ggml.h +206 -10
- package/ios/libs/llama.xcframework/ios-arm64_x86_64-simulator/llama.framework/Headers/llama.h +8 -43
- package/ios/libs/llama.xcframework/ios-arm64_x86_64-simulator/llama.framework/llama +0 -0
- package/ios/libs/llama.xcframework/macos-arm64_x86_64/dSYMs/llama.dSYM/Contents/Resources/DWARF/llama +0 -0
- package/ios/libs/llama.xcframework/macos-arm64_x86_64/dSYMs/llama.dSYM/Contents/Resources/Relocations/aarch64/llama.yml +5030 -4834
- package/ios/libs/llama.xcframework/macos-arm64_x86_64/dSYMs/llama.dSYM/Contents/Resources/Relocations/x86_64/llama.yml +3891 -3744
- package/ios/libs/llama.xcframework/macos-arm64_x86_64/llama.framework/Headers/ggml-backend.h +1 -1
- package/ios/libs/llama.xcframework/macos-arm64_x86_64/llama.framework/Headers/ggml-cpu.h +2 -0
- package/ios/libs/llama.xcframework/macos-arm64_x86_64/llama.framework/Headers/ggml.h +206 -10
- package/ios/libs/llama.xcframework/macos-arm64_x86_64/llama.framework/Headers/llama.h +8 -43
- package/ios/libs/llama.xcframework/macos-arm64_x86_64/llama.framework/Versions/A/Headers/ggml-backend.h +1 -1
- package/ios/libs/llama.xcframework/macos-arm64_x86_64/llama.framework/Versions/A/Headers/ggml-cpu.h +2 -0
- package/ios/libs/llama.xcframework/macos-arm64_x86_64/llama.framework/Versions/A/Headers/ggml.h +206 -10
- package/ios/libs/llama.xcframework/macos-arm64_x86_64/llama.framework/Versions/A/Headers/llama.h +8 -43
- package/ios/libs/llama.xcframework/macos-arm64_x86_64/llama.framework/Versions/A/llama +0 -0
- package/ios/libs/llama.xcframework/macos-arm64_x86_64/llama.framework/Versions/Current/Headers/ggml-backend.h +1 -1
- package/ios/libs/llama.xcframework/macos-arm64_x86_64/llama.framework/Versions/Current/Headers/ggml-cpu.h +2 -0
- package/ios/libs/llama.xcframework/macos-arm64_x86_64/llama.framework/Versions/Current/Headers/ggml.h +206 -10
- package/ios/libs/llama.xcframework/macos-arm64_x86_64/llama.framework/Versions/Current/Headers/llama.h +8 -43
- package/ios/libs/llama.xcframework/macos-arm64_x86_64/llama.framework/Versions/Current/llama +0 -0
- package/ios/libs/llama.xcframework/macos-arm64_x86_64/llama.framework/llama +0 -0
- package/ios/libs/llama.xcframework/tvos-arm64/dSYMs/llama.dSYM/Contents/Resources/DWARF/llama +0 -0
- package/ios/libs/llama.xcframework/tvos-arm64/dSYMs/llama.dSYM/Contents/Resources/Relocations/aarch64/llama.yml +5059 -4863
- package/ios/libs/llama.xcframework/tvos-arm64/llama.framework/Headers/ggml-backend.h +1 -1
- package/ios/libs/llama.xcframework/tvos-arm64/llama.framework/Headers/ggml-cpu.h +2 -0
- package/ios/libs/llama.xcframework/tvos-arm64/llama.framework/Headers/ggml.h +206 -10
- package/ios/libs/llama.xcframework/tvos-arm64/llama.framework/Headers/llama.h +8 -43
- package/ios/libs/llama.xcframework/tvos-arm64/llama.framework/llama +0 -0
- package/ios/libs/llama.xcframework/tvos-arm64_x86_64-simulator/dSYMs/llama.dSYM/Contents/Resources/DWARF/llama +0 -0
- package/ios/libs/llama.xcframework/tvos-arm64_x86_64-simulator/dSYMs/llama.dSYM/Contents/Resources/Relocations/aarch64/llama.yml +5030 -4834
- package/ios/libs/llama.xcframework/tvos-arm64_x86_64-simulator/dSYMs/llama.dSYM/Contents/Resources/Relocations/x86_64/llama.yml +3889 -3742
- package/ios/libs/llama.xcframework/tvos-arm64_x86_64-simulator/llama.framework/Headers/ggml-backend.h +1 -1
- package/ios/libs/llama.xcframework/tvos-arm64_x86_64-simulator/llama.framework/Headers/ggml-cpu.h +2 -0
- package/ios/libs/llama.xcframework/tvos-arm64_x86_64-simulator/llama.framework/Headers/ggml.h +206 -10
- package/ios/libs/llama.xcframework/tvos-arm64_x86_64-simulator/llama.framework/Headers/llama.h +8 -43
- package/ios/libs/llama.xcframework/tvos-arm64_x86_64-simulator/llama.framework/llama +0 -0
- package/ios/libs/llama.xcframework/xros-arm64/dSYMs/llama.dSYM/Contents/Resources/DWARF/llama +0 -0
- package/ios/libs/llama.xcframework/xros-arm64/dSYMs/llama.dSYM/Contents/Resources/Relocations/aarch64/llama.yml +5095 -4900
- package/ios/libs/llama.xcframework/xros-arm64/llama.framework/Headers/ggml-backend.h +1 -1
- package/ios/libs/llama.xcframework/xros-arm64/llama.framework/Headers/ggml-cpu.h +2 -0
- package/ios/libs/llama.xcframework/xros-arm64/llama.framework/Headers/ggml.h +206 -10
- package/ios/libs/llama.xcframework/xros-arm64/llama.framework/Headers/llama.h +8 -43
- package/ios/libs/llama.xcframework/xros-arm64/llama.framework/llama +0 -0
- package/ios/libs/llama.xcframework/xros-arm64_x86_64-simulator/dSYMs/llama.dSYM/Contents/Resources/DWARF/llama +0 -0
- package/ios/libs/llama.xcframework/xros-arm64_x86_64-simulator/dSYMs/llama.dSYM/Contents/Resources/Relocations/aarch64/llama.yml +5066 -4871
- package/ios/libs/llama.xcframework/xros-arm64_x86_64-simulator/dSYMs/llama.dSYM/Contents/Resources/Relocations/x86_64/llama.yml +3919 -3773
- package/ios/libs/llama.xcframework/xros-arm64_x86_64-simulator/llama.framework/Headers/ggml-backend.h +1 -1
- package/ios/libs/llama.xcframework/xros-arm64_x86_64-simulator/llama.framework/Headers/ggml-cpu.h +2 -0
- package/ios/libs/llama.xcframework/xros-arm64_x86_64-simulator/llama.framework/Headers/ggml.h +206 -10
- package/ios/libs/llama.xcframework/xros-arm64_x86_64-simulator/llama.framework/Headers/llama.h +8 -43
- package/ios/libs/llama.xcframework/xros-arm64_x86_64-simulator/llama.framework/llama +0 -0
- package/package.json +1 -1
- package/cpp/llama.cpp/ggml/include/ggml-kompute.h +0 -50
- package/cpp/llama.cpp/ggml/src/ggml-kompute/CMakeLists.txt +0 -166
- package/cpp/llama.cpp/ggml/src/ggml-kompute/ggml-kompute.cpp +0 -2251
- package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/common.comp +0 -112
- package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_add.comp +0 -58
- package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_addrow.comp +0 -25
- package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_cpy_f16_f16.comp +0 -52
- package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_cpy_f16_f32.comp +0 -52
- package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_cpy_f32_f16.comp +0 -52
- package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_cpy_f32_f32.comp +0 -52
- package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_diagmask.comp +0 -30
- package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_gelu.comp +0 -22
- package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_getrows.comp +0 -17
- package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_getrows_f16.comp +0 -31
- package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_getrows_f32.comp +0 -31
- package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_getrows_q4_0.comp +0 -38
- package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_getrows_q4_1.comp +0 -39
- package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_getrows_q6_k.comp +0 -44
- package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_mul.comp +0 -52
- package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_mul_mat_f16.comp +0 -69
- package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_mul_mat_mat_f32.comp +0 -51
- package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_mul_mat_q4_0.comp +0 -33
- package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_mul_mat_q4_1.comp +0 -35
- package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_mul_mat_q4_k.comp +0 -140
- package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_mul_mat_q6_k.comp +0 -106
- package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_mul_mat_q8_0.comp +0 -73
- package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_mul_mv_q_n.comp +0 -52
- package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_mul_mv_q_n_pre.comp +0 -28
- package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_norm.comp +0 -84
- package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_relu.comp +0 -21
- package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_rmsnorm.comp +0 -53
- package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_rope_neox_f16.comp +0 -52
- package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_rope_neox_f32.comp +0 -52
- package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_rope_norm_f16.comp +0 -52
- package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_rope_norm_f32.comp +0 -52
- package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_scale.comp +0 -19
- package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_scale_8.comp +0 -23
- package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_silu.comp +0 -22
- package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/op_softmax.comp +0 -72
- package/cpp/llama.cpp/ggml/src/ggml-kompute/kompute-shaders/rope_common.comp +0 -71
|
@@ -196,6 +196,103 @@ void ggml_cuda_op_log(ggml_backend_cuda_context & ctx, ggml_tensor * dst) {
|
|
|
196
196
|
ggml_cuda_op_unary<op_log>(ctx, dst);
|
|
197
197
|
}
|
|
198
198
|
|
|
199
|
+
/* gated ops */
|
|
200
|
+
|
|
201
|
+
template <float (*op)(float), typename T>
|
|
202
|
+
static __global__ void unary_gated_op_kernel(const T * x, const T * g, T * dst, const int64_t k, const int64_t n, const int64_t o0, const int64_t o1) {
|
|
203
|
+
const int64_t i = int64_t(blockDim.x)*blockIdx.x + threadIdx.x;
|
|
204
|
+
|
|
205
|
+
if (i >= k) {
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
// perform base op and multiply with gate (either offset in same tensor or a separate one)
|
|
210
|
+
const int64_t j0 = (i / n) * o0 + (i % n);
|
|
211
|
+
const int64_t j1 = o0 == o1 ? j0 : (i / n) * o1 + (i % n);
|
|
212
|
+
|
|
213
|
+
dst[i] = (T)(op((float)x[j0]) * (float)g[j1]);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
template <float (*op)(float), typename T>
|
|
217
|
+
static void unary_gated_cuda(const T * x, const T * g, T * dst, const int64_t k, const int64_t n, const int64_t o0, const int64_t o1, cudaStream_t stream) {
|
|
218
|
+
const int64_t num_blocks = (k + CUDA_GLU_BLOCK_SIZE - 1) / CUDA_GLU_BLOCK_SIZE;
|
|
219
|
+
unary_gated_op_kernel<op><<<num_blocks, CUDA_GLU_BLOCK_SIZE, 0, stream>>>(x, g, dst, k, n, o0, o1);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
template <float (*op)(float)>
|
|
223
|
+
void ggml_cuda_op_unary_gated(ggml_backend_cuda_context & ctx, ggml_tensor * dst) {
|
|
224
|
+
const ggml_tensor * src0 = dst->src[0];
|
|
225
|
+
const ggml_tensor * src1 = dst->src[1];
|
|
226
|
+
void * src0_d = src0->data;
|
|
227
|
+
void * src1_d = src1 ? src1->data : src0->data;
|
|
228
|
+
const int64_t src0_o = src0->nb[1];
|
|
229
|
+
const int64_t src1_o = src1 ? src1->nb[1] : src0->nb[1];
|
|
230
|
+
void * dst_d = dst->data;
|
|
231
|
+
const int64_t nc = src1 ? src0->ne[0] : src0->ne[0] / 2;
|
|
232
|
+
cudaStream_t stream = ctx.stream();
|
|
233
|
+
|
|
234
|
+
GGML_ASSERT(ggml_is_contiguous_1(src0));
|
|
235
|
+
GGML_ASSERT(src0->nb[0] == ggml_element_size(src0));
|
|
236
|
+
GGML_ASSERT(ggml_is_contiguous(dst));
|
|
237
|
+
|
|
238
|
+
GGML_ASSERT(src0->type == GGML_TYPE_F32 || src0->type == GGML_TYPE_F16);
|
|
239
|
+
GGML_ASSERT( dst->type == GGML_TYPE_F32 || dst->type == GGML_TYPE_F16);
|
|
240
|
+
GGML_ASSERT(src0->type == dst->type);
|
|
241
|
+
GGML_ASSERT(dst->ne[0] == nc);
|
|
242
|
+
GGML_ASSERT(ggml_nrows(dst) == ggml_nrows(src0));
|
|
243
|
+
|
|
244
|
+
if (src1) {
|
|
245
|
+
GGML_ASSERT(ggml_is_contiguous_1(src1));
|
|
246
|
+
GGML_ASSERT(src1->nb[0] == ggml_element_size(src1));
|
|
247
|
+
GGML_ASSERT(src1->ne[0] == nc);
|
|
248
|
+
GGML_ASSERT(src0->type == src1->type);
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
const int32_t swapped = ((const int32_t *) dst->op_params)[1];
|
|
252
|
+
|
|
253
|
+
if (src0->type == GGML_TYPE_F16) {
|
|
254
|
+
half * src0_p = (half *) src0_d;
|
|
255
|
+
half * src1_p = (half *) src1_d;
|
|
256
|
+
|
|
257
|
+
if (!src1) {
|
|
258
|
+
src0_p += swapped ? nc : 0;
|
|
259
|
+
src1_p += swapped ? 0 : nc;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
unary_gated_cuda<op>(src0_p, src1_p, (half *)dst_d, ggml_nelements(dst), nc, src0_o / sizeof(half), src1_o / sizeof(half), stream);
|
|
263
|
+
} else {
|
|
264
|
+
float * src0_p = (float *) src0_d;
|
|
265
|
+
float * src1_p = (float *) src1_d;
|
|
266
|
+
|
|
267
|
+
if (!src1) {
|
|
268
|
+
src0_p += swapped ? nc : 0;
|
|
269
|
+
src1_p += swapped ? 0 : nc;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
unary_gated_cuda<op>(src0_p, src1_p, (float *)dst_d, ggml_nelements(dst), nc, src0_o / sizeof(float), src1_o / sizeof(float), stream);
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
void ggml_cuda_op_reglu(ggml_backend_cuda_context & ctx, ggml_tensor * dst) {
|
|
277
|
+
ggml_cuda_op_unary_gated<op_relu>(ctx, dst);
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
void ggml_cuda_op_geglu(ggml_backend_cuda_context & ctx, ggml_tensor * dst) {
|
|
281
|
+
ggml_cuda_op_unary_gated<op_gelu>(ctx, dst);
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
void ggml_cuda_op_swiglu(ggml_backend_cuda_context & ctx, ggml_tensor * dst) {
|
|
285
|
+
ggml_cuda_op_unary_gated<op_silu>(ctx, dst);
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
void ggml_cuda_op_geglu_erf(ggml_backend_cuda_context & ctx, ggml_tensor * dst) {
|
|
289
|
+
ggml_cuda_op_unary_gated<op_gelu_erf>(ctx, dst);
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
void ggml_cuda_op_geglu_quick(ggml_backend_cuda_context & ctx, ggml_tensor * dst) {
|
|
293
|
+
ggml_cuda_op_unary_gated<op_gelu_quick>(ctx, dst);
|
|
294
|
+
}
|
|
295
|
+
|
|
199
296
|
/* silu_back */
|
|
200
297
|
|
|
201
298
|
static __device__ __forceinline__ float op_silu_back(float grad, float x) {
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
#define CUDA_SQRT_BLOCK_SIZE 256
|
|
16
16
|
#define CUDA_SIN_BLOCK_SIZE 256
|
|
17
17
|
#define CUDA_COS_BLOCK_SIZE 256
|
|
18
|
+
#define CUDA_GLU_BLOCK_SIZE 256
|
|
18
19
|
|
|
19
20
|
void ggml_cuda_op_abs(ggml_backend_cuda_context & ctx, ggml_tensor * dst);
|
|
20
21
|
|
|
@@ -57,3 +58,13 @@ void ggml_cuda_op_sin(ggml_backend_cuda_context & ctx, ggml_tensor * dst);
|
|
|
57
58
|
void ggml_cuda_op_cos(ggml_backend_cuda_context & ctx, ggml_tensor * dst);
|
|
58
59
|
|
|
59
60
|
void ggml_cuda_op_log(ggml_backend_cuda_context & ctx, ggml_tensor * dst);
|
|
61
|
+
|
|
62
|
+
void ggml_cuda_op_reglu(ggml_backend_cuda_context & ctx, ggml_tensor * dst);
|
|
63
|
+
|
|
64
|
+
void ggml_cuda_op_geglu(ggml_backend_cuda_context & ctx, ggml_tensor * dst);
|
|
65
|
+
|
|
66
|
+
void ggml_cuda_op_swiglu(ggml_backend_cuda_context & ctx, ggml_tensor * dst);
|
|
67
|
+
|
|
68
|
+
void ggml_cuda_op_geglu_erf(ggml_backend_cuda_context & ctx, ggml_tensor * dst);
|
|
69
|
+
|
|
70
|
+
void ggml_cuda_op_geglu_quick(ggml_backend_cuda_context & ctx, ggml_tensor * dst);
|
|
@@ -22,17 +22,88 @@ static __global__ void upscale_f32(const float * x, float * dst,
|
|
|
22
22
|
dst[index] = *( (const float *)((const char *)x + i03 * nb03 + i02 * nb02 + i01 * nb01 + i00 * nb00) );
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
+
static __global__ void upscale_f32_bilinear(const float * x, float * dst,
|
|
26
|
+
const int nb00, const int nb01, const int nb02, const int nb03,
|
|
27
|
+
const int ne00_src, const int ne01_src,
|
|
28
|
+
const int ne10_dst, const int ne11_dst, const int ne12_dst, const int ne13_dst,
|
|
29
|
+
const float sf0, const float sf1, const float sf2, const float sf3,
|
|
30
|
+
const float pixel_offset) {
|
|
31
|
+
const int64_t index = threadIdx.x + blockIdx.x * blockDim.x;
|
|
32
|
+
const int64_t dst_total_elements = ne10_dst * ne11_dst * ne12_dst * ne13_dst;
|
|
33
|
+
|
|
34
|
+
if (index >= dst_total_elements) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const int i10_dst = index % ne10_dst;
|
|
39
|
+
const int i11_dst = (index / ne10_dst) % ne11_dst;
|
|
40
|
+
const int i12_dst = (index / (ne10_dst * ne11_dst)) % ne12_dst;
|
|
41
|
+
const int i13_dst = index / (ne10_dst * ne11_dst * ne12_dst);
|
|
42
|
+
|
|
43
|
+
const int i02_src = (int)(i12_dst / sf2);
|
|
44
|
+
const int i03_src = (int)(i13_dst / sf3);
|
|
45
|
+
|
|
46
|
+
const float y_src_f = ((float)i11_dst + pixel_offset) / sf1 - pixel_offset;
|
|
47
|
+
int y0_src = (int)floorf(y_src_f);
|
|
48
|
+
int y1_src = y0_src + 1;
|
|
49
|
+
|
|
50
|
+
y0_src = max(0, min(y0_src, ne01_src - 1));
|
|
51
|
+
y1_src = max(0, min(y1_src, ne01_src - 1));
|
|
52
|
+
|
|
53
|
+
float dy = y_src_f - (float)y0_src;
|
|
54
|
+
dy = max(0.0f, min(dy, 1.0f));
|
|
55
|
+
|
|
56
|
+
float x_src_f = ((float)i10_dst + pixel_offset) / sf0 - pixel_offset;
|
|
57
|
+
int x0_src = (int)floorf(x_src_f);
|
|
58
|
+
int x1_src = x0_src + 1;
|
|
59
|
+
|
|
60
|
+
x0_src = max(0, min(x0_src, ne00_src - 1));
|
|
61
|
+
x1_src = max(0, min(x1_src, ne00_src - 1));
|
|
62
|
+
|
|
63
|
+
float dx = x_src_f - (float)x0_src;
|
|
64
|
+
dx = max(0.0f, min(dx, 1.0f));
|
|
65
|
+
|
|
66
|
+
const float * p_a = (const float *)((const char *)x + (int64_t)x0_src * nb00 + (int64_t)y0_src * nb01 + (int64_t)i02_src * nb02 + (int64_t)i03_src * nb03);
|
|
67
|
+
const float * p_b = (const float *)((const char *)x + (int64_t)x1_src * nb00 + (int64_t)y0_src * nb01 + (int64_t)i02_src * nb02 + (int64_t)i03_src * nb03);
|
|
68
|
+
const float * p_c = (const float *)((const char *)x + (int64_t)x0_src * nb00 + (int64_t)y1_src * nb01 + (int64_t)i02_src * nb02 + (int64_t)i03_src * nb03);
|
|
69
|
+
const float * p_d = (const float *)((const char *)x + (int64_t)x1_src * nb00 + (int64_t)y1_src * nb01 + (int64_t)i02_src * nb02 + (int64_t)i03_src * nb03);
|
|
70
|
+
|
|
71
|
+
const float val_a = *p_a;
|
|
72
|
+
const float val_b = *p_b;
|
|
73
|
+
const float val_c = *p_c;
|
|
74
|
+
const float val_d = *p_d;
|
|
75
|
+
|
|
76
|
+
float result = val_a * (1.0f - dx) * (1.0f - dy) +
|
|
77
|
+
val_b * dx * (1.0f - dy) +
|
|
78
|
+
val_c * (1.0f - dx) * dy +
|
|
79
|
+
val_d * dx * dy;
|
|
80
|
+
|
|
81
|
+
dst[index] = result;
|
|
82
|
+
}
|
|
83
|
+
|
|
25
84
|
static void upscale_f32_cuda(const float * x, float * dst,
|
|
26
85
|
const int nb00, const int nb01, const int nb02, const int nb03,
|
|
27
86
|
const int ne10, const int ne11, const int ne12, const int ne13,
|
|
28
87
|
const float sf0, const float sf1, const float sf2, const float sf3,
|
|
29
88
|
cudaStream_t stream) {
|
|
30
|
-
|
|
31
|
-
|
|
89
|
+
const int64_t dst_size = ne10 * ne11 * ne12 * ne13;
|
|
90
|
+
const int64_t num_blocks = (dst_size + CUDA_UPSCALE_BLOCK_SIZE - 1) / CUDA_UPSCALE_BLOCK_SIZE;
|
|
32
91
|
|
|
33
92
|
upscale_f32<<<num_blocks, CUDA_UPSCALE_BLOCK_SIZE,0,stream>>>(x, dst, nb00, nb01, nb02, nb03, ne10, ne11, ne12, ne13, sf0, sf1, sf2, sf3);
|
|
34
93
|
}
|
|
35
94
|
|
|
95
|
+
static void upscale_f32_bilinear_cuda(const float * x, float * dst,
|
|
96
|
+
const int nb00, const int nb01, const int nb02, const int nb03,
|
|
97
|
+
const int ne00_src, const int ne01_src,
|
|
98
|
+
const int ne10_dst, const int ne11_dst, const int ne12_dst, const int ne13_dst,
|
|
99
|
+
const float sf0, const float sf1, const float sf2, const float sf3,
|
|
100
|
+
const float pixel_offset, cudaStream_t stream) {
|
|
101
|
+
const int64_t dst_size = ne10_dst * ne11_dst * ne12_dst * ne13_dst;
|
|
102
|
+
const int64_t num_blocks = (dst_size + CUDA_UPSCALE_BLOCK_SIZE - 1) / CUDA_UPSCALE_BLOCK_SIZE;
|
|
103
|
+
|
|
104
|
+
upscale_f32_bilinear<<<num_blocks, CUDA_UPSCALE_BLOCK_SIZE,0,stream>>>(x, dst, nb00, nb01, nb02, nb03, ne00_src, ne01_src, ne10_dst, ne11_dst, ne12_dst, ne13_dst, sf0, sf1, sf2, sf3, pixel_offset);
|
|
105
|
+
}
|
|
106
|
+
|
|
36
107
|
void ggml_cuda_op_upscale(ggml_backend_cuda_context & ctx, ggml_tensor * dst) {
|
|
37
108
|
const ggml_tensor * src0 = dst->src[0];
|
|
38
109
|
const float * src0_d = (const float *)src0->data;
|
|
@@ -42,10 +113,25 @@ void ggml_cuda_op_upscale(ggml_backend_cuda_context & ctx, ggml_tensor * dst) {
|
|
|
42
113
|
GGML_ASSERT(src0->type == GGML_TYPE_F32);
|
|
43
114
|
GGML_ASSERT( dst->type == GGML_TYPE_F32);
|
|
44
115
|
|
|
45
|
-
const
|
|
46
|
-
const
|
|
47
|
-
|
|
116
|
+
const int mode_flags = dst->op_params[0];
|
|
117
|
+
const ggml_scale_mode mode = (ggml_scale_mode)(mode_flags & 0xFF);
|
|
118
|
+
|
|
119
|
+
float sf0 = (float)dst->ne[0]/src0->ne[0];
|
|
120
|
+
float sf1 = (float)dst->ne[1]/src0->ne[1];
|
|
121
|
+
float sf2 = (float)dst->ne[2]/src0->ne[2];
|
|
48
122
|
const float sf3 = (float)dst->ne[3]/src0->ne[3];
|
|
49
123
|
|
|
50
|
-
|
|
124
|
+
if (mode == GGML_SCALE_MODE_NEAREST) {
|
|
125
|
+
upscale_f32_cuda(src0_d, dst_d, src0->nb[0], src0->nb[1], src0->nb[2], src0->nb[3], dst->ne[0], dst->ne[1], dst->ne[2], dst->ne[3], sf0, sf1, sf2, sf3, stream);
|
|
126
|
+
} else if (mode == GGML_SCALE_MODE_BILINEAR) {
|
|
127
|
+
float pixel_offset = 0.5f;
|
|
128
|
+
if (mode_flags & GGML_SCALE_FLAG_ALIGN_CORNERS) {
|
|
129
|
+
sf0 = (float)(dst->ne[0] - 1) / (src0->ne[0] - 1);
|
|
130
|
+
sf1 = (float)(dst->ne[1] - 1) / (src0->ne[1] - 1);
|
|
131
|
+
pixel_offset = 0.0f;
|
|
132
|
+
}
|
|
133
|
+
upscale_f32_bilinear_cuda(src0_d, dst_d, src0->nb[0], src0->nb[1], src0->nb[2], src0->nb[3],
|
|
134
|
+
src0->ne[0], src0->ne[1], dst->ne[0], dst->ne[1], dst->ne[2], dst->ne[3],
|
|
135
|
+
sf0, sf1, sf2, sf3, pixel_offset, stream);
|
|
136
|
+
}
|
|
51
137
|
}
|
|
@@ -10,9 +10,6 @@
|
|
|
10
10
|
#include "rocblas/rocblas.h"
|
|
11
11
|
#endif // __HIP_PLATFORM_AMD__
|
|
12
12
|
|
|
13
|
-
#define CUBLAS_COMPUTE_16F HIPBLAS_R_16F
|
|
14
|
-
#define CUBLAS_COMPUTE_32F HIPBLAS_R_32F
|
|
15
|
-
#define CUBLAS_COMPUTE_32F_FAST_16F HIPBLAS_R_32F
|
|
16
13
|
#define CUBLAS_GEMM_DEFAULT HIPBLAS_GEMM_DEFAULT
|
|
17
14
|
#define CUBLAS_GEMM_DEFAULT_TENSOR_OP HIPBLAS_GEMM_DEFAULT
|
|
18
15
|
#define CUBLAS_OP_N HIPBLAS_OP_N
|
|
@@ -30,7 +27,6 @@
|
|
|
30
27
|
#define CU_CHECK(fn) {hipError_t err = fn; if(err != hipSuccess) { GGML_ABORT("HipVMM Failure: %s\n", hipGetErrorString(err)); }}
|
|
31
28
|
#define __shfl_sync(mask, var, laneMask, width) __shfl(var, laneMask, width)
|
|
32
29
|
#define __shfl_xor_sync(mask, var, laneMask, width) __shfl_xor(var, laneMask, width)
|
|
33
|
-
#define cublasComputeType_t hipblasDatatype_t //deprecated, new hipblasComputeType_t not in 5.6
|
|
34
30
|
#define cublasCreate hipblasCreate
|
|
35
31
|
#define cublasDestroy hipblasDestroy
|
|
36
32
|
#define cublasGemmEx hipblasGemmEx
|
|
@@ -42,7 +38,6 @@
|
|
|
42
38
|
#define cublasSgemm hipblasSgemm
|
|
43
39
|
#define cublasStatus_t hipblasStatus_t
|
|
44
40
|
#define cublasOperation_t hipblasOperation_t
|
|
45
|
-
#define cudaDataType_t hipblasDatatype_t //deprecated, new hipblasDatatype not in 5.6
|
|
46
41
|
#define cudaDeviceCanAccessPeer hipDeviceCanAccessPeer
|
|
47
42
|
#define cudaDeviceDisablePeerAccess hipDeviceDisablePeerAccess
|
|
48
43
|
#define cudaDeviceEnablePeerAccess hipDeviceEnablePeerAccess
|
|
@@ -144,6 +139,20 @@
|
|
|
144
139
|
#define CUBLAS_STATUS_INTERNAL_ERROR HIPBLAS_STATUS_INTERNAL_ERROR
|
|
145
140
|
#define CUBLAS_STATUS_NOT_SUPPORTED HIPBLAS_STATUS_NOT_SUPPORTED
|
|
146
141
|
|
|
142
|
+
#if defined(__HIP_PLATFORM_AMD__) && HIP_VERSION >= 70000000
|
|
143
|
+
#define CUBLAS_COMPUTE_16F HIPBLAS_COMPUTE_16F
|
|
144
|
+
#define CUBLAS_COMPUTE_32F HIPBLAS_COMPUTE_32F
|
|
145
|
+
#define CUBLAS_COMPUTE_32F_FAST_16F HIPBLAS_COMPUTE_32F_FAST_16F
|
|
146
|
+
#define cublasComputeType_t hipblasComputeType_t
|
|
147
|
+
#define cudaDataType_t hipDataType
|
|
148
|
+
#else
|
|
149
|
+
#define CUBLAS_COMPUTE_16F HIPBLAS_R_16F
|
|
150
|
+
#define CUBLAS_COMPUTE_32F HIPBLAS_R_32F
|
|
151
|
+
#define CUBLAS_COMPUTE_32F_FAST_16F HIPBLAS_R_32F
|
|
152
|
+
#define cublasComputeType_t hipblasDatatype_t
|
|
153
|
+
#define cudaDataType_t hipblasDatatype_t
|
|
154
|
+
#endif
|
|
155
|
+
|
|
147
156
|
#define __CUDA_ARCH__ 1300
|
|
148
157
|
|
|
149
158
|
#if defined(__gfx803__) || defined(__gfx900__) || defined(__gfx906__)
|
|
@@ -301,6 +301,7 @@ struct ggml_cgraph {
|
|
|
301
301
|
struct ggml_tensor ** grads; // the outputs of these tensors are the gradients of the nodes
|
|
302
302
|
struct ggml_tensor ** grad_accs; // accumulators for node gradients
|
|
303
303
|
struct ggml_tensor ** leafs; // tensors with constant data
|
|
304
|
+
int32_t * use_counts;// number of uses of each tensor, indexed by hash table slot
|
|
304
305
|
|
|
305
306
|
struct ggml_hash_set visited_hash_set;
|
|
306
307
|
|
|
@@ -317,203 +318,81 @@ struct ggml_cgraph ggml_graph_view(struct ggml_cgraph * cgraph, int i0, int i1);
|
|
|
317
318
|
GGML_API void * ggml_aligned_malloc(size_t size);
|
|
318
319
|
GGML_API void ggml_aligned_free(void * ptr, size_t size);
|
|
319
320
|
|
|
320
|
-
// FP16
|
|
321
|
+
// FP16 <-> FP32
|
|
322
|
+
// ref: https://github.com/Maratyszcza/FP16
|
|
321
323
|
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
#define GGML_COMPUTE_FP16_TO_FP32(x) ggml_compute_fp16_to_fp32(x)
|
|
331
|
-
#define GGML_COMPUTE_FP32_TO_FP16(x) ggml_compute_fp32_to_fp16(x)
|
|
332
|
-
|
|
333
|
-
#define GGML_FP16_TO_FP32(x) ggml_compute_fp16_to_fp32(x)
|
|
334
|
-
|
|
335
|
-
static inline float ggml_compute_fp16_to_fp32(ggml_fp16_t h) {
|
|
336
|
-
__fp16 tmp;
|
|
337
|
-
memcpy(&tmp, &h, sizeof(ggml_fp16_t));
|
|
338
|
-
return (float)tmp;
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
static inline ggml_fp16_t ggml_compute_fp32_to_fp16(float f) {
|
|
342
|
-
ggml_fp16_t res;
|
|
343
|
-
__fp16 tmp = f;
|
|
344
|
-
memcpy(&res, &tmp, sizeof(ggml_fp16_t));
|
|
345
|
-
return res;
|
|
346
|
-
}
|
|
347
|
-
|
|
348
|
-
#elif defined(__F16C__)
|
|
349
|
-
|
|
350
|
-
#ifdef _MSC_VER
|
|
351
|
-
#define GGML_COMPUTE_FP16_TO_FP32(x) _mm_cvtss_f32(_mm_cvtph_ps(_mm_cvtsi32_si128(x)))
|
|
352
|
-
#define GGML_COMPUTE_FP32_TO_FP16(x) _mm_extract_epi16(_mm_cvtps_ph(_mm_set_ss(x), 0), 0)
|
|
353
|
-
#else
|
|
354
|
-
#define GGML_COMPUTE_FP16_TO_FP32(x) _cvtsh_ss(x)
|
|
355
|
-
#define GGML_COMPUTE_FP32_TO_FP16(x) _cvtss_sh(x, 0)
|
|
356
|
-
#endif
|
|
357
|
-
|
|
358
|
-
#elif defined(__POWER9_VECTOR__)
|
|
359
|
-
|
|
360
|
-
#define GGML_COMPUTE_FP16_TO_FP32(x) ggml_compute_fp16_to_fp32(x)
|
|
361
|
-
#define GGML_COMPUTE_FP32_TO_FP16(x) ggml_compute_fp32_to_fp16(x)
|
|
362
|
-
/* the inline asm below is about 12% faster than the lookup method */
|
|
363
|
-
#define GGML_FP16_TO_FP32(x) GGML_COMPUTE_FP16_TO_FP32(x)
|
|
364
|
-
#define GGML_FP32_TO_FP16(x) GGML_COMPUTE_FP32_TO_FP16(x)
|
|
365
|
-
|
|
366
|
-
static inline float ggml_compute_fp16_to_fp32(ggml_fp16_t h) {
|
|
367
|
-
float f;
|
|
368
|
-
double d;
|
|
369
|
-
__asm__(
|
|
370
|
-
"mtfprd %0,%2\n"
|
|
371
|
-
"xscvhpdp %0,%0\n"
|
|
372
|
-
"frsp %1,%0\n" :
|
|
373
|
-
/* temp */ "=d"(d),
|
|
374
|
-
/* out */ "=f"(f):
|
|
375
|
-
/* in */ "r"(h));
|
|
376
|
-
return f;
|
|
377
|
-
}
|
|
378
|
-
|
|
379
|
-
static inline ggml_fp16_t ggml_compute_fp32_to_fp16(float f) {
|
|
380
|
-
double d;
|
|
381
|
-
ggml_fp16_t r;
|
|
382
|
-
__asm__( /* xscvdphp can work on double or single precision */
|
|
383
|
-
"xscvdphp %0,%2\n"
|
|
384
|
-
"mffprd %1,%0\n" :
|
|
385
|
-
/* temp */ "=d"(d),
|
|
386
|
-
/* out */ "=r"(r):
|
|
387
|
-
/* in */ "f"(f));
|
|
388
|
-
return r;
|
|
389
|
-
}
|
|
390
|
-
|
|
391
|
-
#elif defined(__riscv) && defined(__riscv_zfhmin)
|
|
392
|
-
|
|
393
|
-
static inline float ggml_compute_fp16_to_fp32(ggml_fp16_t h) {
|
|
394
|
-
float f;
|
|
395
|
-
__asm__(
|
|
396
|
-
"fmv.h.x %[f], %[h]\n\t"
|
|
397
|
-
"fcvt.s.h %[f], %[f]"
|
|
398
|
-
: [f] "=&f" (f)
|
|
399
|
-
: [h] "r" (h)
|
|
400
|
-
);
|
|
401
|
-
return f;
|
|
402
|
-
}
|
|
324
|
+
static inline float fp32_from_bits(uint32_t w) {
|
|
325
|
+
union {
|
|
326
|
+
uint32_t as_bits;
|
|
327
|
+
float as_value;
|
|
328
|
+
} fp32;
|
|
329
|
+
fp32.as_bits = w;
|
|
330
|
+
return fp32.as_value;
|
|
331
|
+
}
|
|
403
332
|
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
return res;
|
|
413
|
-
}
|
|
333
|
+
static inline uint32_t fp32_to_bits(float f) {
|
|
334
|
+
union {
|
|
335
|
+
float as_value;
|
|
336
|
+
uint32_t as_bits;
|
|
337
|
+
} fp32;
|
|
338
|
+
fp32.as_value = f;
|
|
339
|
+
return fp32.as_bits;
|
|
340
|
+
}
|
|
414
341
|
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
342
|
+
static inline float ggml_compute_fp16_to_fp32(ggml_fp16_t h) {
|
|
343
|
+
const uint32_t w = (uint32_t) h << 16;
|
|
344
|
+
const uint32_t sign = w & UINT32_C(0x80000000);
|
|
345
|
+
const uint32_t two_w = w + w;
|
|
419
346
|
|
|
347
|
+
const uint32_t exp_offset = UINT32_C(0xE0) << 23;
|
|
348
|
+
#if (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) || defined(__GNUC__) && !defined(__STRICT_ANSI__)) && (!defined(__cplusplus) || __cplusplus >= 201703L)
|
|
349
|
+
const float exp_scale = 0x1.0p-112f;
|
|
420
350
|
#else
|
|
351
|
+
const float exp_scale = fp32_from_bits(UINT32_C(0x7800000));
|
|
352
|
+
#endif
|
|
353
|
+
const float normalized_value = fp32_from_bits((two_w >> 4) + exp_offset) * exp_scale;
|
|
421
354
|
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
static inline float fp32_from_bits(uint32_t w) {
|
|
426
|
-
union {
|
|
427
|
-
uint32_t as_bits;
|
|
428
|
-
float as_value;
|
|
429
|
-
} fp32;
|
|
430
|
-
fp32.as_bits = w;
|
|
431
|
-
return fp32.as_value;
|
|
432
|
-
}
|
|
433
|
-
|
|
434
|
-
static inline uint32_t fp32_to_bits(float f) {
|
|
435
|
-
union {
|
|
436
|
-
float as_value;
|
|
437
|
-
uint32_t as_bits;
|
|
438
|
-
} fp32;
|
|
439
|
-
fp32.as_value = f;
|
|
440
|
-
return fp32.as_bits;
|
|
441
|
-
}
|
|
442
|
-
|
|
443
|
-
static inline float ggml_compute_fp16_to_fp32(ggml_fp16_t h) {
|
|
444
|
-
const uint32_t w = (uint32_t) h << 16;
|
|
445
|
-
const uint32_t sign = w & UINT32_C(0x80000000);
|
|
446
|
-
const uint32_t two_w = w + w;
|
|
447
|
-
|
|
448
|
-
const uint32_t exp_offset = UINT32_C(0xE0) << 23;
|
|
449
|
-
#if (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) || defined(__GNUC__) && !defined(__STRICT_ANSI__)) && (!defined(__cplusplus) || __cplusplus >= 201703L)
|
|
450
|
-
const float exp_scale = 0x1.0p-112f;
|
|
451
|
-
#else
|
|
452
|
-
const float exp_scale = fp32_from_bits(UINT32_C(0x7800000));
|
|
453
|
-
#endif
|
|
454
|
-
const float normalized_value = fp32_from_bits((two_w >> 4) + exp_offset) * exp_scale;
|
|
455
|
-
|
|
456
|
-
const uint32_t magic_mask = UINT32_C(126) << 23;
|
|
457
|
-
const float magic_bias = 0.5f;
|
|
458
|
-
const float denormalized_value = fp32_from_bits((two_w >> 17) | magic_mask) - magic_bias;
|
|
355
|
+
const uint32_t magic_mask = UINT32_C(126) << 23;
|
|
356
|
+
const float magic_bias = 0.5f;
|
|
357
|
+
const float denormalized_value = fp32_from_bits((two_w >> 17) | magic_mask) - magic_bias;
|
|
459
358
|
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
static inline ggml_fp16_t ggml_compute_fp32_to_fp16(float f) {
|
|
467
|
-
#if (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) || defined(__GNUC__) && !defined(__STRICT_ANSI__)) && (!defined(__cplusplus) || __cplusplus >= 201703L)
|
|
468
|
-
const float scale_to_inf = 0x1.0p+112f;
|
|
469
|
-
const float scale_to_zero = 0x1.0p-110f;
|
|
470
|
-
#else
|
|
471
|
-
const float scale_to_inf = fp32_from_bits(UINT32_C(0x77800000));
|
|
472
|
-
const float scale_to_zero = fp32_from_bits(UINT32_C(0x08800000));
|
|
473
|
-
#endif
|
|
474
|
-
float base = (fabsf(f) * scale_to_inf) * scale_to_zero;
|
|
475
|
-
|
|
476
|
-
const uint32_t w = fp32_to_bits(f);
|
|
477
|
-
const uint32_t shl1_w = w + w;
|
|
478
|
-
const uint32_t sign = w & UINT32_C(0x80000000);
|
|
479
|
-
uint32_t bias = shl1_w & UINT32_C(0xFF000000);
|
|
480
|
-
if (bias < UINT32_C(0x71000000)) {
|
|
481
|
-
bias = UINT32_C(0x71000000);
|
|
482
|
-
}
|
|
359
|
+
const uint32_t denormalized_cutoff = UINT32_C(1) << 27;
|
|
360
|
+
const uint32_t result = sign |
|
|
361
|
+
(two_w < denormalized_cutoff ? fp32_to_bits(denormalized_value) : fp32_to_bits(normalized_value));
|
|
362
|
+
return fp32_from_bits(result);
|
|
363
|
+
}
|
|
483
364
|
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
365
|
+
static inline ggml_fp16_t ggml_compute_fp32_to_fp16(float f) {
|
|
366
|
+
#if (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) || defined(__GNUC__) && !defined(__STRICT_ANSI__)) && (!defined(__cplusplus) || __cplusplus >= 201703L)
|
|
367
|
+
const float scale_to_inf = 0x1.0p+112f;
|
|
368
|
+
const float scale_to_zero = 0x1.0p-110f;
|
|
369
|
+
#else
|
|
370
|
+
const float scale_to_inf = fp32_from_bits(UINT32_C(0x77800000));
|
|
371
|
+
const float scale_to_zero = fp32_from_bits(UINT32_C(0x08800000));
|
|
372
|
+
#endif
|
|
373
|
+
float base = (fabsf(f) * scale_to_inf) * scale_to_zero;
|
|
374
|
+
|
|
375
|
+
const uint32_t w = fp32_to_bits(f);
|
|
376
|
+
const uint32_t shl1_w = w + w;
|
|
377
|
+
const uint32_t sign = w & UINT32_C(0x80000000);
|
|
378
|
+
uint32_t bias = shl1_w & UINT32_C(0xFF000000);
|
|
379
|
+
if (bias < UINT32_C(0x71000000)) {
|
|
380
|
+
bias = UINT32_C(0x71000000);
|
|
490
381
|
}
|
|
491
382
|
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
// defined in ggml.c, initialized in ggml_init()
|
|
499
|
-
GGML_API float ggml_table_f32_f16[1 << 16];
|
|
500
|
-
|
|
501
|
-
// On ARM NEON, it's quicker to directly convert x -> x instead of calling into ggml_lookup_fp16_to_fp32,
|
|
502
|
-
// so we define GGML_FP16_TO_FP32 and GGML_FP32_TO_FP16 elsewhere for NEON.
|
|
503
|
-
// This is also true for POWER9.
|
|
504
|
-
#if !defined(GGML_FP16_TO_FP32)
|
|
505
|
-
inline static float ggml_lookup_fp16_to_fp32(ggml_fp16_t f) {
|
|
506
|
-
uint16_t s;
|
|
507
|
-
memcpy(&s, &f, sizeof(uint16_t));
|
|
508
|
-
return ggml_table_f32_f16[s];
|
|
383
|
+
base = fp32_from_bits((bias >> 1) + UINT32_C(0x07800000)) + base;
|
|
384
|
+
const uint32_t bits = fp32_to_bits(base);
|
|
385
|
+
const uint32_t exp_bits = (bits >> 13) & UINT32_C(0x00007C00);
|
|
386
|
+
const uint32_t mantissa_bits = bits & UINT32_C(0x00000FFF);
|
|
387
|
+
const uint32_t nonsign = exp_bits + mantissa_bits;
|
|
388
|
+
return (sign >> 16) | (shl1_w > UINT32_C(0xFF000000) ? UINT16_C(0x7E00) : nonsign);
|
|
509
389
|
}
|
|
510
390
|
|
|
511
|
-
#define
|
|
512
|
-
#
|
|
391
|
+
#define GGML_COMPUTE_FP16_TO_FP32(x) ggml_compute_fp16_to_fp32(x)
|
|
392
|
+
#define GGML_COMPUTE_FP32_TO_FP16(x) ggml_compute_fp32_to_fp16(x)
|
|
513
393
|
|
|
514
|
-
#
|
|
394
|
+
#define GGML_FP16_TO_FP32(x) GGML_COMPUTE_FP16_TO_FP32(x)
|
|
515
395
|
#define GGML_FP32_TO_FP16(x) GGML_COMPUTE_FP32_TO_FP16(x)
|
|
516
|
-
#endif
|
|
517
396
|
|
|
518
397
|
/**
|
|
519
398
|
* Converts brain16 to float32.
|
|
@@ -589,13 +468,76 @@ static inline ggml_bf16_t ggml_compute_fp32_to_bf16(float s) {
|
|
|
589
468
|
#define GGML_FP32_TO_BF16(x) ggml_compute_fp32_to_bf16(x)
|
|
590
469
|
#define GGML_BF16_TO_FP32(x) ggml_compute_bf16_to_fp32(x)
|
|
591
470
|
|
|
471
|
+
// return true if the node's results are only used by N other nodes
|
|
472
|
+
// and can be fused into their calculations.
|
|
473
|
+
static inline bool ggml_node_has_n_uses(const struct ggml_cgraph * cgraph, int node_idx, int32_t n_uses) {
|
|
474
|
+
const struct ggml_tensor * node = cgraph->nodes[node_idx];
|
|
475
|
+
|
|
476
|
+
// check the use count against how many we're replacing
|
|
477
|
+
size_t hash_pos = ggml_hash_find(&cgraph->visited_hash_set, node);
|
|
478
|
+
if (!ggml_bitset_get(cgraph->visited_hash_set.used, hash_pos) || cgraph->use_counts[hash_pos] != n_uses) {
|
|
479
|
+
return false;
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
// if node is a view, some other node might be using the intermediate result
|
|
483
|
+
// via the view source.
|
|
484
|
+
if (node->view_src) {
|
|
485
|
+
return false;
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
// If the user requested output for the node, can't fuse
|
|
489
|
+
if (node->flags & GGML_TENSOR_FLAG_OUTPUT) {
|
|
490
|
+
return false;
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
return true;
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
// Returns true if nodes [i, i+ops.size()) are the sequence of ggml_ops in ops[]
|
|
497
|
+
// and are fusable. Nodes are considered fusable according to this function if:
|
|
498
|
+
// - all nodes except the last have only one use and are not views/outputs (see ggml_node_has_N_uses).
|
|
499
|
+
// - all nodes except the last are a src of the following node.
|
|
500
|
+
// - all nodes are the same shape.
|
|
501
|
+
// TODO: Consider allowing GGML_OP_NONE nodes in between
|
|
502
|
+
static inline bool ggml_can_fuse(const struct ggml_cgraph * cgraph, int node_idx, const enum ggml_op * ops, int num_ops) {
|
|
503
|
+
if (node_idx + num_ops > cgraph->n_nodes) {
|
|
504
|
+
return false;
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
for (int i = 0; i < num_ops; ++i) {
|
|
508
|
+
struct ggml_tensor * node = cgraph->nodes[node_idx + i];
|
|
509
|
+
if (node->op != ops[i]) {
|
|
510
|
+
return false;
|
|
511
|
+
}
|
|
512
|
+
if (i < num_ops - 1 && !ggml_node_has_n_uses(cgraph, node_idx + i, 1)) {
|
|
513
|
+
return false;
|
|
514
|
+
}
|
|
515
|
+
if (i > 0) {
|
|
516
|
+
struct ggml_tensor * prev = cgraph->nodes[node_idx + i - 1];
|
|
517
|
+
if (node->src[0] != prev && node->src[1] != prev) {
|
|
518
|
+
return false;
|
|
519
|
+
}
|
|
520
|
+
if (!ggml_are_same_shape(node, prev)) {
|
|
521
|
+
return false;
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
return true;
|
|
526
|
+
}
|
|
527
|
+
|
|
592
528
|
#ifdef __cplusplus
|
|
593
529
|
}
|
|
594
530
|
#endif
|
|
595
531
|
|
|
596
532
|
#ifdef __cplusplus
|
|
533
|
+
#include <initializer_list>
|
|
597
534
|
#include <vector>
|
|
598
535
|
|
|
536
|
+
// nicer C++ syntax for ggml_can_fuse
|
|
537
|
+
inline bool ggml_can_fuse(const struct ggml_cgraph * cgraph, int node_idx, std::initializer_list<enum ggml_op> ops) {
|
|
538
|
+
return ggml_can_fuse(cgraph, node_idx, ops.begin(), (int)ops.size());
|
|
539
|
+
}
|
|
540
|
+
|
|
599
541
|
// expose GGUF internals for test code
|
|
600
542
|
GGML_API size_t gguf_type_size(enum gguf_type type);
|
|
601
543
|
GGML_API struct gguf_context * gguf_init_from_file_impl(FILE * file, struct gguf_init_params params);
|
|
@@ -71,7 +71,9 @@ else()
|
|
|
71
71
|
# note: adding -fno-inline fixes the tests when using MTL_SHADER_VALIDATION=1
|
|
72
72
|
# note: unfortunately, we have to call it default.metallib instead of ggml.metallib
|
|
73
73
|
# ref: https://github.com/ggerganov/whisper.cpp/issues/1720
|
|
74
|
-
|
|
74
|
+
# note: adding -g causes segmentation fault during compile
|
|
75
|
+
#set(XC_FLAGS -fno-fast-math -fno-inline -g)
|
|
76
|
+
set(XC_FLAGS -fno-fast-math -fno-inline)
|
|
75
77
|
else()
|
|
76
78
|
set(XC_FLAGS -O3)
|
|
77
79
|
endif()
|
|
@@ -90,7 +92,7 @@ else()
|
|
|
90
92
|
add_custom_command(
|
|
91
93
|
OUTPUT ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/default.metallib
|
|
92
94
|
COMMAND xcrun -sdk macosx metal ${XC_FLAGS} -c ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/ggml-metal.metal -o - |
|
|
93
|
-
|
|
95
|
+
xcrun -sdk macosx metallib - -o ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/default.metallib
|
|
94
96
|
COMMAND rm -f ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/ggml-common.h
|
|
95
97
|
COMMAND rm -f ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/ggml-metal.metal
|
|
96
98
|
DEPENDS ggml-metal.metal ${METALLIB_COMMON}
|