Skip to content

Commit c527a0e

Browse files
[SYCL] Fix device comparison in removeDuplicateDevices (#6730)
Kernel bundles attempt to remove duplicate devices from a passed device list. This is done through the `removeDuplicateDevices` function which creates a set through comparing devices by their native handles. However, the `getNative` member function on `device_impl` used to get these handles will retain the native devices if the backend is OpenCL. For root devices this will not have an effect, but on sub-devices this can potentially lead to a leak of the devices. As a fix this commit compares the PI devices rather than the native handles. Signed-off-by: Larsen, Steffen <[email protected]>
1 parent 3f2403b commit c527a0e

File tree

6 files changed

+17
-14
lines changed

6 files changed

+17
-14
lines changed

sycl/include/sycl/kernel_bundle.hpp

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -373,19 +373,8 @@ __SYCL_EXPORT detail::KernelBundleImplPtr
373373
get_kernel_bundle_impl(const context &Ctx, const std::vector<device> &Devs,
374374
bundle_state State);
375375

376-
inline auto getDeviceComparisonLambda() {
377-
return [](device a, device b) { return a.getNative() != b.getNative(); };
378-
}
379-
380-
inline const std::vector<device>
381-
removeDuplicateDevices(const std::vector<device> &Devs) {
382-
auto compareDevices = getDeviceComparisonLambda();
383-
std::set<device, decltype(compareDevices)> UniqueDeviceSet(
384-
Devs.begin(), Devs.end(), compareDevices);
385-
std::vector<device> UniqueDevices(UniqueDeviceSet.begin(),
386-
UniqueDeviceSet.end());
387-
return UniqueDevices;
388-
}
376+
__SYCL_EXPORT const std::vector<device>
377+
removeDuplicateDevices(const std::vector<device> &Devs);
389378

390379
} // namespace detail
391380

sycl/source/kernel_bundle.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,19 @@ bool kernel_bundle_plain::is_specialization_constant_set(
113113
///// sycl::detail free functions
114114
//////////////////////////////////
115115

116+
const std::vector<device>
117+
removeDuplicateDevices(const std::vector<device> &Devs) {
118+
auto compareDevices = [](device a, device b) {
119+
return getSyclObjImpl(a)->getHandleRef() <
120+
getSyclObjImpl(b)->getHandleRef();
121+
};
122+
std::set<device, decltype(compareDevices)> UniqueDeviceSet(
123+
Devs.begin(), Devs.end(), compareDevices);
124+
std::vector<device> UniqueDevices(UniqueDeviceSet.begin(),
125+
UniqueDeviceSet.end());
126+
return UniqueDevices;
127+
}
128+
116129
kernel_id get_kernel_id_impl(std::string KernelName) {
117130
return detail::ProgramManager::getInstance().getSYCLKernelID(KernelName);
118131
}

sycl/test/abi/sycl_symbols_linux.dump

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3841,6 +3841,7 @@ _ZN4sycl3_V16detail22get_kernel_bundle_implERKNS0_7contextERKSt6vectorINS0_6devi
38413841
_ZN4sycl3_V16detail22has_kernel_bundle_implERKNS0_7contextERKSt6vectorINS0_6deviceESaIS6_EENS0_12bundle_stateE
38423842
_ZN4sycl3_V16detail22has_kernel_bundle_implERKNS0_7contextERKSt6vectorINS0_6deviceESaIS6_EERKS5_INS0_9kernel_idESaISB_EENS0_12bundle_stateE
38433843
_ZN4sycl3_V16detail22reduGetPreferredWGSizeERSt10shared_ptrINS1_10queue_implEEm
3844+
_ZN4sycl3_V16detail22removeDuplicateDevicesERKSt6vectorINS0_6deviceESaIS3_EE
38443845
_ZN4sycl3_V16detail23constructorNotificationEPvS2_NS0_6access6targetENS3_4modeERKNS1_13code_locationE
38453846
_ZN4sycl3_V16detail23getESIMDDeviceInterfaceEv
38463847
_ZN4sycl3_V16detail24find_device_intersectionERKSt6vectorINS0_13kernel_bundleILNS0_12bundle_stateE1EEESaIS5_EE

sycl/unittests/kernel-and-program/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@ add_sycl_unittest(KernelAndProgramTests OBJECT
55
KernelInfo.cpp
66
DeviceInfo.cpp
77
PersistentDeviceCodeCache.cpp
8+
KernelBuildOptions.cpp
89
)
910
target_compile_definitions(KernelAndProgramTests PRIVATE -D__SYCL_INTERNAL_API)

sycl/unittests/misc/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,5 @@ set(sycl_lib_dir $<TARGET_FILE_DIR:sycl>)
22
add_definitions(-DSYCL_LIB_DIR="${sycl_lib_dir}")
33
add_sycl_unittest(MiscTests SHARED
44
CircularBuffer.cpp
5-
KernelBuildOptions.cpp
65
OsUtils.cpp
76
)

0 commit comments

Comments
 (0)