ggml : fix time overflow in ggml_time_us (#30969)
* fix time overflow * use double
This commit is contained in:
1 parent
f00c9083b2
commit
4231b23dc2
1 file changed
+2
-5
+2
-5
@@ -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) {}
|
||||
|
||||
Reference in new issue
Block a user