Skip to content

[BUG]: Libcudaxx headers such as <cuda/stream_ref> should compile even without CUDA compilers #3372

@caugonnet

Description

@caugonnet

Is this a duplicate?

Type of Bug

Compile-time Error

Component

libcu++

Describe the bug

When using non CUDA compilers on the <cuda/stream_ref> header from libcudacxx, the ::cuda::__throw_cuda_error(__result, "Failed to query stream."); call is not compiling because libcudacxx/include/cuda/std/__exception/cuda_error.h only defines __throw_cuda_error for CUDA compilers.

This issue is raised in practice when compiling cuGraph with a recent version of CCCL.

One strategy could be to implement ::cuda::__throw_cuda_error for non CUDA compilers (#3369 ) but the first argument is a cudaError_t which is not necessarily defined (eg. in Thrust with a host backend). Pretending we did implement it by simply throwing away the cuda error is also a suspicious strategy.

The other strategy is to adapt call sites (<cuda/stream_ref> in this case) to avoid ::cuda::__throw_cuda_error. This is what #3370 implements, but does a lot of code bloating to replace ::cuda::__throw_cuda_error(__result, "Failed to query stream."); in the "unlikely" situation where we have a non CUDA compiler.

#  ifdef _CCCL_HAS_CUDA_COMPILER
        ::cuda::__throw_cuda_error(__result, "Failed to query stream.");
#  else
#    ifndef _CCCL_NO_EXCEPTIONS
        throw ::std::runtime_error("Failed to query stream.");
#    else
        ::std::terminate();
#    else
#    endif

How to Reproduce

Compile the cpp lib for that branch which updates CCCL in cuGraph rapidsai/cugraph#4833

Expected behavior

  • Provide a <cuda/stream_ref> which can be included from any C++ compiler
  • Define/Document whether ::cuda::__throw_cuda_error can be used without a CUDA compiler

Infrastructure :

  • Possibly add CI tests to assess whether CCCL features are available on non CUDA compilers
  • Automatically check in CI that all headers can be included from g++/clang even if features are disabled (generating some simple code that includes the file with an int main() {} ?)

Reproduction link

No response

Operating System

No response

nvidia-smi output

No response

NVCC version

No response

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions