Skip to content

Commit e8fb612

Browse files
committed
Support mcc20 C++20 MUSA builds
1 parent d9dd4fd commit e8fb612

8 files changed

Lines changed: 59 additions & 26 deletions

File tree

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ endif()
1212
set( CMAKE_INSTALL_PREFIX "/usr/local/musa" CACHE PATH
1313
"Install path prefix, prepended onto install directories" )
1414
set ( VERSION_STRING "1.17.2" )
15-
project(Thrust VERSION ${VERSION_STRING})
15+
project(Thrust VERSION ${VERSION_STRING} LANGUAGES NONE)
1616
# MUSA Configuration
1717
include(cmake/SimpleMUSA.cmake)
1818

cmake/SimpleMUSA.cmake

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,40 @@
11
# SimpleMUSA.cmake
22
# Minimal MUSA configuration without external dependencies
33

4-
# Set MUSA paths
5-
set(MUSA_ROOT "/usr/local/musa" CACHE PATH "MUSA toolkit root directory")
6-
set(MUSA_INCLUDE_DIR "${MUSA_ROOT}/include")
7-
set(MUSA_LIBRARY_DIR "${MUSA_ROOT}/lib")
4+
# Set MUSA paths. MUSA_ROOT points at the runtime toolkit, while
5+
# MUSA_COMPILER_ROOT may point at an alternate mcc compiler install.
6+
set(MUSA_ROOT "/usr/local/musa" CACHE PATH "MUSA runtime toolkit root directory")
7+
set(MUSA_COMPILER_ROOT "${MUSA_ROOT}" CACHE PATH "MUSA compiler root directory")
8+
set(MUSA_INCLUDE_DIR "${MUSA_ROOT}/include" CACHE PATH "MUSA runtime include directory")
9+
set(MUSA_LIBRARY_DIR "${MUSA_ROOT}/lib" CACHE PATH "MUSA runtime library directory")
10+
set(MUSA_COMPILER_INCLUDE_DIR "${MUSA_COMPILER_ROOT}/include" CACHE PATH "MUSA compiler include directory")
811

912
# Find MUSA compiler (mcc)
1013
find_program(MCC_EXECUTABLE
1114
NAMES mcc
12-
PATHS "${MUSA_ROOT}/bin"
15+
PATHS "${MUSA_COMPILER_ROOT}/bin"
1316
ENV MUSA_PATH
1417
ENV MUSA_BIN_PATH
1518
PATH_SUFFIXES bin
19+
NO_DEFAULT_PATH
1620
)
1721

1822
if(NOT MCC_EXECUTABLE)
19-
message(FATAL_ERROR "MUSA compiler (mcc) not found. Set MUSA_ROOT or MUSA_PATH.")
23+
find_program(MCC_EXECUTABLE
24+
NAMES mcc
25+
ENV MUSA_PATH
26+
ENV MUSA_BIN_PATH
27+
PATH_SUFFIXES bin
28+
)
29+
endif()
30+
31+
if(NOT MCC_EXECUTABLE)
32+
message(FATAL_ERROR "MUSA compiler (mcc) not found. Set MUSA_COMPILER_ROOT, MUSA_ROOT, or MUSA_PATH.")
2033
endif()
2134

2235
message(STATUS "Found MUSA compiler: ${MCC_EXECUTABLE}")
36+
message(STATUS "MUSA compiler root: ${MUSA_COMPILER_ROOT}")
37+
message(STATUS "MUSA runtime root: ${MUSA_ROOT}")
2338

2439
# Set MUSA_FOUND so ThrustCudaConfig.cmake can detect MUSA
2540
set(MUSA_FOUND TRUE CACHE INTERNAL "MUSA found")
@@ -43,6 +58,9 @@ message(STATUS "Found MUSA library: ${MUSA_LIBRARY}")
4358
set(CMAKE_CXX_COMPILER "${MCC_EXECUTABLE}" CACHE FILEPATH "C++ compiler" FORCE)
4459

4560
# Add MUSA path to compile options globally
61+
if(EXISTS "${MUSA_COMPILER_INCLUDE_DIR}")
62+
add_compile_options(-isystem ${MUSA_COMPILER_INCLUDE_DIR})
63+
endif()
4664
add_compile_options(--musa-path=${MUSA_ROOT})
4765

4866
# Set default MUSA architecture if not specified
@@ -122,8 +140,12 @@ function(musa_add_executable target_name)
122140
# Link MUSA runtime (no keyword to match existing code)
123141
target_link_libraries(${target_name} ${MUSA_LIBRARY})
124142

125-
# Include MUSA headers (use include_directories for directory-level)
126-
include_directories(${MUSA_INCLUDE_DIR})
143+
# Prefer compiler-matched headers such as mp_ext_32_intrinsics.h, while
144+
# still taking the runtime API and musart from MUSA_ROOT.
145+
if(EXISTS "${MUSA_COMPILER_INCLUDE_DIR}")
146+
target_include_directories(${target_name} SYSTEM BEFORE PRIVATE ${MUSA_COMPILER_INCLUDE_DIR})
147+
endif()
148+
target_include_directories(${target_name} SYSTEM PRIVATE ${MUSA_INCLUDE_DIR})
127149
endfunction()
128150

129151
# Function to build MUSA libraries
@@ -185,6 +207,10 @@ function(musa_add_library target_name)
185207
# Link MUSA runtime (no keyword to match existing code)
186208
target_link_libraries(${target_name} ${MUSA_LIBRARY})
187209

188-
# Include MUSA headers (use include_directories for directory-level)
189-
include_directories(${MUSA_INCLUDE_DIR})
210+
# Prefer compiler-matched headers such as mp_ext_32_intrinsics.h, while
211+
# still taking the runtime API and musart from MUSA_ROOT.
212+
if(EXISTS "${MUSA_COMPILER_INCLUDE_DIR}")
213+
target_include_directories(${target_name} SYSTEM BEFORE PRIVATE ${MUSA_COMPILER_INCLUDE_DIR})
214+
endif()
215+
target_include_directories(${target_name} SYSTEM PRIVATE ${MUSA_INCLUDE_DIR})
190216
endfunction()

cmake/ThrustBuildCompilerTargets.cmake

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
# thrust.compiler_interface_cpp11
1010
# thrust.compiler_interface_cpp14
1111
# thrust.compiler_interface_cpp17
12+
# thrust.compiler_interface_cpp20
1213
# - Interface targets providing compiler-specific options that should only be
1314
# applied to certain dialects of C++.
1415
#
@@ -129,6 +130,14 @@ function(thrust_build_compiler_targets)
129130
"-Wno-deprecated-declarations"
130131
"-Wno-pass-failed"
131132
)
133+
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND
134+
CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 20)
135+
list(APPEND cxx_compile_options
136+
"-Wno-deprecated-builtins"
137+
"-Wno-deprecated-volatile"
138+
"-Wno-deprecated-anon-enum-enum-conversion"
139+
)
140+
endif()
132141
message(STATUS "Thrust: MUSA compiler detected: Suppressing selected warnings")
133142
endif()
134143
endif()
@@ -211,6 +220,7 @@ function(thrust_build_compiler_targets)
211220
add_library(thrust.compiler_interface_cpp11 INTERFACE)
212221
add_library(thrust.compiler_interface_cpp14 INTERFACE)
213222
add_library(thrust.compiler_interface_cpp17 INTERFACE)
223+
add_library(thrust.compiler_interface_cpp20 INTERFACE)
214224

215225
if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
216226
# C4127: conditional expression is constant

cmake/ThrustBuildTargetList.cmake

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
# - <prop> is one of the following:
2020
# - HOST: The host system. Valid values: CPP, OMP, TBB.
2121
# - DEVICE: The device system. Valid values: CUDA, CPP, OMP, TBB.
22-
# - DIALECT: The C++ dialect. Valid values: 11, 14, 17.
22+
# - DIALECT: The C++ dialect. Valid values: 11, 14, 17, 20.
2323
# - PREFIX: A unique prefix that should be used to name all
2424
# targets/tests/examples that use this configuration.
2525
#
@@ -43,8 +43,8 @@ define_property(TARGET PROPERTY _THRUST_DEVICE
4343
FULL_DOCS "A target's device system: CUDA, CPP, TBB, or OMP."
4444
)
4545
define_property(TARGET PROPERTY _THRUST_DIALECT
46-
BRIEF_DOCS "A target's C++ dialect: 11, 14, or 17."
47-
FULL_DOCS "A target's C++ dialect: 11, 14, or 17."
46+
BRIEF_DOCS "A target's C++ dialect: 11, 14, 17, or 20."
47+
FULL_DOCS "A target's C++ dialect: 11, 14, 17, or 20."
4848
)
4949
define_property(TARGET PROPERTY _THRUST_PREFIX
5050
BRIEF_DOCS "A prefix describing the config, eg. 'thrust.cpp.cuda.cpp14'."

cmake/ThrustMultiConfig.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ function(thrust_configure_multiconfig)
77

88
# Dialects:
99
set(THRUST_CPP_DIALECT_OPTIONS
10-
11 14 17
10+
11 14 17 20
1111
CACHE INTERNAL "C++ dialects supported by Thrust." FORCE
1212
)
1313

thrust/detail/type_traits.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -724,7 +724,8 @@ struct is_empty_helper_base
724724

725725
template<typename T>
726726
struct is_empty : integral_constant<bool,
727-
sizeof(is_empty_helper_base) == sizeof(is_empty_helper<T>)
727+
sizeof(is_empty_helper_base) ==
728+
sizeof(is_empty_helper<typename remove_cv<T>::type>)
728729
>
729730
{
730731
};
@@ -738,4 +739,3 @@ using detail::false_type;
738739
THRUST_NAMESPACE_END
739740

740741
#include <thrust/detail/type_traits/has_trivial_assign.h>
741-

thrust/optional.h

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2767,14 +2767,12 @@ template <class T> class optional<T &> {
27672767
///
27682768
/// \group emplace
27692769
__thrust_exec_check_disable__
2770-
template <class... Args>
2770+
template <class U = T>
27712771
__host__ __device__
2772-
T &emplace(Args &&... args) noexcept {
2773-
static_assert(std::is_constructible<T, Args &&...>::value,
2774-
"T must be constructible with Args");
2775-
2776-
*this = nullopt;
2777-
this->construct(std::forward<Args>(args)...);
2772+
T &emplace(U &&u) noexcept {
2773+
static_assert(std::is_lvalue_reference<U>::value, "U must be an lvalue");
2774+
m_value = addressof(u);
2775+
return *m_value;
27782776
}
27792777

27802778
/// Swaps this optional with the other.
@@ -2894,4 +2892,3 @@ template <class T> struct hash<THRUST_NS_QUALIFIER::optional<T>> {
28942892
} // namespace std
28952893

28962894
#endif // THRUST_CPP_DIALECT >= 2011
2897-

0 commit comments

Comments
 (0)