Skip to content

Commit

Permalink
[SYCL] Remove device_error exception and its subclasses (intel#14486)
Browse files Browse the repository at this point in the history
Remove both `compile_program_error` and `invalid_object_error` in a
single PR because `getOrBuild` interface uses both and cannot be updated
for one without another.
  • Loading branch information
aelovikov-intel committed Jul 9, 2024
1 parent fa4ef51 commit 902b5ac
Show file tree
Hide file tree
Showing 36 changed files with 163 additions and 217 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ a|
template<typename propertyT>
propertyT get_property() const;
``` | Returns a copy of the property of type propertyT that T was constructed with.
Must throw an exception with the errc::invalid_object_error error code if T was not constructed with the propertyT property.
Must throw an exception with the errc::invalid error code if T was not constructed with the propertyT property.
Available only if propertyT is not a compile-time-constant property.
a|
```c++
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ This document describes an extension that introduces a +sycl::ext::oneapi::prope

|Property |Description
|`syc::ext::oneapi::property::buffer::use_pinned_host_memory`
| The `use_pinned_host_memory` property adds the requirement that the SYCL runtime must allocate host pinned memory for the `sycl::buffer`. The property cannot be used with the `sycl::buffer` constructors that take hostData parameter, an invalid_object_error SYCL exception must be thrown in this case.
| The `use_pinned_host_memory` property adds the requirement that the SYCL runtime must allocate host pinned memory for the `sycl::buffer`. The property cannot be used with the `sycl::buffer` constructors that take hostData parameter, a SYCL exception with errc::invalid error code must be thrown in this case.
|===

== Feature test macro
Expand Down
33 changes: 14 additions & 19 deletions sycl/include/sycl/accessor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1434,10 +1434,9 @@ class __SYCL_EBO __SYCL_SPECIAL_CLASS __SYCL_TYPE(accessor) accessor :
addHostAccessorAndWait(AccessorBaseHost::impl.get());
if (BufferRef.isOutOfBounds(AccessOffset, AccessRange,
BufferRef.get_range()))
throw sycl::invalid_object_error(
"accessor with requested offset and range would exceed the bounds of "
"the buffer",
PI_ERROR_INVALID_VALUE);
throw sycl::exception(make_error_code(errc::invalid),
"accessor with requested offset and range would "
"exceed the bounds of the buffer");

initHostAcc();
detail::constructorNotification(detail::getSyclObjImpl(BufferRef).get(),
Expand Down Expand Up @@ -1478,10 +1477,9 @@ class __SYCL_EBO __SYCL_SPECIAL_CLASS __SYCL_TYPE(accessor) accessor :
addHostAccessorAndWait(AccessorBaseHost::impl.get());
if (BufferRef.isOutOfBounds(AccessOffset, AccessRange,
BufferRef.get_range()))
throw sycl::invalid_object_error(
"accessor with requested offset and range would exceed the bounds of "
"the buffer",
PI_ERROR_INVALID_VALUE);
throw sycl::exception(make_error_code(errc::invalid),
"accessor with requested offset and range would "
"exceed the bounds of the buffer");

initHostAcc();
detail::constructorNotification(detail::getSyclObjImpl(BufferRef).get(),
Expand Down Expand Up @@ -1549,10 +1547,9 @@ class __SYCL_EBO __SYCL_SPECIAL_CLASS __SYCL_TYPE(accessor) accessor :
preScreenAccessor(PropertyList);
if (BufferRef.isOutOfBounds(AccessOffset, AccessRange,
BufferRef.get_range()))
throw sycl::invalid_object_error(
"accessor with requested offset and range would exceed the bounds of "
"the buffer",
PI_ERROR_INVALID_VALUE);
throw sycl::exception(make_error_code(errc::invalid),
"accessor with requested offset and range would "
"exceed the bounds of the buffer");

initHostAcc();
detail::associateWithHandler(CommandGroupHandler, this, AccessTarget);
Expand Down Expand Up @@ -1593,10 +1590,9 @@ class __SYCL_EBO __SYCL_SPECIAL_CLASS __SYCL_TYPE(accessor) accessor :
preScreenAccessor(PropertyList);
if (BufferRef.isOutOfBounds(AccessOffset, AccessRange,
BufferRef.get_range()))
throw sycl::invalid_object_error(
"accessor with requested offset and range would exceed the bounds of "
"the buffer",
PI_ERROR_INVALID_VALUE);
throw sycl::exception(make_error_code(errc::invalid),
"accessor with requested offset and range would "
"exceed the bounds of the buffer");

initHostAcc();
detail::associateWithHandler(CommandGroupHandler, this, AccessTarget);
Expand Down Expand Up @@ -1946,9 +1942,8 @@ class __SYCL_EBO __SYCL_SPECIAL_CLASS __SYCL_TYPE(accessor) accessor :
// check that no_init property is compatible with access mode
if (PropertyList.template has_property<property::no_init>() &&
AccessMode == access::mode::read) {
throw sycl::invalid_object_error(
"accessor would cannot be both read_only and no_init",
PI_ERROR_INVALID_VALUE);
throw sycl::exception(make_error_code(errc::invalid),
"accessor cannot be both read_only and no_init");
}
}

Expand Down
37 changes: 16 additions & 21 deletions sycl/include/sycl/buffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -438,16 +438,14 @@ class buffer : public detail::buffer_plain,
dimensions, sizeof(T), detail::rangeToArray(Range).data());

if (b.is_sub_buffer())
throw sycl::invalid_object_error(
"Cannot create sub buffer from sub buffer.", PI_ERROR_INVALID_VALUE);
throw sycl::exception(make_error_code(errc::invalid),
"Cannot create sub buffer from sub buffer.");
if (isOutOfBounds(baseIndex, subRange, b.Range))
throw sycl::invalid_object_error(
"Requested sub-buffer size exceeds the size of the parent buffer",
PI_ERROR_INVALID_VALUE);
throw sycl::exception(make_error_code(errc::invalid),
"Requested sub-buffer size exceeds the size of the parent buffer");
if (!isContiguousRegion(baseIndex, subRange, b.Range))
throw sycl::invalid_object_error(
"Requested sub-buffer region is not contiguous",
PI_ERROR_INVALID_VALUE);
throw sycl::exception(make_error_code(errc::invalid),
"Requested sub-buffer region is not contiguous");
}

buffer(const buffer &rhs,
Expand Down Expand Up @@ -539,9 +537,8 @@ class buffer : public detail::buffer_plain,
id<dimensions> accessOffset = {},
const detail::code_location CodeLoc = detail::code_location::current()) {
if (isOutOfBounds(accessOffset, accessRange, this->Range))
throw sycl::invalid_object_error(
"Requested accessor would exceed the bounds of the buffer",
PI_ERROR_INVALID_VALUE);
throw sycl::exception(make_error_code(errc::invalid),
"Requested accessor would exceed the bounds of the buffer");

return accessor<T, dimensions, mode, target, access::placeholder::false_t,
ext::oneapi::accessor_property_list<>>(
Expand All @@ -562,9 +559,8 @@ class buffer : public detail::buffer_plain,
detail::code_location::
current()) {
if (isOutOfBounds(accessOffset, accessRange, this->Range))
throw sycl::invalid_object_error(
"Requested accessor would exceed the bounds of the buffer",
PI_ERROR_INVALID_VALUE);
throw sycl::exception(make_error_code(errc::invalid),
"Requested accessor would exceed the bounds of the buffer");

return accessor<T, dimensions, mode, access::target::host_buffer,
access::placeholder::false_t,
Expand Down Expand Up @@ -659,11 +655,11 @@ class buffer : public detail::buffer_plain,
std::remove_const_t<ReinterpretT>>>
reinterpret(range<ReinterpretDim> reinterpretRange) const {
if (sizeof(ReinterpretT) * reinterpretRange.size() != byte_size())
throw sycl::invalid_object_error(
throw sycl::exception(
make_error_code(errc::invalid),
"Total size in bytes represented by the type and range of the "
"reinterpreted SYCL buffer does not equal the total size in bytes "
"represented by the type and range of this SYCL buffer",
PI_ERROR_INVALID_VALUE);
"represented by the type and range of this SYCL buffer");

return buffer<ReinterpretT, ReinterpretDim,
typename std::allocator_traits<AllocatorT>::
Expand Down Expand Up @@ -692,10 +688,9 @@ class buffer : public detail::buffer_plain,
reinterpret() const {
long sz = byte_size();
if (sz % sizeof(ReinterpretT) != 0)
throw sycl::invalid_object_error(
"Total byte size of buffer is not evenly divisible by the size of "
"the reinterpreted type",
PI_ERROR_INVALID_VALUE);
throw sycl::exception(make_error_code(errc::invalid),
"Total byte size of buffer is not evenly divisible "
"by the size of the reinterpreted type");

return buffer<ReinterpretT, ReinterpretDim, AllocatorT>(
impl, range<1>{sz / sizeof(ReinterpretT)}, OffsetInBytes, IsSubBuffer);
Expand Down
4 changes: 2 additions & 2 deletions sycl/include/sycl/context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,8 @@ class __SYCL_EXPORT context : public detail::OwnerLessBase<context> {

/// Gets the specified property of this context.
///
/// Throws invalid_object_error if this context does not have a property
/// of type propertyT.
/// Throws an exception with errc::invalid error code if this context does not
/// have a property of type propertyT.
///
/// \return a copy of the property of type propertyT.
template <typename propertyT> propertyT get_property() const;
Expand Down
10 changes: 5 additions & 5 deletions sycl/include/sycl/detail/property_list_base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

#include <sycl/detail/pi.h> // for PI_ERROR_INVALID_VALUE
#include <sycl/detail/property_helper.hpp> // for DataLessPropKind, Propert...
#include <sycl/exception.hpp> // for invalid_object_error
#include <sycl/exception.hpp>

#include <algorithm> // for iter_swap
#include <bitset> // for bitset
Expand Down Expand Up @@ -92,15 +92,15 @@ class PropertyListBase {
get_property_helper() const {
const int PropKind = static_cast<int>(PropT::getKind());
if (PropKind >= PropWithDataKind::PropWithDataKindSize)
throw sycl::invalid_object_error("The property is not found",
PI_ERROR_INVALID_VALUE);
throw sycl::exception(make_error_code(errc::invalid),
"The property is not found");

for (const std::shared_ptr<PropertyWithDataBase> &Prop : MPropsWithData)
if (Prop->isSame(PropKind))
return *static_cast<PropT *>(Prop.get());

throw sycl::invalid_object_error("The property is not found",
PI_ERROR_INVALID_VALUE);
throw sycl::exception(make_error_code(errc::invalid),
"The property is not found");
}

void add_or_replace_accessor_properties_helper(
Expand Down
4 changes: 2 additions & 2 deletions sycl/include/sycl/event.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ class __SYCL_EXPORT event : public detail::OwnerLessBase<event> {
/// call to this member function will block until the requested info is
/// available. If the queue which submitted the command group this event is
/// associated with was not constructed with the
/// property::queue::enable_profiling property, an invalid_object_error SYCL
/// exception is thrown.
/// property::queue::enable_profiling property, an a SYCL exception with
/// errc::invalid error code is thrown.
///
/// \return depends on template parameter.
template <typename Param>
Expand Down
45 changes: 0 additions & 45 deletions sycl/include/sycl/exception.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,51 +203,6 @@ class __SYCL2020_DEPRECATED(
: runtime_error(make_error_code(errc::kernel_argument), Msg, Err) {}
};

class __SYCL2020_DEPRECATED(
"use sycl::exception with a sycl::errc enum value instead.") device_error
: public exception {
public:
device_error() : exception(make_error_code(errc::invalid)) {}

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

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

protected:
device_error(std::error_code Ec) : exception(Ec) {}

device_error(std::error_code Ec, const std::string &Msg, const pi_int32 PIErr)
: exception(Ec, Msg, PIErr) {}
};

class __SYCL2020_DEPRECATED(
"use sycl::exception with a sycl::errc enum value instead.")
compile_program_error : public device_error {
public:
compile_program_error() : device_error(make_error_code(errc::build)) {}

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

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

class __SYCL2020_DEPRECATED(
"use sycl::exception with a sycl::errc enum value instead.")
invalid_object_error : public device_error {
public:
invalid_object_error() : device_error(make_error_code(errc::invalid)) {}

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

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

} // namespace _V1
} // namespace sycl

Expand Down
6 changes: 3 additions & 3 deletions sycl/include/sycl/ext/oneapi/accessor_property_list.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include <sycl/detail/pi.h> // for PI_ERROR_INVALID_VALUE
#include <sycl/detail/property_helper.hpp> // for DataLessPropKind, Prop...
#include <sycl/detail/property_list_base.hpp> // for PropertyListBase
#include <sycl/exception.hpp> // for invalid_object_error
#include <sycl/exception.hpp>
#include <sycl/property_list.hpp> // for property_list

#include <bitset> // for bitset
Expand Down Expand Up @@ -184,8 +184,8 @@ class __SYCL_TYPE(accessor_property_list) accessor_property_list
!is_compile_time_property<PropT>::value>>
PropT get_property() const {
if (!has_property<PropT>())
throw sycl::invalid_object_error("The property is not found",
PI_ERROR_INVALID_VALUE);
throw sycl::exception(make_error_code(errc::invalid),
"The property is not found");

return get_property_helper<PropT>();
}
Expand Down
6 changes: 3 additions & 3 deletions sycl/include/sycl/handler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2732,9 +2732,9 @@ class __SYCL_EXPORT handler {
static_assert(isValidModeForDestinationAccessor(AccessMode_Dst),
"Invalid destination accessor mode for the copy method.");
if (Dst.get_size() < Src.get_size())
throw sycl::invalid_object_error(
"The destination accessor size is too small to copy the memory into.",
PI_ERROR_INVALID_OPERATION);
throw sycl::exception(make_error_code(errc::invalid),
"The destination accessor size is too small to "
"copy the memory into.");

if (copyAccToAccHelper(Src, Dst))
return;
Expand Down
22 changes: 11 additions & 11 deletions sycl/include/sycl/interop_handle.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include <sycl/detail/impl_utils.hpp> // for getSyclObjImpl
#include <sycl/detail/pi.h> // for _pi_mem, pi_native_...
#include <sycl/device.hpp> // for device, device_impl
#include <sycl/exception.hpp> // for invalid_object_error
#include <sycl/exception.hpp>
#include <sycl/exception_list.hpp> // for queue_impl
#include <sycl/ext/oneapi/accessor_property_list.hpp> // for accessor_property_list
#include <sycl/image.hpp> // for image
Expand Down Expand Up @@ -71,8 +71,8 @@ class interop_handle {
"The method is available only for target::device accessors");
#ifndef __SYCL_DEVICE_ONLY__
if (Backend != get_backend())
throw invalid_object_error("Incorrect backend argument was passed",
PI_ERROR_INVALID_MEM_OBJECT);
throw exception(make_error_code(errc::invalid),
"Incorrect backend argument was passed");
const auto *AccBase = static_cast<const detail::AccessorBaseHost *>(&Acc);
return getMemImpl<Backend, DataT, Dims>(
detail::getSyclObjImpl(*AccBase).get());
Expand All @@ -97,8 +97,8 @@ class interop_handle {
IsPlh /*, PropertyListT */> &Acc) const {
#ifndef __SYCL_DEVICE_ONLY__
if (Backend != get_backend())
throw invalid_object_error("Incorrect backend argument was passed",
PI_ERROR_INVALID_MEM_OBJECT);
throw exception(make_error_code(errc::invalid),
"Incorrect backend argument was passed");
const auto *AccBase = static_cast<const detail::AccessorBaseHost *>(&Acc);
return getMemImpl<Backend, Dims>(detail::getSyclObjImpl(*AccBase).get());
#else
Expand Down Expand Up @@ -127,8 +127,8 @@ class interop_handle {
// with the error code 'errc::backend_mismatch' when those new exceptions
// are ready to be used.
if (Backend != get_backend())
throw invalid_object_error("Incorrect backend argument was passed",
PI_ERROR_INVALID_MEM_OBJECT);
throw exception(make_error_code(errc::invalid),
"Incorrect backend argument was passed");
int32_t NativeHandleDesc;
return reinterpret_cast<backend_return_t<Backend, queue>>(
getNativeQueue(NativeHandleDesc));
Expand All @@ -150,8 +150,8 @@ class interop_handle {
// with the error code 'errc::backend_mismatch' when those new exceptions
// are ready to be used.
if (Backend != get_backend())
throw invalid_object_error("Incorrect backend argument was passed",
PI_ERROR_INVALID_MEM_OBJECT);
throw exception(make_error_code(errc::invalid),
"Incorrect backend argument was passed");
// C-style cast required to allow various native types
return (backend_return_t<Backend, device>)getNativeDevice();
#else
Expand All @@ -172,8 +172,8 @@ class interop_handle {
// with the error code 'errc::backend_mismatch' when those new exceptions
// are ready to be used.
if (Backend != get_backend())
throw invalid_object_error("Incorrect backend argument was passed",
PI_ERROR_INVALID_MEM_OBJECT);
throw exception(make_error_code(errc::invalid),
"Incorrect backend argument was passed");
return reinterpret_cast<backend_return_t<Backend, context>>(
getNativeContext());
#else
Expand Down
6 changes: 3 additions & 3 deletions sycl/include/sycl/property_list.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include <sycl/detail/pi.h> // for PI_ERROR_INVALID_VALUE
#include <sycl/detail/property_helper.hpp> // for DataLessPropKind, Pro...
#include <sycl/detail/property_list_base.hpp> // for PropertyListBase
#include <sycl/exception.hpp> // for invalid_object_error
#include <sycl/exception.hpp>
#include <sycl/properties/property_traits.hpp> // for is_property

#include <bitset> // for bitset
Expand Down Expand Up @@ -46,8 +46,8 @@ class property_list : protected detail::PropertyListBase {

template <typename PropT> PropT get_property() const {
if (!has_property<PropT>())
throw sycl::invalid_object_error("The property is not found",
PI_ERROR_INVALID_VALUE);
throw sycl::exception(make_error_code(errc::invalid),
"The property is not found");

return get_property_helper<PropT>();
}
Expand Down
2 changes: 1 addition & 1 deletion sycl/include/sycl/queue.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ class __SYCL_EXPORT queue : public detail::OwnerLessBase<queue> {

/// \return a copy of the property of type PropertyT that the queue was
/// constructed with. If the queue was not constructed with the PropertyT
/// property, an invalid_object_error SYCL exception.
/// property, an SYCL exception with errc::invalid error code.
template <typename PropertyT> PropertyT get_property() const;

/// Fills the specified memory with the specified pattern.
Expand Down
Loading

0 comments on commit 902b5ac

Please sign in to comment.