Skip to content

Commit 172d504

Browse files
committed
Defer arg extraction until handler::finalize
Rather than extracting arguments from the lambda when the kernel is enqueued, store a pointer to the lambda alongside relevant information from the integration header or compiler builtins. Storing this information will allow us to defer the extraction of arguments until we reach handler::finalize(), at which point it may be possible to set the kernel arguments directly without populating MArgs. Signed-off-by: John Pennycook <[email protected]>
1 parent 713a9dd commit 172d504

File tree

5 files changed

+39
-8
lines changed

5 files changed

+39
-8
lines changed

sycl/include/sycl/handler.hpp

+11-7
Original file line numberDiff line numberDiff line change
@@ -749,8 +749,8 @@ class __SYCL_EXPORT handler {
749749

750750
/// Stores lambda to the template-free object
751751
///
752-
/// Also initializes kernel name, list of arguments and requirements using
753-
/// information from the integration header/built-ins.
752+
/// Also initializes the kernel name and prepares for arguments to
753+
/// be extracted from the lambda in handler::finalize().
754754
///
755755
/// \param KernelFunc is a SYCL kernel function
756756
/// \param ParamDescs is the vector of kernel parameter descriptors.
@@ -796,11 +796,11 @@ class __SYCL_EXPORT handler {
796796
if constexpr (KernelHasName) {
797797
// TODO support ESIMD in no-integration-header case too.
798798

799-
clearArgs();
800-
extractArgsAndReqsFromLambda(MHostKernel->getPtr(),
801-
&(detail::getKernelParamDesc<KernelName>),
802-
detail::getKernelNumParams<KernelName>(),
803-
detail::isKernelESIMD<KernelName>());
799+
setKernelInfo((void *)MHostKernel->getPtr(),
800+
detail::getKernelNumParams<KernelName>(),
801+
&(detail::getKernelParamDesc<KernelName>),
802+
detail::isKernelESIMD<KernelName>());
803+
804804
MKernelName = detail::getKernelName<KernelName>();
805805
} else {
806806
// In case w/o the integration header it is necessary to process
@@ -3761,6 +3761,10 @@ class __SYCL_EXPORT handler {
37613761
sycl::range<3> LocalSize, sycl::id<3> Offset,
37623762
int Dims);
37633763

3764+
void setKernelInfo(void *KernelFuncPtr, int KernelNumArgs,
3765+
detail::kernel_param_desc_t (*KernelParamDescGetter)(int),
3766+
bool KernelIsESIMD);
3767+
37643768
friend class detail::HandlerAccess;
37653769

37663770
#ifdef __INTEL_PREVIEW_BREAKING_CHANGES

sycl/source/detail/handler_impl.hpp

+6
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,12 @@ class handler_impl {
198198

199199
// Allocation ptr to be freed asynchronously.
200200
void *MFreePtr = nullptr;
201+
202+
// Store information about the kernel arguments.
203+
void *MKernelFuncPtr = nullptr;
204+
int MKernelNumArgs = 0;
205+
detail::kernel_param_desc_t (*MKernelParamDescGetter)(int) = nullptr;
206+
bool MKernelIsESIMD = false;
201207
};
202208

203209
} // namespace detail

sycl/source/handler.cpp

+20-1
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,16 @@ event handler::finalize() {
411411
return MLastEvent;
412412
MIsFinalized = true;
413413

414+
// Extract arguments from the kernel lambda.
415+
// TODO: Skip this in simple cases.
416+
const auto &type = getType();
417+
if (type == detail::CGType::Kernel && impl->MKernelFuncPtr) {
418+
clearArgs();
419+
extractArgsAndReqsFromLambda((char *)impl->MKernelFuncPtr,
420+
impl->MKernelParamDescGetter,
421+
impl->MKernelNumArgs, impl->MKernelIsESIMD);
422+
}
423+
414424
// According to 4.7.6.9 of SYCL2020 spec, if a placeholder accessor is passed
415425
// to a command without being bound to a command group, an exception should
416426
// be thrown.
@@ -448,7 +458,6 @@ event handler::finalize() {
448458
}
449459
}
450460

451-
const auto &type = getType();
452461
if (type == detail::CGType::Kernel) {
453462
// If there were uses of set_specialization_constant build the kernel_bundle
454463
std::shared_ptr<detail::kernel_bundle_impl> KernelBundleImpPtr =
@@ -2254,6 +2263,16 @@ void handler::setNDRangeDescriptorPadded(sycl::range<3> NumWorkItems,
22542263
impl->MNDRDesc = NDRDescT{NumWorkItems, LocalSize, Offset, Dims};
22552264
}
22562265

2266+
void handler::setKernelInfo(
2267+
void *KernelFuncPtr, int KernelNumArgs,
2268+
detail::kernel_param_desc_t (*KernelParamDescGetter)(int),
2269+
bool KernelIsESIMD) {
2270+
impl->MKernelFuncPtr = KernelFuncPtr;
2271+
impl->MKernelNumArgs = KernelNumArgs;
2272+
impl->MKernelParamDescGetter = KernelParamDescGetter;
2273+
impl->MKernelIsESIMD = KernelIsESIMD;
2274+
}
2275+
22572276
void handler::saveCodeLoc(detail::code_location CodeLoc, bool IsTopCodeLoc) {
22582277
MCodeLoc = CodeLoc;
22592278
impl->MIsTopCodeLoc = IsTopCodeLoc;

sycl/test/abi/sycl_symbols_linux.dump

+1
Original file line numberDiff line numberDiff line change
@@ -3523,6 +3523,7 @@ _ZN4sycl3_V17handler12addReductionERKSt10shared_ptrIKvE
35233523
_ZN4sycl3_V17handler12setArgHelperEiRNS0_3ext6oneapi12experimental6detail30dynamic_work_group_memory_baseE
35243524
_ZN4sycl3_V17handler12setArgHelperEiRNS0_6detail22work_group_memory_implE
35253525
_ZN4sycl3_V17handler13getKernelNameEv
3526+
_ZN4sycl3_V17handler13setKernelInfoEPviPFNS0_6detail19kernel_param_desc_tEiEb
35263527
_ZN4sycl3_V17handler14addAccessorReqESt10shared_ptrINS0_6detail16AccessorImplHostEE
35273528
_ZN4sycl3_V17handler14setNDRangeUsedEb
35283529
_ZN4sycl3_V17handler15ext_oneapi_copyENS0_3ext6oneapi12experimental16image_mem_handleENS0_5rangeILi3EEERKNS4_16image_descriptorEPvS7_S7_S7_

sycl/test/abi/sycl_symbols_windows.dump

+1
Original file line numberDiff line numberDiff line change
@@ -4377,6 +4377,7 @@
43774377
?setHandlerKernelBundle@handler@_V1@sycl@@AEAAXVkernel@23@@Z
43784378
?setKernelCacheConfig@handler@_V1@sycl@@AEAAXW4StableKernelCacheConfig@123@@Z
43794379
?setKernelClusterLaunch@handler@_V1@sycl@@AEAAXV?$range@$02@23@H@Z
4380+
?setKernelInfo@handler@_V1@sycl@@AEAAXPEAXHP6A?AUkernel_param_desc_t@detail@23@H@Z_N@Z
43804381
?setKernelIsCooperative@handler@_V1@sycl@@AEAAX_N@Z
43814382
?setKernelWorkGroupMem@handler@_V1@sycl@@AEAAX_K@Z
43824383
?setLocalAccessorArgHelper@handler@_V1@sycl@@AEAAXHAEAVLocalAccessorBaseHost@detail@23@@Z

0 commit comments

Comments
 (0)