Skip to content

Commit 08febcf

Browse files
author
Steffen Larsen
authored
[SYCL] Add -fpreview-breaking-changes option (#11629)
This commit adds the -fpreview-breaking-changes option to supersede the SYCL2020_CONFORMANT_APIS preprocessor macro. This new option allows the SYCL library to also make breaking changes outside a SYCL major release by guarding breaking changes behind the __INTEL_PREVIEW_BREAKING_CHANGES macro. When -fpreview-breaking-changes is used together with -fsycl the compiled program is linked against a variant of the SYCL library with the __INTEL_PREVIEW_BREAKING_CHANGES macro defined. --------- Signed-off-by: Larsen, Steffen <[email protected]>
1 parent 7b94ac1 commit 08febcf

File tree

19 files changed

+213
-21
lines changed

19 files changed

+213
-21
lines changed

buildbot/configure.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ def do_configure(args):
5151
llvm_build_shared_libs = 'OFF'
5252
llvm_enable_lld = 'OFF'
5353
sycl_enabled_plugins = ["opencl"]
54+
sycl_preview_lib = 'ON'
5455

5556
sycl_enable_xpti_tracing = 'ON'
5657
xpti_enable_werror = 'OFF'
@@ -141,6 +142,9 @@ def do_configure(args):
141142
if args.enable_plugin:
142143
sycl_enabled_plugins += args.enable_plugin
143144

145+
if args.disable_preview_lib:
146+
sycl_preview_lib = 'OFF'
147+
144148
install_dir = os.path.join(abs_obj_dir, "install")
145149

146150
cmake_cmd = [
@@ -174,6 +178,7 @@ def do_configure(args):
174178
"-DSYCL_CLANG_EXTRA_FLAGS={}".format(sycl_clang_extra_flags),
175179
"-DSYCL_ENABLE_PLUGINS={}".format(';'.join(set(sycl_enabled_plugins))),
176180
"-DSYCL_ENABLE_KERNEL_FUSION={}".format(sycl_enable_fusion),
181+
"-DSYCL_ENABLE_MAJOR_RELEASE_PREVIEW_LIB={}".format(sycl_preview_lib),
177182
"-DBUG_REPORT_URL=https://github.com/intel/llvm/issues",
178183
]
179184

@@ -256,6 +261,7 @@ def main():
256261
parser.add_argument("--llvm-external-projects", help="Add external projects to build. Add as comma seperated list.")
257262
parser.add_argument("--ci-defaults", action="store_true", help="Enable default CI parameters")
258263
parser.add_argument("--enable-plugin", action='append', help="Enable SYCL plugin")
264+
parser.add_argument("--disable-preview-lib", action='store_true', help="Disable building of the SYCL runtime major release preview library")
259265
parser.add_argument("--disable-fusion", action="store_true", help="Disable the kernel fusion JIT compiler")
260266
parser.add_argument("--add_security_flags", type=str, choices=['none', 'default', 'sanitize'], default=None, help="Enables security flags for compile & link. Two values are supported: 'default' and 'sanitize'. 'Sanitize' option is an extension of 'default' set.")
261267
args = parser.parse_args()

clang/include/clang/Driver/Options.td

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1306,6 +1306,14 @@ defm cuda_prec_sqrt : BoolFOption<"cuda-prec-sqrt",
13061306
def emit_static_lib : Flag<["--"], "emit-static-lib">,
13071307
HelpText<"Enable linker job to emit a static library.">;
13081308

1309+
def fpreview_breaking_changes : Flag<["-"], "fpreview-breaking-changes">, Flags<[NoXarchOption]>,
1310+
Visibility<[ClangOption, CLOption]>,
1311+
HelpText<"When specified, it informs the compiler driver and compilation phases "
1312+
"that it is allowed to break backward compatibility. When this option is "
1313+
"specified the compiler will also set the macro __INTEL_PREVIEW_BREAKING_CHANGES.\n"
1314+
"When this option is used in conjunction with -fsycl, the driver will link against "
1315+
"an alternate form of libsycl, libsycl-preview.">;
1316+
13091317
def mprintf_kind_EQ : Joined<["-"], "mprintf-kind=">, Group<m_Group>,
13101318
HelpText<"Specify the printf lowering scheme (AMDGPU only), allowed values are "
13111319
"\"hostcall\"(printing happens during kernel execution, this scheme "

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4785,6 +4785,11 @@ void Clang::ConstructHostCompilerJob(Compilation &C, const JobAction &JA,
47854785
if (IsMSVCHostCompiler)
47864786
HostCompileArgs.push_back("/Zc:__cplusplus");
47874787

4788+
if (TCArgs.hasArg(options::OPT_fpreview_breaking_changes)) {
4789+
HostCompileArgs.push_back(IsMSVCHostCompiler ? "/D" : "-D");
4790+
HostCompileArgs.push_back("__INTEL_PREVIEW_BREAKING_CHANGES");
4791+
}
4792+
47884793
// FIXME: Reuse existing toolchains which are already supported to put
47894794
// together the options.
47904795
// FIXME: For any potential obscure host compilers that do not use the
@@ -4992,10 +4997,19 @@ static void ProcessVSRuntimeLibrary(const ArgList &Args,
49924997
// Add SYCL dependent library
49934998
if (Args.hasArg(options::OPT_fsycl) &&
49944999
!Args.hasArg(options::OPT_nolibsycl)) {
4995-
if (RTOptionID == options::OPT__SLASH_MDd)
4996-
CmdArgs.push_back("--dependent-lib=sycl" SYCL_MAJOR_VERSION "d");
4997-
else
4998-
CmdArgs.push_back("--dependent-lib=sycl" SYCL_MAJOR_VERSION);
5000+
if (RTOptionID == options::OPT__SLASH_MDd) {
5001+
if (Args.hasArg(options::OPT_fpreview_breaking_changes))
5002+
CmdArgs.push_back("--dependent-lib=sycl" SYCL_MAJOR_VERSION
5003+
"-previewd");
5004+
else
5005+
CmdArgs.push_back("--dependent-lib=sycl" SYCL_MAJOR_VERSION "d");
5006+
} else {
5007+
if (Args.hasArg(options::OPT_fpreview_breaking_changes))
5008+
CmdArgs.push_back("--dependent-lib=sycl" SYCL_MAJOR_VERSION
5009+
"-preview");
5010+
else
5011+
CmdArgs.push_back("--dependent-lib=sycl" SYCL_MAJOR_VERSION);
5012+
}
49995013
CmdArgs.push_back("--dependent-lib=sycl-devicelib-host");
50005014
}
50015015
}
@@ -5309,6 +5323,9 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
53095323
options::OPT_fno_sycl_id_queries_fit_in_int))
53105324
A->render(Args, CmdArgs);
53115325

5326+
if (Args.hasArg(options::OPT_fpreview_breaking_changes))
5327+
CmdArgs.push_back("-D__INTEL_PREVIEW_BREAKING_CHANGES");
5328+
53125329
if (SYCLStdArg) {
53135330
// Use of -sycl-std=1.2.1 is deprecated. Emit a diagnostic stating so.
53145331
// TODO: remove support at next approprate major release.
@@ -6478,10 +6495,19 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
64786495
// library.
64796496
if (Args.hasArg(options::OPT_fsycl) && !Args.hasArg(options::OPT_nolibsycl)) {
64806497
if (!D.IsCLMode() && TC.getTriple().isWindowsMSVCEnvironment()) {
6481-
if (isDependentLibAdded(Args, "msvcrtd"))
6482-
CmdArgs.push_back("--dependent-lib=sycl" SYCL_MAJOR_VERSION "d");
6498+
if (isDependentLibAdded(Args, "msvcrtd")) {
6499+
if (Args.hasArg(options::OPT_fpreview_breaking_changes))
6500+
CmdArgs.push_back("--dependent-lib=sycl" SYCL_MAJOR_VERSION
6501+
"-previewd");
6502+
else
6503+
CmdArgs.push_back("--dependent-lib=sycl" SYCL_MAJOR_VERSION "d");
6504+
}
64836505
} else if (!D.IsCLMode() && TC.getTriple().isWindowsGNUEnvironment()) {
6484-
CmdArgs.push_back("--dependent-lib=sycl" SYCL_MAJOR_VERSION ".dll");
6506+
if (Args.hasArg(options::OPT_fpreview_breaking_changes))
6507+
CmdArgs.push_back("--dependent-lib=sycl" SYCL_MAJOR_VERSION
6508+
"-preview.dll");
6509+
else
6510+
CmdArgs.push_back("--dependent-lib=sycl" SYCL_MAJOR_VERSION ".dll");
64856511
}
64866512
CmdArgs.push_back("--dependent-lib=sycl-devicelib-host");
64876513
}

clang/lib/Driver/ToolChains/Gnu.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -730,7 +730,10 @@ void tools::gnutools::Linker::ConstructJob(Compilation &C, const JobAction &JA,
730730

731731
if (Args.hasArg(options::OPT_fsycl) &&
732732
!Args.hasArg(options::OPT_nolibsycl)) {
733-
CmdArgs.push_back("-lsycl");
733+
if (Args.hasArg(options::OPT_fpreview_breaking_changes))
734+
CmdArgs.push_back("-lsycl-preview");
735+
else
736+
CmdArgs.push_back("-lsycl");
734737
CmdArgs.push_back("-lsycl-devicelib-host");
735738
// Use of -fintelfpga implies -lOpenCL.
736739
// FIXME: Adjust to use plugin interface when available.

clang/lib/Driver/ToolChains/MSVC.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,12 @@ void visualstudio::Linker::ConstructJob(Compilation &C, const JobAction &JA,
137137
TC.getDriver().Dir + "/../lib"));
138138
// When msvcrtd is added via --dependent-lib, we add the sycld
139139
// equivalent. Do not add the -defaultlib as it conflicts.
140-
if (!isDependentLibAdded(Args, "msvcrtd"))
141-
CmdArgs.push_back("-defaultlib:sycl" SYCL_MAJOR_VERSION ".lib");
140+
if (!isDependentLibAdded(Args, "msvcrtd")) {
141+
if (Args.hasArg(options::OPT_fpreview_breaking_changes))
142+
CmdArgs.push_back("-defaultlib:sycl" SYCL_MAJOR_VERSION "-preview.lib");
143+
else
144+
CmdArgs.push_back("-defaultlib:sycl" SYCL_MAJOR_VERSION ".lib");
145+
}
142146
CmdArgs.push_back("-defaultlib:sycl-devicelib-host.lib");
143147
}
144148

clang/test/Driver/sycl-offload.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -654,3 +654,17 @@
654654
// RUN: %clang -### -fsycl %s 2>&1 | FileCheck -check-prefix FSYCL-CHECK %s
655655
// RUN: %clang_cl -### -fsycl %s 2>&1 | FileCheck -check-prefix FSYCL-CHECK %s
656656
// FSYCL-CHECK: warning: treating 'c' input as 'c++' when -fsycl is used [-Wexpected-file-type]
657+
658+
/// Check for linked sycl lib when using -fpreview-breaking-changes with -fsycl
659+
// RUN: %clang -### -fsycl -fpreview-breaking-changes -target x86_64-unknown-windows-msvc %s 2>&1 | FileCheck -check-prefix FSYCL-PREVIEW-BREAKING-CHANGES-CHECK %s
660+
// RUN: %clang_cl -### -fsycl -fpreview-breaking-changes %s 2>&1 | FileCheck -check-prefix FSYCL-PREVIEW-BREAKING-CHANGES-CHECK-CL %s
661+
// FSYCL-PREVIEW-BREAKING-CHANGES-CHECK: -defaultlib:sycl{{[0-9]*}}-preview.lib
662+
// FSYCL-PREVIEW-BREAKING-CHANGES-CHECK-NOT: -defaultlib:sycl{{[0-9]*}}.lib
663+
// FSYCL-PREVIEW-BREAKING-CHANGES-CHECK-CL: "--dependent-lib=sycl{{[0-9]*}}-preview"
664+
665+
/// Check for linked sycl lib when using -fpreview-breaking-changes with -fsycl
666+
// RUN: %clang -### -fsycl -fpreview-breaking-changes -target x86_64-unknown-windows-msvc -Xclang --dependent-lib=msvcrtd %s 2>&1 | FileCheck -check-prefix FSYCL-PREVIEW-BREAKING-CHANGES-DEBUG-CHECK %s
667+
// RUN: %clang_cl -### -fsycl -fpreview-breaking-changes /MDd %s 2>&1 | FileCheck -check-prefix FSYCL-PREVIEW-BREAKING-CHANGES-DEBUG-CHECK %s
668+
// FSYCL-PREVIEW-BREAKING-CHANGES-DEBUG-CHECK: --dependent-lib=sycl{{[0-9]*}}-previewd
669+
// FSYCL-PREVIEW-BREAKING-CHANGES-DEBUG-CHECK-NOT: -defaultlib:sycl{{[0-9]*}}.lib
670+
// FSYCL-PREVIEW-BREAKING-CHANGES-DEBUG-CHECK-NOT: -defaultlib:sycl{{[0-9]*}}-preview.lib

sycl/CMakeLists.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,9 @@ if(SYCL_ENABLE_KERNEL_FUSION AND WIN32)
152152
BOOL "Kernel fusion not yet supported on Windows" FORCE)
153153
endif()
154154

155+
# Option for enabling building the SYCL major release preview library.
156+
option(SYCL_ENABLE_MAJOR_RELEASE_PREVIEW_LIB "Enable build of the SYCL major release preview library" ON)
157+
155158
# Needed for feature_test.hpp
156159
if ("cuda" IN_LIST SYCL_ENABLE_PLUGINS)
157160
set(SYCL_BUILD_PI_CUDA ON)
@@ -259,12 +262,21 @@ install(FILES "${sycl_inc_dir}/syclcompat.hpp" DESTINATION ${SYCL_INCLUDE_DIR} C
259262

260263
if (WIN32)
261264
set(SYCL_RT_LIBS sycl${SYCL_MAJOR_VERSION})
265+
if(SYCL_ENABLE_MAJOR_RELEASE_PREVIEW_LIB)
266+
list(APPEND SYCL_RT_LIBS sycl${SYCL_MAJOR_VERSION}-preview)
267+
endif()
262268
# Do we really support non-MSVC ABI on WIN?
263269
if (MSVC)
264270
list(APPEND SYCL_RT_LIBS sycl${SYCL_MAJOR_VERSION}d)
271+
if(SYCL_ENABLE_MAJOR_RELEASE_PREVIEW_LIB)
272+
list(APPEND SYCL_RT_LIBS sycl${SYCL_MAJOR_VERSION}-previewd)
273+
endif()
265274
endif()
266275
else()
267276
set(SYCL_RT_LIBS sycl)
277+
if(SYCL_ENABLE_MAJOR_RELEASE_PREVIEW_LIB)
278+
list(APPEND SYCL_RT_LIBS sycl-preview)
279+
endif()
268280
endif()
269281

270282
# This function allows building multiple libraries with the same options.

sycl/doc/PreprocessorMacros.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,12 @@ This file describes macros that have effect on SYCL compiler and run-time.
4848
support for `assert()` via `aspect::ext_oneapi_native_assert`.
4949
This macro is undefined by default.
5050

51-
- **SYCL2020_CONFORMANT_APIS**
51+
- **SYCL2020_CONFORMANT_APIS (deprecated)**
5252
This macro is used to comply with the SYCL 2020 specification, as some of the current
5353
implementations may be widespread and not conform to it.
5454
Defining this macro currently has no effect on the API.
55+
This preprocessor macro has been deprecated in favor of the
56+
`-fpreview-breaking-changes` compiler option.
5557

5658
## Version macros
5759

sycl/include/sycl/handler.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1243,7 +1243,8 @@ class __SYCL_EXPORT handler {
12431243
"Kernel argument cannot have a sycl::nd_item type in "
12441244
"sycl::parallel_for with sycl::range");
12451245

1246-
#ifdef SYCL2020_CONFORMANT_APIS
1246+
#if defined(SYCL2020_CONFORMANT_APIS) || \
1247+
defined(__INTEL_PREVIEW_BREAKING_CHANGES)
12471248
static_assert(
12481249
(std::is_invocable_v<KernelType, item<Dims>> ||
12491250
std::is_invocable_v<
@@ -1337,7 +1338,8 @@ class __SYCL_EXPORT handler {
13371338
verifyUsedKernelBundle(detail::KernelInfo<NameT>::getName());
13381339
using LambdaArgType =
13391340
sycl::detail::lambda_arg_type<KernelType, nd_item<Dims>>;
1340-
#ifdef SYCL2020_CONFORMANT_APIS
1341+
#if defined(SYCL2020_CONFORMANT_APIS) || \
1342+
defined(__INTEL_PREVIEW_BREAKING_CHANGES)
13411343
static_assert(
13421344
std::is_convertible_v<sycl::nd_item<Dims>, LambdaArgType>,
13431345
"Kernel argument of a sycl::parallel_for with sycl::nd_range "

sycl/include/sycl/sycl.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@
9696
#include <sycl/ext/oneapi/sub_group_mask.hpp>
9797
#include <sycl/ext/oneapi/weak_object.hpp>
9898

99-
#ifndef SYCL2020_CONFORMANT_APIS
99+
#if !defined(SYCL2020_CONFORMANT_APIS) && \
100+
!defined(__INTEL_PREVIEW_BREAKING_CHANGES)
100101
// We used to include those and some code might be reliant on that.
101102
#include <cmath>
102103
#include <complex>

0 commit comments

Comments
 (0)