Skip to content

Commit cabb43f

Browse files
authored
[SYCL] Remove unnecessary template parameter (#5127)
Replacing unnecessary KernelName parameter with a bool value that is actually used in `HostKernel` class reduces the number of instantiated templates and may improve host-side frontend time by ~9%.
1 parent d3649d8 commit cabb43f

File tree

3 files changed

+20
-29
lines changed

3 files changed

+20
-29
lines changed

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

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ class HostTask {
242242
};
243243

244244
// Class which stores specific lambda object.
245-
template <class KernelType, class KernelArgType, int Dims, typename KernelName>
245+
template <class KernelType, class KernelArgType, int Dims, bool StoreLocation>
246246
class HostKernel : public HostKernelBase {
247247
using IDBuilder = sycl::detail::Builder;
248248
KernelType MKernel;
@@ -290,9 +290,6 @@ class HostKernel : public HostKernelBase {
290290
template <class ArgT = KernelArgType>
291291
typename detail::enable_if_t<std::is_same<ArgT, sycl::id<Dims>>::value>
292292
runOnHost(const NDRDescT &NDRDesc) {
293-
using KI = detail::KernelInfo<KernelName>;
294-
constexpr bool StoreLocation = KI::callsAnyThisFreeFunction();
295-
296293
sycl::range<Dims> Range(InitializedVal<Dims, range>::template get<0>());
297294
sycl::id<Dims> Offset;
298295
sycl::range<Dims> Stride(
@@ -323,9 +320,6 @@ class HostKernel : public HostKernelBase {
323320
typename detail::enable_if_t<
324321
std::is_same<ArgT, item<Dims, /*Offset=*/false>>::value>
325322
runOnHost(const NDRDescT &NDRDesc) {
326-
using KI = detail::KernelInfo<KernelName>;
327-
constexpr bool StoreLocation = KI::callsAnyThisFreeFunction();
328-
329323
sycl::id<Dims> ID;
330324
sycl::range<Dims> Range(InitializedVal<Dims, range>::template get<0>());
331325
for (int I = 0; I < Dims; ++I)
@@ -348,9 +342,6 @@ class HostKernel : public HostKernelBase {
348342
typename detail::enable_if_t<
349343
std::is_same<ArgT, item<Dims, /*Offset=*/true>>::value>
350344
runOnHost(const NDRDescT &NDRDesc) {
351-
using KI = detail::KernelInfo<KernelName>;
352-
constexpr bool StoreLocation = KI::callsAnyThisFreeFunction();
353-
354345
sycl::range<Dims> Range(InitializedVal<Dims, range>::template get<0>());
355346
sycl::id<Dims> Offset;
356347
sycl::range<Dims> Stride(
@@ -380,9 +371,6 @@ class HostKernel : public HostKernelBase {
380371
template <class ArgT = KernelArgType>
381372
typename detail::enable_if_t<std::is_same<ArgT, nd_item<Dims>>::value>
382373
runOnHost(const NDRDescT &NDRDesc) {
383-
using KI = detail::KernelInfo<KernelName>;
384-
constexpr bool StoreLocation = KI::callsAnyThisFreeFunction();
385-
386374
sycl::range<Dims> GroupSize(InitializedVal<Dims, range>::template get<0>());
387375
for (int I = 0; I < Dims; ++I) {
388376
if (NDRDesc.LocalSize[I] == 0 ||

sycl/include/CL/sycl/handler.hpp

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -576,22 +576,22 @@ class __SYCL_EXPORT handler {
576576

577577
// For 'id, item w/wo offset, nd_item' kernel arguments
578578
template <class KernelType, class NormalizedKernelType, int Dims,
579-
typename KernelName>
579+
bool StoreLocation>
580580
KernelType *ResetHostKernelHelper(const KernelType &KernelFunc) {
581581
NormalizedKernelType NormalizedKernel(KernelFunc);
582582
auto NormalizedKernelFunc =
583583
std::function<void(const sycl::nd_item<Dims> &)>(NormalizedKernel);
584584
auto HostKernelPtr =
585585
new detail::HostKernel<decltype(NormalizedKernelFunc),
586-
sycl::nd_item<Dims>, Dims, KernelName>(
586+
sycl::nd_item<Dims>, Dims, StoreLocation>(
587587
NormalizedKernelFunc);
588588
MHostKernel.reset(HostKernelPtr);
589589
return &HostKernelPtr->MKernel.template target<NormalizedKernelType>()
590590
->MKernelFunc;
591591
}
592592

593593
// For 'sycl::id<Dims>' kernel argument
594-
template <class KernelType, typename ArgT, int Dims, typename KernelName>
594+
template <class KernelType, typename ArgT, int Dims, bool StoreLocation>
595595
typename std::enable_if<std::is_same<ArgT, sycl::id<Dims>>::value,
596596
KernelType *>::type
597597
ResetHostKernel(const KernelType &KernelFunc) {
@@ -604,11 +604,11 @@ class __SYCL_EXPORT handler {
604604
}
605605
};
606606
return ResetHostKernelHelper<KernelType, struct NormalizedKernelType, Dims,
607-
KernelName>(KernelFunc);
607+
StoreLocation>(KernelFunc);
608608
}
609609

610610
// For 'sycl::nd_item<Dims>' kernel argument
611-
template <class KernelType, typename ArgT, int Dims, typename KernelName>
611+
template <class KernelType, typename ArgT, int Dims, bool StoreLocation>
612612
typename std::enable_if<std::is_same<ArgT, sycl::nd_item<Dims>>::value,
613613
KernelType *>::type
614614
ResetHostKernel(const KernelType &KernelFunc) {
@@ -621,11 +621,11 @@ class __SYCL_EXPORT handler {
621621
}
622622
};
623623
return ResetHostKernelHelper<KernelType, struct NormalizedKernelType, Dims,
624-
KernelName>(KernelFunc);
624+
StoreLocation>(KernelFunc);
625625
}
626626

627627
// For 'sycl::item<Dims, without_offset>' kernel argument
628-
template <class KernelType, typename ArgT, int Dims, typename KernelName>
628+
template <class KernelType, typename ArgT, int Dims, bool StoreLocation>
629629
typename std::enable_if<std::is_same<ArgT, sycl::item<Dims, false>>::value,
630630
KernelType *>::type
631631
ResetHostKernel(const KernelType &KernelFunc) {
@@ -640,11 +640,11 @@ class __SYCL_EXPORT handler {
640640
}
641641
};
642642
return ResetHostKernelHelper<KernelType, struct NormalizedKernelType, Dims,
643-
KernelName>(KernelFunc);
643+
StoreLocation>(KernelFunc);
644644
}
645645

646646
// For 'sycl::item<Dims, with_offset>' kernel argument
647-
template <class KernelType, typename ArgT, int Dims, typename KernelName>
647+
template <class KernelType, typename ArgT, int Dims, bool StoreLocation>
648648
typename std::enable_if<std::is_same<ArgT, sycl::item<Dims, true>>::value,
649649
KernelType *>::type
650650
ResetHostKernel(const KernelType &KernelFunc) {
@@ -659,7 +659,7 @@ class __SYCL_EXPORT handler {
659659
}
660660
};
661661
return ResetHostKernelHelper<KernelType, struct NormalizedKernelType, Dims,
662-
KernelName>(KernelFunc);
662+
StoreLocation>(KernelFunc);
663663
}
664664

665665
/* 'wrapper'-based approach using 'NormalizedKernelType' struct is
@@ -669,13 +669,14 @@ class __SYCL_EXPORT handler {
669669
* not supported in ESIMD.
670670
*/
671671
// For 'void' and 'sycl::group<Dims>' kernel argument
672-
template <class KernelType, typename ArgT, int Dims, typename KernelName>
672+
template <class KernelType, typename ArgT, int Dims, bool StoreLocation>
673673
typename std::enable_if<std::is_same<ArgT, void>::value ||
674674
std::is_same<ArgT, sycl::group<Dims>>::value,
675675
KernelType *>::type
676676
ResetHostKernel(const KernelType &KernelFunc) {
677677
MHostKernel.reset(
678-
new detail::HostKernel<KernelType, ArgT, Dims, KernelName>(KernelFunc));
678+
new detail::HostKernel<KernelType, ArgT, Dims, StoreLocation>(
679+
KernelFunc));
679680
return (KernelType *)(MHostKernel->getPtr());
680681
}
681682

@@ -697,6 +698,9 @@ class __SYCL_EXPORT handler {
697698
template <typename KernelName, typename KernelType, int Dims,
698699
typename LambdaArgType>
699700
void StoreLambda(KernelType KernelFunc) {
701+
using KI = detail::KernelInfo<KernelName>;
702+
constexpr bool StoreLocation = KI::callsAnyThisFreeFunction();
703+
700704
constexpr bool IsCallableWithKernelHandler =
701705
detail::KernelLambdaHasKernelHandlerArgT<KernelType,
702706
LambdaArgType>::value;
@@ -707,7 +711,7 @@ class __SYCL_EXPORT handler {
707711
PI_INVALID_OPERATION);
708712
}
709713
KernelType *KernelPtr =
710-
ResetHostKernel<KernelType, LambdaArgType, Dims, KernelName>(
714+
ResetHostKernel<KernelType, LambdaArgType, Dims, StoreLocation>(
711715
KernelFunc);
712716

713717
using KI = sycl::detail::KernelInfo<KernelName>;
@@ -1481,7 +1485,7 @@ class __SYCL_EXPORT handler {
14811485

14821486
MArgs = std::move(MAssociatedAccesors);
14831487
MHostKernel.reset(
1484-
new detail::HostKernel<FuncT, void, 1, void>(std::move(Func)));
1488+
new detail::HostKernel<FuncT, void, 1, false>(std::move(Func)));
14851489
setType(detail::CG::RunOnHostIntel);
14861490
}
14871491

sycl/unittests/scheduler/StreamInitDependencyOnHost.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ class MockHandler : public sycl::handler {
2626
typename KernelName>
2727
void setHostKernel(KernelType Kernel) {
2828
static_cast<sycl::handler *>(this)->MHostKernel.reset(
29-
new sycl::detail::HostKernel<KernelType, ArgType, Dims, KernelName>(
30-
Kernel));
29+
new sycl::detail::HostKernel<KernelType, ArgType, Dims, false>(Kernel));
3130
}
3231

3332
template <int Dims> void setNDRangeDesc(sycl::nd_range<Dims> Range) {

0 commit comments

Comments
 (0)