← Back to Pull requests

fix(rocrand): Device Sobol generator on second GPU faults or hangs #16673

Closed
unknown closed this pull request without merging on Nov 30, 2026 20:00 UTC
View on GitHub
unknown unknown commented on Nov 24, 2026 20:38 UTC
Author

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:

  • plain: device 0 had 0 mismatches of 1,048,576; on device 1 the kernel faulted. Memory access fault by GPU node-3, kernel generate_sobol_kernel<1u, false, sobol32_engine<true>, unsigned int, float, sobol_uniform_distribution<float>, 256>. Process aborted, exit 134.
  • After fix:

  • plain: 0 mismatches of 1,048,576, exit 0
  • Full test suite passes locally: 0 failed out of 61.

  • [X] Look over the contributing guidelines at https://github.com/ROCm/ROCm/blob/develop/CONTRIBUTING.md#pull-requests.
  • Co-Authored-By: Claude Opus 5 (1M context)

    Diff: 397 lines (+297 / -100) across 4 files Reviewer: amd-jmahovsky Review duration: 8602m
    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
    0.43
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    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
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 43.2% (MEDIUM) · Higher = larger blast radius
    43.2%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 17.1% · Safe to merge
    17.1%