fix(rocrand): Device Sobol generator on second GPU faults or hangs #16673
All Vouch review confidence checks passed
Residual risk 0.17 = Change Risk (0.43) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.43 · 397 lines diff across 4 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.358
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #16673"
general
weight: 0.35
amd-jmahovsky
JIRA ID : AIPRIMS-286
Motivation
A device Sobol generator created on a second GPU faults with HSA_STATUS_ERROR_MEMORY_FAULT on gfx90a, and hangs in hipStreamSynchronize on MI300A. It happens when an earlier generator of the same Sobol variant was created on another device and peer access is not enabled, which is the default. One generator per GPU, each created after hipSetDevice, is the ordinary multi-GPU pattern.
sobol_generator_template::get_constants() returned a function-local static constant_accessor. Its constructor allocates the direction vectors and scramble constants with hipMalloc on whichever device happens to be current at first use, and fills them with a blocking hipMemcpy. Every later generator of that variant copied the same two pointers in its own constructor and handed them to a kernel on its own stream. A generator on device 1 therefore dereferenced device 0 memory. Note hipDeviceCanAccessPeer(1, 0) returns 1 on an affected system: capability is not access, and rocRAND never enables it.
Technical Details
Cache one sobol_constant_accessor per device per variant, keyed by the device of the generator's stream and filled on first use with that device current. This mirrors the per-device architecture cache already in config_types.hpp.
sobol.hpp:
- Replace the single static accessor with a 512-entry per-device cache.
- Resolve the tables in generate(), immediately before the launch, rather than caching them in members at construction.
- Prime the cache in the constructor and in set_stream().
config_types.hpp:
- Make get_device_from_stream available regardless of USE_DEVICE_DISPATCH, which is 0 on Windows and non-AMD platforms, with a hipGetDevice fallback.
- Add a scoped_device RAII guard. hipMalloc allocates on the current device rather than on the device of any stream.
Test Plan
Reproducer graph_repro.cpp, source in AIPRIMS-285, mode sobol_xdev:
- Computes a reference with the host generator rocrand_create_generator_host_blocking(ROCRAND_RNG_QUASI_SOBOL32), which does not create the device table.
- Per device: hipSetDevice(dev), a non-blocking stream, a device Sobol32 generator on it, rocrand_generate_uniform, synchronize, compare, destroy.
- plain: device 0, then 1. dev1_only: device 1 only. peer: like plain, with hipDeviceEnablePeerAccess(0, 0) on device 1 first.
The failure needs two GPUs, and rocRAND's CI runners have one, so a regression test would GTEST_SKIP everywhere it runs and guard nothing. testing.md already records multi-GPU as explicitly not validated. The fix is verified with the reproducer instead.
Test Result
Before fix:
After fix:
Full test suite passes locally: 0 failed out of 61.
Co-Authored-By: Claude Opus 5 (1M context)