Skip to content

Commit f7f05fb

Browse files
authored
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.
1 parent 6167e29 commit f7f05fb

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

CMakeLists.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,10 @@ endif()
119119

120120
set(CMAKE_POLICY_DEFAULT_CMP0077 NEW)
121121

122-
# see https://github.com/ggerganov/ggml/pull/682
123-
add_definitions(-DGGML_MAX_NAME=128)
122+
if (NOT SD_USE_SYSTEM_GGML)
123+
# see https://github.com/ggerganov/ggml/pull/682
124+
add_definitions(-DGGML_MAX_NAME=128)
125+
endif()
124126

125127
# deps
126128
# Only add ggml if it hasn't been added yet

ggml_extend.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@
5656
#define __STATIC_INLINE__ static inline
5757
#endif
5858

59+
static_assert(GGML_MAX_NAME >= 128, "GGML_MAX_NAME must be at least 128");
60+
5961
// n-mode trensor-matrix product
6062
// example: 2-mode product
6163
// A: [ne03, k, ne01, ne00]

0 commit comments

Comments
 (0)