← Back to Pull requests

fix(rocthrust): don't pick up NVIDIA libcu++ in HIP builds #13342

Open
unknown opened this pull request with 406 lines diff across 5 files
View on GitHub
unknown unknown commented on Oct 08, 2026 18:37 UTC
Author

Motivation

Fixes #104. HIP builds of rocThrust fail with reference to __host__ function ... in __host__ __device__ function when NVIDIA's libcu++ headers are in a default include directory (e.g. Debian/Ubuntu libcu++-dev, pulled in by nvidia-cuda-toolkit or libthrust-dev).

thrust/detail/config/libcxx.h probes <cuda/std/version> to detect libhipcxx, but that also matches NVIDIA's libcu++. It pulls in NVIDIA's <nv/target>, which shares its include guard with rocThrust's HIP shim and always selects the host branch of NV_IF_TARGET, even in device code.

Technical Details

In thrust/detail/config/libcxx.h:

  • Select the library by THRUST_DEVICE_SYSTEM, not the compiler, so host-compiled and HIP-compiled sources agree. Non-CUDA device systems only probe libhipcxx's <hip/std/version> alias (exported by its CMake target), which NVIDIA doesn't ship; <cuda/std/version> is only probed for THRUST_DEVICE_SYSTEM_CUDA.

  • Fix the version check in the <hip/std/version> branch (it compared MAJOR against the required MINOR, so the branch could never succeed).

  • #error with a clear message if NVIDIA's <nv/target> is included in a HIP build, instead of many unrelated-looking errors.
  • libcxx.h now includes device_system.h itself, since config.h includes it later (in rocthrust/hipccl2, device_system.h now includes compiler.h for its default). Builds without NVIDIA's headers are functionally unchanged. Applied to projects/rocthrust and the hipccl2/hipccl3 copies.

    Test Plan

    Compiled the reproducer from #104 and a broader smoke test (sort_by_key, scans, unique, copy_if, binary_search) with NVIDIA's libcu++ added via -idirafter to mimic /usr/include: versions 1.6.0, 1.8.1, 1.9.0, 2.3.2, 2.5.0, 2.8.5, 3.0.3 (Debian, Ubuntu and NVIDIA builds). Also: no CCCL, libhipcxx 10.1 (with and without NVIDIA's headers), the old -DUSE_LIBCUDACXX=0 -DUSE_LIBHIPCXX=0 workaround, a g++ host-only build, and device resource usage of a kernel using thrust::seq.

    After review, re-ran with 1.9.0, 2.8.5, 3.0.3 and libhipcxx 385f456 (hipccl3's pin), adding GCC/Clang host TUs with -DTHRUST_DEVICE_SYSTEM=5, a thrust::pair call split between a Clang host TU and a hipcc TU, and a preprocessed-output comparison against develop.

    Test Result

  • Before: every NVIDIA libcu++ version fails. After: all compile in all three copies.

  • libhipcxx is still detected; NVIDIA's headers are no longer included.

  • Device resource usage identical to the clean build; host-only builds no longer pick up NVIDIA's libcu++ either.

  • Host TUs with -DTHRUST_DEVICE_SYSTEM=5 now select the same library as HIP TUs (previously NVIDIA's cuda::std, which failed to link against the HIP TU). Without NVIDIA's headers, preprocessed output matches develop (hipccl3 with libhipcxx differs only in hip::/cuda:: aliases).

  • User code that includes NVIDIA's headers itself now gets the clear #error.
  • No regression test is included. Reviewers: is one wanted? It would compile the reproducer against two small fake NVIDIA headers via a per-test test/<name>.cmake.

    Submission Checklist

  • Look over the contributing guidelines at https://github.com/ROCm/ROCm/blob/develop/CONTRIBUTING.md#pull-requests.
  • Diff: 406 lines (+304 / -102) across 5 files Reviewer: umfranzw Review duration: 77228m
    All Vouch review confidence checks passed
    Residual risk 0.29 = Change Risk (0.52) × (1 − Review Confidence (0.45)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.52 · 406 lines diff across 5 files
    0.52
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    44%
    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.359
    Shallow Review Depth shallow_review_depth
    0.344
    Real PR Conversation Timeline
    1 comments
    "Review active on #13342"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 44.7% 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: 51.8% (MEDIUM) · Higher = larger blast radius
    51.8%
    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: 44.7% · Lower = rushed or shallow review
    44.7%
    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: 28.6% · Safe to merge
    28.6%