Skip to content

Commit ac30c32

Browse files
[SYCL] Split throwOnKernelParameterMisuse to improve compile time (#17670)
For the following code (note no submit, just bare minimum `cgh.single_task`): ``` int main() { int *p; sycl::detail::loop<2>([&](auto outer_idx) { sycl::detail::loop<200>([&](auto idx) { auto krn = [=]() { *p = 42; }; auto s = [&](sycl::handler &cgh) { cgh.single_task(krn); }; (void)sycl::detail::type_erased_cgfo_ty{s}; }); }); } ``` compiled as ` $ time clang++ -isystem ~/sycl/build/include a.cpp -c -o /dev/null -Wno-deprecated` (to simulate host-only compilation), improves 3.4s -> 3.0s.
1 parent af4c2fa commit ac30c32

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

sycl/include/sycl/handler.hpp

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3779,13 +3779,13 @@ class __SYCL_EXPORT handler {
37793779
/// According to section 4.7.6.11. of the SYCL specification, a local accessor
37803780
/// must not be used in a SYCL kernel function that is invoked via single_task
37813781
/// or via the simple form of parallel_for that takes a range parameter.
3782-
template <typename KernelName, typename KernelType>
3783-
void throwOnKernelParameterMisuse() const {
3784-
using NameT =
3785-
typename detail::get_kernel_name_t<KernelName, KernelType>::name;
3786-
for (unsigned I = 0; I < detail::getKernelNumParams<NameT>(); ++I) {
3787-
const detail::kernel_param_desc_t ParamDesc =
3788-
detail::getKernelParamDesc<NameT>(I);
3782+
//
3783+
// Exception handling generates lots of code, outline it out of template
3784+
// method to improve compilation times.
3785+
void throwOnKernelParameterMisuseHelper(
3786+
int N, detail::kernel_param_desc_t (*f)(int)) const {
3787+
for (int I = 0; I < N; ++I) {
3788+
detail::kernel_param_desc_t ParamDesc = (*f)(I);
37893789
const detail::kernel_param_kind_t &Kind = ParamDesc.kind;
37903790
const access::target AccTarget =
37913791
static_cast<access::target>(ParamDesc.info & AccessTargetMask);
@@ -3805,6 +3805,13 @@ class __SYCL_EXPORT handler {
38053805
"of parallel_for that takes a range parameter.");
38063806
}
38073807
}
3808+
template <typename KernelName, typename KernelType>
3809+
void throwOnKernelParameterMisuse() const {
3810+
using NameT =
3811+
typename detail::get_kernel_name_t<KernelName, KernelType>::name;
3812+
throwOnKernelParameterMisuseHelper(detail::getKernelNumParams<NameT>(),
3813+
&detail::getKernelParamDesc<NameT>);
3814+
}
38083815

38093816
template <typename T, int Dims, access::mode AccessMode,
38103817
access::target AccessTarget,

sycl/test/abi/sycl_symbols_windows.dump

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4408,6 +4408,7 @@
44084408
?supportsUSMMemset2D@handler@_V1@sycl@@AEAA_NXZ
44094409
?sycl_category@_V1@sycl@@YAAEBVerror_category@std@@XZ
44104410
?throwIfActionIsCreated@handler@_V1@sycl@@AEAAXXZ
4411+
?throwOnKernelParameterMisuseHelper@handler@_V1@sycl@@AEBAXHP6A?AUkernel_param_desc_t@detail@23@H@Z@Z
44114412
?throw_asynchronous@queue@_V1@sycl@@QEAAXXZ
44124413
?unmap@experimental@oneapi@ext@_V1@sycl@@YAXPEBX_KAEBVcontext@45@@Z
44134414
?unsampledImageConstructorNotification@detail@_V1@sycl@@YAXPEAX0AEBV?$optional@W4image_target@_V1@sycl@@@std@@W4mode@access@23@PEBXIAEBUcode_location@123@@Z

0 commit comments

Comments
 (0)