Skip to content

Commit 47e9ed2

Browse files
committed
[SYCL] Check that apps using sycl also use dynamic C++ RT even without -fsycl
With -fsycl switch the dynamic runtime is used. The patches (intel#2478, intel#2480, intel#2497 implemented that with -fsycl. This patch adds check that dynamic runtime is used when -fsycl is not used. That is done by a static_assert in sycl/stl.hpp. Also, lots of LIT tests had to be changed to comply with the new requirement (apps must use dynamic C++ RT with use SYCL). Signed-off-by: Vyacheslav N Klochkov <[email protected]>
1 parent 9a734f6 commit 47e9ed2

23 files changed

+75
-71
lines changed

sycl/include/CL/sycl/stl.hpp

Lines changed: 37 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -22,34 +22,52 @@
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>;
25+
#if defined(_WIN32) && !defined(__SYCL_DEVICE_ONLY__)
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 in general.
29+
// Only 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 // defined(_WIN32) && !defined(__SYCL_DEVICE_ONLY__)
2745

28-
using string_class = std::string;
46+
template <class T, class Alloc = std::allocator<T>>
47+
using vector_class = std::vector<T, Alloc>;
2948

30-
template <class Sig>
31-
using function_class = std::function<Sig>;
49+
using string_class = std::string;
3250

33-
using mutex_class = std::mutex;
51+
template <class Sig> using function_class = std::function<Sig>;
3452

35-
template <class T, class Deleter = std::default_delete<T>>
36-
using unique_ptr_class = std::unique_ptr<T, Deleter>;
53+
using mutex_class = std::mutex;
3754

38-
template <class T>
39-
using shared_ptr_class = std::shared_ptr<T>;
55+
template <class T, class Deleter = std::default_delete<T>>
56+
using unique_ptr_class = std::unique_ptr<T, Deleter>;
4057

41-
template <class T>
42-
using weak_ptr_class = std::weak_ptr<T>;
58+
template <class T> using shared_ptr_class = std::shared_ptr<T>;
4359

44-
template <class T>
45-
using hash_class = std::hash<T>;
60+
template <class T> using weak_ptr_class = std::weak_ptr<T>;
4661

47-
using exception_ptr_class = std::exception_ptr;
62+
template <class T> using hash_class = std::hash<T>;
63+
64+
using exception_ptr_class = std::exception_ptr;
65+
66+
template <typename T, typename... ArgsT>
67+
unique_ptr_class<T> make_unique_ptr(ArgsT &&... Args) {
68+
return unique_ptr_class<T>(new T(std::forward<ArgsT>(Args)...));
69+
}
4870

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-
}
5371
} // sycl
5472
} // cl
5573

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)