Skip to content

Commit 5d23a0a

Browse files
improved error handling of zero count
1 parent 9aceb2d commit 5d23a0a

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

dpctl-capi/source/dpctl_sycl_device_interface.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,12 @@ DPCTLDevice_CreateSubDevicesEqually(__dpctl_keep const DPCTLSyclDeviceRef DRef,
578578
size_t count)
579579
{
580580
vector_class<DPCTLSyclDeviceRef> *Devices = nullptr;
581-
if (DRef && count) {
581+
if (DRef) {
582+
if (count == 0) {
583+
std::cerr << "Can not create sub-devices with zero compute units"
584+
<< '\n';
585+
return nullptr;
586+
}
582587
auto D = unwrap(DRef);
583588
try {
584589
auto subDevices = D->create_sub_devices<
@@ -611,10 +616,15 @@ DPCTLDevice_CreateSubDevicesByCounts(__dpctl_keep const DPCTLSyclDeviceRef DRef,
611616
size_t ncounts)
612617
{
613618
vector_class<DPCTLSyclDeviceRef> *Devices = nullptr;
614-
std::vector<size_t> vcounts;
619+
std::vector<size_t> vcounts(ncounts);
615620
vcounts.assign(counts, counts + ncounts);
616621
size_t min_elem = *std::min_element(vcounts.begin(), vcounts.end());
617-
if (DRef && min_elem) {
622+
if (min_elem == 0) {
623+
std::cerr << "Can not create sub-devices with zero compute units"
624+
<< '\n';
625+
return nullptr;
626+
}
627+
if (DRef) {
618628
auto D = unwrap(DRef);
619629
vector_class<std::remove_pointer<decltype(D)>::type> subDevices;
620630
try {

0 commit comments

Comments
 (0)