Skip to content

Commit ad93ed9

Browse files
[NFCI][SYCL] Simplify retrieveKernelBinary (#19378)
Not sure if side effects of `createURProgram` were necessary and even if they were, don't know if I'm removing them or just delaying till the next access of some cache.
1 parent fa07e70 commit ad93ed9

File tree

4 files changed

+20
-35
lines changed

4 files changed

+20
-35
lines changed

sycl/source/detail/helpers.cpp

Lines changed: 17 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ markBufferAsInternal(const std::shared_ptr<buffer_impl> &BufImpl) {
3939
BufImpl->markAsInternal();
4040
}
4141

42-
std::tuple<const RTDeviceBinaryImage *, ur_program_handle_t>
43-
retrieveKernelBinary(queue_impl &Queue, KernelNameStrRefT KernelName,
44-
CGExecKernel *KernelCG) {
42+
const RTDeviceBinaryImage *retrieveKernelBinary(queue_impl &Queue,
43+
KernelNameStrRefT KernelName,
44+
CGExecKernel *KernelCG) {
4545
device_impl &Dev = Queue.getDeviceImpl();
4646
bool isNvidia = Dev.getBackend() == backend::ext_oneapi_cuda;
4747
bool isHIP = Dev.getBackend() == backend::ext_oneapi_hip;
@@ -58,36 +58,22 @@ retrieveKernelBinary(queue_impl &Queue, KernelNameStrRefT KernelName,
5858
return DI->getFormat() == SYCL_DEVICE_BINARY_TYPE_LLVMIR_BITCODE &&
5959
DI->getRawData().DeviceTargetSpec == TargetSpec;
6060
});
61-
if (DeviceImage == DeviceImages.end()) {
62-
return {nullptr, nullptr};
63-
}
64-
context_impl &ContextImpl = Queue.getContextImpl();
65-
ur_program_handle_t Program =
66-
detail::ProgramManager::getInstance().createURProgram(
67-
**DeviceImage, ContextImpl, {createSyclObjFromImpl<device>(Dev)});
68-
return {*DeviceImage, Program};
61+
assert(DeviceImage != DeviceImages.end() &&
62+
"Failed to obtain a binary image.");
63+
return *DeviceImage;
6964
}
7065

71-
const RTDeviceBinaryImage *DeviceImage = nullptr;
72-
ur_program_handle_t Program = nullptr;
73-
auto KernelBundleImpl = KernelCG->getKernelBundle();
74-
if (KernelCG->MSyclKernel != nullptr) {
75-
DeviceImage = KernelCG->MSyclKernel->getDeviceImage()->get_bin_image_ref();
76-
Program = KernelCG->MSyclKernel->getDeviceImage()->get_ur_program_ref();
77-
} else if (auto SyclKernelImpl =
78-
KernelBundleImpl ? KernelBundleImpl->tryGetKernel(KernelName)
79-
: std::shared_ptr<kernel_impl>{nullptr}) {
80-
// Retrieve the device image from the kernel bundle.
81-
DeviceImage = SyclKernelImpl->getDeviceImage()->get_bin_image_ref();
82-
Program = SyclKernelImpl->getDeviceImage()->get_ur_program_ref();
83-
} else {
84-
context_impl &ContextImpl = Queue.getContextImpl();
85-
DeviceImage = &detail::ProgramManager::getInstance().getDeviceImage(
86-
KernelName, ContextImpl, Dev);
87-
Program = detail::ProgramManager::getInstance().createURProgram(
88-
*DeviceImage, ContextImpl, {createSyclObjFromImpl<device>(Dev)});
89-
}
90-
return {DeviceImage, Program};
66+
if (KernelCG->MSyclKernel != nullptr)
67+
return KernelCG->MSyclKernel->getDeviceImage()->get_bin_image_ref();
68+
69+
if (auto KernelBundleImpl = KernelCG->getKernelBundle())
70+
if (auto SyclKernelImpl = KernelBundleImpl->tryGetKernel(KernelName))
71+
// Retrieve the device image from the kernel bundle.
72+
return SyclKernelImpl->getDeviceImage()->get_bin_image_ref();
73+
74+
context_impl &ContextImpl = Queue.getContextImpl();
75+
return &detail::ProgramManager::getInstance().getDeviceImage(
76+
KernelName, ContextImpl, Dev);
9177
}
9278

9379
} // namespace detail

sycl/source/detail/helpers.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class CGExecKernel;
2626
class queue_impl;
2727
class RTDeviceBinaryImage;
2828

29-
std::tuple<const RTDeviceBinaryImage *, ur_program_handle_t>
29+
const RTDeviceBinaryImage *
3030
retrieveKernelBinary(queue_impl &Queue, KernelNameStrRefT KernelName,
3131
CGExecKernel *CGKernel = nullptr);
3232

sycl/source/detail/scheduler/commands.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3260,8 +3260,7 @@ ur_result_t ExecCGCommand::enqueueImpQueue() {
32603260

32613261
const RTDeviceBinaryImage *BinImage = nullptr;
32623262
if (detail::SYCLConfig<detail::SYCL_JIT_AMDGCN_PTX_KERNELS>::get()) {
3263-
std::tie(BinImage, std::ignore) =
3264-
retrieveKernelBinary(*MQueue, KernelName);
3263+
BinImage = retrieveKernelBinary(*MQueue, KernelName);
32653264
assert(BinImage && "Failed to obtain a binary image.");
32663265
}
32673266
enqueueImpKernel(

sycl/source/handler.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,7 @@ event handler::finalize() {
597597
#endif
598598
const detail::RTDeviceBinaryImage *BinImage = nullptr;
599599
if (detail::SYCLConfig<detail::SYCL_JIT_AMDGCN_PTX_KERNELS>::get()) {
600-
std::tie(BinImage, std::ignore) = detail::retrieveKernelBinary(
600+
BinImage = detail::retrieveKernelBinary(
601601
impl->get_queue(), toKernelNameStrT(MKernelName));
602602
assert(BinImage && "Failed to obtain a binary image.");
603603
}

0 commit comments

Comments
 (0)