From f7f05fb185f075e80cc22cda65b7dab64feec1ca Mon Sep 17 00:00:00 2001 From: Wagner Bruna Date: Sat, 2 Aug 2025 14:24:40 -0300 Subject: [PATCH] chore: avoid setting GGML_MAX_NAME when building against external ggml (#751) An external ggml will most likely have been built with the default GGML_MAX_NAME value (64), which would be inconsistent with the value set by our build (128). That would be an ODR violation, and it could easily cause memory corruption issues due to the different sizeof(struct ggml_tensor) values. For now, when linking against an external ggml, we demand it has been patched with a bigger GGML_MAX_NAME, since we can't check against a value defined only at build time. --- CMakeLists.txt | 6 ++++-- ggml_extend.hpp | 2 ++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index dc8ca78..c0e5e15 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -119,8 +119,10 @@ endif() set(CMAKE_POLICY_DEFAULT_CMP0077 NEW) -# see https://github.com/ggerganov/ggml/pull/682 -add_definitions(-DGGML_MAX_NAME=128) +if (NOT SD_USE_SYSTEM_GGML) + # see https://github.com/ggerganov/ggml/pull/682 + add_definitions(-DGGML_MAX_NAME=128) +endif() # deps # Only add ggml if it hasn't been added yet diff --git a/ggml_extend.hpp b/ggml_extend.hpp index d4e4278..0be8d4b 100644 --- a/ggml_extend.hpp +++ b/ggml_extend.hpp @@ -56,6 +56,8 @@ #define __STATIC_INLINE__ static inline #endif +static_assert(GGML_MAX_NAME >= 128, "GGML_MAX_NAME must be at least 128"); + // n-mode trensor-matrix product // example: 2-mode product // A: [ne03, k, ne01, ne00]