From: RapidMark Date: Thu, 9 Jul 2026 08:02:26 +0000 (-0700) Subject: ggml-hip: enable -funsafe-math-optimizations (llama/24668) X-Git-Tag: upstream/1.9.2~46 X-Git-Url: https://git.djapps.eu/?a=commitdiff_plain;h=cc7a521508f6aee3b7987ffd33ec6b5d9c7a06f1;p=pkg%2Fggml%2Fsources%2Fwhisper.cpp ggml-hip: enable -funsafe-math-optimizations (llama/24668) CUDA is compiled with fast math and AMD/HIP is not — this flag lets AMD use fast math too. We can't use -ffast-math: it implies -ffinite-math-only, which won't compile (ggml uses INFINITY for masking) and produces NaNs. -funsafe-math-optimizations gives the speedup without the NaN problems. Co-authored-by: Mark Caldwell --- diff --git a/ggml/src/ggml-hip/CMakeLists.txt b/ggml/src/ggml-hip/CMakeLists.txt index 44fd3f3c..7121193f 100644 --- a/ggml/src/ggml-hip/CMakeLists.txt +++ b/ggml/src/ggml-hip/CMakeLists.txt @@ -130,6 +130,9 @@ if (GGML_HIP_EXPORT_METRICS) set(CMAKE_HIP_FLAGS "${CMAKE_HIP_FLAGS} -Rpass-analysis=kernel-resource-usage --save-temps") endif() +# Fast math for HIP, like CUDA's -use_fast_math. Not -ffast-math: that implies -ffinite-math-only, which breaks ggml's INFINITY masking and produces NaNs. +set(CMAKE_HIP_FLAGS "${CMAKE_HIP_FLAGS} -funsafe-math-optimizations") + if (NOT GGML_CUDA_FA) add_compile_definitions(GGML_CUDA_NO_FA) endif()