@@ -767,130 +767,6 @@ class __SYCL_EXPORT handler {
767767          &DynamicParamBase,
768768      int  ArgIndex);
769769
770-   /*  The kernel passed to StoreLambda can take an id, an item or an nd_item as
771-    * its argument. Since esimd adapter directly invokes the kernel (doesn’t use 
772-    * urKernelSetArg), the kernel argument type must be known to the adapter. 
773-    * However, passing kernel argument type to the adapter requires changing ABI 
774-    * in HostKernel class. To overcome this problem, helpers below wrap the 
775-    * “original” kernel with a functor that always takes an nd_item as argument. 
776-    * A functor is used instead of a lambda because extractArgsAndReqsFromLambda 
777-    * needs access to the “original” kernel and keeps references to its internal 
778-    * data, i.e. the kernel passed as argument cannot be local in scope. The 
779-    * functor itself is again encapsulated in a std::function since functor’s 
780-    * type is unknown to the adapter. 
781-    */  
782- 
783-   //  For 'id, item w/wo offset, nd_item' kernel arguments
784-   template  <class  KernelType , class  NormalizedKernelType , int  Dims>
785-   KernelType *ResetHostKernelHelper (const  KernelType &KernelFunc) {
786-     NormalizedKernelType NormalizedKernel (KernelFunc);
787-     auto  NormalizedKernelFunc =
788-         std::function<void (const  sycl::nd_item<Dims> &)>(NormalizedKernel);
789-     auto  HostKernelPtr = new  detail::HostKernel<decltype (NormalizedKernelFunc),
790-                                                 sycl::nd_item<Dims>, Dims>(
791-         std::move (NormalizedKernelFunc));
792-     MHostKernel.reset (HostKernelPtr);
793-     return  &HostKernelPtr->MKernel .template  target <NormalizedKernelType>()
794-                 ->MKernelFunc ;
795-   }
796- 
797-   //  For 'sycl::id<Dims>' kernel argument
798-   template  <class  KernelType , typename  ArgT, int  Dims>
799-   std::enable_if_t <std::is_same_v<ArgT, sycl::id<Dims>>, KernelType *>
800-   ResetHostKernel (const  KernelType &KernelFunc) {
801-     struct  NormalizedKernelType  {
802-       KernelType MKernelFunc;
803-       NormalizedKernelType (const  KernelType &KernelFunc)
804-           : MKernelFunc(KernelFunc) {}
805-       void  operator ()(const  nd_item<Dims> &Arg) {
806-         detail::runKernelWithArg (MKernelFunc, Arg.get_global_id ());
807-       }
808-     };
809-     return  ResetHostKernelHelper<KernelType, struct  NormalizedKernelType , Dims>(
810-         KernelFunc);
811-   }
812- 
813-   //  For 'sycl::nd_item<Dims>' kernel argument
814-   template  <class  KernelType , typename  ArgT, int  Dims>
815-   std::enable_if_t <std::is_same_v<ArgT, sycl::nd_item<Dims>>, KernelType *>
816-   ResetHostKernel (const  KernelType &KernelFunc) {
817-     struct  NormalizedKernelType  {
818-       KernelType MKernelFunc;
819-       NormalizedKernelType (const  KernelType &KernelFunc)
820-           : MKernelFunc(KernelFunc) {}
821-       void  operator ()(const  nd_item<Dims> &Arg) {
822-         detail::runKernelWithArg (MKernelFunc, Arg);
823-       }
824-     };
825-     return  ResetHostKernelHelper<KernelType, struct  NormalizedKernelType , Dims>(
826-         KernelFunc);
827-   }
828- 
829-   //  For 'sycl::item<Dims, without_offset>' kernel argument
830-   template  <class  KernelType , typename  ArgT, int  Dims>
831-   std::enable_if_t <std::is_same_v<ArgT, sycl::item<Dims, false >>, KernelType *>
832-   ResetHostKernel (const  KernelType &KernelFunc) {
833-     struct  NormalizedKernelType  {
834-       KernelType MKernelFunc;
835-       NormalizedKernelType (const  KernelType &KernelFunc)
836-           : MKernelFunc(KernelFunc) {}
837-       void  operator ()(const  nd_item<Dims> &Arg) {
838-         sycl::item<Dims, false > Item = detail::Builder::createItem<Dims, false >(
839-             Arg.get_global_range (), Arg.get_global_id ());
840-         detail::runKernelWithArg (MKernelFunc, Item);
841-       }
842-     };
843-     return  ResetHostKernelHelper<KernelType, struct  NormalizedKernelType , Dims>(
844-         KernelFunc);
845-   }
846- 
847-   //  For 'sycl::item<Dims, with_offset>' kernel argument
848-   template  <class  KernelType , typename  ArgT, int  Dims>
849-   std::enable_if_t <std::is_same_v<ArgT, sycl::item<Dims, true >>, KernelType *>
850-   ResetHostKernel (const  KernelType &KernelFunc) {
851-     struct  NormalizedKernelType  {
852-       KernelType MKernelFunc;
853-       NormalizedKernelType (const  KernelType &KernelFunc)
854-           : MKernelFunc(KernelFunc) {}
855-       void  operator ()(const  nd_item<Dims> &Arg) {
856-         sycl::item<Dims, true > Item = detail::Builder::createItem<Dims, true >(
857-             Arg.get_global_range (), Arg.get_global_id (), Arg.get_offset ());
858-         detail::runKernelWithArg (MKernelFunc, Item);
859-       }
860-     };
861-     return  ResetHostKernelHelper<KernelType, struct  NormalizedKernelType , Dims>(
862-         KernelFunc);
863-   }
864- 
865-   //  For 'void' kernel argument (single_task)
866-   template  <class  KernelType , typename  ArgT, int  Dims>
867-   typename  std::enable_if_t <std::is_same_v<ArgT, void >, KernelType *>
868-   ResetHostKernel (const  KernelType &KernelFunc) {
869-     struct  NormalizedKernelType  {
870-       KernelType MKernelFunc;
871-       NormalizedKernelType (const  KernelType &KernelFunc)
872-           : MKernelFunc(KernelFunc) {}
873-       void  operator ()(const  nd_item<Dims> &Arg) {
874-         (void )Arg;
875-         detail::runKernelWithoutArg (MKernelFunc);
876-       }
877-     };
878-     return  ResetHostKernelHelper<KernelType, struct  NormalizedKernelType , Dims>(
879-         KernelFunc);
880-   }
881- 
882-   //  For 'sycl::group<Dims>' kernel argument
883-   //  'wrapper'-based approach using 'NormalizedKernelType' struct is not used
884-   //  for 'void(sycl::group<Dims>)' since 'void(sycl::group<Dims>)' is not
885-   //  supported in ESIMD.
886-   template  <class  KernelType , typename  ArgT, int  Dims>
887-   std::enable_if_t <std::is_same_v<ArgT, sycl::group<Dims>>, KernelType *>
888-   ResetHostKernel (const  KernelType &KernelFunc) {
889-     MHostKernel.reset (
890-         new  detail::HostKernel<KernelType, ArgT, Dims>(KernelFunc));
891-     return  (KernelType *)(MHostKernel->getPtr ());
892-   }
893- 
894770  // / Verifies the kernel bundle to be used if any is set. This throws a
895771  // / sycl::exception with error code errc::kernel_not_supported if the used
896772  // / kernel bundle does not contain a suitable device image with the requested
@@ -918,8 +794,8 @@ class __SYCL_EXPORT handler {
918794        detail::KernelLambdaHasKernelHandlerArgT<KernelType,
919795                                                 LambdaArgType>::value;
920796
921-     KernelType *KernelPtr = 
922-         ResetHostKernel <KernelType, LambdaArgType, Dims>(KernelFunc);
797+     MHostKernel = std::make_unique< 
798+         detail::HostKernel <KernelType, LambdaArgType, Dims> >(KernelFunc);
923799
924800    constexpr  bool  KernelHasName =
925801        detail::getKernelName<KernelName>() != nullptr  &&
@@ -950,7 +826,7 @@ class __SYCL_EXPORT handler {
950826    if  (KernelHasName) {
951827      //  TODO support ESIMD in no-integration-header case too.
952828      clearArgs ();
953-       extractArgsAndReqsFromLambda (reinterpret_cast < char  *>(KernelPtr ),
829+       extractArgsAndReqsFromLambda (MHostKernel-> getPtr ( ),
954830                                   detail::getKernelParamDescs<KernelName>(),
955831                                   detail::isKernelESIMD<KernelName>());
956832      MKernelName = detail::getKernelName<KernelName>();
0 commit comments