Skip to content

Commit

Permalink
[SYCL] Remove sycl::feature_not_supported exception (#14423)
Browse files Browse the repository at this point in the history
One of the SYCL 1.2 exception subclasses being removed during the ABI
breaking window since these subclasses have been removed in SYCL 2020.

We still want to be able to carry information about backend error code,
so `MPIErr` data member in `sycl::exception` remains. However, since
none of the standard ctors can accept it (per the specification), I've
introduced a new helper `detail::set_pi_error` to set it. It should only
be used when propagating an error comming from the PI/UR level and *NOT*
for the error conditions originated in the SYCL RT (which is a change
from previous implementation but a logical/justifiable one).
  • Loading branch information
aelovikov-intel authored Jul 8, 2024
1 parent be34c68 commit 5630b82
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 57 deletions.
30 changes: 13 additions & 17 deletions sycl/include/sycl/detail/image_accessor_util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -447,10 +447,9 @@ void convertReadData(const vec<ChannelType, 4> PixelData,
case image_channel_type::unorm_short_555:
case image_channel_type::unorm_int_101010:
// TODO: Missing information in OpenCL spec.
throw sycl::feature_not_supported(
"Currently unsupported datatype conversion from image_channel_type "
"to cl_half4.",
PI_ERROR_INVALID_OPERATION);
throw sycl::exception(make_error_code(errc::feature_not_supported),
"Currently unsupported datatype conversion from "
"image_channel_type to cl_half4.");
case image_channel_type::signed_int8:
case image_channel_type::signed_int16:
case image_channel_type::signed_int32:
Expand Down Expand Up @@ -579,10 +578,9 @@ convertWriteData(const float4 WriteData,
return processFloatDataToPixel<ChannelType>(WriteData, 65535.0f);
case image_channel_type::unorm_short_565:
// TODO: Missing information in OpenCL spec.
throw sycl::feature_not_supported(
"Currently unsupported datatype conversion from image_channel_type "
"to cl_float4.",
PI_ERROR_INVALID_OPERATION);
throw sycl::exception(make_error_code(errc::feature_not_supported),
"Currently unsupported datatype conversion from "
"image_channel_type to cl_float4.");
case image_channel_type::unorm_short_555:
// TODO: Missing information in OpenCL spec.
// Check if the below code is correct after the spec is updated.
Expand Down Expand Up @@ -657,10 +655,9 @@ convertWriteData(const half4 WriteData,
case image_channel_type::unorm_short_555:
case image_channel_type::unorm_int_101010:
// TODO: Missing information in OpenCL spec.
throw sycl::feature_not_supported(
"Currently unsupported datatype conversion from image_channel_type "
"to cl_half4.",
PI_ERROR_INVALID_OPERATION);
throw sycl::exception(make_error_code(errc::feature_not_supported),
"Currently unsupported datatype conversion from "
"image_channel_type to cl_half4.");
case image_channel_type::signed_int8:
case image_channel_type::signed_int16:
case image_channel_type::signed_int32:
Expand Down Expand Up @@ -1045,11 +1042,10 @@ DataT imageReadSamplerHostImpl(
switch (SmplAddrMode) {
case addressing_mode::mirrored_repeat:
case addressing_mode::repeat:
throw sycl::feature_not_supported(
"Sampler used with unsupported configuration of "
"mirrored_repeat/repeat filtering mode with unnormalized "
"coordinates. ",
PI_ERROR_INVALID_OPERATION);
throw sycl::exception(make_error_code(errc::feature_not_supported),
"Sampler used with unsupported configuration of "
"mirrored_repeat/repeat filtering mode with "
"unnormalized coordinates. ");
case addressing_mode::clamp_to_edge:
case addressing_mode::clamp:
case addressing_mode::none:
Expand Down
23 changes: 9 additions & 14 deletions sycl/include/sycl/exception.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ class __SYCL_EXPORT SYCLCategory : public std::error_category {

// Forward declare to declare as a friend in sycl::excepton.
__SYCL_EXPORT pi_int32 get_pi_error(const exception &e);
// TODO: Should it be exported at all?
__SYCL_EXPORT exception set_pi_error(exception &&e, pi_int32 pi_err);
} // namespace detail

// Derive from std::exception so uncaught exceptions are printed in c++ default
Expand Down Expand Up @@ -145,6 +147,13 @@ class __SYCL_EXPORT exception : public virtual std::exception {
const char *WhatArg);

friend __SYCL_EXPORT pi_int32 detail::get_pi_error(const exception &);
// To be used like this:
// throw/return detail::set_pi_error(exception(...), some_pi_error);
// *only* when such a error is coming from the PI/UR level. Otherwise it
// *should be left unset/default-initialized and exception should be thrown
// as-is using public ctors.
friend __SYCL_EXPORT exception detail::set_pi_error(exception &&e,
pi_int32 pi_err);
};

class __SYCL2020_DEPRECATED(
Expand Down Expand Up @@ -239,20 +248,6 @@ class __SYCL2020_DEPRECATED(
: device_error(make_error_code(errc::invalid), Msg, Err) {}
};

class __SYCL2020_DEPRECATED(
"use sycl::exception with sycl::errc::feature_not_supported instead.")
feature_not_supported : public device_error {
public:
feature_not_supported()
: device_error(make_error_code(errc::feature_not_supported)) {}

feature_not_supported(const char *Msg, pi_int32 Err)
: feature_not_supported(std::string(Msg), Err) {}

feature_not_supported(const std::string &Msg, pi_int32 Err)
: device_error(make_error_code(errc::feature_not_supported), Msg, Err) {}
};

} // namespace _V1
} // namespace sycl

Expand Down
6 changes: 3 additions & 3 deletions sycl/include/sycl/kernel_handler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ class __SYCL_TYPE(kernel_handler) kernel_handler {
#ifdef __SYCL_DEVICE_ONLY__
return getSpecializationConstantOnDevice<S>();
#else
throw sycl::feature_not_supported("kernel_handler::get_specialization_"
"constant() is not supported on host",
PI_ERROR_INVALID_OPERATION);
throw sycl::exception(make_error_code(errc::feature_not_supported),
"kernel_handler::get_specialization_constant() is "
"not supported on host.");
#endif // __SYCL_DEVICE_ONLY__
}

Expand Down
42 changes: 21 additions & 21 deletions sycl/source/detail/device_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,10 +206,9 @@ device_impl::create_sub_devices(const cl_device_partition_property *Properties,

std::vector<device> device_impl::create_sub_devices(size_t ComputeUnits) const {
if (!is_partition_supported(info::partition_property::partition_equally)) {
throw sycl::feature_not_supported(
"Device does not support "
"sycl::info::partition_property::partition_equally.",
PI_ERROR_INVALID_OPERATION);
throw sycl::exception(make_error_code(errc::feature_not_supported),
"Device does not support "
"sycl::info::partition_property::partition_equally.");
}
// If count exceeds the total number of compute units in the device, an
// exception with the errc::invalid error code must be thrown.
Expand All @@ -228,10 +227,10 @@ std::vector<device> device_impl::create_sub_devices(size_t ComputeUnits) const {
std::vector<device>
device_impl::create_sub_devices(const std::vector<size_t> &Counts) const {
if (!is_partition_supported(info::partition_property::partition_by_counts)) {
throw sycl::feature_not_supported(
throw sycl::exception(
make_error_code(errc::feature_not_supported),
"Device does not support "
"sycl::info::partition_property::partition_by_counts.",
PI_ERROR_INVALID_OPERATION);
"sycl::info::partition_property::partition_by_counts.");
}
static const pi_device_partition_property P[] = {
PI_DEVICE_PARTITION_BY_COUNTS, PI_DEVICE_PARTITION_BY_COUNTS_LIST_END, 0};
Expand Down Expand Up @@ -270,16 +269,15 @@ std::vector<device> device_impl::create_sub_devices(
info::partition_affinity_domain AffinityDomain) const {
if (!is_partition_supported(
info::partition_property::partition_by_affinity_domain)) {
throw sycl::feature_not_supported(
throw sycl::exception(
make_error_code(errc::feature_not_supported),
"Device does not support "
"sycl::info::partition_property::partition_by_affinity_domain.",
PI_ERROR_INVALID_OPERATION);
"sycl::info::partition_property::partition_by_affinity_domain.");
}
if (!is_affinity_supported(AffinityDomain)) {
throw sycl::feature_not_supported(
"Device does not support " + affinityDomainToString(AffinityDomain) +
".",
PI_ERROR_INVALID_VALUE);
throw sycl::exception(make_error_code(errc::feature_not_supported),
"Device does not support " +
affinityDomainToString(AffinityDomain) + ".");
}
const pi_device_partition_property Properties[3] = {
PI_DEVICE_PARTITION_BY_AFFINITY_DOMAIN,
Expand All @@ -296,10 +294,10 @@ std::vector<device> device_impl::create_sub_devices(
std::vector<device> device_impl::create_sub_devices() const {
if (!is_partition_supported(
info::partition_property::ext_intel_partition_by_cslice)) {
throw sycl::feature_not_supported(
throw sycl::exception(
make_error_code(errc::feature_not_supported),
"Device does not support "
"sycl::info::partition_property::ext_intel_partition_by_cslice.",
PI_ERROR_INVALID_OPERATION);
"sycl::info::partition_property::ext_intel_partition_by_cslice.");
}

const pi_device_partition_property Properties[2] = {
Expand Down Expand Up @@ -797,10 +795,12 @@ uint64_t device_impl::getCurrentDeviceTime() {
char *p = nullptr;
Plugin->call_nocheck<detail::PiApiKind::piPluginGetLastError>(&p);
std::string errorMsg(p ? p : "");
throw sycl::feature_not_supported(
"Device and/or backend does not support querying timestamp: " +
errorMsg,
Result);
throw detail::set_pi_error(
sycl::exception(
make_error_code(errc::feature_not_supported),
"Device and/or backend does not support querying timestamp: " +
errorMsg),
PI_ERROR_INVALID_OPERATION);
} else {
Plugin->checkPiResult(Result);
}
Expand Down
4 changes: 4 additions & 0 deletions sycl/source/exception.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ std::error_code make_error_code(sycl::errc Err) noexcept {

namespace detail {
pi_int32 get_pi_error(const exception &e) { return e.MPIErr; }
exception set_pi_error(exception &&e, pi_int32 pi_err) {
e.MPIErr = pi_err;
return std::move(e);
}

__SYCL_EXPORT const char *stringifyErrorCode(pi_int32 error) {
switch (error) {
Expand Down
1 change: 1 addition & 0 deletions sycl/test/abi/sycl_symbols_linux.dump
Original file line number Diff line number Diff line change
Expand Up @@ -3235,6 +3235,7 @@ _ZN4sycl3_V16detail12compile_implERKNS0_13kernel_bundleILNS0_12bundle_stateE0EEE
_ZN4sycl3_V16detail12get_pi_errorERKNS0_9exceptionE
_ZN4sycl3_V16detail12isOutOfRangeENS0_3vecIiLi4EEENS0_15addressing_modeENS0_5rangeILi3EEE
_ZN4sycl3_V16detail12make_contextEmRKSt8functionIFvNS0_14exception_listEEENS0_7backendEbRKSt6vectorINS0_6deviceESaISA_EE
_ZN4sycl3_V16detail12set_pi_errorEONS0_9exceptionEi
_ZN4sycl3_V16detail13host_pipe_map3addEPKvPKc
_ZN4sycl3_V16detail13lgamma_r_implENS1_9half_impl4halfEPi
_ZN4sycl3_V16detail13lgamma_r_implEdPi
Expand Down
1 change: 1 addition & 0 deletions sycl/test/abi/sycl_symbols_windows.dump
Original file line number Diff line number Diff line change
Expand Up @@ -4407,6 +4407,7 @@
?set_flag@stream@_V1@sycl@@AEBAXI@Z
?set_flag@stream@_V1@sycl@@AEBAXII@Z
?set_manipulator@stream@_V1@sycl@@AEBAXW4stream_manipulator@23@@Z
?set_pi_error@detail@_V1@sycl@@YA?AVexception@23@$$QEAV423@H@Z
?set_specialization_constant_impl@kernel_bundle_plain@detail@_V1@sycl@@IEAAXPEBDPEAX_K@Z
?set_write_back@buffer_plain@detail@_V1@sycl@@IEAAX_N@Z
?set_write_back@image_plain@detail@_V1@sycl@@IEAAX_N@Z
Expand Down
2 changes: 0 additions & 2 deletions sycl/test/warnings/sycl_2020_deprecations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,6 @@ int main() {
sycl::compile_program_error cpe;
// expected-warning@+1 {{'invalid_object_error' is deprecated: use sycl::exception with a sycl::errc enum value instead.}}
sycl::invalid_object_error ioe;
// expected-warning@+1 {{'feature_not_supported' is deprecated: use sycl::exception with sycl::errc::feature_not_supported instead.}}
sycl::feature_not_supported fns;
// expected-warning@+1{{'exception' is deprecated: The version of an exception constructor which takes no arguments is deprecated.}}
sycl::exception ex;

Expand Down

0 comments on commit 5630b82

Please sign in to comment.