Skip to content

Commit 84ba1d8

Browse files
committed
Move UR device type conversion to separate function
Signed-off-by: Larsen, Steffen <[email protected]>
1 parent c02dd4e commit 84ba1d8

File tree

3 files changed

+26
-60
lines changed

3 files changed

+26
-60
lines changed

sycl/source/detail/allowlist.cpp

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -399,25 +399,7 @@ void applyAllowList(std::vector<ur_device_handle_t> &UrDevices,
399399
Device, UR_DEVICE_INFO_TYPE, sizeof(UrDevType), &UrDevType, nullptr);
400400
// TODO need mechanism to do these casts, there's a bunch of this sort of
401401
// thing
402-
sycl::info::device_type DeviceType = [UrDevType]() {
403-
switch (UrDevType) {
404-
default:
405-
case UR_DEVICE_TYPE_ALL:
406-
return info::device_type::all;
407-
case UR_DEVICE_TYPE_GPU:
408-
return info::device_type::gpu;
409-
case UR_DEVICE_TYPE_CPU:
410-
return info::device_type::cpu;
411-
case UR_DEVICE_TYPE_FPGA:
412-
return info::device_type::accelerator;
413-
case UR_DEVICE_TYPE_CUSTOM:
414-
case UR_DEVICE_TYPE_MCA:
415-
case UR_DEVICE_TYPE_VPU:
416-
return info::device_type::custom;
417-
case UR_DEVICE_TYPE_DEFAULT:
418-
return info::device_type::automatic;
419-
}
420-
}();
402+
sycl::info::device_type DeviceType = detail::ConvertDeviceType(UrDevType);
421403
for (const auto &SyclDeviceType :
422404
getSyclDeviceTypeMap<true /*Enable 'acc'*/>()) {
423405
if (SyclDeviceType.second == DeviceType) {

sycl/source/detail/device_impl.hpp

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,29 @@ ConvertAffinityDomain(const ur_device_affinity_domain_flags_t Domain) {
6464
}
6565
}
6666

67+
inline info::device_type ConvertDeviceType(ur_device_type_t UrDevType) {
68+
switch (UrDevType) {
69+
case UR_DEVICE_TYPE_DEFAULT:
70+
return info::device_type::automatic;
71+
case UR_DEVICE_TYPE_ALL:
72+
return info::device_type::all;
73+
case UR_DEVICE_TYPE_GPU:
74+
return info::device_type::gpu;
75+
case UR_DEVICE_TYPE_CPU:
76+
return info::device_type::cpu;
77+
case UR_DEVICE_TYPE_FPGA:
78+
return info::device_type::accelerator;
79+
case UR_DEVICE_TYPE_MCA:
80+
case UR_DEVICE_TYPE_VPU:
81+
case UR_DEVICE_TYPE_CUSTOM:
82+
return info::device_type::custom;
83+
default:
84+
assert(false);
85+
// FIXME: what is that???
86+
return info::device_type::custom;
87+
}
88+
}
89+
6790
// Note that UR's enums have weird *_FORCE_UINT32 values, we ignore them in the
6891
// callers. But we also can't write a fully-covered switch without mentioning it
6992
// there, which wouldn't make any sense. As such, ensure that "real" values
@@ -582,28 +605,7 @@ class device_impl : public std::enable_shared_from_this<device_impl> {
582605
// device_traits.def
583606

584607
CASE(info::device::device_type) {
585-
using device_type = info::device_type;
586-
switch (get_info_impl<UR_DEVICE_INFO_TYPE>()) {
587-
case UR_DEVICE_TYPE_DEFAULT:
588-
return device_type::automatic;
589-
case UR_DEVICE_TYPE_ALL:
590-
return device_type::all;
591-
case UR_DEVICE_TYPE_GPU:
592-
return device_type::gpu;
593-
case UR_DEVICE_TYPE_CPU:
594-
return device_type::cpu;
595-
case UR_DEVICE_TYPE_FPGA:
596-
return device_type::accelerator;
597-
case UR_DEVICE_TYPE_MCA:
598-
case UR_DEVICE_TYPE_VPU:
599-
case UR_DEVICE_TYPE_CUSTOM:
600-
return device_type::custom;
601-
default: {
602-
assert(false);
603-
// FIXME: what is that???
604-
return device_type::custom;
605-
}
606-
}
608+
return detail::ConvertDeviceType(get_info_impl<UR_DEVICE_INFO_TYPE>());
607609
}
608610

609611
CASE(info::device::max_work_item_sizes<3>) {

sycl/source/detail/platform_impl.cpp

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -248,25 +248,7 @@ platform_impl::filterDeviceFilter(std::vector<ur_device_handle_t> &UrDevices,
248248
MAdapter->call<UrApiKind::urDeviceGetInfo>(Device, UR_DEVICE_INFO_TYPE,
249249
sizeof(ur_device_type_t),
250250
&UrDevType, nullptr);
251-
info::device_type DeviceType = [UrDevType]() {
252-
switch (UrDevType) {
253-
default:
254-
case UR_DEVICE_TYPE_ALL:
255-
return info::device_type::all;
256-
case UR_DEVICE_TYPE_GPU:
257-
return info::device_type::gpu;
258-
case UR_DEVICE_TYPE_CPU:
259-
return info::device_type::cpu;
260-
case UR_DEVICE_TYPE_FPGA:
261-
return info::device_type::accelerator;
262-
case UR_DEVICE_TYPE_CUSTOM:
263-
case UR_DEVICE_TYPE_MCA:
264-
case UR_DEVICE_TYPE_VPU:
265-
return info::device_type::custom;
266-
case UR_DEVICE_TYPE_DEFAULT:
267-
return info::device_type::automatic;
268-
}
269-
}();
251+
info::device_type DeviceType = detail::ConvertDeviceType(UrDevType);
270252

271253
for (const FilterT &Filter : FilterList->get()) {
272254
backend FilterBackend = Filter.Backend.value_or(backend::all);

0 commit comments

Comments
 (0)