Skip to content

Commit 62e51e6

Browse files
committed
Adjusting for comments
Signed-off-by: Steffen Larsen <[email protected]>
1 parent 0380d1c commit 62e51e6

File tree

5 files changed

+37
-94
lines changed

5 files changed

+37
-94
lines changed

sycl/include/CL/sycl/handler.hpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -730,8 +730,7 @@ class __SYCL_EXPORT handler {
730730
// If the kernel lambda is callable with a kernel_handler argument, manifest
731731
// the associated kernel handler.
732732
if (IsCallableWithKernelHandler) {
733-
getOrInsertHandlerKernelBundle(/*Insert=*/true,
734-
get_kernel_id<KernelName>());
733+
getOrInsertHandlerKernelBundle(/*Insert=*/true);
735734
}
736735
}
737736

@@ -1273,9 +1272,6 @@ class __SYCL_EXPORT handler {
12731272
std::shared_ptr<detail::kernel_bundle_impl>
12741273
getOrInsertHandlerKernelBundle(bool Insert) const;
12751274

1276-
std::shared_ptr<detail::kernel_bundle_impl>
1277-
getOrInsertHandlerKernelBundle(bool Insert, const kernel_id &KernelId) const;
1278-
12791275
void setHandlerKernelBundle(
12801276
const std::shared_ptr<detail::kernel_bundle_impl> &NewKernelBundleImpPtr);
12811277

sycl/source/detail/kernel_bundle_impl.hpp

Lines changed: 16 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,7 @@ class kernel_bundle_impl {
7979

8080
public:
8181
kernel_bundle_impl(context Ctx, std::vector<device> Devs, bundle_state State)
82-
: MContext(std::move(Ctx)), MDevices(std::move(Devs)),
83-
MInitialState(State) {
82+
: MContext(std::move(Ctx)), MDevices(std::move(Devs)), MState(State) {
8483

8584
common_ctor_checks(State);
8685

@@ -90,7 +89,7 @@ class kernel_bundle_impl {
9089

9190
// Interop constructor used by make_kernel
9291
kernel_bundle_impl(context Ctx, std::vector<device> Devs)
93-
: MContext(Ctx), MDevices(Devs), MInitialState(bundle_state::executable) {
92+
: MContext(Ctx), MDevices(Devs), MState(bundle_state::executable) {
9493
if (!checkAllDevicesAreInContext(Devs, Ctx))
9594
throw sycl::exception(
9695
make_error_code(errc::invalid),
@@ -113,7 +112,7 @@ class kernel_bundle_impl {
113112
std::vector<device> Devs, const property_list &PropList,
114113
bundle_state TargetState)
115114
: MContext(InputBundle.get_context()), MDevices(std::move(Devs)),
116-
MInitialState(TargetState) {
115+
MState(TargetState) {
117116

118117
MSpecConstValues = getSyclObjImpl(InputBundle)->get_spec_const_map_ref();
119118

@@ -163,7 +162,7 @@ class kernel_bundle_impl {
163162
kernel_bundle_impl(
164163
const std::vector<kernel_bundle<bundle_state::object>> &ObjectBundles,
165164
std::vector<device> Devs, const property_list &PropList)
166-
: MDevices(std::move(Devs)), MInitialState(bundle_state::executable) {
165+
: MDevices(std::move(Devs)), MState(bundle_state::executable) {
167166

168167
if (MDevices.empty())
169168
throw sycl::exception(make_error_code(errc::invalid),
@@ -243,8 +242,7 @@ class kernel_bundle_impl {
243242
kernel_bundle_impl(context Ctx, std::vector<device> Devs,
244243
const std::vector<kernel_id> &KernelIDs,
245244
bundle_state State)
246-
: MContext(std::move(Ctx)), MDevices(std::move(Devs)),
247-
MInitialState(State) {
245+
: MContext(std::move(Ctx)), MDevices(std::move(Devs)), MState(State) {
248246

249247
// TODO: Add a check that all kernel ids are compatible with at least one
250248
// device in Devs
@@ -256,8 +254,7 @@ class kernel_bundle_impl {
256254

257255
kernel_bundle_impl(context Ctx, std::vector<device> Devs,
258256
const DevImgSelectorImpl &Selector, bundle_state State)
259-
: MContext(std::move(Ctx)), MDevices(std::move(Devs)),
260-
MInitialState(State) {
257+
: MContext(std::move(Ctx)), MDevices(std::move(Devs)), MState(State) {
261258

262259
common_ctor_checks(State);
263260

@@ -268,7 +265,7 @@ class kernel_bundle_impl {
268265
// C'tor matches sycl::join API
269266
kernel_bundle_impl(const std::vector<detail::KernelBundleImplPtr> &Bundles,
270267
bundle_state State)
271-
: MInitialState(State) {
268+
: MState(State) {
272269
if (Bundles.empty())
273270
return;
274271

@@ -492,7 +489,7 @@ class kernel_bundle_impl {
492489
return bundle_state::executable;
493490
// All device images are expected to have the same state
494491
return MDeviceImages.empty()
495-
? MInitialState
492+
? MState
496493
: detail::getSyclObjImpl(MDeviceImages[0])->get_state();
497494
}
498495

@@ -502,38 +499,31 @@ class kernel_bundle_impl {
502499

503500
bool isInterop() const { return MIsInterop; }
504501

505-
void add_kernel(const kernel_id &KernelID, const device &Dev) {
502+
bool add_kernel(const kernel_id &KernelID, const device &Dev) {
506503
// Skip if kernel is already there
507504
if (has_kernel(KernelID, Dev))
508-
return;
505+
return true;
509506

510507
// First try and get images in current bundle state
511508
const bundle_state BundleState = get_bundle_state();
512509
std::vector<device_image_plain> NewDevImgs =
513510
detail::ProgramManager::getInstance().getSYCLDeviceImages(
514511
MContext, {Dev}, {KernelID}, BundleState);
515512

516-
// If no images were found and the bundle is in input state we try and get
517-
// the image in executable state and then bring the existing binaries into
518-
// executable as well
519-
if (NewDevImgs.empty() && BundleState == bundle_state::input) {
520-
NewDevImgs = detail::ProgramManager::getInstance().getSYCLDeviceImages(
521-
MContext, {Dev}, {KernelID}, bundle_state::executable);
522-
detail::ProgramManager::getInstance().bringSYCLDeviceImagesToState(
523-
MDeviceImages, bundle_state::executable);
524-
}
525-
526-
assert(!NewDevImgs.empty() && "Device images for kernel was not found.");
513+
// No images found so we report as not inserted
514+
if (NewDevImgs.empty())
515+
return false;
527516

528517
// Propagate already set specialization constants to the new images
529-
for (device_image_plain DevImg : NewDevImgs)
518+
for (device_image_plain &DevImg : NewDevImgs)
530519
for (auto SpecConst : MSpecConstValues)
531520
getSyclObjImpl(DevImg)->set_specialization_constant_raw_value(
532521
SpecConst.first.c_str(), SpecConst.second.data());
533522

534523
// Add the images to the collection
535524
MDeviceImages.insert(MDeviceImages.end(), NewDevImgs.begin(),
536525
NewDevImgs.end());
526+
return true;
537527
}
538528

539529
private:
@@ -544,7 +534,7 @@ class kernel_bundle_impl {
544534
// from any device image.
545535
SpecConstMapT MSpecConstValues;
546536
bool MIsInterop = false;
547-
bundle_state MInitialState;
537+
bundle_state MState;
548538
};
549539

550540
} // namespace detail

sycl/source/handler.cpp

Lines changed: 20 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -126,66 +126,6 @@ handler::getOrInsertHandlerKernelBundle(bool Insert) const {
126126
return KernelBundleImpPtr;
127127
}
128128

129-
// Returns a shared_ptr to kernel_bundle stored in the extended members vector.
130-
//
131-
// If there is no kernel_bundle created:
132-
// returns newly created kernel_bundle with KernelId if Insert is true
133-
// returns shared_ptr(nullptr) if Insert is false
134-
//
135-
// If there already existed an implicitly created kernel_bundle, the kernel is
136-
// inserted into that bundle.
137-
std::shared_ptr<detail::kernel_bundle_impl>
138-
handler::getOrInsertHandlerKernelBundle(bool Insert,
139-
const kernel_id &KernelId) const {
140-
141-
std::lock_guard<std::mutex> Lock(
142-
detail::GlobalHandler::instance().getHandlerExtendedMembersMutex());
143-
144-
assert(!MSharedPtrStorage.empty());
145-
146-
std::shared_ptr<std::vector<detail::ExtendedMemberT>> ExtendedMembersVec =
147-
detail::convertToExtendedMembers(MSharedPtrStorage[0]);
148-
// Look for the kernel bundle in extended members
149-
std::shared_ptr<detail::kernel_bundle_impl> KernelBundleImpPtr;
150-
for (const detail::ExtendedMemberT &EMember : *ExtendedMembersVec)
151-
if (detail::ExtendedMembersType::HANDLER_KERNEL_BUNDLE == EMember.MType) {
152-
KernelBundleImpPtr =
153-
std::static_pointer_cast<detail::kernel_bundle_impl>(EMember.MData);
154-
break;
155-
}
156-
157-
// No kernel bundle yet, create one
158-
if (!KernelBundleImpPtr) {
159-
if (Insert) {
160-
KernelBundleImpPtr =
161-
detail::getSyclObjImpl(get_kernel_bundle<bundle_state::input>(
162-
MQueue->get_context(), {MQueue->get_device()}, {KernelId}));
163-
if (KernelBundleImpPtr->empty()) {
164-
KernelBundleImpPtr =
165-
detail::getSyclObjImpl(get_kernel_bundle<bundle_state::executable>(
166-
MQueue->get_context(), {MQueue->get_device()}, {KernelId}));
167-
}
168-
169-
detail::ExtendedMemberT EMember = {
170-
detail::ExtendedMembersType::HANDLER_KERNEL_BUNDLE,
171-
KernelBundleImpPtr};
172-
ExtendedMembersVec->push_back(EMember);
173-
}
174-
return KernelBundleImpPtr;
175-
}
176-
177-
auto HandlerImplMember = (*ExtendedMembersVec)[0];
178-
assert(detail::ExtendedMembersType::HANDLER_IMPL == HandlerImplMember.MType);
179-
auto HandlerImpl =
180-
std::static_pointer_cast<detail::handler_impl>(HandlerImplMember.MData);
181-
182-
// Kernel bundles set explicitly by the user must not be filtered
183-
if (!HandlerImpl->isStateExplicitKernelBundle())
184-
KernelBundleImpPtr->add_kernel(KernelId, MQueue->get_device());
185-
186-
return KernelBundleImpPtr;
187-
}
188-
189129
// Sets kernel bundle to the provided one. Either replaces existing one or
190130
// create a new entry in the extended members vector.
191131
void handler::setHandlerKernelBundle(
@@ -232,7 +172,26 @@ event handler::finalize() {
232172
!getHandlerImpl()->isStateExplicitKernelBundle()) {
233173
kernel_id KernelID =
234174
detail::ProgramManager::getInstance().getSYCLKernelID(MKernelName);
235-
KernelBundleImpPtr->add_kernel(KernelID, MQueue->get_device());
175+
bool KernelInserted =
176+
KernelBundleImpPtr->add_kernel(KernelID, MQueue->get_device());
177+
// If kernel was not inserted and the bundle is in input mode we try
178+
// building it and trying to find the kernel in executable mode
179+
if (!KernelInserted &&
180+
KernelBundleImpPtr->get_bundle_state() == bundle_state::input) {
181+
auto KernelBundle =
182+
detail::createSyclObjFromImpl<kernel_bundle<bundle_state::input>>(
183+
KernelBundleImpPtr);
184+
kernel_bundle<bundle_state::executable> ExecKernelBundle =
185+
build(KernelBundle);
186+
KernelBundleImpPtr = detail::getSyclObjImpl(ExecKernelBundle);
187+
setHandlerKernelBundle(KernelBundleImpPtr);
188+
KernelInserted =
189+
KernelBundleImpPtr->add_kernel(KernelID, MQueue->get_device());
190+
}
191+
// If the kernel was not found in executable mode we throw an exception
192+
if (!KernelInserted)
193+
throw runtime_error("Failed to add kernel to kernel bundle.",
194+
PI_INVALID_KERNEL_NAME);
236195
}
237196

238197
switch (KernelBundleImpPtr->get_bundle_state()) {

sycl/test/abi/sycl_symbols_linux.dump

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4321,7 +4321,6 @@ _ZNK2cl4sycl7context9getNativeEv
43214321
_ZNK2cl4sycl7handler14getHandlerImplEv
43224322
_ZNK2cl4sycl7handler27isStateExplicitKernelBundleEv
43234323
_ZNK2cl4sycl7handler30getOrInsertHandlerKernelBundleEb
4324-
_ZNK2cl4sycl7handler30getOrInsertHandlerKernelBundleEbRKNS0_9kernel_idE
43254324
_ZNK2cl4sycl7program10get_kernelENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
43264325
_ZNK2cl4sycl7program10get_kernelENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEb
43274326
_ZNK2cl4sycl7program10has_kernelENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE

sycl/test/abi/sycl_symbols_windows.dump

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2132,7 +2132,6 @@
21322132
?getOSModuleHandle@OSUtil@detail@sycl@cl@@SA_JPEBX@Z
21332133
?getOrCreateSampler@sampler_impl@detail@sycl@cl@@QEAAPEAU_pi_sampler@@AEBVcontext@34@@Z
21342134
?getOrInsertHandlerKernelBundle@handler@sycl@cl@@AEBA?AV?$shared_ptr@Vkernel_bundle_impl@detail@sycl@cl@@@std@@_N@Z
2135-
?getOrInsertHandlerKernelBundle@handler@sycl@cl@@AEBA?AV?$shared_ptr@Vkernel_bundle_impl@detail@sycl@cl@@@std@@_NAEBVkernel_id@23@@Z
21362135
?getOrWaitEvents@detail@sycl@cl@@YA?AV?$vector@PEAU_pi_event@@V?$allocator@PEAU_pi_event@@@std@@@std@@V?$vector@Vevent@sycl@cl@@V?$allocator@Vevent@sycl@cl@@@std@@@5@V?$shared_ptr@Vcontext_impl@detail@sycl@cl@@@5@@Z
21372136
?getPixelCoordLinearFiltMode@detail@sycl@cl@@YA?AV?$vec@H$07@23@V?$vec@M$03@23@W4addressing_mode@23@V?$range@$02@23@AEAV523@@Z
21382137
?getPixelCoordNearestFiltMode@detail@sycl@cl@@YA?AV?$vec@H$03@23@V?$vec@M$03@23@W4addressing_mode@23@V?$range@$02@23@@Z

0 commit comments

Comments
 (0)