Skip to content

Commit 2d97c0b

Browse files
committed
Merge remote-tracking branch 'upstream/sycl' into stmt-attr-cleanups
2 parents 42141da + 815b43b commit 2d97c0b

File tree

20 files changed

+603
-123
lines changed

20 files changed

+603
-123
lines changed

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8258,8 +8258,7 @@ void SPIRVTranslator::ConstructJob(Compilation &C, const JobAction &JA,
82588258
// Prevent crash in the translator if input IR contains DIExpression
82598259
// operations which don't have mapping to OpenCL.DebugInfo.100 spec.
82608260
TranslatorArgs.push_back("-spirv-allow-extra-diexpressions");
8261-
if (C.getArgs().hasArg(options::OPT_fsycl_esimd))
8262-
TranslatorArgs.push_back("-spirv-allow-unknown-intrinsics");
8261+
TranslatorArgs.push_back("-spirv-allow-unknown-intrinsics=llvm.genx.");
82638262

82648263
// Disable SPV_INTEL_usm_storage_classes by default since it adds new
82658264
// storage classes that represent global_device and global_host address

clang/lib/Driver/ToolChains/SYCL.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@ const char *SYCL::Linker::constructLLVMSpirvCommand(
4343
CmdArgs.push_back("-spirv-ext=+all");
4444
CmdArgs.push_back("-spirv-debug-info-version=legacy");
4545
CmdArgs.push_back("-spirv-allow-extra-diexpressions");
46-
if (C.getArgs().hasArg(options::OPT_fsycl_esimd))
47-
CmdArgs.push_back("-spirv-allow-unknown-intrinsics");
46+
CmdArgs.push_back("-spirv-allow-unknown-intrinsics=llvm.genx.");
4847
CmdArgs.push_back("-o");
4948
CmdArgs.push_back(Output.getFilename());
5049
}

clang/test/Driver/sycl-offload-intelfpga.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
// CHK-FPGA-LINK: sycl-post-link
3636
// CHK-FPGA-LINK-NOT: -split-esimd
3737
// CHK-FPGA-LINK: "-ir-output-only" "-O2" "-spec-const=default" "-o" "[[OUTPUT2:.+\.bc]]" "[[OUTPUT2_1]]"
38-
// CHK-FPGA-LINK: llvm-spirv{{.*}} "-o" "[[OUTPUT3:.+\.spv]]" "-spirv-max-version=1.3" "-spirv-debug-info-version=legacy" "-spirv-allow-extra-diexpressions" "-spirv-ext=+all,-SPV_INTEL_usm_storage_classes,-SPV_INTEL_optnone" "[[OUTPUT2]]"
38+
// CHK-FPGA-LINK: llvm-spirv{{.*}} "-o" "[[OUTPUT3:.+\.spv]]" "-spirv-max-version=1.3" "-spirv-debug-info-version=legacy" "-spirv-allow-extra-diexpressions" "-spirv-allow-unknown-intrinsics=llvm.genx." "-spirv-ext=+all,-SPV_INTEL_usm_storage_classes,-SPV_INTEL_optnone" "[[OUTPUT2]]"
3939
// CHK-FPGA-EARLY: aoc{{.*}} "-o" "[[OUTPUT4:.+\.aocr]]" "[[OUTPUT3]]" "-sycl" "-rtl"
4040
// CHK-FPGA-IMAGE: aoc{{.*}} "-o" "[[OUTPUT5:.+\.aocx]]" "[[OUTPUT3]]" "-sycl"
4141
// CHK-FPGA-LINK: clang-offload-wrapper{{.*}} "-o=[[WRAPOUT:.+\.bc]]" "-host=x86_64-unknown-linux-gnu" {{.*}} "-kind=sycl"
@@ -69,7 +69,7 @@
6969
// CHK-FPGA-LINK-WIN: sycl-post-link
7070
// CHK-FPGA-LINK-WIN-NOT: -split-esimd
7171
// CHK-FPGA-LINK-WIN: "-ir-output-only" "-O2" "-spec-const=default" "-o" "[[OUTPUT2:.+\.bc]]" "[[OUTPUT2_1]]"
72-
// CHK-FPGA-LINK-WIN: llvm-spirv{{.*}} "-o" "[[OUTPUT3:.+\.spv]]" "-spirv-max-version=1.3" "-spirv-debug-info-version=legacy" "-spirv-allow-extra-diexpressions" "-spirv-ext=+all,-SPV_INTEL_usm_storage_classes,-SPV_INTEL_optnone" "[[OUTPUT2]]"
72+
// CHK-FPGA-LINK-WIN: llvm-spirv{{.*}} "-o" "[[OUTPUT3:.+\.spv]]" "-spirv-max-version=1.3" "-spirv-debug-info-version=legacy" "-spirv-allow-extra-diexpressions" "-spirv-allow-unknown-intrinsics=llvm.genx." "-spirv-ext=+all,-SPV_INTEL_usm_storage_classes,-SPV_INTEL_optnone" "[[OUTPUT2]]"
7373
// CHK-FPGA-LINK-WIN: aoc{{.*}} "-o" "[[OUTPUT5:.+\.aocr]]" "[[OUTPUT3]]" "-sycl" "-rtl"
7474
// CHK-FPGA-LINK-WIN: clang-offload-wrapper{{.*}} "-o=[[WRAPOUT:.+\.bc]]" {{.*}} "-kind=sycl"
7575
// CHK-FPGA-LINK-WIN: llc{{.*}} "-o" "[[OBJOUTDEV:.+\.obj]]" "[[WRAPOUT]]"
@@ -134,7 +134,7 @@
134134
// CHK-FPGA: sycl-post-link
135135
// CHK-FPGA-NOT: -split-esimd
136136
// CHK-FPGA: "-ir-output-only" "-O2" "-spec-const=default" "-o" "[[OUTPUT3_BC:.+\.bc]]" "[[OUTPUT2_BC]]"
137-
// CHK-FPGA: llvm-spirv{{.*}} "-o" "[[OUTPUT5:.+\.spv]]" "-spirv-max-version=1.3" "-spirv-debug-info-version=legacy" "-spirv-allow-extra-diexpressions" "-spirv-ext=+all,-SPV_INTEL_usm_storage_classes,-SPV_INTEL_optnone" "[[OUTPUT3_BC]]"
137+
// CHK-FPGA: llvm-spirv{{.*}} "-o" "[[OUTPUT5:.+\.spv]]" "-spirv-max-version=1.3" "-spirv-debug-info-version=legacy" "-spirv-allow-extra-diexpressions" "-spirv-allow-unknown-intrinsics=llvm.genx." "-spirv-ext=+all,-SPV_INTEL_usm_storage_classes,-SPV_INTEL_optnone" "[[OUTPUT3_BC]]"
138138
// CHK-FPGA: clang-offload-bundler{{.*}} "-type=o" "-targets=sycl-fpga_dep" {{.*}} "-outputs=[[DEPFILE:.+\.d]]" "-unbundle"
139139
// CHK-FPGA: aoc{{.*}} "-o" "[[OUTPUT6:.+\.aocx]]" "[[OUTPUT5]]" "-sycl" "-dep-files=[[DEPFILE]]"
140140
// CHK-FPGA: clang-offload-wrapper{{.*}} "-o=[[OUTPUT7:.+\.bc]]" "-host=x86_64-unknown-linux-gnu" "-target=spir64_fpga" "-kind=sycl" "[[OUTPUT6]]"

clang/test/Driver/sycl-offload.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -594,9 +594,10 @@
594594
// CHECK-LINK-SYCL-DEBUG: "--dependent-lib=sycld"
595595
// CHECK-LINK-SYCL-DEBUG-NOT: "-defaultlib:sycld.lib"
596596

597-
/// Check "-spirv-allow-unknown-intrinsics" option is emitted for llvm-spirv tool for esimd mode
598-
// RUN: %clangxx %s -fsycl -fsycl-explicit-simd -### 2>&1 | FileCheck %s --check-prefix=CHK-FSYCL-ESIMD
599-
// CHK-FSYCL-ESIMD: llvm-spirv{{.*}}-spirv-allow-unknown-intrinsics
597+
/// Check "-spirv-allow-unknown-intrinsics=llvm.genx." option is emitted for llvm-spirv tool
598+
// RUN: %clangxx %s -fsycl -### 2>&1 | FileCheck %s --check-prefix=CHK-ALLOW-INTRIN
599+
// RUN: %clangxx %s -fsycl -fsycl-explicit-simd -### 2>&1 | FileCheck %s --check-prefix=CHK-ALLOW-INTRIN
600+
// CHK-ALLOW-INTRIN: llvm-spirv{{.*}}-spirv-allow-unknown-intrinsics=llvm.genx.
600601

601602
/// ###########################################################################
602603

@@ -670,10 +671,10 @@
670671
// CHK-TOOLS-AOT: clang{{.*}} "-fsycl-is-device" {{.*}} "-o" "[[OUTPUT1:.+\.bc]]"
671672
// CHK-TOOLS-AOT: llvm-link{{.*}} "[[OUTPUT1]]" "-o" "[[OUTPUT2:.+\.bc]]"
672673
// CHK-TOOLS-AOT: sycl-post-link{{.*}} "-o" "[[OUTPUT2_1:.+\.bc]]" "[[OUTPUT2]]"
673-
// CHK-TOOLS-CPU: llvm-spirv{{.*}} "-o" "[[OUTPUT3:.+\.spv]]" "-spirv-max-version=1.3" "-spirv-debug-info-version=legacy" "-spirv-allow-extra-diexpressions" "-spirv-ext=+all,-SPV_INTEL_usm_storage_classes,-SPV_INTEL_optnone" "[[OUTPUT2_1]]"
674-
// CHK-TOOLS-GEN: llvm-spirv{{.*}} "-o" "[[OUTPUT3:.+\.spv]]" "-spirv-max-version=1.3" "-spirv-debug-info-version=legacy" "-spirv-allow-extra-diexpressions" "-spirv-ext=+all,-SPV_INTEL_usm_storage_classes,-SPV_INTEL_optnone" "[[OUTPUT2_1]]"
675-
// CHK-TOOLS-FPGA-USM-DISABLE: llvm-spirv{{.*}} "-o" "[[OUTPUT3:.+\.spv]]" "-spirv-max-version=1.3" "-spirv-debug-info-version=legacy" "-spirv-allow-extra-diexpressions" "-spirv-ext=+all,-SPV_INTEL_usm_storage_classes,-SPV_INTEL_optnone" "[[OUTPUT2_1]]"
676-
// CHK-TOOLS-FPGA-USM-ENABLE: llvm-spirv{{.*}} "-o" "[[OUTPUT3:.+\.spv]]" "-spirv-max-version=1.3" "-spirv-debug-info-version=legacy" "-spirv-allow-extra-diexpressions" "-spirv-ext=+all,-SPV_INTEL_optnone" "[[OUTPUT2_1]]"
674+
// CHK-TOOLS-CPU: llvm-spirv{{.*}} "-o" "[[OUTPUT3:.+\.spv]]" "-spirv-max-version=1.3" "-spirv-debug-info-version=legacy" "-spirv-allow-extra-diexpressions" "-spirv-allow-unknown-intrinsics=llvm.genx." "-spirv-ext=+all,-SPV_INTEL_usm_storage_classes,-SPV_INTEL_optnone" "[[OUTPUT2_1]]"
675+
// CHK-TOOLS-GEN: llvm-spirv{{.*}} "-o" "[[OUTPUT3:.+\.spv]]" "-spirv-max-version=1.3" "-spirv-debug-info-version=legacy" "-spirv-allow-extra-diexpressions" "-spirv-allow-unknown-intrinsics=llvm.genx." "-spirv-ext=+all,-SPV_INTEL_usm_storage_classes,-SPV_INTEL_optnone" "[[OUTPUT2_1]]"
676+
// CHK-TOOLS-FPGA-USM-DISABLE: llvm-spirv{{.*}} "-o" "[[OUTPUT3:.+\.spv]]" "-spirv-max-version=1.3" "-spirv-debug-info-version=legacy" "-spirv-allow-extra-diexpressions" "-spirv-allow-unknown-intrinsics=llvm.genx." "-spirv-ext=+all,-SPV_INTEL_usm_storage_classes,-SPV_INTEL_optnone" "[[OUTPUT2_1]]"
677+
// CHK-TOOLS-FPGA-USM-ENABLE: llvm-spirv{{.*}} "-o" "[[OUTPUT3:.+\.spv]]" "-spirv-max-version=1.3" "-spirv-debug-info-version=legacy" "-spirv-allow-extra-diexpressions" "-spirv-allow-unknown-intrinsics=llvm.genx." "-spirv-ext=+all,-SPV_INTEL_optnone" "[[OUTPUT2_1]]"
677678
// CHK-TOOLS-FPGA: aoc{{.*}} "-o" "[[OUTPUT4:.+\.aocx]]" "[[OUTPUT3]]"
678679
// CHK-TOOLS-GEN: ocloc{{.*}} "-output" "[[OUTPUT4:.+\.out]]" {{.*}} "[[OUTPUT3]]"
679680
// CHK-TOOLS-CPU: opencl-aot{{.*}} "-o=[[OUTPUT4:.+\.out]]" {{.*}} "[[OUTPUT3]]"

sycl/include/CL/sycl.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include <CL/sycl/item.hpp>
3636
#include <CL/sycl/kernel.hpp>
3737
#include <CL/sycl/kernel_bundle.hpp>
38+
#include <CL/sycl/kernel_handler.hpp>
3839
#include <CL/sycl/marray.hpp>
3940
#include <CL/sycl/multi_ptr.hpp>
4041
#include <CL/sycl/nd_item.hpp>
@@ -48,6 +49,7 @@
4849
#include <CL/sycl/range.hpp>
4950
#include <CL/sycl/reduction.hpp>
5051
#include <CL/sycl/sampler.hpp>
52+
#include <CL/sycl/specialization_id.hpp>
5153
#include <CL/sycl/stream.hpp>
5254
#include <CL/sycl/types.hpp>
5355
#include <CL/sycl/usm.hpp>

sycl/include/CL/sycl/detail/cg_types.hpp

Lines changed: 120 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <CL/sycl/interop_handle.hpp>
1616
#include <CL/sycl/interop_handler.hpp>
1717
#include <CL/sycl/kernel.hpp>
18+
#include <CL/sycl/kernel_handler.hpp>
1819
#include <CL/sycl/nd_item.hpp>
1920
#include <CL/sycl/range.hpp>
2021

@@ -122,6 +123,97 @@ class NDRDescT {
122123
size_t Dims;
123124
};
124125

126+
template <typename, typename T> struct check_fn_signature {
127+
static_assert(std::integral_constant<T, false>::value,
128+
"Second template parameter is required to be of function type");
129+
};
130+
131+
template <typename F, typename RetT, typename... Args>
132+
struct check_fn_signature<F, RetT(Args...)> {
133+
private:
134+
template <typename T>
135+
static constexpr auto check(T *) -> typename std::is_same<
136+
decltype(std::declval<T>().operator()(std::declval<Args>()...)),
137+
RetT>::type;
138+
139+
template <typename> static constexpr std::false_type check(...);
140+
141+
using type = decltype(check<F>(0));
142+
143+
public:
144+
static constexpr bool value = type::value;
145+
};
146+
147+
template <typename F, typename... Args>
148+
static constexpr bool check_kernel_lambda_takes_args() {
149+
return check_fn_signature<std::remove_reference_t<F>, void(Args...)>::value;
150+
}
151+
152+
// isKernelLambdaCallableWithKernelHandlerImpl checks if LambdaArgType is void
153+
// (e.g., in single_task), and based on that, calls
154+
// check_kernel_lambda_takes_args with proper set of arguments. Also this type
155+
// trait workarounds compilation error which happens only with msvc.
156+
157+
template <typename KernelType, typename LambdaArgType,
158+
typename std::enable_if_t<std::is_same<LambdaArgType, void>::value>
159+
* = nullptr>
160+
constexpr bool isKernelLambdaCallableWithKernelHandlerImpl() {
161+
return check_kernel_lambda_takes_args<KernelType, kernel_handler>();
162+
}
163+
164+
template <typename KernelType, typename LambdaArgType,
165+
typename std::enable_if_t<!std::is_same<LambdaArgType, void>::value>
166+
* = nullptr>
167+
constexpr bool isKernelLambdaCallableWithKernelHandlerImpl() {
168+
return check_kernel_lambda_takes_args<KernelType, LambdaArgType,
169+
kernel_handler>();
170+
}
171+
172+
// Type traits to find out if kernal lambda has kernel_handler argument
173+
174+
template <typename KernelType>
175+
constexpr bool isKernelLambdaCallableWithKernelHandler() {
176+
return check_kernel_lambda_takes_args<KernelType, kernel_handler>();
177+
}
178+
179+
template <typename KernelType, typename LambdaArgType>
180+
constexpr bool isKernelLambdaCallableWithKernelHandler() {
181+
return isKernelLambdaCallableWithKernelHandlerImpl<KernelType,
182+
LambdaArgType>();
183+
}
184+
185+
// Helpers for running kernel lambda on the host device
186+
187+
template <typename KernelType,
188+
typename std::enable_if_t<isKernelLambdaCallableWithKernelHandler<
189+
KernelType>()> * = nullptr>
190+
constexpr void runKernelWithoutArg(KernelType KernelName) {
191+
kernel_handler KH;
192+
KernelName(KH);
193+
}
194+
195+
template <typename KernelType,
196+
typename std::enable_if_t<!isKernelLambdaCallableWithKernelHandler<
197+
KernelType>()> * = nullptr>
198+
constexpr void runKernelWithoutArg(KernelType KernelName) {
199+
KernelName();
200+
}
201+
202+
template <typename ArgType, typename KernelType,
203+
typename std::enable_if_t<isKernelLambdaCallableWithKernelHandler<
204+
KernelType, ArgType>()> * = nullptr>
205+
constexpr void runKernelWithArg(KernelType KernelName, ArgType Arg) {
206+
kernel_handler KH;
207+
KernelName(Arg, KH);
208+
}
209+
210+
template <typename ArgType, typename KernelType,
211+
typename std::enable_if_t<!isKernelLambdaCallableWithKernelHandler<
212+
KernelType, ArgType>()> * = nullptr>
213+
constexpr void runKernelWithArg(KernelType KernelName, ArgType Arg) {
214+
KernelName(Arg);
215+
}
216+
125217
// The pure virtual class aimed to store lambda/functors of any type.
126218
class HostKernelBase {
127219
public:
@@ -197,7 +289,7 @@ class HostKernel : public HostKernelBase {
197289
template <class ArgT = KernelArgType>
198290
typename detail::enable_if_t<std::is_same<ArgT, void>::value>
199291
runOnHost(const NDRDescT &) {
200-
MKernel();
292+
runKernelWithoutArg(MKernel);
201293
}
202294

203295
template <class ArgT = KernelArgType>
@@ -218,18 +310,18 @@ class HostKernel : public HostKernelBase {
218310
UpperBound[I] = Range[I] + Offset[I];
219311
}
220312

221-
detail::NDLoop<Dims>::iterate(/*LowerBound=*/Offset, Stride, UpperBound,
222-
[&](const sycl::id<Dims> &ID) {
223-
sycl::item<Dims, /*Offset=*/true> Item =
224-
IDBuilder::createItem<Dims, true>(
225-
Range, ID, Offset);
226-
227-
if (StoreLocation) {
228-
store_id(&ID);
229-
store_item(&Item);
230-
}
231-
MKernel(ID);
232-
});
313+
detail::NDLoop<Dims>::iterate(
314+
/*LowerBound=*/Offset, Stride, UpperBound,
315+
[&](const sycl::id<Dims> &ID) {
316+
sycl::item<Dims, /*Offset=*/true> Item =
317+
IDBuilder::createItem<Dims, true>(Range, ID, Offset);
318+
319+
if (StoreLocation) {
320+
store_id(&ID);
321+
store_item(&Item);
322+
}
323+
runKernelWithArg<const sycl::id<Dims> &>(MKernel, ID);
324+
});
233325
}
234326

235327
template <class ArgT = KernelArgType>
@@ -253,7 +345,7 @@ class HostKernel : public HostKernelBase {
253345
store_id(&ID);
254346
store_item(&ItemWithOffset);
255347
}
256-
MKernel(Item);
348+
runKernelWithArg<sycl::item<Dims, /*Offset=*/false>>(MKernel, Item);
257349
});
258350
}
259351

@@ -276,18 +368,18 @@ class HostKernel : public HostKernelBase {
276368
UpperBound[I] = Range[I] + Offset[I];
277369
}
278370

279-
detail::NDLoop<Dims>::iterate(/*LowerBound=*/Offset, Stride, UpperBound,
280-
[&](const sycl::id<Dims> &ID) {
281-
sycl::item<Dims, /*Offset=*/true> Item =
282-
IDBuilder::createItem<Dims, true>(
283-
Range, ID, Offset);
284-
285-
if (StoreLocation) {
286-
store_id(&ID);
287-
store_item(&Item);
288-
}
289-
MKernel(Item);
290-
});
371+
detail::NDLoop<Dims>::iterate(
372+
/*LowerBound=*/Offset, Stride, UpperBound,
373+
[&](const sycl::id<Dims> &ID) {
374+
sycl::item<Dims, /*Offset=*/true> Item =
375+
IDBuilder::createItem<Dims, true>(Range, ID, Offset);
376+
377+
if (StoreLocation) {
378+
store_id(&ID);
379+
store_item(&Item);
380+
}
381+
runKernelWithArg<sycl::item<Dims, /*Offset=*/true>>(MKernel, Item);
382+
});
291383
}
292384

293385
template <class ArgT = KernelArgType>
@@ -336,7 +428,7 @@ class HostKernel : public HostKernelBase {
336428
auto g = NDItem.get_group();
337429
store_group(&g);
338430
}
339-
MKernel(NDItem);
431+
runKernelWithArg<const sycl::nd_item<Dims>>(MKernel, NDItem);
340432
});
341433
});
342434
}
@@ -364,7 +456,7 @@ class HostKernel : public HostKernelBase {
364456
detail::NDLoop<Dims>::iterate(NGroups, [&](const id<Dims> &GroupID) {
365457
sycl::group<Dims> Group =
366458
IDBuilder::createGroup<Dims>(GlobalSize, LocalSize, NGroups, GroupID);
367-
MKernel(Group);
459+
runKernelWithArg<sycl::group<Dims>>(MKernel, Group);
368460
});
369461
}
370462

sycl/include/CL/sycl/detail/kernel_desc.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ enum class kernel_param_kind_t {
2626
kind_accessor = 0,
2727
kind_std_layout = 1, // standard layout object parameters
2828
kind_sampler = 2,
29-
kind_pointer = 3
29+
kind_pointer = 3,
30+
kind_specialization_constants_buffer = 4,
3031
};
3132

3233
// describes a kernel parameter

0 commit comments

Comments
 (0)