Skip to content

Commit 6d87519

Browse files
committed
[SYCL] Add a static_assert/check that app and sycl use consistent C++ RT on win
SYCL library is designed such a way that STL objects must cross the sycl.dll boundary, which is guaranteed to work safe on Windows only if the runtime in the app using sycl.dll and in sycl.dll is the same and is dynamic. It is not possible to implement safe approach for using sycl libraries built/linked with static C++ RT as it would cause having multiple copies of C++ objects (such as scheduler, etc), which are supposed to be singletones. This check reports a compile-time error when user tries to compile the application using sycl.dll with /MT or /MTd switches implying using static C++ runtime libcmt[d].lib. sycl.dll is built with /MD and sycld.dll is built with /MDd. Thus /MD and /MDd are allowed, and /MT /MTd switches are prohibited now.
1 parent 93081e1 commit 6d87519

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

sycl/include/CL/sycl/stl.hpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,27 @@
2222
__SYCL_INLINE_NAMESPACE(cl) {
2323
namespace sycl {
2424

25+
#ifdef _WIN32
26+
namespace detail {
27+
// SYCL library is designed such a way that STL objects cross DLL boundary,
28+
// which is not guaranteed to work and considered not safe.
29+
// Using same dynamic C++ runtime library for sycl[d].dll and for
30+
// the application using sycl[d].dll is guaranteed to work properly.
31+
inline constexpr bool isMSVCDynamicCXXRuntime() {
32+
// The options /MD and /MDd that make the code to use dynamic runtime also
33+
// define the _DLL macro.
34+
#ifdef _DLL
35+
return true;
36+
#else
37+
return false;
38+
#endif
39+
}
40+
static_assert(isMSVCDynamicCXXRuntime(),
41+
"SYCL library is designed to work with dynamic C++ runtime, "
42+
"please use /MD or /MDd switches.");
43+
} // namespace detail
44+
#endif // _WIN32
45+
2546
template < class T, class Alloc = std::allocator<T> >
2647
using vector_class = std::vector<T, Alloc>;
2748

0 commit comments

Comments
 (0)