Skip to content

Commit 4db1941

Browse files
committed
[SYCL] sycl::kernel::get_kernel_bundle() may return a kernel_bundle with a null impl.
This is an issue complaining about that return from getSyclObjImpl can be null. I talked to @steffenlarsen off line and although this is considered to be impossible (every constructor should create for itself and impl), it doesn't seem to be enforced anywhere in the code. We decided that would be a good compromise to make sure that impl is always non-null. Signed-off-by: Zahira Ammarguellat <[email protected]>
1 parent 54655a2 commit 4db1941

File tree

4 files changed

+20
-7
lines changed

4 files changed

+20
-7
lines changed

sycl/include/sycl/detail/common.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ namespace detail {
226226
// template <class T>
227227
// friend decltype(T::impl) detail::getSyclObjImpl(const T &SyclObject);
228228
template <class Obj> decltype(Obj::impl) getSyclObjImpl(const Obj &SyclObject) {
229+
assert(SyclObject.impl && "every constructor should create an impl");
229230
return SyclObject.impl;
230231
}
231232

sycl/include/sycl/handler.hpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1290,6 +1290,8 @@ class __SYCL_EXPORT handler {
12901290
std::shared_ptr<detail::kernel_bundle_impl>
12911291
getOrInsertHandlerKernelBundle(bool Insert) const;
12921292

1293+
void setHandlerKernelBundle(kernel Kernel);
1294+
12931295
void setHandlerKernelBundle(
12941296
const std::shared_ptr<detail::kernel_bundle_impl> &NewKernelBundleImpPtr);
12951297

@@ -1918,7 +1920,7 @@ class __SYCL_EXPORT handler {
19181920
throwIfActionIsCreated();
19191921
verifyKernelInvoc(Kernel);
19201922
// Ignore any set kernel bundles and use the one associated with the kernel
1921-
setHandlerKernelBundle(detail::getSyclObjImpl(Kernel.get_kernel_bundle()));
1923+
setHandlerKernelBundle(Kernel);
19221924
// No need to check if range is out of INT_MAX limits as it's compile-time
19231925
// known constant
19241926
MNDRDesc.set(range<1>{1});
@@ -1991,7 +1993,7 @@ class __SYCL_EXPORT handler {
19911993
void single_task(kernel Kernel, _KERNELFUNCPARAM(KernelFunc)) {
19921994
throwIfActionIsCreated();
19931995
// Ignore any set kernel bundles and use the one associated with the kernel
1994-
setHandlerKernelBundle(detail::getSyclObjImpl(Kernel.get_kernel_bundle()));
1996+
setHandlerKernelBundle(Kernel);
19951997
using NameT =
19961998
typename detail::get_kernel_name_t<KernelName, KernelType>::name;
19971999
verifyUsedKernelBundle(detail::KernelInfo<NameT>::getName());
@@ -2037,7 +2039,7 @@ class __SYCL_EXPORT handler {
20372039
_KERNELFUNCPARAM(KernelFunc)) {
20382040
throwIfActionIsCreated();
20392041
// Ignore any set kernel bundles and use the one associated with the kernel
2040-
setHandlerKernelBundle(detail::getSyclObjImpl(Kernel.get_kernel_bundle()));
2042+
setHandlerKernelBundle(Kernel);
20412043
using NameT =
20422044
typename detail::get_kernel_name_t<KernelName, KernelType>::name;
20432045
verifyUsedKernelBundle(detail::KernelInfo<NameT>::getName());
@@ -2075,7 +2077,7 @@ class __SYCL_EXPORT handler {
20752077
id<Dims> WorkItemOffset, _KERNELFUNCPARAM(KernelFunc)) {
20762078
throwIfActionIsCreated();
20772079
// Ignore any set kernel bundles and use the one associated with the kernel
2078-
setHandlerKernelBundle(detail::getSyclObjImpl(Kernel.get_kernel_bundle()));
2080+
setHandlerKernelBundle(Kernel);
20792081
using NameT =
20802082
typename detail::get_kernel_name_t<KernelName, KernelType>::name;
20812083
verifyUsedKernelBundle(detail::KernelInfo<NameT>::getName());
@@ -2113,7 +2115,7 @@ class __SYCL_EXPORT handler {
21132115
_KERNELFUNCPARAM(KernelFunc)) {
21142116
throwIfActionIsCreated();
21152117
// Ignore any set kernel bundles and use the one associated with the kernel
2116-
setHandlerKernelBundle(detail::getSyclObjImpl(Kernel.get_kernel_bundle()));
2118+
setHandlerKernelBundle(Kernel);
21172119
using NameT =
21182120
typename detail::get_kernel_name_t<KernelName, KernelType>::name;
21192121
verifyUsedKernelBundle(detail::KernelInfo<NameT>::getName());
@@ -2155,7 +2157,7 @@ class __SYCL_EXPORT handler {
21552157
_KERNELFUNCPARAM(KernelFunc)) {
21562158
throwIfActionIsCreated();
21572159
// Ignore any set kernel bundles and use the one associated with the kernel
2158-
setHandlerKernelBundle(detail::getSyclObjImpl(Kernel.get_kernel_bundle()));
2160+
setHandlerKernelBundle(Kernel);
21592161
using NameT =
21602162
typename detail::get_kernel_name_t<KernelName, KernelType>::name;
21612163
verifyUsedKernelBundle(detail::KernelInfo<NameT>::getName());
@@ -2195,7 +2197,7 @@ class __SYCL_EXPORT handler {
21952197
_KERNELFUNCPARAM(KernelFunc)) {
21962198
throwIfActionIsCreated();
21972199
// Ignore any set kernel bundles and use the one associated with the kernel
2198-
setHandlerKernelBundle(detail::getSyclObjImpl(Kernel.get_kernel_bundle()));
2200+
setHandlerKernelBundle(Kernel);
21992201
using NameT =
22002202
typename detail::get_kernel_name_t<KernelName, KernelType>::name;
22012203
verifyUsedKernelBundle(detail::KernelInfo<NameT>::getName());

sycl/source/handler.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,15 @@ void handler::setHandlerKernelBundle(
8282
MImpl->MKernelBundle = NewKernelBundleImpPtr;
8383
}
8484

85+
void handler::setHandlerKernelBundle(kernel Kernel) {
86+
// Kernel may not have an associated kernel bundle if it is created from a
87+
// program. As such, apply getSyclObjImpl directly on the kernel, i.e. not
88+
// the other way around: getSyclObjImp(Kernel->get_kernel_bundle()).
89+
std::shared_ptr<detail::kernel_bundle_impl> KernelBundleImpl =
90+
detail::getSyclObjImpl(Kernel)->get_kernel_bundle();
91+
setHandlerKernelBundle(KernelBundleImpl);
92+
}
93+
8594
event handler::finalize() {
8695
// This block of code is needed only for reduction implementation.
8796
// It is harmless (does nothing) for everything else.

sycl/test/abi/sycl_symbols_linux.dump

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3957,6 +3957,7 @@ _ZN4sycl3_V17handler18extractArgsAndReqsEv
39573957
_ZN4sycl3_V17handler20DisableRangeRoundingEv
39583958
_ZN4sycl3_V17handler20associateWithHandlerEPNS0_6detail16AccessorBaseHostENS0_6access6targetE
39593959
_ZN4sycl3_V17handler20setStateSpecConstSetEv
3960+
_ZN4sycl3_V17handler22setHandlerKernelBundleENS0_6kernelE
39603961
_ZN4sycl3_V17handler22setHandlerKernelBundleERKSt10shared_ptrINS0_6detail18kernel_bundle_implEE
39613962
_ZN4sycl3_V17handler22verifyUsedKernelBundleERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
39623963
_ZN4sycl3_V17handler24GetRangeRoundingSettingsERmS2_S2_

0 commit comments

Comments
 (0)