Skip to content

Commit 3b3a5d1

Browse files
[NFCI][SYCL] Assert KernelHasName in StoreLambda
I don't understand what not having a name was supposed to mean and it doesn't make any sense to me. The only failures I've seen after implementing this change is when we compile SYCL code with non-SYCL compiler without any SYCL knowledge (as in `clang++ -fsycl -fsycl-host-compiler=<...>` does have SYCL knowledge provided via integration headers). If anyone knows why this change would be incorrect, please let me know.
1 parent e86363f commit 3b3a5d1

File tree

8 files changed

+40
-42
lines changed

8 files changed

+40
-42
lines changed

sycl/include/sycl/handler.hpp

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -825,16 +825,24 @@ class __SYCL_EXPORT handler {
825825
#endif
826826
constexpr auto Info = detail::CompileTimeKernelInfo<KernelName>;
827827

828-
constexpr bool KernelHasName = (Info.Name != std::string_view{});
828+
// SYCL unittests are built without sycl compiler, so "host" information
829+
// about kernels isn't provided (e.g., via integration headers or compiler
830+
// builtins).
831+
//
832+
// However, some copy/fill USM operation are implemented via SYCL kernels
833+
// and are instantiated resulting in all the `static_assert` checks being
834+
// exercised. Without kernel information that would fail, so we explicitly
835+
// disable such checks when this macro is defined. Note that the unittests
836+
// don't actually execute those operation, that's why disabling
837+
// unconditional `static_asserts`s is enough for now.
838+
#ifndef __SYCL_UNITTESTS
839+
static_assert(Info.Name != std::string_view{}, "Kernel must have a name!");
829840

830841
// Some host compilers may have different captures from Clang. Currently
831842
// there is no stable way of handling this when extracting the captures,
832843
// so a static assert is made to fail for incompatible kernel lambdas.
833-
834-
// TODO remove the ifdef once the kernel size builtin is supported.
835-
#ifdef __INTEL_SYCL_USE_INTEGRATION_HEADERS
836844
static_assert(
837-
!KernelHasName || sizeof(KernelType) == Info.KernelSize,
845+
sizeof(KernelType) == Info.KernelSize,
838846
"Unexpected kernel lambda size. This can be caused by an "
839847
"external host compiler producing a lambda with an "
840848
"unexpected layout. This is a limitation of the compiler."
@@ -846,25 +854,13 @@ class __SYCL_EXPORT handler {
846854
"-fsycl-host-compiler-options='/std:c++latest' "
847855
"might also help.");
848856
#endif
849-
// Empty name indicates that the compilation happens without integration
850-
// header, so don't perform things that require it.
851-
if constexpr (KernelHasName) {
852-
// TODO support ESIMD in no-integration-header case too.
853-
854-
// Force hasSpecialCaptures to be evaluated at compile-time.
855-
setKernelInfo((void *)MHostKernel->getPtr(), Info.NumParams,
856-
Info.ParamDescGetter, Info.IsESIMD,
857-
Info.HasSpecialCaptures);
858-
859-
MKernelName = Info.Name;
860-
setDeviceKernelInfoPtr(&detail::getDeviceKernelInfo<KernelName>());
861-
} else {
862-
// In case w/o the integration header it is necessary to process
863-
// accessors from the list(which are associated with this handler) as
864-
// arguments. We must copy the associated accessors as they are checked
865-
// later during finalize.
866-
setArgsToAssociatedAccessors();
867-
}
857+
858+
// Force hasSpecialCaptures to be evaluated at compile-time.
859+
setKernelInfo((void *)MHostKernel->getPtr(), Info.NumParams,
860+
Info.ParamDescGetter, Info.IsESIMD, Info.HasSpecialCaptures);
861+
862+
MKernelName = Info.Name;
863+
setDeviceKernelInfoPtr(&detail::getDeviceKernelInfo<KernelName>());
868864

869865
// If the kernel lambda is callable with a kernel_handler argument, manifest
870866
// the associated kernel handler.

sycl/test/basic_tests/fp-accuracy.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %clangxx -%fsycl-host-only -c -ffp-accuracy=high -faltmathlib=SVMLAltMathLibrary -fno-math-errno %s
1+
// RUN: %clangxx -fsycl -c -ffp-accuracy=high -faltmathlib=SVMLAltMathLibrary -fno-math-errno %s
22

33
#include <sycl/sycl.hpp>
44

sycl/test/basic_tests/single_task_error_message.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %clangxx %fsycl-host-only -fsyntax-only -Xclang -verify -Xclang -verify-ignore-unexpected=note %s
1+
// RUN: %clangxx -fsycl-device-only -fsyntax-only -Xclang -verify -Xclang -verify-ignore-unexpected=note %s
22
#include <iostream>
33
#include <sycl/sycl.hpp>
44
int main() {
@@ -11,7 +11,7 @@ int main() {
1111
myQueue
1212
.single_task([&](sycl::handler &cgh) {
1313
// expected-error-re@sycl/queue.hpp:* {{static assertion failed due to requirement '{{.*}}': sycl::queue.single_task() requires a kernel instead of command group.{{.*}} Use queue.submit() instead}}
14-
// expected-error-re@sycl/detail/cg_types.hpp:* {{no matching function for call to object of type '(lambda at {{.*}}single_task_error_message.cpp:{{.*}})'}}
14+
// expected-error-re@sycl/detail/kernel_launch_helper.hpp:* {{no matching function for call to object of type 'const (lambda at {{.*}}single_task_error_message.cpp:{{.*}})'}}
1515
})
1616
.wait();
1717
}
@@ -27,7 +27,7 @@ int main() {
2727
.single_task(e,
2828
[&](sycl::handler &cgh) {
2929
// expected-error-re@sycl/queue.hpp:* {{static assertion failed due to requirement '{{.*}}': sycl::queue.single_task() requires a kernel instead of command group.{{.*}} Use queue.submit() instead}}
30-
// expected-error-re@sycl/detail/cg_types.hpp:* {{no matching function for call to object of type '(lambda at {{.*}}single_task_error_message.cpp:{{.*}})'}}
30+
// expected-error-re@sycl/detail/kernel_launch_helper.hpp:* {{no matching function for call to object of type 'const (lambda at {{.*}}single_task_error_message.cpp:{{.*}})'}}
3131
})
3232
.wait();
3333
}
@@ -43,7 +43,7 @@ int main() {
4343
.single_task(vector_event,
4444
[&](sycl::handler &cgh) {
4545
// expected-error-re@sycl/queue.hpp:* {{static assertion failed due to requirement '{{.*}}': sycl::queue.single_task() requires a kernel instead of command group.{{.*}} Use queue.submit() instead}}
46-
// expected-error-re@sycl/detail/cg_types.hpp:* {{no matching function for call to object of type '(lambda at {{.*}}single_task_error_message.cpp:{{.*}})'}}
46+
// expected-error-re@sycl/detail/kernel_launch_helper.hpp:* {{no matching function for call to object of type 'const (lambda at {{.*}}single_task_error_message.cpp:{{.*}})'}}
4747
})
4848
.wait();
4949
}

sycl/test/extensions/properties/non_esimd_kernel_fp_control.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %clangxx %fsycl-host-only -fsyntax-only -Xclang -verify -Xclang -verify-ignore-unexpected=note,warning %s
1+
// RUN: %clangxx -D__SYCL_UNITTESTS %fsycl-host-only -fsyntax-only -Xclang -verify -Xclang -verify-ignore-unexpected=note,warning %s
22

33
#include <sycl/sycl.hpp>
44

sycl/test/virtual-functions/properties-negative.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %clangxx %fsycl-host-only -fsyntax-only -Xclang -verify -Xclang -verify-ignore-unexpected=note,warning %s
1+
// RUN: %clangxx -D__SYCL_UNITTESTS %fsycl-host-only -fsyntax-only -Xclang -verify -Xclang -verify-ignore-unexpected=note,warning %s
22

33
#include <sycl/sycl.hpp>
44

sycl/test/warnings/deprecated_get_backend_info.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %clangxx %fsycl-host-only -fsyntax-only -Xclang -verify -Xclang -verify-ignore-unexpected=note %s
1+
// RUN: %clangxx -fsycl-device-only -fsyntax-only -Xclang -verify -Xclang -verify-ignore-unexpected=note %s
22
#include <iostream>
33
#include <sycl/detail/core.hpp>
44
#include <sycl/kernel_bundle.hpp>

sycl/test/warnings/sycl_2020_deprecations.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %clangxx %fsycl-host-only -fsyntax-only -ferror-limit=0 -sycl-std=2020 -Xclang -verify -Xclang -verify-ignore-unexpected=note %s
1+
// RUN: %clangxx -fsycl-device-only -fsyntax-only -ferror-limit=0 -sycl-std=2020 -Xclang -verify -Xclang -verify-ignore-unexpected=note %s
22

33
// expected-warning@CL/sycl.hpp:* {{CL/sycl.hpp is deprecated, use sycl/sycl.hpp}}
44
#include <CL/sycl.hpp>
@@ -283,23 +283,23 @@ int main() {
283283

284284
// expected-warning@+8{{'get_pointer' is deprecated: accessor::get_pointer() is deprecated, please use get_multi_ptr()}}
285285
// expected-warning@+7{{'get_pointer<sycl::access::target::device, void>' is deprecated: accessor::get_pointer() is deprecated, please use get_multi_ptr()}}
286-
// expected-warning@+4{{'make_ptr<int, sycl::access::address_space::global_space, sycl::access::decorated::legacy, void>' is deprecated: make_ptr is deprecated since SYCL 2020. Please use address_space_cast instead.}}
286+
// expected-warning@+4{{'make_ptr<int, sycl::access::address_space::global_space, sycl::access::decorated::legacy>' is deprecated: make_ptr is deprecated since SYCL 2020. Please use address_space_cast instead.}}
287287
sycl::multi_ptr<int, sycl::access::address_space::global_space,
288288
sycl::access::decorated::legacy>
289289
LegacyGlobalMptr =
290290
sycl::make_ptr<int, sycl::access::address_space::global_space,
291291
sycl::access::decorated::legacy>(
292292
GlobalAcc.get_pointer());
293293
// expected-warning@+7{{'get_pointer' is deprecated: local_accessor::get_pointer() is deprecated, please use get_multi_ptr()}}
294-
// expected-warning@+4{{'make_ptr<int, sycl::access::address_space::local_space, sycl::access::decorated::legacy, void>' is deprecated: make_ptr is deprecated since SYCL 2020. Please use address_space_cast instead.}}
294+
// expected-warning@+4{{'make_ptr<int, sycl::access::address_space::local_space, sycl::access::decorated::legacy>' is deprecated: make_ptr is deprecated since SYCL 2020. Please use address_space_cast instead.}}
295295
sycl::multi_ptr<int, sycl::access::address_space::local_space,
296296
sycl::access::decorated::legacy>
297297
LegacyLocalMptr =
298298
sycl::make_ptr<int, sycl::access::address_space::local_space,
299299
sycl::access::decorated::legacy>(
300300
LocalAcc.get_pointer());
301301

302-
// expected-warning@+4{{'make_ptr<int, sycl::access::address_space::private_space, sycl::access::decorated::legacy, void>' is deprecated: make_ptr is deprecated since SYCL 2020. Please use address_space_cast instead.}}
302+
// expected-warning@+4{{'make_ptr<int, sycl::access::address_space::private_space, sycl::access::decorated::legacy>' is deprecated: make_ptr is deprecated since SYCL 2020. Please use address_space_cast instead.}}
303303
sycl::multi_ptr<int, sycl::access::address_space::private_space,
304304
sycl::access::decorated::legacy>
305305
LegacyPrivateMptr =
@@ -329,27 +329,27 @@ int main() {
329329
sycl::access::decorated::yes>
330330
UndecoratedPrivateMptr = DecoratedPrivateMptr;
331331

332-
// expected-warning@+2{{'operator int *' is deprecated: Conversion to pointer type is deprecated since SYCL 2020. Please use get() instead.}}
332+
// expected-warning@+2{{'operator __global int *' is deprecated: Conversion to pointer type is deprecated since SYCL 2020. Please use get() instead.}}
333333
auto DecoratedGlobalPtr =
334334
static_cast<typename decltype(DecoratedGlobalMptr)::pointer>(
335335
DecoratedGlobalMptr);
336-
// expected-warning@+2{{'operator int *' is deprecated: Conversion to pointer type is deprecated since SYCL 2020. Please use get() instead.}}
336+
// expected-warning@+2{{'operator __local int *' is deprecated: Conversion to pointer type is deprecated since SYCL 2020. Please use get() instead.}}
337337
auto DecoratedLocalPtr =
338338
static_cast<typename decltype(DecoratedLocalMptr)::pointer>(
339339
DecoratedLocalMptr);
340-
// expected-warning@+2{{'operator int *' is deprecated: Conversion to pointer type is deprecated since SYCL 2020. Please use get() instead.}}
340+
// expected-warning@+2{{'operator __private int *' is deprecated: Conversion to pointer type is deprecated since SYCL 2020. Please use get() instead.}}
341341
auto DecoratedPrivatePtr =
342342
static_cast<typename decltype(DecoratedPrivateMptr)::pointer>(
343343
DecoratedPrivateMptr);
344-
// expected-warning@+2{{'operator int *' is deprecated: Conversion to pointer type is deprecated since SYCL 2020. Please use get() instead.}}
344+
// expected-warning@+2{{'operator __global int *' is deprecated: Conversion to pointer type is deprecated since SYCL 2020. Please use get() instead.}}
345345
auto UndecoratedGlobalPtr =
346346
static_cast<typename decltype(UndecoratedGlobalMptr)::pointer>(
347347
UndecoratedGlobalMptr);
348-
// expected-warning@+2{{'operator int *' is deprecated: Conversion to pointer type is deprecated since SYCL 2020. Please use get() instead.}}
348+
// expected-warning@+2{{'operator __local int *' is deprecated: Conversion to pointer type is deprecated since SYCL 2020. Please use get() instead.}}
349349
auto UndecoratedLocalPtr =
350350
static_cast<typename decltype(UndecoratedLocalMptr)::pointer>(
351351
UndecoratedLocalMptr);
352-
// expected-warning@+2{{'operator int *' is deprecated: Conversion to pointer type is deprecated since SYCL 2020. Please use get() instead.}}
352+
// expected-warning@+2{{'operator __private int *' is deprecated: Conversion to pointer type is deprecated since SYCL 2020. Please use get() instead.}}
353353
auto UndecoratedPrivatePtr =
354354
static_cast<typename decltype(UndecoratedPrivateMptr)::pointer>(
355355
UndecoratedPrivateMptr);

sycl/unittests/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ endforeach()
99

1010
add_compile_definitions(SYCL2020_DISABLE_DEPRECATION_WARNINGS SYCL_DISABLE_FSYCL_SYCLHPP_WARNING)
1111

12+
add_compile_definitions(__SYCL_UNITTESTS)
13+
1214
# suppress warnings which came from Google Test sources
1315
if (CXX_SUPPORTS_SUGGEST_OVERRIDE_FLAG)
1416
add_compile_options("-Wno-suggest-override")

0 commit comments

Comments
 (0)