Skip to content
This repository has been archived by the owner on Mar 21, 2024. It is now read-only.

Commit

Permalink
Fix clang / nvcc CI build
Browse files Browse the repository at this point in the history
  • Loading branch information
gevtushenko committed Mar 5, 2023
1 parent f80316a commit c3ddc5f
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 1 deletion.
17 changes: 17 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,23 @@ else()
set(THRUST_TOPLEVEL_PROJECT OFF)
endif()

## thrust_fix_clang_nvcc_build_for
#
# Modifies the given target to include a fix for the clang host compiler case.
# The fix consists of force-including a header into each compilation unit.
#
function(thrust_fix_clang_nvcc_build_for target)
if (UNIX)
# Path to the header containing the fix for clang + nvcc < 11.6. For more info,
# check the content of this header.
set(clang_fix_header_path "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/testing/fix_clang_nvcc_11.5.h")

# Only affects host compiler
target_compile_options(${target} PRIVATE
$<$<COMPILE_LANGUAGE:CUDA>:-include"${clang_fix_header_path}">)
endif()
endfunction()

# This must be done before any languages are enabled:
if (THRUST_TOPLEVEL_PROJECT)
include(cmake/ThrustCompilerHacks.cmake)
Expand Down
2 changes: 2 additions & 0 deletions cmake/ThrustHeaderTesting.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ foreach(thrust_target IN LISTS THRUST_TARGETS)
)
endif()

thrust_fix_clang_nvcc_build_for(${headertest_target})

add_dependencies(thrust.all.headers ${headertest_target})
add_dependencies(${config_prefix}.all ${headertest_target})
endforeach()
1 change: 1 addition & 0 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ function(thrust_add_example target_name_var example_name example_src thrust_targ
target_link_libraries(${example_target} ${thrust_target})
target_include_directories(${example_target} PRIVATE "${Thrust_SOURCE_DIR}/examples")
thrust_clone_target_properties(${example_target} ${thrust_target})
thrust_fix_clang_nvcc_build_for(${example_target})

# Add to the active configuration's meta target
add_dependencies(${config_meta_target} ${example_target})
Expand Down
1 change: 1 addition & 0 deletions internal/benchmark/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ foreach(thrust_target IN LISTS THRUST_TARGETS)
target_link_libraries(${bench_target} PRIVATE ${thrust_target})
target_include_directories(${bench_target} PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}")
thrust_clone_target_properties(${bench_target} ${thrust_target})
thrust_fix_clang_nvcc_build_for(${bench_target})

add_dependencies(thrust.all.bench ${bench_target})
add_dependencies(${config_prefix}.all ${bench_target})
Expand Down
2 changes: 2 additions & 0 deletions testing/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ function(thrust_add_test target_name_var test_name test_src thrust_target)
target_compile_definitions(${test_target} PRIVATE THRUST_TEST_DEVICE_SIDE)
endif()

thrust_fix_clang_nvcc_build_for(${test_target})

# Add to the active configuration's meta target
add_dependencies(${config_meta_target} ${test_target})

Expand Down
1 change: 0 additions & 1 deletion testing/cuda/copy_if.cu
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#include <thrust/sequence.h>
#include <thrust/execution_policy.h>


template<typename T>
struct is_even
{
Expand Down
2 changes: 2 additions & 0 deletions testing/cuda/stream_per_thread.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ set_target_properties(${test_target} PROPERTIES
$<$<AND:$<COMPILE_LANGUAGE:CUDA>,$<CUDA_COMPILER_ID:NVIDIA>>:--default-stream=per-thread>
)

thrust_fix_clang_nvcc_build_for(${test_target})

# NVC++ does not have an equivalent option, and will always
# use the global stream by default.
if (CMAKE_CUDA_COMPILER_ID STREQUAL "Feta")
Expand Down
24 changes: 24 additions & 0 deletions testing/fix_clang_nvcc_11.5.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#pragma once

#if defined(__NVCC__) && defined(__clang__) && __CUDACC_VER_MAJOR__ == 11 && \
__CUDACC_VER_MINOR__ <= 5

#if defined(__NVCC_DIAG_PRAGMA_SUPPORT__)
# pragma nv_diag_suppress 3171
#else
# pragma diag_suppress 3171
#endif

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wkeyword-compat"

// Clang has a builtin called `__is_signed`. Unfortunately, libstdc++ headers
// use this name as an identifier. Clang has a workaround for that, it checks
// if `__is_signed` is `const static bool` as in libstdc++ headers and if so,
// disables the intrinsic for the rest of the TU:
// https://github.com/llvm/llvm-project/blob/f49b6afc231242dfee027d5da69734836097cd43/clang/lib/Parse/ParseDecl.cpp#L3552-L3566
const static bool __is_signed = false;

#pragma clang diagnostic pop
#endif // defined(__NVCC__) && defined(__clang__) && __CUDACC_VER_MAJOR__ == 11 &&
// __CUDACC_VER_MINOR__ <= 5
3 changes: 3 additions & 0 deletions testing/unittest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,7 @@ foreach(thrust_target IN LISTS THRUST_TARGETS)
target_link_libraries(${framework_target} PUBLIC ${thrust_target})
target_include_directories(${framework_target} PRIVATE "${Thrust_SOURCE_DIR}/testing")
thrust_clone_target_properties(${framework_target} ${thrust_target})

thrust_fix_clang_nvcc_build_for(${framework_target})

endforeach()

0 comments on commit c3ddc5f

Please sign in to comment.