From 4231b23dc2c46661d01157aac5245bdcf03ce4b1 Mon Sep 17 00:00:00 2001 From: Kartik Gulia Date: Fri, 23 Oct 2026 18:26:59 +0530 Subject: [PATCH] ggml : fix time overflow in ggml_time_us (#30969) * fix time overflow * use double --- ggml/src/ggml.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/ggml/src/ggml.c b/ggml/src/ggml.c index 004970db0..0b2adf6e4 100644 --- a/ggml/src/ggml.c +++ b/ggml/src/ggml.c @@ -546,9 +546,6 @@ static BOOL CALLBACK ggml_time_init_once(PINIT_ONCE once, PVOID param, PVOID *ct QueryPerformanceFrequency(&t); timer_freq = t.QuadPart; - // The multiplication by 1000 or 1000000 below can cause an overflow if timer_freq - // and the uptime is high enough. - // We subtract the program start time to reduce the likelihood of that happening. QueryPerformanceCounter(&t); timer_start = t.QuadPart; @@ -561,12 +558,12 @@ void ggml_time_init(void) { int64_t ggml_time_ms(void) { LARGE_INTEGER t; QueryPerformanceCounter(&t); - return ((t.QuadPart-timer_start) * 1000) / timer_freq; + return (int64_t) (((double) (t.QuadPart - timer_start) / timer_freq) * 1000); } int64_t ggml_time_us(void) { LARGE_INTEGER t; QueryPerformanceCounter(&t); - return ((t.QuadPart-timer_start) * 1000000) / timer_freq; + return (int64_t) (((double) (t.QuadPart - timer_start) / timer_freq) * 1000000); } #else void ggml_time_init(void) {}