Skip to content

[NFCI][SYCL] Simplify retrieveKernelBinary #19378

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 17 additions & 31 deletions sycl/source/detail/helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ markBufferAsInternal(const std::shared_ptr<buffer_impl> &BufImpl) {
BufImpl->markAsInternal();
}

std::tuple<const RTDeviceBinaryImage *, ur_program_handle_t>
retrieveKernelBinary(queue_impl &Queue, KernelNameStrRefT KernelName,
CGExecKernel *KernelCG) {
const RTDeviceBinaryImage *retrieveKernelBinary(queue_impl &Queue,
KernelNameStrRefT KernelName,
CGExecKernel *KernelCG) {
device_impl &Dev = Queue.getDeviceImpl();
bool isNvidia = Dev.getBackend() == backend::ext_oneapi_cuda;
bool isHIP = Dev.getBackend() == backend::ext_oneapi_hip;
Expand All @@ -58,36 +58,22 @@ retrieveKernelBinary(queue_impl &Queue, KernelNameStrRefT KernelName,
return DI->getFormat() == SYCL_DEVICE_BINARY_TYPE_LLVMIR_BITCODE &&
DI->getRawData().DeviceTargetSpec == TargetSpec;
});
if (DeviceImage == DeviceImages.end()) {
return {nullptr, nullptr};
}
context_impl &ContextImpl = Queue.getContextImpl();
ur_program_handle_t Program =
detail::ProgramManager::getInstance().createURProgram(
**DeviceImage, ContextImpl, {createSyclObjFromImpl<device>(Dev)});
return {*DeviceImage, Program};
assert(DeviceImage != DeviceImages.end() &&
"Failed to obtain a binary image.");
return *DeviceImage;
}

const RTDeviceBinaryImage *DeviceImage = nullptr;
ur_program_handle_t Program = nullptr;
auto KernelBundleImpl = KernelCG->getKernelBundle();
if (KernelCG->MSyclKernel != nullptr) {
DeviceImage = KernelCG->MSyclKernel->getDeviceImage()->get_bin_image_ref();
Program = KernelCG->MSyclKernel->getDeviceImage()->get_ur_program_ref();
} else if (auto SyclKernelImpl =
KernelBundleImpl ? KernelBundleImpl->tryGetKernel(KernelName)
: std::shared_ptr<kernel_impl>{nullptr}) {
// Retrieve the device image from the kernel bundle.
DeviceImage = SyclKernelImpl->getDeviceImage()->get_bin_image_ref();
Program = SyclKernelImpl->getDeviceImage()->get_ur_program_ref();
} else {
context_impl &ContextImpl = Queue.getContextImpl();
DeviceImage = &detail::ProgramManager::getInstance().getDeviceImage(
KernelName, ContextImpl, Dev);
Program = detail::ProgramManager::getInstance().createURProgram(
*DeviceImage, ContextImpl, {createSyclObjFromImpl<device>(Dev)});
}
return {DeviceImage, Program};
if (KernelCG->MSyclKernel != nullptr)
return KernelCG->MSyclKernel->getDeviceImage()->get_bin_image_ref();

if (auto KernelBundleImpl = KernelCG->getKernelBundle())
if (auto SyclKernelImpl = KernelBundleImpl->tryGetKernel(KernelName))
// Retrieve the device image from the kernel bundle.
return SyclKernelImpl->getDeviceImage()->get_bin_image_ref();

context_impl &ContextImpl = Queue.getContextImpl();
return &detail::ProgramManager::getInstance().getDeviceImage(
KernelName, ContextImpl, Dev);
}

} // namespace detail
Expand Down
2 changes: 1 addition & 1 deletion sycl/source/detail/helpers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class CGExecKernel;
class queue_impl;
class RTDeviceBinaryImage;

std::tuple<const RTDeviceBinaryImage *, ur_program_handle_t>
const RTDeviceBinaryImage *
retrieveKernelBinary(queue_impl &Queue, KernelNameStrRefT KernelName,
CGExecKernel *CGKernel = nullptr);
} // namespace detail
Expand Down
3 changes: 1 addition & 2 deletions sycl/source/detail/scheduler/commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3260,8 +3260,7 @@ ur_result_t ExecCGCommand::enqueueImpQueue() {

const RTDeviceBinaryImage *BinImage = nullptr;
if (detail::SYCLConfig<detail::SYCL_JIT_AMDGCN_PTX_KERNELS>::get()) {
std::tie(BinImage, std::ignore) =
retrieveKernelBinary(*MQueue, KernelName);
BinImage = retrieveKernelBinary(*MQueue, KernelName);
assert(BinImage && "Failed to obtain a binary image.");
}
enqueueImpKernel(
Expand Down
2 changes: 1 addition & 1 deletion sycl/source/handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@ event handler::finalize() {
#endif
const detail::RTDeviceBinaryImage *BinImage = nullptr;
if (detail::SYCLConfig<detail::SYCL_JIT_AMDGCN_PTX_KERNELS>::get()) {
std::tie(BinImage, std::ignore) = detail::retrieveKernelBinary(
BinImage = detail::retrieveKernelBinary(
impl->get_queue(), toKernelNameStrT(MKernelName));
assert(BinImage && "Failed to obtain a binary image.");
}
Expand Down
Loading