Skip to content

[SYCL] Remove uses of invalid_parameter_error exception #14487

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions sycl/include/sycl/detail/array.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

#include <sycl/detail/defines_elementary.hpp> // for __SYCL_ALWAYS_INLINE
#include <sycl/detail/pi.h> // for PI_ERROR_INVALID_VALUE
#include <sycl/exception.hpp> // for invalid_parameter_error
#include <sycl/exception.hpp>

#include <stddef.h> // for size_t
#include <type_traits> // for enable_if_t
Expand Down Expand Up @@ -106,8 +106,8 @@ template <int dimensions = 1> class array {
__SYCL_ALWAYS_INLINE void check_dimension(int dimension) const {
#ifndef __SYCL_DEVICE_ONLY__
if (dimension >= dimensions || dimension < 0) {
throw sycl::invalid_parameter_error("Index out of range",
PI_ERROR_INVALID_VALUE);
throw sycl::exception(make_error_code(errc::invalid),
"Index out of range");
}
#endif
(void)dimension;
Expand Down
70 changes: 31 additions & 39 deletions sycl/include/sycl/detail/image_accessor_util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@
#include <sycl/detail/array.hpp> // for array
#include <sycl/detail/export.hpp> // for __SYCL_EXPORT
#include <sycl/detail/generic_type_traits.hpp> // for max_v, min_v, TryToGe...
#include <sycl/detail/pi.h> // for PI_ERROR_INVALID_VALUE
#include <sycl/detail/type_list.hpp> // for is_contained, type_list
#include <sycl/exception.hpp> // for invalid_parameter_error
#include <sycl/exception.hpp>
#include <sycl/id.hpp> // for id
#include <sycl/image.hpp> // for image_channel_type
#include <sycl/range.hpp> // for range
Expand Down Expand Up @@ -301,10 +300,9 @@ void convertReadData(const vec<ChannelType, 4> PixelData,
// OpenCL Spec section 6.12.14.2 does not allow reading uint4 data from an
// image with channel datatype other than unsigned_int8,unsigned_int16 and
// unsigned_int32.
throw sycl::invalid_parameter_error(
"Datatype of read data - cl_uint4 is incompatible with the "
"image_channel_type of the image.",
PI_ERROR_INVALID_VALUE);
throw sycl::exception(make_error_code(errc::invalid),
"Datatype of read data - cl_uint4 is incompatible "
"with the image_channel_type of the image.");
}
}

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

Expand Down Expand Up @@ -404,10 +400,9 @@ void convertReadData(const vec<ChannelType, 4> PixelData,
// OpenCL Spec section 6.12.14.2 does not allow reading float4 data from an
// image with channel datatype - signed/unsigned_int8,signed/unsigned_int16
// and signed/unsigned_int32.
throw sycl::invalid_parameter_error(
"Datatype of read data - cl_float4 is incompatible with the "
"image_channel_type of the image.",
PI_ERROR_INVALID_VALUE);
throw sycl::exception(make_error_code(errc::invalid),
"Datatype of read data - cl_float4 is incompatible "
"with the image_channel_type of the image.");
case image_channel_type::fp16:
// Host has conversion from float to half with accuracy as required in
// section 8.3.2 OpenCL spec.
Expand Down Expand Up @@ -459,18 +454,16 @@ void convertReadData(const vec<ChannelType, 4> PixelData,
// OpenCL Spec section 6.12.14.2 does not allow reading float4 data to an
// image with channel datatype - signed/unsigned_int8,signed/unsigned_int16
// and signed/unsigned_int32.
throw sycl::invalid_parameter_error(
"Datatype to read- cl_half4 is incompatible with the "
"image_channel_type of the image.",
PI_ERROR_INVALID_VALUE);
throw sycl::exception(make_error_code(errc::invalid),
"Datatype to read- cl_half4 is incompatible with the "
"image_channel_type of the image.");
case image_channel_type::fp16:
RetData = PixelData.template convert<half>();
return;
case image_channel_type::fp32:
throw sycl::invalid_parameter_error(
"Datatype to read - cl_half4 is incompatible with the "
"image_channel_type of the image.",
PI_ERROR_INVALID_VALUE);
throw sycl::exception(make_error_code(errc::invalid),
"Datatype to read - cl_half4 is incompatible with "
"the image_channel_type of the image.");
}
RetData = RetDataFloat.template convert<half>();
}
Expand Down Expand Up @@ -507,10 +500,10 @@ convertWriteData(const uint4 WriteData,
// OpenCL Spec section 6.12.14.4 does not allow writing uint4 data to an
// image with channel datatype other than unsigned_int8,unsigned_int16 and
// unsigned_int32.
throw sycl::invalid_parameter_error(
throw sycl::exception(
make_error_code(errc::invalid),
"Datatype of data to write - cl_uint4 is incompatible with the "
"image_channel_type of the image.",
PI_ERROR_INVALID_VALUE);
"image_channel_type of the image.");
}
}

Expand Down Expand Up @@ -540,10 +533,9 @@ convertWriteData(const int4 WriteData,
// OpenCL Spec section 6.12.14.4 does not allow writing int4 data to an
// image with channel datatype other than signed_int8,signed_int16 and
// signed_int32.
throw sycl::invalid_parameter_error(
"Datatype of data to write - cl_int4 is incompatible with the "
"image_channel_type of the image.",
PI_ERROR_INVALID_VALUE);
throw sycl::exception(make_error_code(errc::invalid),
"Datatype of data to write - cl_int4 is incompatible "
"with the image_channel_type of the image.");
}
}

Expand Down Expand Up @@ -620,10 +612,10 @@ convertWriteData(const float4 WriteData,
// OpenCL Spec section 6.12.14.4 does not allow writing float4 data to an
// image with channel datatype - signed/unsigned_int8,signed/unsigned_int16
// and signed/unsigned_int32.
throw sycl::invalid_parameter_error(
throw sycl::exception(
make_error_code(errc::invalid),
"Datatype of data to write - cl_float4 is incompatible with the "
"image_channel_type of the image.",
PI_ERROR_INVALID_VALUE);
"image_channel_type of the image.");
case image_channel_type::fp16:
// Host has conversion from float to half with accuracy as required in
// section 8.3.2 OpenCL spec.
Expand Down Expand Up @@ -667,17 +659,17 @@ convertWriteData(const half4 WriteData,
// OpenCL Spec section 6.12.14.4 does not allow writing float4 data to an
// image with channel datatype - signed/unsigned_int8,signed/unsigned_int16
// and signed/unsigned_int32.
throw sycl::invalid_parameter_error(
throw sycl::exception(
make_error_code(errc::invalid),
"Datatype of data to write - cl_float4 is incompatible with the "
"image_channel_type of the image.",
PI_ERROR_INVALID_VALUE);
"image_channel_type of the image.");
case image_channel_type::fp16:
return WriteData.convert<ChannelType>();
case image_channel_type::fp32:
throw sycl::invalid_parameter_error(
throw sycl::exception(
make_error_code(errc::invalid),
"Datatype of data to write - cl_float4 is incompatible with the "
"image_channel_type of the image.",
PI_ERROR_INVALID_VALUE);
"image_channel_type of the image.");
}
}

Expand Down
8 changes: 3 additions & 5 deletions sycl/source/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ context::context(const std::vector<device> &DeviceList,
context::context(const std::vector<device> &DeviceList,
async_handler AsyncHandler, const property_list &PropList) {
if (DeviceList.empty()) {
throw invalid_parameter_error("DeviceList is empty.",
PI_ERROR_INVALID_VALUE);
throw exception(make_error_code(errc::invalid), "DeviceList is empty.");
}

const auto &RefPlatform =
Expand All @@ -64,9 +63,8 @@ context::context(const std::vector<device> &DeviceList,
return (detail::getSyclObjImpl(CurrentDevice.get_platform())
->getHandleRef() != RefPlatform);
}))
throw invalid_parameter_error(
"Can't add devices across platforms to a single context.",
PI_ERROR_INVALID_DEVICE);
throw exception(make_error_code(errc::invalid),
"Can't add devices across platforms to a single context.");
else
impl = std::make_shared<detail::context_impl>(DeviceList, AsyncHandler,
PropList);
Expand Down
20 changes: 9 additions & 11 deletions sycl/source/detail/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -272,10 +272,9 @@ template <> class SYCLConfig<ONEAPI_DEVICE_SELECTOR> {
if (ValStr) {
// Throw if the input string is empty.
if (ValStr[0] == '\0')
throw invalid_parameter_error(
"Invalid value for ONEAPI_DEVICE_SELECTOR environment "
"variable: value should not be null.",
PI_ERROR_INVALID_VALUE);
throw exception(make_error_code(errc::invalid),
"Invalid value for ONEAPI_DEVICE_SELECTOR environment "
"variable: value should not be null.");

DeviceTargets =
&GlobalHandler::instance().getOneapiDeviceSelectorTargets(ValStr);
Expand Down Expand Up @@ -333,17 +332,16 @@ template <> class SYCLConfig<SYCL_QUEUE_THREAD_POOL_SIZE> {
try {
Result = std::stoi(ValueStr);
} catch (...) {
throw invalid_parameter_error(
"Invalid value for SYCL_QUEUE_THREAD_POOL_SIZE environment "
"variable: value should be a number",
PI_ERROR_INVALID_VALUE);
throw exception(make_error_code(errc::invalid),
"Invalid value for SYCL_QUEUE_THREAD_POOL_SIZE "
"environment variable: value should be a number");
}

if (Result < 1)
throw invalid_parameter_error(
throw exception(
make_error_code(errc::invalid),
"Invalid value for SYCL_QUEUE_THREAD_POOL_SIZE environment "
"variable: value should be larger than zero",
PI_ERROR_INVALID_VALUE);
"variable: value should be larger than zero");

return Result;
}();
Expand Down
23 changes: 11 additions & 12 deletions sycl/source/detail/context_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,19 +89,18 @@ context_impl::context_impl(sycl::detail::pi::PiContext PiContext,
sizeof(sycl::detail::pi::PiDevice) * DevicesNum, &DeviceIds[0],
nullptr);

if (!DeviceIds.empty()) {
std::shared_ptr<detail::platform_impl> Platform =
platform_impl::getPlatformFromPiDevice(DeviceIds[0], Plugin);
for (sycl::detail::pi::PiDevice Dev : DeviceIds) {
MDevices.emplace_back(createSyclObjFromImpl<device>(
Platform->getOrMakeDeviceImpl(Dev, Platform)));
}
MPlatform = Platform;
} else {
throw invalid_parameter_error(
"No devices in the provided device list and native context.",
PI_ERROR_INVALID_VALUE);
if (DeviceIds.empty())
throw exception(
make_error_code(errc::invalid),
"No devices in the provided device list and native context.");

std::shared_ptr<detail::platform_impl> Platform =
platform_impl::getPlatformFromPiDevice(DeviceIds[0], Plugin);
for (sycl::detail::pi::PiDevice Dev : DeviceIds) {
MDevices.emplace_back(createSyclObjFromImpl<device>(
Platform->getOrMakeDeviceImpl(Dev, Platform)));
}
MPlatform = Platform;
}
// TODO catch an exception and put it to list of asynchronous exceptions
// getPlugin() will be the same as the Plugin passed. This should be taken
Expand Down
Loading
Loading