Fix race condition in the predicate in thunks. #23057
Open
+399
−27
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.
Fix race condition in the predicate in thunks.
WhileThunk and ConditionalThunk stored CUDA host memory that would store the predicate. The thunks would transfer the predicate from device to host into the CUDA host memory. But if the thunks were called multiple times in parallel, each call would use the same memory, causing a race condition which could result in incorrect predicate values.
Now a pool of host memory is used so different calls to the thunk get different pointers to host memory. The pool has a fixed size of 128, so if there are more parallel callers than that, an error will be raised. I think it's unlikely there will be that many parallel calls in practice.