[STF] Fix two races in tests and examples: fence() timing events and threads_multiple_graphs #12178
All Vouch review confidence checks passed
Residual risk 0.16 = Change Risk (0.40) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.40 · 316 lines diff across 3 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.345
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #12178"
general
weight: 0.35
caugonnet
Description
closes #12175
Two races in CUDASTF tests and examples. Neither is in the library itself.
1. Timing with
fence()events (17 files). These tests and examples record their stop event in a stream returned byctx.fence(), then callctx.finalize()andcudaEventElapsedTime().finalize()waits for the context's own work, not for work recorded in afence()stream, so the stop event may not have completed yet, andcudaEventElapsedTime()returnscudaErrorNotReady. Code that checks the result aborts, for example09-nbody-blockedat line 279 when the GPU is shared. Thejacobi*andheat_mgpuexamples ignore it and print an uninitialized time. This PR synchronizes the stop event first, asexamples/stf/mandelbrot.cualready does.2.
threads_multiple_graphs. Each worker thread gets views of frozen data in its own stream and runs a graph context on it. The main thread then unfreezes the data in a different stream that does not depend on the worker's stream.docs/cudax/stf.rstsays that "the stream passed tounfreezemust depend on the completion of the work in the streams used for any precedingfreezeandgetcalls". This PR waits for the worker stream before the thread returns.Testing
RTX 5070 Ti (sm_120), WSL2, nvcc 13.4.59, gcc 16.2.1,
cudaxpreset with examples. "Contention" means 6 processes running the same binary at the same time.| test | contention before | contention after (6 processes × 6 runs) |
|---|---|---|
|
stf.examples.09-nbody-blocked| 24/30 runs abort withcudaErrorNotReady(6 processes × 5 runs) | 0/36 ||
stf.stress.launch_vs_parallelfor| 36/36 runs abort | 0/36 ||
stf.local_stf.threads_multiple_graphs| 8/36 runs fail (wrong results) | 0/36 ||
stf.utility.timing_with_fences| not measured | 0/36 |Run alone, all four tests and the examples
heat_mgpu,jacobi,jacobi_pfor,jacobi_stackable,jacobi_stackable_raii,launch_histogram,launch_scanandscanpass.Not built locally:
examples/stf/linear_algebra/{06-pdgemm,06-pdgemm-stackable,07-cholesky,07-potri}.cu,test/stf/examples/07-cholesky-redux.cuandtest/stf/gnu/07-cholesky.cpp, because my toolkit has no cuBLAS/cuSOLVER. They get the same one-linecudaEventSynchronize()before the existingcudaEventElapsedTime()call, on the same event variable.Checklist