Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG]: thrust/execution_policy.h is not safe to include without cuda runtime available #3483

Open
1 task done
vyasr opened this issue Jan 22, 2025 · 3 comments
Open
1 task done
Labels
bug Something isn't working right.

Comments

@vyasr
Copy link
Contributor

vyasr commented Jan 22, 2025

Is this a duplicate?

Type of Bug

Compile-time Error

Component

Thrust

Describe the bug

Including the execution_policy.h file in a TU being compiled by a host compiler without the CUDA runtime libraries present triggers an immediate compile error:

In file included from /home/vyasr/local/cccl/examples/basic/build/_deps/cccl-src/lib/cmake/thrust/../../../thrust/thrust/system/cuda/config.h:48,
                 from /home/vyasr/local/cccl/examples/basic/build/_deps/cccl-src/lib/cmake/thrust/../../../thrust/thrust/system/cuda/detail/execution_policy.h:40,
                 from /home/vyasr/local/cccl/examples/basic/build/_deps/cccl-src/lib/cmake/thrust/../../../thrust/thrust/iterator/detail/device_system_tag.h:31,
                 from /home/vyasr/local/cccl/examples/basic/build/_deps/cccl-src/lib/cmake/thrust/../../../thrust/thrust/iterator/iterator_traits.h:74,
                 from /home/vyasr/local/cccl/examples/basic/build/_deps/cccl-src/lib/cmake/thrust/../../../thrust/thrust/detail/type_traits/pointer_traits.h:31,
                 from /home/vyasr/local/cccl/examples/basic/build/_deps/cccl-src/lib/cmake/thrust/../../../thrust/thrust/detail/allocator/allocator_traits.h:37,
                 from /home/vyasr/local/cccl/examples/basic/build/_deps/cccl-src/lib/cmake/thrust/../../../thrust/thrust/detail/execute_with_allocator.h:29,
                 from /home/vyasr/local/cccl/examples/basic/build/_deps/cccl-src/lib/cmake/thrust/../../../thrust/thrust/execution_policy.h:32,
                 from /home/vyasr/local/cccl/examples/basic/example.cpp:1:
/home/vyasr/local/cccl/examples/basic/build/_deps/cccl-src/lib/cmake/cub/../../../cub/cub/detail/detect_cuda_runtime.cuh:49:12: fatal error: cuda_runtime_api.h: No such file or direct
ory
   49 | #  include <cuda_runtime_api.h>

How to Reproduce

With this CMake:

cmake_minimum_required(VERSION 3.26.1 FATAL_ERROR)
project(ExecutionPolicyError CXX)
file(DOWNLOAD
        https://github.com/cpm-cmake/CPM.cmake/releases/download/v0.40.2/CPM.cmake
    ${CMAKE_CURRENT_BINARY_DIR}/CPM.cmake LOG download_log)
include(${CMAKE_CURRENT_BINARY_DIR}/CPM.cmake)
CPMAddPackage(
    NAME CCCL
    GITHUB_REPOSITORY nvidia/cccl
    GIT_TAG main
)
add_executable(example_project example.cpp)
target_link_libraries(example_project PRIVATE CCCL::CCCL)

and this C++ file

#include <thrust/execution_policy.h>

running cmake -S . -B build/ && cmake --build build/ is sufficient to trigger the compilation error.

Expected behavior

Thrust should be safe to include in host TUs without the CUDA libraries available.

Reproduction link

No response

Operating System

Ubuntu Linux 24.04

nvidia-smi output

N/A (not using GPU)

NVCC version

N/A (not using nvcc)

@bernhardmgruber
Copy link
Contributor

Reproducer: https://godbolt.org/z/4MY4x8WG3

@bernhardmgruber
Copy link
Contributor

I think this is expected. If you don't specify the device system to use (not defining -THRUST_DEVICE_SYSTEM), the CUDA system is used, so it expects to be compiled by a CUDA compiler. If you want to use a different device system, you can specify this either in cmake or by telling the compiler, e.g. via -DTHRUST_DEVICE_SYSTEM=4 for the CPP device system. This makes the error disappear.

What cannot work is to compile for the CUDA device system and not using a CUDA compiler.

@vyasr
Copy link
Contributor Author

vyasr commented Jan 24, 2025

I think the only question would be whether compiler detection should be used to determine a default target device, i.e. if you're compiling with a host compiler should you target the host by default unless the system is specified? That would be a huge behavior change of course so I'm not proposing it lightly, but it's worth asking the question.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working right.
Projects
Status: Todo
Development

No branches or pull requests

2 participants