Skip to content

Commit 1c9ddba

Browse files
[SYCL] Improve error messages on unsupported device partitioning (#6650)
Previously sycl::feature_not_supported thrown by the create_sub_devices member functions did not have an error message. This commit adds an error message to each failure case with information about the unsupported partitioning. Signed-off-by: Larsen, Steffen <[email protected]>
1 parent 2a3271b commit 1c9ddba

File tree

2 files changed

+45
-5
lines changed

2 files changed

+45
-5
lines changed

sycl/source/detail/device_impl.cpp

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,10 @@ std::vector<device> device_impl::create_sub_devices(size_t ComputeUnits) const {
161161
PI_ERROR_INVALID_DEVICE);
162162

163163
if (!is_partition_supported(info::partition_property::partition_equally)) {
164-
throw sycl::feature_not_supported();
164+
throw sycl::feature_not_supported(
165+
"Device does not support "
166+
"sycl::info::partition_property::partition_equally.",
167+
PI_ERROR_INVALID_OPERATION);
165168
}
166169
// If count exceeds the total number of compute units in the device, an
167170
// exception with the errc::invalid error code must be thrown.
@@ -187,7 +190,10 @@ device_impl::create_sub_devices(const std::vector<size_t> &Counts) const {
187190
PI_ERROR_INVALID_DEVICE);
188191

189192
if (!is_partition_supported(info::partition_property::partition_by_counts)) {
190-
throw sycl::feature_not_supported();
193+
throw sycl::feature_not_supported(
194+
"Device does not support "
195+
"sycl::info::partition_property::partition_by_counts.",
196+
PI_ERROR_INVALID_OPERATION);
191197
}
192198
static const pi_device_partition_property P[] = {
193199
PI_DEVICE_PARTITION_BY_COUNTS, PI_DEVICE_PARTITION_BY_COUNTS_LIST_END, 0};
@@ -232,9 +238,17 @@ std::vector<device> device_impl::create_sub_devices(
232238
PI_ERROR_INVALID_DEVICE);
233239

234240
if (!is_partition_supported(
235-
info::partition_property::partition_by_affinity_domain) ||
236-
!is_affinity_supported(AffinityDomain)) {
237-
throw sycl::feature_not_supported();
241+
info::partition_property::partition_by_affinity_domain)) {
242+
throw sycl::feature_not_supported(
243+
"Device does not support "
244+
"sycl::info::partition_property::partition_by_affinity_domain.",
245+
PI_ERROR_INVALID_OPERATION);
246+
}
247+
if (!is_affinity_supported(AffinityDomain)) {
248+
throw sycl::feature_not_supported(
249+
"Device does not support " + affinityDomainToString(AffinityDomain) +
250+
".",
251+
PI_ERROR_INVALID_VALUE);
238252
}
239253
const pi_device_partition_property Properties[3] = {
240254
PI_DEVICE_PARTITION_BY_AFFINITY_DOMAIN,

sycl/source/detail/device_info.hpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,32 @@ read_execution_bitfield(pi_device_exec_capabilities bits) {
7777
return result;
7878
}
7979

80+
inline std::string
81+
affinityDomainToString(info::partition_affinity_domain AffinityDomain) {
82+
switch (AffinityDomain) {
83+
#define __SYCL_AFFINITY_DOMAIN_STRING_CASE(DOMAIN) \
84+
case DOMAIN: \
85+
return #DOMAIN;
86+
87+
__SYCL_AFFINITY_DOMAIN_STRING_CASE(
88+
sycl::info::partition_affinity_domain::numa)
89+
__SYCL_AFFINITY_DOMAIN_STRING_CASE(
90+
sycl::info::partition_affinity_domain::L4_cache)
91+
__SYCL_AFFINITY_DOMAIN_STRING_CASE(
92+
sycl::info::partition_affinity_domain::L3_cache)
93+
__SYCL_AFFINITY_DOMAIN_STRING_CASE(
94+
sycl::info::partition_affinity_domain::L2_cache)
95+
__SYCL_AFFINITY_DOMAIN_STRING_CASE(
96+
sycl::info::partition_affinity_domain::L1_cache)
97+
__SYCL_AFFINITY_DOMAIN_STRING_CASE(
98+
sycl::info::partition_affinity_domain::next_partitionable)
99+
#undef __SYCL_AFFINITY_DOMAIN_STRING_CASE
100+
default:
101+
assert(false && "Missing case for affinity domain.");
102+
return "unknown";
103+
}
104+
}
105+
80106
// Mapping expected SYCL return types to those returned by PI calls
81107
template <typename T> struct sycl_to_pi {
82108
using type = T;

0 commit comments

Comments
 (0)