Skip to content

Commit 8199b47

Browse files
committed
[CUDA][HIP] Fix std::is_invocable
Currently std::is_invocable does not work for CUDA/HIP since its implementation requires checking whether a function is invocable in the context of a synthesized host function. In general, to make <type_traits> work with CUDA/HIP, the template functions need to be defined as so that they are available in both host and device contexts. Fixes: #69956 Fixes: SWDEV-428314
1 parent 278d557 commit 8199b47

File tree

5 files changed

+57
-2
lines changed

5 files changed

+57
-2
lines changed

clang/lib/Headers/CMakeLists.txt

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,12 +283,18 @@ set(cuda_wrapper_files
283283
cuda_wrappers/cmath
284284
cuda_wrappers/complex
285285
cuda_wrappers/new
286+
cuda_wrappers/type_traits
286287
)
287288

288289
set(cuda_wrapper_bits_files
289290
cuda_wrappers/bits/shared_ptr_base.h
290291
cuda_wrappers/bits/basic_string.h
291292
cuda_wrappers/bits/basic_string.tcc
293+
cuda_wrappers/bits/move.h
294+
)
295+
296+
set(cuda_wrapper_utility_files
297+
cuda_wrappers/__utility/swap.h
292298
)
293299

294300
set(ppc_wrapper_files
@@ -363,7 +369,7 @@ endfunction(clang_generate_header)
363369
# Copy header files from the source directory to the build directory
364370
foreach( f ${files} ${cuda_wrapper_files} ${cuda_wrapper_bits_files}
365371
${ppc_wrapper_files} ${openmp_wrapper_files} ${hlsl_files}
366-
${llvm_libc_wrapper_files})
372+
${llvm_libc_wrapper_files} ${cuda_wrapper_utility_files})
367373
copy_header_to_output_dir(${CMAKE_CURRENT_SOURCE_DIR} ${f})
368374
endforeach( f )
369375

@@ -468,7 +474,7 @@ add_header_target("arm-common-resource-headers" "${arm_common_files};${arm_commo
468474
# Architecture/platform specific targets
469475
add_header_target("arm-resource-headers" "${arm_only_files};${arm_only_generated_files}")
470476
add_header_target("aarch64-resource-headers" "${aarch64_only_files};${aarch64_only_generated_files}")
471-
add_header_target("cuda-resource-headers" "${cuda_files};${cuda_wrapper_files};${cuda_wrapper_bits_files}")
477+
add_header_target("cuda-resource-headers" "${cuda_files};${cuda_wrapper_files};${cuda_wrapper_bits_files};${cuda_wrapper_utility_files}")
472478
add_header_target("hexagon-resource-headers" "${hexagon_files}")
473479
add_header_target("hip-resource-headers" "${hip_files}")
474480
add_header_target("loongarch-resource-headers" "${loongarch_files}")
@@ -561,6 +567,12 @@ install(
561567
EXCLUDE_FROM_ALL
562568
COMPONENT cuda-resource-headers)
563569

570+
install(
571+
FILES ${cuda_wrapper_utility_files}
572+
DESTINATION ${header_install_dir}/cuda_wrappers/__utility
573+
EXCLUDE_FROM_ALL
574+
COMPONENT cuda-resource-headers)
575+
564576
install(
565577
FILES ${cuda_files}
566578
DESTINATION ${header_install_dir}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#pragma clang force_cuda_host_device begin
2+
#include_next "__utility/swap.h"
3+
#pragma clang force_cuda_host_device end
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#pragma clang force_cuda_host_device begin
2+
#include_next "bits/move.h"
3+
#pragma clang force_cuda_host_device end

clang/lib/Headers/cuda_wrappers/cmath

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@
2727
#include_next <cmath>
2828

2929
#if defined(_LIBCPP_STD_VER)
30+
#if !defined(_LIBCPP_CONSTEXPR_SINCE_CXX14)
31+
#define _LIBCPP_CONSTEXPR_SINCE_CXX14
32+
#endif
33+
#if !defined(_LIBCPP_CONSTEXPR_SINCE_CXX20)
34+
#define _LIBCPP_CONSTEXPR_SINCE_CXX20
35+
#endif
3036

3137
// libc++ will need long double variants of these functions, but CUDA does not
3238
// provide them. We'll provide their declarations, which should allow the
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*===---- type_traits - CUDA wrapper for <type_traits> ---------------------===
2+
*
3+
* Permission is hereby granted, free of charge, to any person obtaining a copy
4+
* of this software and associated documentation files (the "Software"), to deal
5+
* in the Software without restriction, including without limitation the rights
6+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
* copies of the Software, and to permit persons to whom the Software is
8+
* furnished to do so, subject to the following conditions:
9+
*
10+
* The above copyright notice and this permission notice shall be included in
11+
* all copies or substantial portions of the Software.
12+
*
13+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19+
* THE SOFTWARE.
20+
*
21+
*===-----------------------------------------------------------------------===
22+
*/
23+
24+
#ifndef __CLANG_CUDA_WRAPPERS_TYPE_TRAITS
25+
#define __CLANG_CUDA_WRAPPERS_TYPE_TRAITS
26+
27+
#pragma clang force_cuda_host_device begin
28+
#include_next <type_traits>
29+
#pragma clang force_cuda_host_device end
30+
31+
#endif // __CLANG_CUDA_WRAPPERS_TYPE_TRAITS

0 commit comments

Comments
 (0)