Skip to content

Commit 5c9c9e7

Browse files
Workaround missing cudaLaunchKernelEx on MSVC
cudaLaunchKernelEx requires C++11, but unfortunately <cuda_runtime.h> checks this using the __cplusplus macro, which is reported wrongly for MSVC. CTK 12.3 fixed this by additionally detecting _MSV_VER. As a workaround, we provide our own copy of cudaLaunchKernelEx when it is not available from the CTK.
1 parent 4babbfa commit 5c9c9e7

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

thrust/thrust/system/cuda/detail/core/triple_chevron_launch.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,22 @@ struct _CCCL_VISIBILITY_HIDDEN triple_chevron
6767
, stream(stream_)
6868
{}
6969

70+
// cudaLaunchKernelEx requires C++11, but unfortunately <cuda_runtime.h> checks this using the __cplusplus macro,
71+
// which is reported wrongly for MSVC. CTK 12.3 fixed this by additionally detecting _MSV_VER. As a workaround, we
72+
// provide our own copy of cudaLaunchKernelEx when it is not available from the CTK.
73+
#if _CCCL_COMPILER(MSVC) && _CCCL_CUDACC_BELOW(12, 3)
74+
// Copied from <cuda_runtime.h>
75+
template <typename... ExpTypes, typename... ActTypes>
76+
cudaError_t _CCCL_HOST
77+
cudaLaunchKernelEx_MSVC_workaround(const cudaLaunchConfig_t* config, void (*kernel)(ExpTypes...), ActTypes&&... args)
78+
{
79+
return [&](ExpTypes... coercedArgs) {
80+
void* pArgs[] = {&coercedArgs...};
81+
return ::cudaLaunchKernelExC(config, (const void*) kernel, pArgs);
82+
}(std::forward<ActTypes>(args)...);
83+
}
84+
#endif
85+
7086
template <class K, class... Args>
7187
cudaError_t _CCCL_HOST doit_host(K k, Args const&... args) const
7288
{
@@ -84,7 +100,11 @@ struct _CCCL_VISIBILITY_HIDDEN triple_chevron
84100
config.stream = stream;
85101
config.attrs = attribute;
86102
config.numAttrs = 1;
103+
# if _CCCL_COMPILER(MSVC) && _CCCL_CUDACC_BELOW(12, 3)
104+
cudaLaunchKernelEx_MSVC_workaround(&config, k, args...);
105+
# else
87106
cudaLaunchKernelEx(&config, k, args...);
107+
# endif
88108
}
89109
else
90110
#endif // _THRUST_HAS_PDL

0 commit comments

Comments
 (0)