Repository navigation
Conversation
The cancellation API added in OpenMathLib#5882 gives every thread a generation slot that the level-3 drivers advance at operation entry, and cancels by a compare-and-set against a slot value loaded by the canceller. That protocol cannot be used safely from another thread: the slot lives in the issuing thread's storage, so a canceller must hold that thread inside the call while it loads and updates the slot, or it may touch a dead thread's storage or cancel a later, unrelated operation. With that exclusion in place the generation check is redundant, and without it the only safe caller is a handler running on the issuing thread itself, i.e. in async-signal context. Advancing the slot at entry also erases a cancellation requested before the driver starts. Replace it with `char *openblas_set_thread_cancel_flag(char *)`, which designates a byte owned by the caller as the calling thread's cancellation flag (NULL: none) and returns the previous designation, so that nested designations can restore it. The level-3 drivers read the issuing thread's flag pointer at entry, forward it to the worker threads, and poll it with a relaxed atomic load at the same points as before, returning early once it is nonzero. OpenBLAS never writes the flag, so there is nothing to clear, reuse or disambiguate: the caller sets it from any thread and keeps it valid while it is designated. openblas_cancel and openblas_cancel_token are removed; neither has been in a release, and due to mistakes in the gensymbol edits, wasn't previously actually in the exported API either. Assisted-by: Claude Code (Opus 5.5)
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The cancellation API added in #5882 gives every thread a generation slot that the level-3 drivers advance at operation entry, and cancels by a compare-and-set against a slot value loaded by the canceller. That protocol cannot be used safely from any thread: the slot lives in the issuing thread's storage, so another thread canceller must stop that thread inside the call while it loads and updates the slot, or it may touch a dead thread's storage or cancel a later, unrelated operation. With that exclusion in place the generation check is redundant, and without it the only safe caller would be a handler running on the issuing thread itself, i.e. in async-signal context. However, calling
openblas_cancel_slotcalls malloc (either explicitly, or via__threadimplementation details), so it isn't async-signal-safe. That leaves no places where this code was ever valid to use. Additionally, advancing the slot at entry as done in #5882 would have miss a cancellation requested before the driver starts.This replaces it with an API function
char *openblas_set_thread_cancel_flag$_suffix(char *), which designates a byte pointer, owned by the caller, as the calling thread's cancellation flag (NULL: none) and returns the previous designation, so that nested designations can restore it. The level-3 drivers read the issuing thread's flag pointer at entry, forward it to the worker threads, and poll it with a relaxed atomic load at the same points as before, returning early once it is nonzero. OpenBLAS never writes the flag, so there is nothing to clear, reuse or disambiguate: the caller sets it from any thread and keeps it valid while it is designated.openblas_cancelandopenblas_cancel_tokenare removed; neither has been in a release yet, and it seems that potentially weren't actually in the exported API currently either, due to mistakes in the gensymbol edits (which also get reverted here since they were not necessary or desirable).The downstream PR driving this change is up at JuliaLang/LinearAlgebra.jl#2008
Assisted-by: Claude Code (Opus 5.5)