Skip to content

Commit 67f6bba

Browse files
authored
[SYCL] Implement sycl::is_compatible() function (#7510)
1 parent 85f2b97 commit 67f6bba

File tree

4 files changed

+33
-1
lines changed

4 files changed

+33
-1
lines changed

sycl/include/sycl/kernel_bundle.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,8 @@ bool has_kernel_bundle(const context &Ctx, const std::vector<device> &Devs) {
564564

565565
/// \returns true if all of the kernels identified by KernelIDs are compatible
566566
/// with the device Dev.
567-
bool is_compatible(const std::vector<kernel_id> &KernelIDs, const device &Dev);
567+
__SYCL_EXPORT bool is_compatible(const std::vector<kernel_id> &KernelIDs,
568+
const device &Dev);
568569

569570
template <typename KernelName> bool is_compatible(const device &Dev) {
570571
return is_compatible({get_kernel_id<KernelName>()}, Dev);

sycl/source/kernel_bundle.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include <detail/kernel_bundle_impl.hpp>
1010
#include <detail/kernel_id_impl.hpp>
11+
#include <detail/program_manager/program_manager.hpp>
1112

1213
#include <set>
1314

@@ -294,5 +295,33 @@ std::vector<kernel_id> get_kernel_ids() {
294295
return detail::ProgramManager::getInstance().getAllSYCLKernelIDs();
295296
}
296297

298+
bool is_compatible(const std::vector<kernel_id> &KernelIDs, const device &Dev) {
299+
for (const auto &KernelId : KernelIDs) {
300+
const detail::RTDeviceBinaryImage &Img =
301+
detail::ProgramManager::getInstance().getDeviceImage(
302+
detail::OSUtil::ExeModuleHandle, KernelId.get_name(), context(Dev),
303+
Dev);
304+
const detail::RTDeviceBinaryImage::PropertyRange &ARange =
305+
Img.getDeviceRequirements();
306+
for (detail::RTDeviceBinaryImage::PropertyRange::ConstIterator It :
307+
ARange) {
308+
using namespace std::literals;
309+
if ((*It)->Name != "aspects"sv)
310+
continue;
311+
detail::ByteArray Aspects =
312+
detail::DeviceBinaryProperty(*It).asByteArray();
313+
// Drop 8 bytes describing the size of the byte array
314+
Aspects.dropBytes(8);
315+
while (!Aspects.empty()) {
316+
aspect Aspect = Aspects.consume<aspect>();
317+
if (!Dev.has(Aspect))
318+
return false;
319+
}
320+
}
321+
}
322+
323+
return true;
324+
}
325+
297326
} // __SYCL_INLINE_VER_NAMESPACE(_V1)
298327
} // namespace sycl

sycl/test/abi/sycl_symbols_linux.dump

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3619,6 +3619,7 @@ _ZN4sycl3_V113aligned_allocEmmRKNS0_5queueENS0_3usm5allocERKNS0_13property_listE
36193619
_ZN4sycl3_V113aligned_allocEmmRKNS0_5queueENS0_3usm5allocERKNS0_6detail13code_locationE
36203620
_ZN4sycl3_V113aligned_allocEmmRKNS0_6deviceERKNS0_7contextENS0_3usm5allocERKNS0_13property_listERKNS0_6detail13code_locationE
36213621
_ZN4sycl3_V113aligned_allocEmmRKNS0_6deviceERKNS0_7contextENS0_3usm5allocERKNS0_6detail13code_locationE
3622+
_ZN4sycl3_V113is_compatibleERKSt6vectorINS0_9kernel_idESaIS2_EERKNS0_6deviceE
36223623
_ZN4sycl3_V113malloc_deviceEmRKNS0_5queueERKNS0_13property_listERKNS0_6detail13code_locationE
36233624
_ZN4sycl3_V113malloc_deviceEmRKNS0_5queueERKNS0_6detail13code_locationE
36243625
_ZN4sycl3_V113malloc_deviceEmRKNS0_6deviceERKNS0_7contextERKNS0_13property_listERKNS0_6detail13code_locationE

sycl/test/abi/sycl_symbols_windows.dump

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -948,6 +948,7 @@
948948
?isValidModeForSourceAccessor@handler@_V1@sycl@@CA_NW4mode@access@23@@Z
949949
?isValidTargetForExplicitOp@handler@_V1@sycl@@CA_NW4target@access@23@@Z
950950
?is_accelerator@device@_V1@sycl@@QEBA_NXZ
951+
?is_compatible@_V1@sycl@@YA_NAEBV?$vector@Vkernel_id@_V1@sycl@@V?$allocator@Vkernel_id@_V1@sycl@@@std@@@std@@AEBVdevice@12@@Z
951952
?is_cpu@device@_V1@sycl@@QEBA_NXZ
952953
?is_gpu@device@_V1@sycl@@QEBA_NXZ
953954
?is_host@context@_V1@sycl@@QEBA_NXZ

0 commit comments

Comments
 (0)