Skip to content

Commit 4f3cbba

Browse files
authored
[SYCL] Reduce overhead of root device search (#17849)
The change reduces the overhead of a root device search, if the given device is already a root device. It also removes the unnecessary UR call and shared_ptr copy in such a case.
1 parent 8299b60 commit 4f3cbba

File tree

1 file changed

+17
-13
lines changed

1 file changed

+17
-13
lines changed

sycl/source/detail/program_manager/program_manager.cpp

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -836,22 +836,26 @@ CheckAndDecompressImage([[maybe_unused]] RTDeviceBinaryImage *Img) {
836836
ur_program_handle_t ProgramManager::getBuiltURProgram(
837837
const ContextImplPtr &ContextImpl, const DeviceImplPtr &DeviceImpl,
838838
const std::string &KernelName, const NDRDescT &NDRDesc) {
839+
DeviceImplPtr RootDevImpl;
840+
ur_bool_t MustBuildOnSubdevice = true;
841+
839842
// Check if we can optimize program builds for sub-devices by using a program
840843
// built for the root device
841-
DeviceImplPtr RootDevImpl = DeviceImpl;
842-
while (!RootDevImpl->isRootDevice()) {
843-
auto ParentDev = detail::getSyclObjImpl(
844-
RootDevImpl->get_info<info::device::parent_device>());
845-
// Sharing is allowed within a single context only
846-
if (!ContextImpl->hasDevice(ParentDev))
847-
break;
848-
RootDevImpl = std::move(ParentDev);
849-
}
844+
if (!DeviceImpl->isRootDevice()) {
845+
RootDevImpl = DeviceImpl;
846+
while (!RootDevImpl->isRootDevice()) {
847+
auto ParentDev = detail::getSyclObjImpl(
848+
RootDevImpl->get_info<info::device::parent_device>());
849+
// Sharing is allowed within a single context only
850+
if (!ContextImpl->hasDevice(ParentDev))
851+
break;
852+
RootDevImpl = std::move(ParentDev);
853+
}
850854

851-
ur_bool_t MustBuildOnSubdevice = true;
852-
ContextImpl->getAdapter()->call<UrApiKind::urDeviceGetInfo>(
853-
RootDevImpl->getHandleRef(), UR_DEVICE_INFO_BUILD_ON_SUBDEVICE,
854-
sizeof(ur_bool_t), &MustBuildOnSubdevice, nullptr);
855+
ContextImpl->getAdapter()->call<UrApiKind::urDeviceGetInfo>(
856+
RootDevImpl->getHandleRef(), UR_DEVICE_INFO_BUILD_ON_SUBDEVICE,
857+
sizeof(ur_bool_t), &MustBuildOnSubdevice, nullptr);
858+
}
855859

856860
auto Context = createSyclObjFromImpl<context>(ContextImpl);
857861
auto Device = createSyclObjFromImpl<device>(

0 commit comments

Comments
 (0)