Skip to content

ggml : make ggml_time_init idempotent - #24422

Merged
ggerganov merged 2 commits into
ggml-org:masterfrom
aisk:fix/ggml-time-init-idempotent
Jul 7, 2026
Merged

ggerganov merged 2 commits into
ggml-org:masterfrom
aisk:fix/ggml-time-init-idempotent

Conversation

@aisk

@aisk aisk commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

ggml_time_init() is not idempotent: each call resets timer_start to the current QueryPerformanceCounter value, so calling it more than once shifts the timer baseline and breaks any elapsed-time delta computed against an earlier timestamp (it can even go negative). ggml_init() already calls it once behind an is_first_call guard, but that is not the only entry point. Some code calls ggml_time_init() directly before ggml_init() to time the initialization itself (e.g. main-ctx.cpp), and a user unaware that ggml_init() already initializes the timer may call it again, silently resetting the baseline.

Since the function only has a real implementation on Windows (a no-op elsewhere), this uses the native InitOnceExecuteOnce / INIT_ONCE primitive to capture the baseline exactly once. It is also thread-safe, so concurrent first calls are handled correctly. Minimal change, no extra dependency, and windows.h is already included.

@aisk
aisk requested a review from ggerganov as a code owner June 10, 2026 15:54
@aisk aisk changed the title Make ggml_time_init idempotent ggml : make ggml_time_init idempotent Jun 10, 2026
@github-actions github-actions Bot added the ggml changes relating to the ggml tensor library for machine learning label Jul 5, 2026
@ggerganov ggerganov added the merge ready A maintainer can use this label to indicate that they consider the changes final and ready to merge. label Jul 6, 2026
@ggerganov
ggerganov merged commit 1a7c25b into ggml-org:master Jul 7, 2026
24 of 25 checks passed
@aisk
aisk deleted the fix/ggml-time-init-idempotent branch July 7, 2026 08:33
satindergrewal pushed a commit to satindergrewal/llama.cpp that referenced this pull request Aug 12, 2026
zbrad pushed a commit to zbrad/llama.cpp that referenced this pull request Sep 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ggml changes relating to the ggml tensor library for machine learning merge ready A maintainer can use this label to indicate that they consider the changes final and ready to merge.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants