Skip to content

Commit 1207b15

Browse files
[SYCL] Remove uses of invalid_parameter_error exception (#14487)
Not removing the exception subclass itself as that would result in merge conflicts with our PRs.
1 parent 17ee3e2 commit 1207b15

File tree

14 files changed

+120
-144
lines changed

14 files changed

+120
-144
lines changed

sycl/include/sycl/detail/array.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
#include <sycl/detail/defines_elementary.hpp> // for __SYCL_ALWAYS_INLINE
1212
#include <sycl/detail/pi.h> // for PI_ERROR_INVALID_VALUE
13-
#include <sycl/exception.hpp> // for invalid_parameter_error
13+
#include <sycl/exception.hpp>
1414

1515
#include <stddef.h> // for size_t
1616
#include <type_traits> // for enable_if_t
@@ -106,8 +106,8 @@ template <int dimensions = 1> class array {
106106
__SYCL_ALWAYS_INLINE void check_dimension(int dimension) const {
107107
#ifndef __SYCL_DEVICE_ONLY__
108108
if (dimension >= dimensions || dimension < 0) {
109-
throw sycl::invalid_parameter_error("Index out of range",
110-
PI_ERROR_INVALID_VALUE);
109+
throw sycl::exception(make_error_code(errc::invalid),
110+
"Index out of range");
111111
}
112112
#endif
113113
(void)dimension;

sycl/include/sycl/detail/image_accessor_util.hpp

Lines changed: 31 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,8 @@
1818
#include <sycl/detail/array.hpp> // for array
1919
#include <sycl/detail/export.hpp> // for __SYCL_EXPORT
2020
#include <sycl/detail/generic_type_traits.hpp> // for max_v, min_v, TryToGe...
21-
#include <sycl/detail/pi.h> // for PI_ERROR_INVALID_VALUE
2221
#include <sycl/detail/type_list.hpp> // for is_contained, type_list
23-
#include <sycl/exception.hpp> // for invalid_parameter_error
22+
#include <sycl/exception.hpp>
2423
#include <sycl/id.hpp> // for id
2524
#include <sycl/image.hpp> // for image_channel_type
2625
#include <sycl/range.hpp> // for range
@@ -301,10 +300,9 @@ void convertReadData(const vec<ChannelType, 4> PixelData,
301300
// OpenCL Spec section 6.12.14.2 does not allow reading uint4 data from an
302301
// image with channel datatype other than unsigned_int8,unsigned_int16 and
303302
// unsigned_int32.
304-
throw sycl::invalid_parameter_error(
305-
"Datatype of read data - cl_uint4 is incompatible with the "
306-
"image_channel_type of the image.",
307-
PI_ERROR_INVALID_VALUE);
303+
throw sycl::exception(make_error_code(errc::invalid),
304+
"Datatype of read data - cl_uint4 is incompatible "
305+
"with the image_channel_type of the image.");
308306
}
309307
}
310308

@@ -322,11 +320,9 @@ void convertReadData(const vec<ChannelType, 4> PixelData,
322320
// OpenCL Spec section 6.12.14.2 does not allow reading int4 data from an
323321
// image with channel datatype other than signed_int8,signed_int16 and
324322
// signed_int32.
325-
throw sycl::invalid_parameter_error(
326-
"Datatype of read data - cl_int4 is incompatible with "
327-
"the "
328-
"image_channel_type of the image.",
329-
PI_ERROR_INVALID_VALUE);
323+
throw sycl::exception(make_error_code(errc::invalid),
324+
"Datatype of read data - cl_int4 is incompatible "
325+
"with the image_channel_type of the image.");
330326
}
331327
}
332328

@@ -404,10 +400,9 @@ void convertReadData(const vec<ChannelType, 4> PixelData,
404400
// OpenCL Spec section 6.12.14.2 does not allow reading float4 data from an
405401
// image with channel datatype - signed/unsigned_int8,signed/unsigned_int16
406402
// and signed/unsigned_int32.
407-
throw sycl::invalid_parameter_error(
408-
"Datatype of read data - cl_float4 is incompatible with the "
409-
"image_channel_type of the image.",
410-
PI_ERROR_INVALID_VALUE);
403+
throw sycl::exception(make_error_code(errc::invalid),
404+
"Datatype of read data - cl_float4 is incompatible "
405+
"with the image_channel_type of the image.");
411406
case image_channel_type::fp16:
412407
// Host has conversion from float to half with accuracy as required in
413408
// section 8.3.2 OpenCL spec.
@@ -459,18 +454,16 @@ void convertReadData(const vec<ChannelType, 4> PixelData,
459454
// OpenCL Spec section 6.12.14.2 does not allow reading float4 data to an
460455
// image with channel datatype - signed/unsigned_int8,signed/unsigned_int16
461456
// and signed/unsigned_int32.
462-
throw sycl::invalid_parameter_error(
463-
"Datatype to read- cl_half4 is incompatible with the "
464-
"image_channel_type of the image.",
465-
PI_ERROR_INVALID_VALUE);
457+
throw sycl::exception(make_error_code(errc::invalid),
458+
"Datatype to read- cl_half4 is incompatible with the "
459+
"image_channel_type of the image.");
466460
case image_channel_type::fp16:
467461
RetData = PixelData.template convert<half>();
468462
return;
469463
case image_channel_type::fp32:
470-
throw sycl::invalid_parameter_error(
471-
"Datatype to read - cl_half4 is incompatible with the "
472-
"image_channel_type of the image.",
473-
PI_ERROR_INVALID_VALUE);
464+
throw sycl::exception(make_error_code(errc::invalid),
465+
"Datatype to read - cl_half4 is incompatible with "
466+
"the image_channel_type of the image.");
474467
}
475468
RetData = RetDataFloat.template convert<half>();
476469
}
@@ -507,10 +500,10 @@ convertWriteData(const uint4 WriteData,
507500
// OpenCL Spec section 6.12.14.4 does not allow writing uint4 data to an
508501
// image with channel datatype other than unsigned_int8,unsigned_int16 and
509502
// unsigned_int32.
510-
throw sycl::invalid_parameter_error(
503+
throw sycl::exception(
504+
make_error_code(errc::invalid),
511505
"Datatype of data to write - cl_uint4 is incompatible with the "
512-
"image_channel_type of the image.",
513-
PI_ERROR_INVALID_VALUE);
506+
"image_channel_type of the image.");
514507
}
515508
}
516509

@@ -540,10 +533,9 @@ convertWriteData(const int4 WriteData,
540533
// OpenCL Spec section 6.12.14.4 does not allow writing int4 data to an
541534
// image with channel datatype other than signed_int8,signed_int16 and
542535
// signed_int32.
543-
throw sycl::invalid_parameter_error(
544-
"Datatype of data to write - cl_int4 is incompatible with the "
545-
"image_channel_type of the image.",
546-
PI_ERROR_INVALID_VALUE);
536+
throw sycl::exception(make_error_code(errc::invalid),
537+
"Datatype of data to write - cl_int4 is incompatible "
538+
"with the image_channel_type of the image.");
547539
}
548540
}
549541

@@ -620,10 +612,10 @@ convertWriteData(const float4 WriteData,
620612
// OpenCL Spec section 6.12.14.4 does not allow writing float4 data to an
621613
// image with channel datatype - signed/unsigned_int8,signed/unsigned_int16
622614
// and signed/unsigned_int32.
623-
throw sycl::invalid_parameter_error(
615+
throw sycl::exception(
616+
make_error_code(errc::invalid),
624617
"Datatype of data to write - cl_float4 is incompatible with the "
625-
"image_channel_type of the image.",
626-
PI_ERROR_INVALID_VALUE);
618+
"image_channel_type of the image.");
627619
case image_channel_type::fp16:
628620
// Host has conversion from float to half with accuracy as required in
629621
// section 8.3.2 OpenCL spec.
@@ -667,17 +659,17 @@ convertWriteData(const half4 WriteData,
667659
// OpenCL Spec section 6.12.14.4 does not allow writing float4 data to an
668660
// image with channel datatype - signed/unsigned_int8,signed/unsigned_int16
669661
// and signed/unsigned_int32.
670-
throw sycl::invalid_parameter_error(
662+
throw sycl::exception(
663+
make_error_code(errc::invalid),
671664
"Datatype of data to write - cl_float4 is incompatible with the "
672-
"image_channel_type of the image.",
673-
PI_ERROR_INVALID_VALUE);
665+
"image_channel_type of the image.");
674666
case image_channel_type::fp16:
675667
return WriteData.convert<ChannelType>();
676668
case image_channel_type::fp32:
677-
throw sycl::invalid_parameter_error(
669+
throw sycl::exception(
670+
make_error_code(errc::invalid),
678671
"Datatype of data to write - cl_float4 is incompatible with the "
679-
"image_channel_type of the image.",
680-
PI_ERROR_INVALID_VALUE);
672+
"image_channel_type of the image.");
681673
}
682674
}
683675

sycl/source/context.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,7 @@ context::context(const std::vector<device> &DeviceList,
5353
context::context(const std::vector<device> &DeviceList,
5454
async_handler AsyncHandler, const property_list &PropList) {
5555
if (DeviceList.empty()) {
56-
throw invalid_parameter_error("DeviceList is empty.",
57-
PI_ERROR_INVALID_VALUE);
56+
throw exception(make_error_code(errc::invalid), "DeviceList is empty.");
5857
}
5958

6059
const auto &RefPlatform =
@@ -64,9 +63,8 @@ context::context(const std::vector<device> &DeviceList,
6463
return (detail::getSyclObjImpl(CurrentDevice.get_platform())
6564
->getHandleRef() != RefPlatform);
6665
}))
67-
throw invalid_parameter_error(
68-
"Can't add devices across platforms to a single context.",
69-
PI_ERROR_INVALID_DEVICE);
66+
throw exception(make_error_code(errc::invalid),
67+
"Can't add devices across platforms to a single context.");
7068
else
7169
impl = std::make_shared<detail::context_impl>(DeviceList, AsyncHandler,
7270
PropList);

sycl/source/detail/config.hpp

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -272,10 +272,9 @@ template <> class SYCLConfig<ONEAPI_DEVICE_SELECTOR> {
272272
if (ValStr) {
273273
// Throw if the input string is empty.
274274
if (ValStr[0] == '\0')
275-
throw invalid_parameter_error(
276-
"Invalid value for ONEAPI_DEVICE_SELECTOR environment "
277-
"variable: value should not be null.",
278-
PI_ERROR_INVALID_VALUE);
275+
throw exception(make_error_code(errc::invalid),
276+
"Invalid value for ONEAPI_DEVICE_SELECTOR environment "
277+
"variable: value should not be null.");
279278

280279
DeviceTargets =
281280
&GlobalHandler::instance().getOneapiDeviceSelectorTargets(ValStr);
@@ -333,17 +332,16 @@ template <> class SYCLConfig<SYCL_QUEUE_THREAD_POOL_SIZE> {
333332
try {
334333
Result = std::stoi(ValueStr);
335334
} catch (...) {
336-
throw invalid_parameter_error(
337-
"Invalid value for SYCL_QUEUE_THREAD_POOL_SIZE environment "
338-
"variable: value should be a number",
339-
PI_ERROR_INVALID_VALUE);
335+
throw exception(make_error_code(errc::invalid),
336+
"Invalid value for SYCL_QUEUE_THREAD_POOL_SIZE "
337+
"environment variable: value should be a number");
340338
}
341339

342340
if (Result < 1)
343-
throw invalid_parameter_error(
341+
throw exception(
342+
make_error_code(errc::invalid),
344343
"Invalid value for SYCL_QUEUE_THREAD_POOL_SIZE environment "
345-
"variable: value should be larger than zero",
346-
PI_ERROR_INVALID_VALUE);
344+
"variable: value should be larger than zero");
347345

348346
return Result;
349347
}();

sycl/source/detail/context_impl.cpp

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -89,19 +89,18 @@ context_impl::context_impl(sycl::detail::pi::PiContext PiContext,
8989
sizeof(sycl::detail::pi::PiDevice) * DevicesNum, &DeviceIds[0],
9090
nullptr);
9191

92-
if (!DeviceIds.empty()) {
93-
std::shared_ptr<detail::platform_impl> Platform =
94-
platform_impl::getPlatformFromPiDevice(DeviceIds[0], Plugin);
95-
for (sycl::detail::pi::PiDevice Dev : DeviceIds) {
96-
MDevices.emplace_back(createSyclObjFromImpl<device>(
97-
Platform->getOrMakeDeviceImpl(Dev, Platform)));
98-
}
99-
MPlatform = Platform;
100-
} else {
101-
throw invalid_parameter_error(
102-
"No devices in the provided device list and native context.",
103-
PI_ERROR_INVALID_VALUE);
92+
if (DeviceIds.empty())
93+
throw exception(
94+
make_error_code(errc::invalid),
95+
"No devices in the provided device list and native context.");
96+
97+
std::shared_ptr<detail::platform_impl> Platform =
98+
platform_impl::getPlatformFromPiDevice(DeviceIds[0], Plugin);
99+
for (sycl::detail::pi::PiDevice Dev : DeviceIds) {
100+
MDevices.emplace_back(createSyclObjFromImpl<device>(
101+
Platform->getOrMakeDeviceImpl(Dev, Platform)));
104102
}
103+
MPlatform = Platform;
105104
}
106105
// TODO catch an exception and put it to list of asynchronous exceptions
107106
// getPlugin() will be the same as the Plugin passed. This should be taken

0 commit comments

Comments
 (0)