Skip to content

Commit d4180f4

Browse files
authored
[SYCL] Warning if use sycl without dynamic C++ RT on Windows (#2501)
With -fsycl switch the dynamic runtime is used. The patches (#2478, #2480, #2497 implemented that with -fsycl. Applications using sycl headers and linked with sycl[d].dll must be linked with dynamic C++ runtime on Windows even if compiled without -fsycl. This patch adds a compile time warning emitted when wrong C++ runtime is used. Signed-off-by: Vyacheslav N Klochkov <[email protected]>
1 parent 0a990f8 commit d4180f4

24 files changed

+89
-84
lines changed

sycl/include/CL/sycl/stl.hpp

Lines changed: 50 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -22,34 +22,53 @@
2222
__SYCL_INLINE_NAMESPACE(cl) {
2323
namespace sycl {
2424

25-
template < class T, class Alloc = std::allocator<T> >
26-
using vector_class = std::vector<T, Alloc>;
27-
28-
using string_class = std::string;
29-
30-
template <class Sig>
31-
using function_class = std::function<Sig>;
32-
33-
using mutex_class = std::mutex;
34-
35-
template <class T, class Deleter = std::default_delete<T>>
36-
using unique_ptr_class = std::unique_ptr<T, Deleter>;
37-
38-
template <class T>
39-
using shared_ptr_class = std::shared_ptr<T>;
40-
41-
template <class T>
42-
using weak_ptr_class = std::weak_ptr<T>;
43-
44-
template <class T>
45-
using hash_class = std::hash<T>;
46-
47-
using exception_ptr_class = std::exception_ptr;
48-
49-
template <typename T, typename... ArgsT>
50-
unique_ptr_class<T> make_unique_ptr(ArgsT &&... Args) {
51-
return unique_ptr_class<T>(new T(std::forward<ArgsT>(Args)...));
52-
}
53-
} // sycl
54-
} // cl
55-
25+
#if defined(_WIN32) && !defined(_DLL) && !defined(__SYCL_DEVICE_ONLY__)
26+
// SYCL library is designed such a way that STL objects cross DLL boundary,
27+
// which is guaranteed to work properly only when the application uses the same
28+
// C++ runtime that SYCL library uses.
29+
// The appplications using sycl.dll must be linked with dynamic/release C++ MSVC
30+
// runtime, i.e. be compiled with /MD switch. Similarly, the applications using
31+
// sycld.dll must be linked with dynamic/debug C++ runtime and be compiled with
32+
// /MDd switch.
33+
// Compiler automatically adds /MD or /MDd when -fsycl switch is used.
34+
// The options /MD and /MDd that make the code to use dynamic runtime also
35+
// define the _DLL macro.
36+
#if defined(_MSC_VER)
37+
#pragma message( \
38+
"SYCL library is designed to work safely with dynamic C++ runtime." \
39+
"Please use /MD switch with sycl.dll, /MDd switch with sycld.dll, " \
40+
"or -fsycl switch to set C++ runtime automatically.")
41+
#else
42+
#warning "SYCL library is designed to work safely with dynamic C++ runtime."\
43+
"Please use /MD switch with sycl.dll, /MDd switch with sycld.dll, "\
44+
"or -fsycl switch to set C++ runtime automatically."
45+
#endif
46+
#endif // defined(_WIN32) && !defined(_DLL) && !defined(__SYCL_DEVICE_ONLY__)
47+
48+
template <class T, class Alloc = std::allocator<T>>
49+
using vector_class = std::vector<T, Alloc>;
50+
51+
using string_class = std::string;
52+
53+
template <class Sig> using function_class = std::function<Sig>;
54+
55+
using mutex_class = std::mutex;
56+
57+
template <class T, class Deleter = std::default_delete<T>>
58+
using unique_ptr_class = std::unique_ptr<T, Deleter>;
59+
60+
template <class T> using shared_ptr_class = std::shared_ptr<T>;
61+
62+
template <class T> using weak_ptr_class = std::weak_ptr<T>;
63+
64+
template <class T> using hash_class = std::hash<T>;
65+
66+
using exception_ptr_class = std::exception_ptr;
67+
68+
template <typename T, typename... ArgsT>
69+
unique_ptr_class<T> make_unique_ptr(ArgsT &&... Args) {
70+
return unique_ptr_class<T>(new T(std::forward<ArgsT>(Args)...));
71+
}
72+
73+
} // namespace sycl
74+
} // __SYCL_INLINE_NAMESPACE(cl)

sycl/test/basic_tests/aspects.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %clangxx %s -o %t.out -I %sycl_include -lsycl
1+
// RUN: %clangxx -fsycl %s -o %t.out
22
// RUN: %t.out
33

44
//==--------------- aspects.cpp - SYCL device test ------------------------==//

sycl/test/basic_tests/buffer/buffer_ctad.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %clangxx -std=c++17 -fsyntax-only -Xclang -verify %s -I %sycl_include -Xclang -verify-ignore-unexpected=note,warning
1+
// RUN: %clangxx -fsycl -fsyntax-only -Xclang -verify %s -Xclang -verify-ignore-unexpected=note,warning
22
// expected-no-diagnostics
33

44
#include <CL/sycl.hpp>

sycl/test/basic_tests/context.cpp

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
1-
// RUN: %clangxx %s -o %t.out -lsycl -I %sycl_include
1+
// RUN: %clangxx -fsycl %s -o %t.out
22
// RUN: %RUN_ON_HOST %t.out
33

4-
//==--------------- context.cpp - SYCL context test ------------------------==//
5-
//
6-
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
7-
// See https://llvm.org/LICENSE.txt for license information.
8-
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
9-
//
10-
//===----------------------------------------------------------------------===//
4+
// This test performs basic check of the SYCL context class.
115

126
#include <sycl/sycl.hpp>
137
#include <iostream>

sycl/test/basic_tests/device.cpp

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
1-
// RUN: %clangxx %s -o %t.out -I %sycl_include -lsycl
1+
// RUN: %clangxx -fsycl %s -o %t.out
22
// RUN: %RUN_ON_HOST %t.out
33

4-
//==--------------- device.cpp - SYCL device test --------------------------==//
5-
//
6-
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
7-
// See https://llvm.org/LICENSE.txt for license information.
8-
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
9-
//
10-
//===----------------------------------------------------------------------===//
4+
// This test performs basic check of the SYCL device class.
115

126
#include <CL/sycl.hpp>
137
#include <cassert>

sycl/test/basic_tests/id_ctad.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %clangxx -std=c++17 -fsyntax-only -Xclang -verify %s -I %sycl_include -Xclang -verify-ignore-unexpected=note,warning
1+
// RUN: %clangxx -fsycl -fsyntax-only -Xclang -verify %s -Xclang -verify-ignore-unexpected=note,warning
22
// expected-no-diagnostics
33
//==--------------- id_ctad.cpp - SYCL id CTAD test ----------------------==//
44
//

sycl/test/basic_tests/implicit_conversion_error.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// RUN: %clangxx -fsyntax-only -Xclang -verify %s -I %sycl_include -Xclang -verify-ignore-unexpected=note,warning
2-
//==-- implicit_conversion_error.cpp - Unintended implicit conversion check --==//
1+
// RUN: %clangxx -fsycl -fsyntax-only -Xclang -verify %s -Xclang -verify-ignore-unexpected=note,warning
2+
//=- implicit_conversion_error.cpp - Unintended implicit conversion check -=//
33
//
44
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
55
// See https://llvm.org/LICENSE.txt for license information.

sycl/test/basic_tests/marray/marray.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
// RUN: %clangxx %s -o %t.out -lsycl -I %sycl_include
2-
// RUN: %t.out
1+
// RUN: %clangxx -fsycl %s -o %t.out
2+
// RUN: %RUN_ON_HOST %t.out
3+
34
//==--------------- marray.cpp - SYCL marray test --------------------------==//
45
//
56
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.

sycl/test/basic_tests/property_list.cpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
1-
// RUN: %clangxx %s -o %t.out -lsycl -I%sycl_include
1+
// RUN: %clangxx -fsycl %s -o %t.out
22
// RUN: %RUN_ON_HOST %t.out
33
//
44
// CHECK: PASSED
5-
//==--------------- property_list.cpp - SYCL property list test ------------==//
6-
//
7-
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
8-
// See https://llvm.org/LICENSE.txt for license information.
9-
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
10-
//
11-
//===----------------------------------------------------------------------===//
5+
6+
// This test performs basic check of the SYCL property_list class.
7+
128
#include <CL/sycl.hpp>
139
#include <iostream>
1410

sycl/test/basic_tests/range_ctad.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %clangxx -std=c++17 -fsyntax-only -Xclang -verify %s -I %sycl_include -Xclang -verify-ignore-unexpected=note,warning
1+
// RUN: %clangxx -fsycl -fsyntax-only -Xclang -verify %s -Xclang -verify-ignore-unexpected=note,warning
22
// expected-no-diagnostics
33
//==--------------- range_ctad.cpp - SYCL range CTAD test ----------------------==//
44
//

0 commit comments

Comments
 (0)