Skip to content

Commit 902b5ac

Browse files
[SYCL] Remove device_error exception and its subclasses (intel#14486)
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.
1 parent fa4ef51 commit 902b5ac

36 files changed

+163
-217
lines changed

sycl/doc/extensions/supported/sycl_ext_oneapi_accessor_properties.asciidoc

+1-1
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ a|
242242
template<typename propertyT>
243243
propertyT get_property() const;
244244
``` | Returns a copy of the property of type propertyT that T was constructed with.
245-
Must throw an exception with the errc::invalid_object_error error code if T was not constructed with the propertyT property.
245+
Must throw an exception with the errc::invalid error code if T was not constructed with the propertyT property.
246246
Available only if propertyT is not a compile-time-constant property.
247247
a|
248248
```c++

sycl/doc/extensions/supported/sycl_ext_oneapi_use_pinned_host_memory_property.asciidoc

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ This document describes an extension that introduces a +sycl::ext::oneapi::prope
1818

1919
|Property |Description
2020
|`syc::ext::oneapi::property::buffer::use_pinned_host_memory`
21-
| 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.
21+
| 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.
2222
|===
2323

2424
== Feature test macro

sycl/include/sycl/accessor.hpp

+14-19
Original file line numberDiff line numberDiff line change
@@ -1434,10 +1434,9 @@ class __SYCL_EBO __SYCL_SPECIAL_CLASS __SYCL_TYPE(accessor) accessor :
14341434
addHostAccessorAndWait(AccessorBaseHost::impl.get());
14351435
if (BufferRef.isOutOfBounds(AccessOffset, AccessRange,
14361436
BufferRef.get_range()))
1437-
throw sycl::invalid_object_error(
1438-
"accessor with requested offset and range would exceed the bounds of "
1439-
"the buffer",
1440-
PI_ERROR_INVALID_VALUE);
1437+
throw sycl::exception(make_error_code(errc::invalid),
1438+
"accessor with requested offset and range would "
1439+
"exceed the bounds of the buffer");
14411440

14421441
initHostAcc();
14431442
detail::constructorNotification(detail::getSyclObjImpl(BufferRef).get(),
@@ -1478,10 +1477,9 @@ class __SYCL_EBO __SYCL_SPECIAL_CLASS __SYCL_TYPE(accessor) accessor :
14781477
addHostAccessorAndWait(AccessorBaseHost::impl.get());
14791478
if (BufferRef.isOutOfBounds(AccessOffset, AccessRange,
14801479
BufferRef.get_range()))
1481-
throw sycl::invalid_object_error(
1482-
"accessor with requested offset and range would exceed the bounds of "
1483-
"the buffer",
1484-
PI_ERROR_INVALID_VALUE);
1480+
throw sycl::exception(make_error_code(errc::invalid),
1481+
"accessor with requested offset and range would "
1482+
"exceed the bounds of the buffer");
14851483

14861484
initHostAcc();
14871485
detail::constructorNotification(detail::getSyclObjImpl(BufferRef).get(),
@@ -1549,10 +1547,9 @@ class __SYCL_EBO __SYCL_SPECIAL_CLASS __SYCL_TYPE(accessor) accessor :
15491547
preScreenAccessor(PropertyList);
15501548
if (BufferRef.isOutOfBounds(AccessOffset, AccessRange,
15511549
BufferRef.get_range()))
1552-
throw sycl::invalid_object_error(
1553-
"accessor with requested offset and range would exceed the bounds of "
1554-
"the buffer",
1555-
PI_ERROR_INVALID_VALUE);
1550+
throw sycl::exception(make_error_code(errc::invalid),
1551+
"accessor with requested offset and range would "
1552+
"exceed the bounds of the buffer");
15561553

15571554
initHostAcc();
15581555
detail::associateWithHandler(CommandGroupHandler, this, AccessTarget);
@@ -1593,10 +1590,9 @@ class __SYCL_EBO __SYCL_SPECIAL_CLASS __SYCL_TYPE(accessor) accessor :
15931590
preScreenAccessor(PropertyList);
15941591
if (BufferRef.isOutOfBounds(AccessOffset, AccessRange,
15951592
BufferRef.get_range()))
1596-
throw sycl::invalid_object_error(
1597-
"accessor with requested offset and range would exceed the bounds of "
1598-
"the buffer",
1599-
PI_ERROR_INVALID_VALUE);
1593+
throw sycl::exception(make_error_code(errc::invalid),
1594+
"accessor with requested offset and range would "
1595+
"exceed the bounds of the buffer");
16001596

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

sycl/include/sycl/buffer.hpp

+16-21
Original file line numberDiff line numberDiff line change
@@ -438,16 +438,14 @@ class buffer : public detail::buffer_plain,
438438
dimensions, sizeof(T), detail::rangeToArray(Range).data());
439439

440440
if (b.is_sub_buffer())
441-
throw sycl::invalid_object_error(
442-
"Cannot create sub buffer from sub buffer.", PI_ERROR_INVALID_VALUE);
441+
throw sycl::exception(make_error_code(errc::invalid),
442+
"Cannot create sub buffer from sub buffer.");
443443
if (isOutOfBounds(baseIndex, subRange, b.Range))
444-
throw sycl::invalid_object_error(
445-
"Requested sub-buffer size exceeds the size of the parent buffer",
446-
PI_ERROR_INVALID_VALUE);
444+
throw sycl::exception(make_error_code(errc::invalid),
445+
"Requested sub-buffer size exceeds the size of the parent buffer");
447446
if (!isContiguousRegion(baseIndex, subRange, b.Range))
448-
throw sycl::invalid_object_error(
449-
"Requested sub-buffer region is not contiguous",
450-
PI_ERROR_INVALID_VALUE);
447+
throw sycl::exception(make_error_code(errc::invalid),
448+
"Requested sub-buffer region is not contiguous");
451449
}
452450

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

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

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

668664
return buffer<ReinterpretT, ReinterpretDim,
669665
typename std::allocator_traits<AllocatorT>::
@@ -692,10 +688,9 @@ class buffer : public detail::buffer_plain,
692688
reinterpret() const {
693689
long sz = byte_size();
694690
if (sz % sizeof(ReinterpretT) != 0)
695-
throw sycl::invalid_object_error(
696-
"Total byte size of buffer is not evenly divisible by the size of "
697-
"the reinterpreted type",
698-
PI_ERROR_INVALID_VALUE);
691+
throw sycl::exception(make_error_code(errc::invalid),
692+
"Total byte size of buffer is not evenly divisible "
693+
"by the size of the reinterpreted type");
699694

700695
return buffer<ReinterpretT, ReinterpretDim, AllocatorT>(
701696
impl, range<1>{sz / sizeof(ReinterpretT)}, OffsetInBytes, IsSubBuffer);

sycl/include/sycl/context.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,8 @@ class __SYCL_EXPORT context : public detail::OwnerLessBase<context> {
200200

201201
/// Gets the specified property of this context.
202202
///
203-
/// Throws invalid_object_error if this context does not have a property
204-
/// of type propertyT.
203+
/// Throws an exception with errc::invalid error code if this context does not
204+
/// have a property of type propertyT.
205205
///
206206
/// \return a copy of the property of type propertyT.
207207
template <typename propertyT> propertyT get_property() const;

sycl/include/sycl/detail/property_list_base.hpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
#include <sycl/detail/pi.h> // for PI_ERROR_INVALID_VALUE
1212
#include <sycl/detail/property_helper.hpp> // for DataLessPropKind, Propert...
13-
#include <sycl/exception.hpp> // for invalid_object_error
13+
#include <sycl/exception.hpp>
1414

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

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

102-
throw sycl::invalid_object_error("The property is not found",
103-
PI_ERROR_INVALID_VALUE);
102+
throw sycl::exception(make_error_code(errc::invalid),
103+
"The property is not found");
104104
}
105105

106106
void add_or_replace_accessor_properties_helper(

sycl/include/sycl/event.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,8 @@ class __SYCL_EXPORT event : public detail::OwnerLessBase<event> {
122122
/// call to this member function will block until the requested info is
123123
/// available. If the queue which submitted the command group this event is
124124
/// associated with was not constructed with the
125-
/// property::queue::enable_profiling property, an invalid_object_error SYCL
126-
/// exception is thrown.
125+
/// property::queue::enable_profiling property, an a SYCL exception with
126+
/// errc::invalid error code is thrown.
127127
///
128128
/// \return depends on template parameter.
129129
template <typename Param>

sycl/include/sycl/exception.hpp

-45
Original file line numberDiff line numberDiff line change
@@ -203,51 +203,6 @@ class __SYCL2020_DEPRECATED(
203203
: runtime_error(make_error_code(errc::kernel_argument), Msg, Err) {}
204204
};
205205

206-
class __SYCL2020_DEPRECATED(
207-
"use sycl::exception with a sycl::errc enum value instead.") device_error
208-
: public exception {
209-
public:
210-
device_error() : exception(make_error_code(errc::invalid)) {}
211-
212-
device_error(const char *Msg, pi_int32 Err)
213-
: device_error(std::string(Msg), Err) {}
214-
215-
device_error(const std::string &Msg, pi_int32 Err)
216-
: exception(make_error_code(errc::invalid), Msg, Err) {}
217-
218-
protected:
219-
device_error(std::error_code Ec) : exception(Ec) {}
220-
221-
device_error(std::error_code Ec, const std::string &Msg, const pi_int32 PIErr)
222-
: exception(Ec, Msg, PIErr) {}
223-
};
224-
225-
class __SYCL2020_DEPRECATED(
226-
"use sycl::exception with a sycl::errc enum value instead.")
227-
compile_program_error : public device_error {
228-
public:
229-
compile_program_error() : device_error(make_error_code(errc::build)) {}
230-
231-
compile_program_error(const char *Msg, pi_int32 Err)
232-
: compile_program_error(std::string(Msg), Err) {}
233-
234-
compile_program_error(const std::string &Msg, pi_int32 Err)
235-
: device_error(make_error_code(errc::build), Msg, Err) {}
236-
};
237-
238-
class __SYCL2020_DEPRECATED(
239-
"use sycl::exception with a sycl::errc enum value instead.")
240-
invalid_object_error : public device_error {
241-
public:
242-
invalid_object_error() : device_error(make_error_code(errc::invalid)) {}
243-
244-
invalid_object_error(const char *Msg, pi_int32 Err)
245-
: invalid_object_error(std::string(Msg), Err) {}
246-
247-
invalid_object_error(const std::string &Msg, pi_int32 Err)
248-
: device_error(make_error_code(errc::invalid), Msg, Err) {}
249-
};
250-
251206
} // namespace _V1
252207
} // namespace sycl
253208

sycl/include/sycl/ext/oneapi/accessor_property_list.hpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#include <sycl/detail/pi.h> // for PI_ERROR_INVALID_VALUE
1414
#include <sycl/detail/property_helper.hpp> // for DataLessPropKind, Prop...
1515
#include <sycl/detail/property_list_base.hpp> // for PropertyListBase
16-
#include <sycl/exception.hpp> // for invalid_object_error
16+
#include <sycl/exception.hpp>
1717
#include <sycl/property_list.hpp> // for property_list
1818

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

190190
return get_property_helper<PropT>();
191191
}

sycl/include/sycl/handler.hpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -2732,9 +2732,9 @@ class __SYCL_EXPORT handler {
27322732
static_assert(isValidModeForDestinationAccessor(AccessMode_Dst),
27332733
"Invalid destination accessor mode for the copy method.");
27342734
if (Dst.get_size() < Src.get_size())
2735-
throw sycl::invalid_object_error(
2736-
"The destination accessor size is too small to copy the memory into.",
2737-
PI_ERROR_INVALID_OPERATION);
2735+
throw sycl::exception(make_error_code(errc::invalid),
2736+
"The destination accessor size is too small to "
2737+
"copy the memory into.");
27382738

27392739
if (copyAccToAccHelper(Src, Dst))
27402740
return;

sycl/include/sycl/interop_handle.hpp

+11-11
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#include <sycl/detail/impl_utils.hpp> // for getSyclObjImpl
1818
#include <sycl/detail/pi.h> // for _pi_mem, pi_native_...
1919
#include <sycl/device.hpp> // for device, device_impl
20-
#include <sycl/exception.hpp> // for invalid_object_error
20+
#include <sycl/exception.hpp>
2121
#include <sycl/exception_list.hpp> // for queue_impl
2222
#include <sycl/ext/oneapi/accessor_property_list.hpp> // for accessor_property_list
2323
#include <sycl/image.hpp> // for image
@@ -71,8 +71,8 @@ class interop_handle {
7171
"The method is available only for target::device accessors");
7272
#ifndef __SYCL_DEVICE_ONLY__
7373
if (Backend != get_backend())
74-
throw invalid_object_error("Incorrect backend argument was passed",
75-
PI_ERROR_INVALID_MEM_OBJECT);
74+
throw exception(make_error_code(errc::invalid),
75+
"Incorrect backend argument was passed");
7676
const auto *AccBase = static_cast<const detail::AccessorBaseHost *>(&Acc);
7777
return getMemImpl<Backend, DataT, Dims>(
7878
detail::getSyclObjImpl(*AccBase).get());
@@ -97,8 +97,8 @@ class interop_handle {
9797
IsPlh /*, PropertyListT */> &Acc) const {
9898
#ifndef __SYCL_DEVICE_ONLY__
9999
if (Backend != get_backend())
100-
throw invalid_object_error("Incorrect backend argument was passed",
101-
PI_ERROR_INVALID_MEM_OBJECT);
100+
throw exception(make_error_code(errc::invalid),
101+
"Incorrect backend argument was passed");
102102
const auto *AccBase = static_cast<const detail::AccessorBaseHost *>(&Acc);
103103
return getMemImpl<Backend, Dims>(detail::getSyclObjImpl(*AccBase).get());
104104
#else
@@ -127,8 +127,8 @@ class interop_handle {
127127
// with the error code 'errc::backend_mismatch' when those new exceptions
128128
// are ready to be used.
129129
if (Backend != get_backend())
130-
throw invalid_object_error("Incorrect backend argument was passed",
131-
PI_ERROR_INVALID_MEM_OBJECT);
130+
throw exception(make_error_code(errc::invalid),
131+
"Incorrect backend argument was passed");
132132
int32_t NativeHandleDesc;
133133
return reinterpret_cast<backend_return_t<Backend, queue>>(
134134
getNativeQueue(NativeHandleDesc));
@@ -150,8 +150,8 @@ class interop_handle {
150150
// with the error code 'errc::backend_mismatch' when those new exceptions
151151
// are ready to be used.
152152
if (Backend != get_backend())
153-
throw invalid_object_error("Incorrect backend argument was passed",
154-
PI_ERROR_INVALID_MEM_OBJECT);
153+
throw exception(make_error_code(errc::invalid),
154+
"Incorrect backend argument was passed");
155155
// C-style cast required to allow various native types
156156
return (backend_return_t<Backend, device>)getNativeDevice();
157157
#else
@@ -172,8 +172,8 @@ class interop_handle {
172172
// with the error code 'errc::backend_mismatch' when those new exceptions
173173
// are ready to be used.
174174
if (Backend != get_backend())
175-
throw invalid_object_error("Incorrect backend argument was passed",
176-
PI_ERROR_INVALID_MEM_OBJECT);
175+
throw exception(make_error_code(errc::invalid),
176+
"Incorrect backend argument was passed");
177177
return reinterpret_cast<backend_return_t<Backend, context>>(
178178
getNativeContext());
179179
#else

sycl/include/sycl/property_list.hpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#include <sycl/detail/pi.h> // for PI_ERROR_INVALID_VALUE
1212
#include <sycl/detail/property_helper.hpp> // for DataLessPropKind, Pro...
1313
#include <sycl/detail/property_list_base.hpp> // for PropertyListBase
14-
#include <sycl/exception.hpp> // for invalid_object_error
14+
#include <sycl/exception.hpp>
1515
#include <sycl/properties/property_traits.hpp> // for is_property
1616

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

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

5252
return get_property_helper<PropT>();
5353
}

sycl/include/sycl/queue.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ class __SYCL_EXPORT queue : public detail::OwnerLessBase<queue> {
473473

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

479479
/// Fills the specified memory with the specified pattern.

0 commit comments

Comments
 (0)