From b5f0b389a36cc5cec5bfd56a763f74bacb4d82bd Mon Sep 17 00:00:00 2001 From: Daniel Bevenius Date: Fri, 27 Jun 2025 07:17:51 +0200 Subject: [PATCH 1/2] ggml : add version function to get lib version This commit adds a function `ggml_version()` to the ggml library that returns the version of the library as a string. The motivation for this is that it can be useful to be able to programmatically check the version of the ggml library being used. Usage: ```c printf("GGML version: %s\n", ggml_version()); ``` Output: ```console GGML version: 0.0.2219 ``` --- CMakeLists.txt | 3 +++ include/ggml.h | 2 ++ src/ggml.c | 4 ++++ 3 files changed, 9 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4e7399f9e6..0e5305cf74 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -359,6 +359,9 @@ write_basic_package_version_file( VERSION ${GGML_INSTALL_VERSION} COMPATIBILITY SameMajorVersion) +target_compile_definitions(ggml-base PRIVATE GGML_VERSION="${GGML_INSTALL_VERSION}") +message(STATUS "ggml version: ${GGML_INSTALL_VERSION}") + install(FILES ${CMAKE_CURRENT_BINARY_DIR}/ggml-config.cmake ${CMAKE_CURRENT_BINARY_DIR}/ggml-version.cmake DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/ggml) diff --git a/include/ggml.h b/include/ggml.h index 9c4e24023b..a6c748bffb 100644 --- a/include/ggml.h +++ b/include/ggml.h @@ -627,6 +627,8 @@ extern "C" { // misc + GGML_API const char * ggml_version(void); + GGML_API void ggml_time_init(void); // call this once at the beginning of the program GGML_API int64_t ggml_time_ms(void); GGML_API int64_t ggml_time_us(void); diff --git a/src/ggml.c b/src/ggml.c index f8e7c595bc..60a2a1e78b 100644 --- a/src/ggml.c +++ b/src/ggml.c @@ -461,6 +461,10 @@ bool ggml_guid_matches(ggml_guid_t guid_a, ggml_guid_t guid_b) { return memcmp(guid_a, guid_b, sizeof(ggml_guid)) == 0; } +const char * ggml_version(void) { + return GGML_VERSION; +} + // // timing // From 91e32b7bc4f7f011688f5d09de9e8eabe6e24f08 Mon Sep 17 00:00:00 2001 From: Georgi Gerganov Date: Wed, 2 Jul 2025 08:13:05 +0300 Subject: [PATCH 2/2] ggml : add ggml_commit() --- CMakeLists.txt | 6 +++++- include/ggml.h | 1 + src/ggml.c | 4 ++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0e5305cf74..5e93cd1c97 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -359,8 +359,12 @@ write_basic_package_version_file( VERSION ${GGML_INSTALL_VERSION} COMPATIBILITY SameMajorVersion) -target_compile_definitions(ggml-base PRIVATE GGML_VERSION="${GGML_INSTALL_VERSION}") +target_compile_definitions(ggml-base PRIVATE + GGML_VERSION="${GGML_INSTALL_VERSION}" + GGML_COMMIT="${GGML_BUILD_COMMIT}" +) message(STATUS "ggml version: ${GGML_INSTALL_VERSION}") +message(STATUS "ggml commit: ${GGML_BUILD_COMMIT}") install(FILES ${CMAKE_CURRENT_BINARY_DIR}/ggml-config.cmake ${CMAKE_CURRENT_BINARY_DIR}/ggml-version.cmake diff --git a/include/ggml.h b/include/ggml.h index a6c748bffb..cb761192df 100644 --- a/include/ggml.h +++ b/include/ggml.h @@ -628,6 +628,7 @@ extern "C" { // misc GGML_API const char * ggml_version(void); + GGML_API const char * ggml_commit(void); GGML_API void ggml_time_init(void); // call this once at the beginning of the program GGML_API int64_t ggml_time_ms(void); diff --git a/src/ggml.c b/src/ggml.c index 60a2a1e78b..9e28caa465 100644 --- a/src/ggml.c +++ b/src/ggml.c @@ -465,6 +465,10 @@ const char * ggml_version(void) { return GGML_VERSION; } +const char * ggml_commit(void) { + return GGML_COMMIT; +} + // // timing //