@@ -491,6 +491,25 @@ class __SYCL_EXPORT handler {
491491 " a single kernel or explicit memory operation." );
492492 }
493493
494+ template <class Kernel > void setDeviceKernelInfo (void *KernelFuncPtr) {
495+ constexpr auto Info = detail::CompileTimeKernelInfo<Kernel>;
496+ MKernelName = Info.Name ;
497+ // TODO support ESIMD in no-integration-header case too.
498+ setKernelInfo (KernelFuncPtr, Info.NumParams , Info.ParamDescGetter ,
499+ Info.IsESIMD , Info.HasSpecialCaptures );
500+ setDeviceKernelInfoPtr (&detail::getDeviceKernelInfo<Kernel>());
501+ setType (detail::CGType::Kernel);
502+ }
503+
504+ void setDeviceKernelInfo (kernel &&Kernel) {
505+ MKernel = detail::getSyclObjImpl (std::move (Kernel));
506+ MKernelName = getKernelName ();
507+ setType (detail::CGType::Kernel);
508+
509+ // If any extra actions are added here make sure that logic around
510+ // `lambdaAndKernelHaveEqualName` calls can handle that.
511+ }
512+
494513#ifndef __INTEL_PREVIEW_BREAKING_CHANGES
495514 // TODO: Those functions are not used anymore, remove it in the next
496515 // ABI-breaking window.
@@ -823,18 +842,27 @@ class __SYCL_EXPORT handler {
823842 detail::GetInstantiateKernelOnHostPtr<KernelType, LambdaArgType,
824843 Dims>());
825844#endif
845+
846+ // SYCL unittests are built without sycl compiler, so "host" information
847+ // about kernels isn't provided (e.g., via integration headers or compiler
848+ // builtins).
849+ //
850+ // However, some copy/fill USM operation are implemented via SYCL kernels
851+ // and are instantiated resulting in all the `static_assert` checks being
852+ // exercised. Without kernel information that would fail, so we explicitly
853+ // disable such checks when this macro is defined. Note that the unittests
854+ // don't actually execute those operation, that's why disabling
855+ // unconditional `static_asserts`s is enough for now.
856+ #ifndef __SYCL_UNITTESTS
826857 constexpr auto Info = detail::CompileTimeKernelInfo<KernelName>;
827858
828- constexpr bool KernelHasName = (Info.Name != std::string_view{});
859+ static_assert (Info.Name != std::string_view{}, " Kernel must have a name! " );
829860
830861 // Some host compilers may have different captures from Clang. Currently
831862 // there is no stable way of handling this when extracting the captures,
832863 // 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
836864 static_assert (
837- !KernelHasName || sizeof (KernelType) == Info.KernelSize ,
865+ sizeof (KernelType) == Info.KernelSize ,
838866 " Unexpected kernel lambda size. This can be caused by an "
839867 " external host compiler producing a lambda with an "
840868 " unexpected layout. This is a limitation of the compiler."
@@ -846,25 +874,8 @@ class __SYCL_EXPORT handler {
846874 " -fsycl-host-compiler-options='/std:c++latest' "
847875 " might also help." );
848876#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- }
877+
878+ setDeviceKernelInfo<KernelName>((void *)MHostKernel->getPtr ());
868879
869880 // If the kernel lambda is callable with a kernel_handler argument, manifest
870881 // the associated kernel handler.
@@ -1306,7 +1317,6 @@ class __SYCL_EXPORT handler {
13061317 setNDRangeDescriptor (RoundedRange);
13071318 StoreLambda<KName, decltype (Wrapper), Dims, TransformedArgType>(
13081319 std::move (Wrapper));
1309- setType (detail::CGType::Kernel);
13101320#endif
13111321 } else
13121322#endif // !__SYCL_DISABLE_PARALLEL_FOR_RANGE_ROUNDING__ &&
@@ -1328,7 +1338,6 @@ class __SYCL_EXPORT handler {
13281338 setNDRangeDescriptor (std::move (UserRange));
13291339 StoreLambda<NameT, KernelType, Dims, TransformedArgType>(
13301340 std::move (KernelFunc));
1331- setType (detail::CGType::Kernel);
13321341#endif
13331342#else
13341343 (void )KernelFunc;
@@ -1350,13 +1359,11 @@ class __SYCL_EXPORT handler {
13501359 [[maybe_unused]] kernel Kernel) {
13511360#ifndef __SYCL_DEVICE_ONLY__
13521361 throwIfActionIsCreated ();
1353- MKernel = detail::getSyclObjImpl (std::move (Kernel));
1362+ setDeviceKernelInfo (std::move (Kernel));
13541363 detail::checkValueRange<Dims>(NumWorkItems);
13551364 setNDRangeDescriptor (std::move (NumWorkItems));
13561365 processLaunchProperties<PropertiesT>(Props);
1357- setType (detail::CGType::Kernel);
13581366 extractArgsAndReqs ();
1359- MKernelName = getKernelName ();
13601367#endif
13611368 }
13621369
@@ -1375,13 +1382,11 @@ class __SYCL_EXPORT handler {
13751382 [[maybe_unused]] kernel Kernel) {
13761383#ifndef __SYCL_DEVICE_ONLY__
13771384 throwIfActionIsCreated ();
1378- MKernel = detail::getSyclObjImpl (std::move (Kernel));
1385+ setDeviceKernelInfo (std::move (Kernel));
13791386 detail::checkValueRange<Dims>(NDRange);
13801387 setNDRangeDescriptor (std::move (NDRange));
13811388 processLaunchProperties (Props);
1382- setType (detail::CGType::Kernel);
13831389 extractArgsAndReqs ();
1384- MKernelName = getKernelName ();
13851390#endif
13861391 }
13871392
@@ -1408,7 +1413,6 @@ class __SYCL_EXPORT handler {
14081413 }
14091414 throwIfActionIsCreated ();
14101415 verifyUsedKernelBundleInternal (Info.Name );
1411- setType (detail::CGType::Kernel);
14121416
14131417 detail::checkValueRange<Dims>(params...);
14141418 if constexpr (SetNumWorkGroups) {
@@ -1454,7 +1458,6 @@ class __SYCL_EXPORT handler {
14541458 // kernel.
14551459 setHandlerKernelBundle (Kernel);
14561460 verifyUsedKernelBundleInternal (Info.Name );
1457- setType (detail::CGType::Kernel);
14581461
14591462 detail::checkValueRange<Dims>(params...);
14601463 if constexpr (SetNumWorkGroups) {
@@ -1464,12 +1467,11 @@ class __SYCL_EXPORT handler {
14641467 setNDRangeDescriptor (std::move (params)...);
14651468 }
14661469
1467- MKernel = detail::getSyclObjImpl (std::move (Kernel));
1468- if (!lambdaAndKernelHaveEqualName<NameT>()) {
1469- extractArgsAndReqs ();
1470- MKernelName = getKernelName ();
1471- } else {
1470+ setDeviceKernelInfo (std::move (Kernel));
1471+ if (lambdaAndKernelHaveEqualName<NameT>()) {
14721472 StoreLambda<NameT, KernelType, Dims, ElementType>(std::move (KernelFunc));
1473+ } else {
1474+ extractArgsAndReqs ();
14731475 }
14741476 processProperties<Info.IsESIMD , PropertiesT>(Props);
14751477#endif
@@ -1849,10 +1851,8 @@ class __SYCL_EXPORT handler {
18491851 // No need to check if range is out of INT_MAX limits as it's compile-time
18501852 // known constant
18511853 setNDRangeDescriptor (range<1 >{1 });
1852- MKernel = detail::getSyclObjImpl (std::move (Kernel));
1853- setType (detail::CGType::Kernel);
1854+ setDeviceKernelInfo (std::move (Kernel));
18541855 extractArgsAndReqs ();
1855- MKernelName = getKernelName ();
18561856 }
18571857
18581858 void parallel_for (range<1 > NumWorkItems, kernel Kernel) {
@@ -1885,12 +1885,10 @@ class __SYCL_EXPORT handler {
18851885 [[maybe_unused]] kernel Kernel) {
18861886#ifndef __SYCL_DEVICE_ONLY__
18871887 throwIfActionIsCreated ();
1888- MKernel = detail::getSyclObjImpl (std::move (Kernel));
1888+ setDeviceKernelInfo (std::move (Kernel));
18891889 detail::checkValueRange<Dims>(NumWorkItems, WorkItemOffset);
18901890 setNDRangeDescriptor (std::move (NumWorkItems), std::move (WorkItemOffset));
1891- setType (detail::CGType::Kernel);
18921891 extractArgsAndReqs ();
1893- MKernelName = getKernelName ();
18941892#endif
18951893 }
18961894
@@ -1928,13 +1926,12 @@ class __SYCL_EXPORT handler {
19281926 // No need to check if range is out of INT_MAX limits as it's compile-time
19291927 // known constant
19301928 setNDRangeDescriptor (range<1 >{1 });
1931- MKernel = detail::getSyclObjImpl (std::move (Kernel));
1932- setType (detail::CGType::Kernel);
1933- if (!lambdaAndKernelHaveEqualName<NameT>()) {
1934- extractArgsAndReqs ();
1935- MKernelName = getKernelName ();
1936- } else
1929+ setDeviceKernelInfo (std::move (Kernel));
1930+ if (lambdaAndKernelHaveEqualName<NameT>()) {
19371931 StoreLambda<NameT, KernelType, /* Dims*/ 1 , void >(std::move (KernelFunc));
1932+ } else {
1933+ extractArgsAndReqs ();
1934+ }
19381935#else
19391936 detail::CheckDeviceCopyable<KernelType>();
19401937#endif
0 commit comments