Repository navigation
ggml-cpu : disable PCH and fix CACHE_LINE_SIZE ambiguity - #28882
Conversation
…corruption Disable the ggml-cpu precompiled header and remove the std::hardware_destructive_interference_size branch from CACHE_LINE_SIZE. The PCH force-includes ggml-impl.h before ops.h, which pulls in <new> via <array>/<vector> and defines __cpp_lib_hardware_interference_size. This makes the C++ kernels use CACHE_LINE_SIZE = 256 (hardware destructive interference size) while the C work-buffer sizing code in ggml-cpu.c always uses the fallback 64. The mismatch undersizes the rope work buffer by (CACHE_LINE_SIZE/4 - 16) * n_threads * 4 bytes, causing a heap-buffer-overflow that corrupts the heap and later crashes in ggml_compute_forward_rope_flt. Disabling the ggml-cpu PCH restores the natural include order so ops.h is processed before <new>, keeping CACHE_LINE_SIZE consistent. Removing the std::hardware_destructive_interference_size branch makes the value deterministic and include-order independent. ref: #28858 Assisted-by: pi:llama.cpp/DeepSeek-V4-Flash-Vision-Exp
f0714a1 to
64d8a73
Compare
deadprogram
left a comment
There was a problem hiding this comment.
Thank you for the fix!
|
I confirmed that this PR resolves the error of CI (webgpu) macos in master branch. Thanks! |
|
@danbev I think we should take step back on the precompiled headers approach. It's tricky to get the PCH right and there might be other such unexpected effects, now and in the future. Would be difficult to guarantee that the codebase is compatible with PCH. The unity builds alone are good improvement already. It reduces most of the |
Yeah, I agree. It looked promising when working on it but in hindsight it was a bad idea. |
|
In any case, the usage of the |
This commit removes the precompiled headers that I added in Commit 3bcfeb7 ("cmake : add PCH and unity build to improve build times (#28091)"). The motivation for this is that this looked good when developing this but has caused multiple issues that I had taken into consideration and we have decided to remove it and only keep the unity builds from the above commit. Refs: #28882 (comment)
…corruption (ggml-org#28882) Disable the ggml-cpu precompiled header and remove the std::hardware_destructive_interference_size branch from CACHE_LINE_SIZE. The PCH force-includes ggml-impl.h before ops.h, which pulls in <new> via <array>/<vector> and defines __cpp_lib_hardware_interference_size. This makes the C++ kernels use CACHE_LINE_SIZE = 256 (hardware destructive interference size) while the C work-buffer sizing code in ggml-cpu.c always uses the fallback 64. The mismatch undersizes the rope work buffer by (CACHE_LINE_SIZE/4 - 16) * n_threads * 4 bytes, causing a heap-buffer-overflow that corrupts the heap and later crashes in ggml_compute_forward_rope_flt. Disabling the ggml-cpu PCH restores the natural include order so ops.h is processed before <new>, keeping CACHE_LINE_SIZE consistent. Removing the std::hardware_destructive_interference_size branch makes the value deterministic and include-order independent. ref: ggml-org#28858 Assisted-by: pi:llama.cpp/DeepSeek-V4-Flash-Vision-Exp
This commit removes the precompiled headers that I added in Commit 3bcfeb7 ("cmake : add PCH and unity build to improve build times (ggml-org#28091)"). The motivation for this is that this looked good when developing this but has caused multiple issues that I had taken into consideration and we have decided to remove it and only keep the unity builds from the above commit. Refs: ggml-org#28882 (comment)
Overview
fix #28858
cont #28091
Fix heap corruption on macOS arm64 caused by the ggml-cpu precompiled header.
The PCH added in #28091 force-includes
ggml-impl.hbeforeops.h.ggml-impl.hpulls in<new>via<array>/<vector>, which defines__cpp_lib_hardware_interference_size. This makesCACHE_LINE_SIZEinops.hresolve tostd::hardware_destructive_interference_size(256 on Apple Silicon) in the C++ kernels, while the C work-buffer sizing code inggml-cpu.calways uses the fallback value (64). The mismatch undersizes the rope work buffer, causing a heap-buffer-overflow that corrupts the heap and later crashes inggml_compute_forward_rope_flt.This PR disables the ggml-cpu PCH (restoring the natural include order so
ops.his processed before<new>) and removes thestd::hardware_destructive_interference_sizebranch fromCACHE_LINE_SIZEso the value is deterministic and include-order independent.Additional information
Reproduce on
masterusing AddressSanitizer withtest-rope:Before the fix,
test-ropeaborts with a heap-buffer-overflow:After the fix,
test-roperuns to completion with exit code 0 and no ASan errors.Requirements