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

+50-31
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

+1-1
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

+1-1
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

+2-8
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

+2-8
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

+1-1
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

+2-2
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

+3-2
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

+4-8
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

+1-1
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
//

sycl/test/basic_tests/range_error.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %clangxx -Xclang -verify %s -I %sycl_include -Xclang -verify-ignore-unexpected=note,warning -fsyntax-only
1+
// RUN: %clangxx -fsycl -Xclang -verify %s -Xclang -verify-ignore-unexpected=note,warning -fsyntax-only
22
//==--------------- range_error.cpp - SYCL range error test ----------------==//
33
//
44
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.

sycl/test/basic_tests/reduction_known_identity.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %clangxx -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
// This test performs basic checks of has_known_identity and known_identity
+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// RUN: %clangxx -fsycl -fsyntax-only -Xclang -verify -Xclang -verify-ignore-unexpected=note,warning %s -c -o %t.out
2-
// RUN: %clangxx -std=c++14 -fsyntax-only -Xclang -verify -I %sycl_include -Xclang -verify-ignore-unexpected=note,warning %s -o -c %t.out
3-
// RUN: %clangxx -std=c++17 -fsyntax-only -Xclang -verify -I %sycl_include -Xclang -verify-ignore-unexpected=note,warning %s -o -c %t.out
4-
// RUN: %clangxx -std=c++20 -fsyntax-only -Xclang -verify -I %sycl_include -Xclang -verify-ignore-unexpected=note,warning %s -o -c %t.out
2+
// RUN: %clangxx -fsycl -std=c++14 -fsyntax-only -Xclang -verify -Xclang -verify-ignore-unexpected=note,warning %s -o -c %t.out
3+
// RUN: %clangxx -fsycl -std=c++17 -fsyntax-only -Xclang -verify -Xclang -verify-ignore-unexpected=note,warning %s -o -c %t.out
4+
// RUN: %clangxx -fsycl -std=c++20 -fsyntax-only -Xclang -verify -Xclang -verify-ignore-unexpected=note,warning %s -o -c %t.out
55
// expected-no-diagnostics
66

77
#include <CL/sycl.hpp>

sycl/test/basic_tests/valid_kernel_args.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
//===----------------------------------------------------------------------===//
88

99
// The test checks that the types can be used to pass kernel parameters by value
10-
// RUN: %clangxx -fsyntax-only %s -I %sycl_include -Wno-sycl-strict -Xclang -verify-ignore-unexpected=note,warning
10+
// RUN: %clangxx -fsycl -fsyntax-only %s -Wno-sycl-strict -Xclang -verify-ignore-unexpected=note,warning
1111

1212
// Check that the test can be compiled with device compiler as well.
13-
// RUN: %clangxx -fsycl-device-only -fsyntax-only %s -I %sycl_include -Wno-sycl-strict
13+
// RUN: %clangxx -fsycl-device-only -fsyntax-only %s -Wno-sycl-strict
1414

1515
#include <CL/sycl.hpp>
1616

sycl/test/basic_tests/vectors/ctad.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %clangxx -std=c++17 -I %sycl_include -fsyntax-only -Xclang -verify %s -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
//==--------------- ctad.cpp - SYCL vector CTAD test --------------------==//
44
//

sycl/test/basic_tests/vectors/vectors.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %clangxx %s -o %t.out -lsycl -I %sycl_include
1+
// RUN: %clangxx -fsycl %s -o %t.out
22
// RUN: %t.out
33
//==--------------- vectors.cpp - SYCL vectors test ------------------------==//
44
//

sycl/test/esimd/vadd.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
// TODO ESIMD enable host device under -fsycl
2-
// RUN: %clangxx -I %sycl_include %s -o %t.out -lsycl
1+
// RUN: %clangxx -fsycl %s -o %t.out
32
// RUN: %RUN_ON_HOST %t.out
43

54
// Check that the code compiles with -O0 and -g

sycl/test/multi_ptr/ctad.cpp

+1-1
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
//==--------------- ctad.cpp - SYCL multi_ptr CTAD test --------------------==//
44
//

sycl/test/on-device/extensions/intel-ext-device.cpp

+1-1
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: env SYCL_DEVICE_FILTER=level_zero:gpu %t.out
33
// RUN: env SYCL_DEVICE_FILTER=opencl:gpu %t.out
44
//

sycl/test/regression/macro_conflict.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %clangxx -fsyntax-only -I %sycl_include -Xclang -verify %s -o %t.out -Xclang -verify-ignore-unexpected=note,warning
1+
// RUN: %clangxx -fsycl -fsyntax-only -Xclang -verify %s -o %t.out -Xclang -verify-ignore-unexpected=note,warning
22
// expected-no-diagnostics
33
//
44
//===----------------------------------------------------------------------===//

sycl/test/regression/sub-group-store-const-ref.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %clangxx -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
//==-- sub-group-store-const-ref.cpp ---------------------------------------==//

sycl/test/regression/unable-to-redeclare-device.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %clangxx -fsyntax-only -Xclang -verify -DCL_TARGET_OPENCL_VERSION=220 %s -I %sycl_include -Xclang -verify-ignore-unexpected=note,warning
1+
// RUN: %clangxx -fsycl -fsyntax-only -Xclang -verify -DCL_TARGET_OPENCL_VERSION=220 %s -Xclang -verify-ignore-unexpected=note,warning
22
// expected-no-diagnostics
33
//
44
//==-- unable-to-redeclare-device.cpp --------------------------------------==//

sycl/test/regression/vec-to-half.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %clang -O0 -fsyntax-only -Xclang -verify %s -I %sycl_include -Xclang -verify-ignore-unexpected=note,warning
1+
// RUN: %clang -fsycl -O0 -fsyntax-only -Xclang -verify %s -Xclang -verify-ignore-unexpected=note,warning
22
// expected-no-diagnostics
33

44
#include <CL/sycl.hpp>

sycl/test/separate-compile/test.cpp

+6-4
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,17 @@
33
//
44
// >> ---- compile src1
55
// >> device compilation...
6-
// RUN: %clangxx -fsycl-device-only -Xclang -fsycl-int-header=sycl_ihdr_a.h %s -c -o a_kernel.bc -I %sycl_include -Wno-sycl-strict
6+
// RUN: %clangxx -fsycl-device-only -Xclang -fsycl-int-header=sycl_ihdr_a.h %s -c -o a_kernel.bc -Wno-sycl-strict
77
// >> host compilation...
8-
// RUN: %clangxx -include sycl_ihdr_a.h -g -c %s -o a.o -I %sycl_include -Wno-sycl-strict
8+
// Driver automatically adds -D_DLL and -D_MT on Windows with -fsycl.
9+
// Add those defines required for Windows and harmless for Linux.
10+
// RUN: %clangxx -D_DLL -D_MT -include sycl_ihdr_a.h -g -c %s -o a.o -I %sycl_include -Wno-sycl-strict
911
//
1012
// >> ---- compile src2
1113
// >> device compilation...
12-
// RUN: %clangxx -DB_CPP=1 -fsycl-device-only -Xclang -fsycl-int-header=sycl_ihdr_b.h %s -c -o b_kernel.bc -I %sycl_include -Wno-sycl-strict
14+
// RUN: %clangxx -DB_CPP=1 -fsycl-device-only -Xclang -fsycl-int-header=sycl_ihdr_b.h %s -c -o b_kernel.bc -Wno-sycl-strict
1315
// >> host compilation...
14-
// RUN: %clangxx -DB_CPP=1 -include sycl_ihdr_b.h -g -c %s -o b.o -I %sycl_include -Wno-sycl-strict
16+
// RUN: %clangxx -DB_CPP=1 -D_DLL -D_MT -include sycl_ihdr_b.h -g -c %s -o b.o -I %sycl_include -Wno-sycl-strict
1517
//
1618
// >> ---- bundle .o with .spv
1719
// >> run bundler

0 commit comments

Comments
 (0)