Skip to content

Commit 478ac8a

Browse files
[SYCL] Follow-up for intel#19990
Downstream CI uncovered another scenario where `detail::CompileTimeKernelInfo<KernelName>.Name` might be empty (other than non-SYCL compilation in some of the [unit]tests). That happens when compiling the same TU using multiple offload models (e.g., both SYCL and OMP) and the device compilation for non-SYCL model doesn't use SYCL integration header to provide kernel information. Ideally, we should be just guarding `static_assert`s with some `#if __SYCL_WHATEVER` but we don't set any SYCL-related macro when using 3rd party host compilers. Deal with that by turning compile-time `static_assert` into a run-time `assert` unless we can guarantee that SYCL kernel information is available.
1 parent d8434b3 commit 478ac8a

File tree

3 files changed

+9
-16
lines changed

3 files changed

+9
-16
lines changed

sycl/include/sycl/handler.hpp

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -836,26 +836,22 @@ class __SYCL_EXPORT handler {
836836
Dims>());
837837
#endif
838838

839-
// SYCL unittests are built without sycl compiler, so "host" information
840-
// about kernels isn't provided (e.g., via integration headers or compiler
841-
// builtins).
842-
//
843-
// However, some copy/fill USM operation are implemented via SYCL kernels
844-
// and are instantiated resulting in all the `static_assert` checks being
845-
// exercised. Without kernel information that would fail, so we explicitly
846-
// disable such checks when this macro is defined. Note that the unittests
847-
// don't actually execute those operation, that's why disabling
848-
// unconditional `static_asserts`s is enough for now.
849-
#ifndef __SYCL_UNITTESTS_BYPASS_KERNEL_NAME_CHECK
850839
constexpr auto Info = detail::CompileTimeKernelInfo<KernelName>;
851840

841+
#ifdef SYCL_LANGUAGE_VERSION
852842
static_assert(Info.Name != std::string_view{}, "Kernel must have a name!");
843+
#else
844+
// Either non-SYCL compilation (e.g., OpenMP device code generation) or
845+
// using custom host compiler.
846+
assert(Info.Name != std::string_view{}, "Kernel must have a name!");
847+
#endif
853848

854849
// Some host compilers may have different captures from Clang. Currently
855850
// there is no stable way of handling this when extracting the captures,
856851
// so a static assert is made to fail for incompatible kernel lambdas.
857852
static_assert(
858-
sizeof(KernelType) == Info.KernelSize,
853+
Info.Name == std::string_view{} ||
854+
sizeof(KernelType) == Info.KernelSize,
859855
"Unexpected kernel lambda size. This can be caused by an "
860856
"external host compiler producing a lambda with an "
861857
"unexpected layout. This is a limitation of the compiler."
@@ -866,7 +862,6 @@ class __SYCL_EXPORT handler {
866862
"In case of MSVC, passing "
867863
"-fsycl-host-compiler-options='/std:c++latest' "
868864
"might also help.");
869-
#endif
870865

871866
setDeviceKernelInfo<KernelName>((void *)MHostKernel->getPtr());
872867

sycl/test/lit.cfg.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@
127127
llvm_config.with_environment("LLVM_SYMBOLIZER_PATH", llvm_symbolizer)
128128

129129
sycl_host_only_options = (
130-
"-std=c++17 -Xclang -fsycl-is-host -D__SYCL_UNITTESTS_BYPASS_KERNEL_NAME_CHECK=1"
130+
"-std=c++17 -Xclang -fsycl-is-host"
131131
)
132132
for include_dir in [
133133
config.sycl_include,

sycl/unittests/CMakeLists.txt

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

1010
add_compile_definitions(SYCL2020_DISABLE_DEPRECATION_WARNINGS SYCL_DISABLE_FSYCL_SYCLHPP_WARNING)
1111

12-
add_compile_definitions(__SYCL_UNITTESTS_BYPASS_KERNEL_NAME_CHECK)
13-
1412
# suppress warnings which came from Google Test sources
1513
if (CXX_SUPPORTS_SUGGEST_OVERRIDE_FLAG)
1614
add_compile_options("-Wno-suggest-override")

0 commit comments

Comments
 (0)