Skip to content

Error early when the CUDA backend is used without a CUDA compiler - #11059

Open
abdeltaehass wants to merge 2 commits into
NVIDIA:mainfrom
abdeltaehass:cuda-compiler-check
Open

Error early when the CUDA backend is used without a CUDA compiler#11059
abdeltaehass wants to merge 2 commits into
NVIDIA:mainfrom
abdeltaehass:cuda-compiler-check

Conversation

@abdeltaehass

Copy link
Copy Markdown
Contributor

Including a Thrust header with the default CUDA device system and a non-CUDA compiler failed with ~1300 unrelated CUB errors, starting with unknown type name 'cudaError_t', none of which named the cause.

This adds a check in thrust/system/cuda/config.h that reports it directly:

The Thrust CUDA device system requires a CUDA compiler. Either compile as CUDA,
or set THRUST_DEVICE_SYSTEM to THRUST_DEVICE_SYSTEM_CPP, THRUST_DEVICE_SYSTEM_OMP,
or THRUST_DEVICE_SYSTEM_TBB. Define THRUST_IGNORE_CUDA_COMPILER_CHECK to ignore this.

It goes in thrust/system/cuda/config.h rather than thrust/detail/config/device_system.h because thrust/version.h includes the latter and compiles fine without CUDA today. Placed here it also fires before CUB is pulled in, so the useful line comes first. It does not reduce the total error count, since #error does not stop preprocessing.

Tested with clang++ and g++, C++17 and C++20:

  • message is now the first error for host_vector, sort, universal_vector and device_vector
  • thrust/version.h still compiles
  • THRUST_DEVICE_SYSTEM=CPP unaffected, 0 errors
  • silent under __CUDACC__ and _NVHPC_CUDA
  • THRUST_IGNORE_CUDA_COMPILER_CHECK restores the previous behavior

No test is included: Thrust has no compile-failure test targets and all of its tests are .cu, so there is no harness for a non-CUDA translation unit. The existing THRUST_IGNORE_CUB_VERSION_CHECK error in the same file is untested for the same reason. Happy to add one if you'd like it wired up.

Fixes #806

Including a Thrust header with the default CUDA device system and a
non-CUDA compiler failed with ~1300 unrelated CUB errors that never
named the cause. Add a check in thrust/system/cuda/config.h that reports
it directly, with THRUST_IGNORE_CUDA_COMPILER_CHECK to opt out.

Tested with clang++ and g++, C++17 and C++20:
- message is now the first error for host_vector, sort, universal_vector
  and device_vector
- thrust/version.h still compiles
- THRUST_DEVICE_SYSTEM=CPP unaffected, 0 errors
- silent under __CUDACC__ and _NVHPC_CUDA
- opt-out macro restores the previous behavior

Fixes NVIDIA#806
@abdeltaehass
abdeltaehass requested a review from a team as a code owner August 29, 2026 00:21
@abdeltaehass
abdeltaehass requested a review from elstehle August 29, 2026 00:21
@github-project-automation github-project-automation Bot moved this to Todo in CCCL Aug 29, 2026
@copy-pr-bot

copy-pr-bot Bot commented Aug 29, 2026

Copy link
Copy Markdown
Contributor

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@cccl-authenticator-app cccl-authenticator-app Bot moved this from Todo to In Review in CCCL Aug 29, 2026
@coderabbitai

coderabbitai Bot commented Aug 29, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: ad45215b-d1c7-4f0e-8b4e-4ef468a3e701

📥 Commits

Reviewing files that changed from the base of the PR and between 1fd240a and a8ba9bf.

📒 Files selected for processing (1)
  • thrust/thrust/system/cuda/config.h
🚧 Files skipped from review as they are similar to previous changes (1)
  • thrust/thrust/system/cuda/config.h

Included review availability: Your plan provides up to 12 included reviews per hour; 11 remain after this review.


📝 Walkthrough

Summary by CodeRabbit

  • Bug Fixes
    • Improved the formatting of CUDA compiler error messages by enclosing the reported error text in quotation marks.
    • This makes compiler-related diagnostics easier to distinguish from surrounding information when reviewing build output.

Walkthrough

Changes

CUDA diagnostic

Layer / File(s) Summary
CUDA compiler validation
thrust/thrust/system/cuda/config.h
The non-CUDA compiler diagnostic is now enclosed in quotes. The compiler guard, alternative device-system list, and override macro remain unchanged.

Assessment against linked issues

Objective Addressed Explanation
Improve the diagnostic when the CUDA device system is used in non-CUDA builds [#806]

Suggested reviewers: elstehle

Merge Risk: ⚪ Minimal · up to a8ba9

This localized change improves the error shown when the CUDA backend is used without a CUDA compiler, without introducing a merge-blocking correctness or production risk; it is merge-ready after normal checks and review.


Comment @coderabbitai help to get the list of available commands.

Comment thread thrust/thrust/system/cuda/config.h Outdated
Comment on lines +17 to +20
#if !_CCCL_CUDA_COMPILATION() && !defined(THRUST_IGNORE_CUDA_COMPILER_CHECK)
# error The Thrust CUDA device system requires a CUDA compiler. Either compile as CUDA, or set \
THRUST_DEVICE_SYSTEM to THRUST_DEVICE_SYSTEM_CPP, THRUST_DEVICE_SYSTEM_OMP, or THRUST_DEVICE_SYSTEM_TBB. \
Define THRUST_IGNORE_CUDA_COMPILER_CHECK to ignore this.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe we conventionally add quotes around the error string

Suggested change
#if !_CCCL_CUDA_COMPILATION() && !defined(THRUST_IGNORE_CUDA_COMPILER_CHECK)
# error The Thrust CUDA device system requires a CUDA compiler. Either compile as CUDA, or set \
THRUST_DEVICE_SYSTEM to THRUST_DEVICE_SYSTEM_CPP, THRUST_DEVICE_SYSTEM_OMP, or THRUST_DEVICE_SYSTEM_TBB. \
Define THRUST_IGNORE_CUDA_COMPILER_CHECK to ignore this.
#if !_CCCL_CUDA_COMPILATION() && !defined(THRUST_IGNORE_CUDA_COMPILER_CHECK)
# error "The Thrust CUDA device system requires a CUDA compiler. Either compile as CUDA, or set \
THRUST_DEVICE_SYSTEM to THRUST_DEVICE_SYSTEM_CPP, THRUST_DEVICE_SYSTEM_OMP, or THRUST_DEVICE_SYSTEM_TBB. \
Define THRUST_IGNORE_CUDA_COMPILER_CHECK to ignore this."

Review feedback: CCCL conventionally wraps #error strings in quotes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In Review

Development

Successfully merging this pull request may close these issues.

Improve diagnostic when the (default) CUDA device system is used in non-CUDA builds.

2 participants