Skip to content

Commit e742845

Browse files
author
iclsrc
committed
Merge from 'sycl' to 'sycl-web'
2 parents b2d2750 + 14e227c commit e742845

25 files changed

+950
-134
lines changed

clang/include/clang/Basic/DiagnosticDriverKinds.td

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ def err_drv_invalid_Xsycl_frontend_with_args : Error<
132132
"invalid -Xsycl-target-frontend argument: '%0', options requiring arguments are unsupported">;
133133
def err_drv_bad_fpga_device_count : Error<
134134
"More than one FPGA specific device binary found in input objects">;
135+
def err_drv_unsupported_opt_dpcpp : Error<"option '%0' unsupported with DPC++">;
135136
def err_drv_argument_only_allowed_with : Error<
136137
"invalid argument '%0' only allowed with '%1'">;
137138
def err_drv_argument_not_allowed_with : Error<

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6794,14 +6794,26 @@ void Clang::AddClangCLArgs(const ArgList &Args, types::ID InputType,
67946794
bool *EmitCodeView) const {
67956795
unsigned RTOptionID = options::OPT__SLASH_MT;
67966796
bool isNVPTX = getToolChain().getTriple().isNVPTX();
6797+
bool isSYCL =
6798+
Args.hasArg(options::OPT_fsycl) ||
6799+
getToolChain().getTriple().getEnvironment() == llvm::Triple::SYCLDevice;
6800+
// For SYCL Windows, /MD is the default.
6801+
if (isSYCL)
6802+
RTOptionID = options::OPT__SLASH_MD;
67976803

67986804
if (Args.hasArg(options::OPT__SLASH_LDd))
6799-
// The /LDd option implies /MTd. The dependent lib part can be overridden,
6800-
// but defining _DEBUG is sticky.
6801-
RTOptionID = options::OPT__SLASH_MTd;
6805+
// The /LDd option implies /MTd (/MDd for SYCL). The dependent lib part
6806+
// can be overridden but defining _DEBUG is sticky.
6807+
RTOptionID = isSYCL ? options::OPT__SLASH_MDd : options::OPT__SLASH_MTd;
68026808

6803-
if (Arg *A = Args.getLastArg(options::OPT__SLASH_M_Group))
6809+
if (Arg *A = Args.getLastArg(options::OPT__SLASH_M_Group)) {
68046810
RTOptionID = A->getOption().getID();
6811+
if (isSYCL && (RTOptionID == options::OPT__SLASH_MT ||
6812+
RTOptionID == options::OPT__SLASH_MTd))
6813+
// Use of /MT or /MTd is not supported for SYCL.
6814+
getToolChain().getDriver().Diag(diag::err_drv_unsupported_opt_dpcpp)
6815+
<< A->getOption().getName();
6816+
}
68056817

68066818
StringRef FlagForCRT;
68076819
switch (RTOptionID) {

clang/lib/Driver/ToolChains/MSVC.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -375,8 +375,7 @@ void visualstudio::Linker::ConstructJob(Compilation &C, const JobAction &JA,
375375

376376
if (!C.getDriver().IsCLMode() && !Args.hasArg(options::OPT_nostdlib) &&
377377
Args.hasArg(options::OPT_fsycl) && !Args.hasArg(options::OPT_nolibsycl)) {
378-
if (Args.hasArg(options::OPT__SLASH_MDd) ||
379-
Args.hasArg(options::OPT__SLASH_MTd))
378+
if (Args.hasArg(options::OPT__SLASH_MDd))
380379
CmdArgs.push_back("-defaultlib:sycld.lib");
381380
else
382381
CmdArgs.push_back("-defaultlib:sycl.lib");

clang/test/Driver/sycl-MD-default.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// REQUIRES: clang-driver
2+
3+
// RUN: %clang_cl -### -fsycl -c %s 2>&1 \
4+
// RUN: | FileCheck -check-prefix=CHK-DEFAULT %s
5+
// RUN: %clang_cl -### -MD -fsycl -c %s 2>&1 \
6+
// RUN: | FileCheck -check-prefix=CHK-DEFAULT %s
7+
// RUN: %clang_cl -### -MDd -fsycl -c %s 2>&1 \
8+
// RUN: | FileCheck -check-prefix=CHK-DEFAULT %s
9+
// CHK-DEFAULT: "-D_MT" "-D_DLL"
10+
// CHK-DEFAULT: "--dependent-lib=msvcrt{{d*}}"
11+
12+
// RUN: %clang_cl -### -MT -fsycl -c %s 2>&1 \
13+
// RUN: | FileCheck -check-prefix=CHK-ERROR %s
14+
// RUN: %clang_cl -### -MTd -fsycl -c %s 2>&1 \
15+
// RUN: | FileCheck -check-prefix=CHK-ERROR %s
16+
// CHK-ERROR: option 'MT{{d*}}' unsupported with DPC++

clang/test/Driver/sycl-offload.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -589,9 +589,8 @@
589589
// CHECK-LINK-NOLIBSYCL: "{{.*}}link{{(.exe)?}}"
590590
// CHECK-LINK-NOLIBSYCL-NOT: "-defaultlib:sycl.lib"
591591

592-
/// Check sycld.lib is chosen with /MDd and /MTd
592+
/// Check sycld.lib is chosen with /MDd
593593
// RUN: %clang_cl -fsycl /MDd %s -o %t -### 2>&1 | FileCheck -check-prefix=CHECK-LINK-SYCL-DEBUG %s
594-
// RUN: %clang_cl -fsycl /MTd %s -o %t -### 2>&1 | FileCheck -check-prefix=CHECK-LINK-SYCL-DEBUG %s
595594
// CHECK-LINK-SYCL-DEBUG: "--dependent-lib=sycld"
596595
// CHECK-LINK-SYCL-DEBUG-NOT: "-defaultlib:sycld.lib"
597596

sycl/doc/EnvironmentVariables.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ subject to change. Do not rely on these variables in production code.
1212
| Environment variable | Values | Description |
1313
| -------------------- | ------ | ----------- |
1414
| SYCL_PI_TRACE | Described [below](#sycl_pi_trace-options) | Enable specified level of tracing for PI. |
15-
| SYCL_BE | PI_OPENCL, PI_LEVEL_ZERO, PI_CUDA | Force SYCL RT to consider only devices of the specified backend during the device selection. |
16-
| SYCL_DEVICE_TYPE | One of: CPU, GPU, ACC, HOST | Force SYCL to use the specified device type. If unset, default selection rules are applied. If set to any unlisted value, this control has no effect. If the requested device type is not found, a `cl::sycl::runtime_error` exception is thrown. If a non-default device selector is used, a device must satisfy both the selector and this control to be chosen. This control only has effect on devices created with a selector. |
15+
| SYCL_BE | PI_OPENCL, PI_LEVEL_ZERO, PI_CUDA | Force SYCL RT to consider only devices of the specified backend during the device selection. We are planning to deprecate SYCL_BE environment variable in the future. The specific grace period is not decided yet. Please use the new env var SYCL_DEVICE_FILTER instead. |
16+
| SYCL_DEVICE_TYPE | One of: CPU, GPU, ACC, HOST | Force SYCL to use the specified device type. If unset, default selection rules are applied. If set to any unlisted value, this control has no effect. If the requested device type is not found, a `cl::sycl::runtime_error` exception is thrown. If a non-default device selector is used, a device must satisfy both the selector and this control to be chosen. This control only has effect on devices created with a selector. We are planning to deprecate SYCL_DEVICE_TYPE environment variable in the future. The specific grace period is not decided yet. Please use the new env var SYCL_DEVICE_FILTER instead. |
17+
| SYCL_DEVICE_FILTER (tentative name) | {backend:device_type:device_num} | Limits the SYCL RT to use only a subset of the system's devices. Setting this environment variable affects all of the device query functions and all of the device selectors. The value of this environment variable is a comma separated list of filters, where each filter is a triple of the form "backend:device_type:device_num" (without the quotes). Each element of the triple is optional, but each filter must have at least one value. Possible values of "backend" are "host", "level_zero", "opencl", "cuda", or "\*". Possible values of "device_type" are "host", "cpu", "gpu", "acc", or "\*". Device_num is an integer that indexes the enumeration of devices from the sycl::platform::get_device() call, where the first device in that enumeration has index zero. Assuming a filter has all three elements of the triple, it selects only those devices that come from the given backend, have the specified device type, AND have the given device index. If more than one filter is specified, the RT is restricted to the union of devices selected by all filters. The RT always includes the "host" backend and the host device regardless of the filter because the SYCL language requires this device to always be present. Therefore, including "host" in the list of filters is allowed but is unnecessary. Note that the standard selectors like gpu_selector or cpu_selector will throw an exception if the filtered list of devices does not include a device that satisfies the selector. In particular, limiting the devices to only those supported by the "level_zero" backend will cause the cpu_selector to throw an exception since that backend does not support any CPU devices. This environment variable can be used to limit loading only specified plugins into the SYCL RT. |
1718
| SYCL_PROGRAM_COMPILE_OPTIONS | String of valid OpenCL compile options | Override compile options for all programs. |
1819
| SYCL_PROGRAM_LINK_OPTIONS | String of valid OpenCL link options | Override link options for all programs. |
1920
| SYCL_USE_KERNEL_SPV | Path to the SPIR-V binary | Load device image from the specified file. If runtime is unable to read the file, `cl::sycl::runtime_error` exception is thrown.|

sycl/include/CL/sycl/backend_types.hpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,26 @@
1818
__SYCL_INLINE_NAMESPACE(cl) {
1919
namespace sycl {
2020

21-
enum class backend : char { host, opencl, level_zero, cuda };
21+
enum class backend : char { host, opencl, level_zero, cuda, all };
2222

2323
template <backend name, typename SYCLObjectT> struct interop;
2424

2525
inline std::ostream &operator<<(std::ostream &Out, backend be) {
2626
switch (be) {
2727
case backend::host:
28-
Out << std::string("host");
28+
Out << "host";
2929
break;
3030
case backend::opencl:
31-
Out << std::string("opencl");
31+
Out << "opencl";
3232
break;
3333
case backend::level_zero:
34-
Out << std::string("level_zero");
34+
Out << "level_zero";
3535
break;
3636
case backend::cuda:
37-
Out << std::string("cuda");
37+
Out << "cuda";
38+
break;
39+
case backend::all:
40+
Out << "all";
3841
}
3942
return Out;
4043
}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
//==---------- device_filter.hpp - SYCL device filter descriptor -----------==//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#pragma once
10+
11+
#include <CL/sycl/backend_types.hpp>
12+
#include <CL/sycl/detail/defines.hpp>
13+
#include <CL/sycl/info/info_desc.hpp>
14+
15+
#include <iostream>
16+
#include <string>
17+
18+
__SYCL_INLINE_NAMESPACE(cl) {
19+
namespace sycl {
20+
namespace detail {
21+
22+
struct device_filter {
23+
backend Backend = backend::all;
24+
info::device_type DeviceType = info::device_type::all;
25+
int DeviceNum = 0;
26+
bool HasBackend = false;
27+
bool HasDeviceType = false;
28+
bool HasDeviceNum = false;
29+
int MatchesSeen = 0;
30+
31+
device_filter(){};
32+
device_filter(const std::string &FilterString);
33+
friend std::ostream &operator<<(std::ostream &Out,
34+
const device_filter &Filter);
35+
};
36+
37+
class device_filter_list {
38+
std::vector<device_filter> FilterList;
39+
40+
public:
41+
device_filter_list() {}
42+
device_filter_list(const std::string &FilterString);
43+
device_filter_list(device_filter &Filter);
44+
void addFilter(device_filter &Filter);
45+
std::vector<device_filter> &get() { return FilterList; }
46+
friend std::ostream &operator<<(std::ostream &Out,
47+
const device_filter_list &List);
48+
};
49+
50+
inline std::ostream &operator<<(std::ostream &Out,
51+
const device_filter &Filter) {
52+
Out << Filter.Backend << ":";
53+
if (Filter.DeviceType == info::device_type::host) {
54+
Out << "host";
55+
} else if (Filter.DeviceType == info::device_type::cpu) {
56+
Out << "cpu";
57+
} else if (Filter.DeviceType == info::device_type::gpu) {
58+
Out << "gpu";
59+
} else if (Filter.DeviceType == info::device_type::accelerator) {
60+
Out << "accelerator";
61+
} else if (Filter.DeviceType == info::device_type::all) {
62+
Out << "*";
63+
} else {
64+
Out << "unknown";
65+
}
66+
if (Filter.HasDeviceNum) {
67+
Out << ":" << Filter.DeviceNum;
68+
}
69+
return Out;
70+
}
71+
72+
inline std::ostream &operator<<(std::ostream &Out,
73+
const device_filter_list &List) {
74+
for (const device_filter &Filter : List.FilterList) {
75+
Out << Filter;
76+
Out << ",";
77+
}
78+
return Out;
79+
}
80+
81+
} // namespace detail
82+
} // namespace sycl
83+
} // __SYCL_INLINE_NAMESPACE(cl)

0 commit comments

Comments
 (0)