Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
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
66 changes: 52 additions & 14 deletions sycl/include/CL/sycl/accessor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1023,7 +1023,7 @@ class __SYCL_SPECIAL_CLASS accessor :
getAdjustedMode(PropertyList),
detail::getSyclObjImpl(BufferRef).get(), AdjustedDim, sizeof(DataT),
BufferRef.OffsetInBytes, BufferRef.IsSubBuffer) {
checkDeviceAccessorBufferSize(BufferRef.size());
preScreenAccessor(BufferRef.size(), PropertyList);
if (!IsPlaceH)
addHostAccessorAndWait(AccessorBaseHost::impl.get());
detail::constructorNotification(detail::getSyclObjImpl(BufferRef).get(),
Expand Down Expand Up @@ -1054,7 +1054,7 @@ class __SYCL_SPECIAL_CLASS accessor :
getAdjustedMode(PropertyList),
detail::getSyclObjImpl(BufferRef).get(), AdjustedDim, sizeof(DataT),
BufferRef.OffsetInBytes, BufferRef.IsSubBuffer) {
checkDeviceAccessorBufferSize(BufferRef.size());
preScreenAccessor(BufferRef.size(), PropertyList);
if (!IsPlaceH)
addHostAccessorAndWait(AccessorBaseHost::impl.get());
detail::constructorNotification(detail::getSyclObjImpl(BufferRef).get(),
Expand Down Expand Up @@ -1084,7 +1084,7 @@ class __SYCL_SPECIAL_CLASS accessor :
getAdjustedMode(PropertyList),
detail::getSyclObjImpl(BufferRef).get(), Dimensions, sizeof(DataT),
BufferRef.OffsetInBytes, BufferRef.IsSubBuffer) {
checkDeviceAccessorBufferSize(BufferRef.size());
preScreenAccessor(BufferRef.size(), PropertyList);
detail::associateWithHandler(CommandGroupHandler, this, AccessTarget);
detail::constructorNotification(detail::getSyclObjImpl(BufferRef).get(),
detail::AccessorBaseHost::impl.get(),
Expand Down Expand Up @@ -1115,7 +1115,7 @@ class __SYCL_SPECIAL_CLASS accessor :
getAdjustedMode(PropertyList),
detail::getSyclObjImpl(BufferRef).get(), Dimensions, sizeof(DataT),
BufferRef.OffsetInBytes, BufferRef.IsSubBuffer) {
checkDeviceAccessorBufferSize(BufferRef.size());
preScreenAccessor(BufferRef.size(), PropertyList);
detail::associateWithHandler(CommandGroupHandler, this, AccessTarget);
detail::constructorNotification(detail::getSyclObjImpl(BufferRef).get(),
detail::AccessorBaseHost::impl.get(),
Expand Down Expand Up @@ -1145,7 +1145,7 @@ class __SYCL_SPECIAL_CLASS accessor :
getAdjustedMode(PropertyList),
detail::getSyclObjImpl(BufferRef).get(), Dimensions, sizeof(DataT),
BufferRef.OffsetInBytes, BufferRef.IsSubBuffer) {
checkDeviceAccessorBufferSize(BufferRef.size());
preScreenAccessor(BufferRef.size(), PropertyList);
if (!IsPlaceH)
addHostAccessorAndWait(AccessorBaseHost::impl.get());
detail::constructorNotification(detail::getSyclObjImpl(BufferRef).get(),
Expand Down Expand Up @@ -1178,7 +1178,7 @@ class __SYCL_SPECIAL_CLASS accessor :
getAdjustedMode(PropertyList),
detail::getSyclObjImpl(BufferRef).get(), Dimensions, sizeof(DataT),
BufferRef.OffsetInBytes, BufferRef.IsSubBuffer) {
checkDeviceAccessorBufferSize(BufferRef.size());
preScreenAccessor(BufferRef.size(), PropertyList);
if (!IsPlaceH)
addHostAccessorAndWait(AccessorBaseHost::impl.get());
detail::constructorNotification(detail::getSyclObjImpl(BufferRef).get(),
Expand Down Expand Up @@ -1237,7 +1237,7 @@ class __SYCL_SPECIAL_CLASS accessor :
getAdjustedMode(PropertyList),
detail::getSyclObjImpl(BufferRef).get(), Dimensions, sizeof(DataT),
BufferRef.OffsetInBytes, BufferRef.IsSubBuffer) {
checkDeviceAccessorBufferSize(BufferRef.size());
preScreenAccessor(BufferRef.size(), PropertyList);
detail::associateWithHandler(CommandGroupHandler, this, AccessTarget);
detail::constructorNotification(detail::getSyclObjImpl(BufferRef).get(),
detail::AccessorBaseHost::impl.get(),
Expand Down Expand Up @@ -1269,7 +1269,7 @@ class __SYCL_SPECIAL_CLASS accessor :
getAdjustedMode(PropertyList),
detail::getSyclObjImpl(BufferRef).get(), Dimensions, sizeof(DataT),
BufferRef.OffsetInBytes, BufferRef.IsSubBuffer) {
checkDeviceAccessorBufferSize(BufferRef.size());
preScreenAccessor(BufferRef.size(), PropertyList);
detail::associateWithHandler(CommandGroupHandler, this, AccessTarget);
detail::constructorNotification(detail::getSyclObjImpl(BufferRef).get(),
detail::AccessorBaseHost::impl.get(),
Expand Down Expand Up @@ -1443,7 +1443,14 @@ class __SYCL_SPECIAL_CLASS accessor :
detail::getSyclObjImpl(BufferRef).get(), Dimensions,
sizeof(DataT), BufferRef.OffsetInBytes,
BufferRef.IsSubBuffer) {
checkDeviceAccessorBufferSize(BufferRef.size());
preScreenAccessor(BufferRef.size(), 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_INVALID_VALUE);

if (!IsPlaceH)
addHostAccessorAndWait(AccessorBaseHost::impl.get());
detail::constructorNotification(detail::getSyclObjImpl(BufferRef).get(),
Expand Down Expand Up @@ -1477,7 +1484,14 @@ class __SYCL_SPECIAL_CLASS accessor :
detail::getSyclObjImpl(BufferRef).get(), Dimensions,
sizeof(DataT), BufferRef.OffsetInBytes,
BufferRef.IsSubBuffer) {
checkDeviceAccessorBufferSize(BufferRef.size());
preScreenAccessor(BufferRef.size(), 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_INVALID_VALUE);

if (!IsPlaceH)
addHostAccessorAndWait(AccessorBaseHost::impl.get());
detail::constructorNotification(detail::getSyclObjImpl(BufferRef).get(),
Expand Down Expand Up @@ -1538,7 +1552,14 @@ class __SYCL_SPECIAL_CLASS accessor :
detail::getSyclObjImpl(BufferRef).get(), Dimensions,
sizeof(DataT), BufferRef.OffsetInBytes,
BufferRef.IsSubBuffer) {
checkDeviceAccessorBufferSize(BufferRef.size());
preScreenAccessor(BufferRef.size(), 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_INVALID_VALUE);

detail::associateWithHandler(CommandGroupHandler, this, AccessTarget);
detail::constructorNotification(detail::getSyclObjImpl(BufferRef).get(),
detail::AccessorBaseHost::impl.get(),
Expand Down Expand Up @@ -1571,7 +1592,14 @@ class __SYCL_SPECIAL_CLASS accessor :
detail::getSyclObjImpl(BufferRef).get(), Dimensions,
sizeof(DataT), BufferRef.OffsetInBytes,
BufferRef.IsSubBuffer) {
checkDeviceAccessorBufferSize(BufferRef.size());
preScreenAccessor(BufferRef.size(), 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_INVALID_VALUE);

detail::associateWithHandler(CommandGroupHandler, this, AccessTarget);
detail::constructorNotification(detail::getSyclObjImpl(BufferRef).get(),
detail::AccessorBaseHost::impl.get(),
Expand Down Expand Up @@ -1761,12 +1789,22 @@ class __SYCL_SPECIAL_CLASS accessor :
return getQualifiedPtr();
}

void checkDeviceAccessorBufferSize(const size_t elemInBuffer) {
void preScreenAccessor(const size_t elemInBuffer,
const PropertyListT &PropertyList) {
// check device accessor buffer size
if (!IsHostBuf && elemInBuffer == 0)
throw cl::sycl::invalid_object_error(
throw sycl::invalid_object_error(
"SYCL buffer size is zero. To create a device accessor, SYCL "
"buffer size must be greater than zero.",
PI_INVALID_VALUE);

// 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_INVALID_VALUE);
}
}
};

Expand Down
9 changes: 6 additions & 3 deletions sycl/include/CL/sycl/backend.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ auto get_native(const SyclObjectT &Obj)
-> backend_return_t<BackendName, SyclObjectT> {
// TODO use SYCL 2020 exception when implemented
if (Obj.get_backend() != BackendName) {
throw runtime_error("Backends mismatch", PI_INVALID_OPERATION);
throw sycl::runtime_error(errc::backend_mismatch, "Backends mismatch",
PI_INVALID_OPERATION);
}
return Obj.template get_native<BackendName>();
}
Expand All @@ -82,7 +83,8 @@ inline backend_return_t<backend::opencl, event>
get_native<backend::opencl, event>(const event &Obj) {
// TODO use SYCL 2020 exception when implemented
if (Obj.get_backend() != backend::opencl) {
throw runtime_error("Backends mismatch", PI_INVALID_OPERATION);
throw sycl::runtime_error(errc::backend_mismatch, "Backends mismatch",
PI_INVALID_OPERATION);
}
backend_return_t<backend::opencl, event> ReturnValue;
for (auto const &element : Obj.getNativeVector()) {
Expand All @@ -104,7 +106,8 @@ inline backend_return_t<backend::opencl, event> get_native<
backend::opencl, event>(const event &Obj) {
// TODO use SYCL 2020 exception when implemented
if (Obj.get_backend() != backend::opencl) {
throw runtime_error("Backends mismatch", PI_INVALID_OPERATION);
throw sycl::runtime_error(errc::backend_mismatch, "Backends mismatch",
PI_INVALID_OPERATION);
}
return reinterpret_cast<
typename detail::interop<backend::opencl, event>::type>(Obj.getNative());
Expand Down
31 changes: 21 additions & 10 deletions sycl/include/CL/sycl/buffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,11 @@ class buffer {
handler &commandGroupHandler, range<dimensions> accessRange,
id<dimensions> accessOffset = {},
const detail::code_location CodeLoc = detail::code_location::current()) {
if (isOutOfBounds(accessOffset, accessRange, this->Range))
throw cl::sycl::invalid_object_error(
"Requested accessor would exceed the bounds of the buffer",
PI_INVALID_VALUE);

return accessor<T, dimensions, mode, target, access::placeholder::false_t,
ext::oneapi::accessor_property_list<>>(
*this, commandGroupHandler, accessRange, accessOffset, {}, CodeLoc);
Expand All @@ -414,6 +419,11 @@ class buffer {
get_access(
range<dimensions> accessRange, id<dimensions> accessOffset = {},
const detail::code_location CodeLoc = detail::code_location::current()) {
if (isOutOfBounds(accessOffset, accessRange, this->Range))
throw cl::sycl::invalid_object_error(
"Requested accessor would exceed the bounds of the buffer",
PI_INVALID_VALUE);

return accessor<T, dimensions, mode, access::target::host_buffer,
access::placeholder::false_t,
ext::oneapi::accessor_property_list<>>(
Expand Down Expand Up @@ -499,6 +509,17 @@ class buffer {
return impl->template get_property<propertyT>();
}

protected:
bool isOutOfBounds(const id<dimensions> &offset,
const range<dimensions> &newRange,
const range<dimensions> &parentRange) {
bool outOfBounds = false;
for (int i = 0; i < dimensions; ++i)
outOfBounds |= newRange[i] + offset[i] > parentRange[i];

return outOfBounds;
}

private:
std::shared_ptr<detail::buffer_impl> impl;
template <class Obj>
Expand Down Expand Up @@ -554,16 +575,6 @@ class buffer {
return detail::getLinearIndex(offset, range) * sizeof(Type);
}

bool isOutOfBounds(const id<dimensions> &offset,
const range<dimensions> &newRange,
const range<dimensions> &parentRange) {
bool outOfBounds = false;
for (int i = 0; i < dimensions; ++i)
outOfBounds |= newRange[i] + offset[i] > parentRange[i];

return outOfBounds;
}

bool isContiguousRegion(const id<1> &, const range<1> &, const range<1> &) {
// 1D sub buffer always has contiguous region
return true;
Expand Down
37 changes: 22 additions & 15 deletions sycl/include/CL/sycl/exception.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,24 +134,26 @@ class __SYCL2020_DEPRECATED(
"use sycl::exception with sycl::errc::runtime instead.") runtime_error
: public exception {
public:
runtime_error() = default;
runtime_error() : exception(make_error_code(errc::runtime)) {}

runtime_error(const char *Msg, cl_int Err)
: runtime_error(std::string(Msg), Err) {}

runtime_error(const std::string &Msg, cl_int Err)
: exception(make_error_code(errc::runtime), Msg, Err) {}

protected:
runtime_error(std::error_code ec, const std::string &Msg, const cl_int CLErr)
: exception(ec, Msg, CLErr) {}

protected:
runtime_error(std::error_code ec) : exception(ec) {}
};

class __SYCL2020_DEPRECATED("use sycl::exception with sycl::errc::kernel or "
"errc::kernel_argument instead.") kernel_error
: public runtime_error {
public:
kernel_error() = default;
kernel_error() : runtime_error(make_error_code(errc::kernel)) {}

kernel_error(const char *Msg, cl_int Err)
: kernel_error(std::string(Msg), Err) {}
Expand All @@ -164,7 +166,7 @@ class __SYCL2020_DEPRECATED(
"use sycl::exception with sycl::errc::accessor instead.") accessor_error
: public runtime_error {
public:
accessor_error() = default;
accessor_error() : runtime_error(make_error_code(errc::accessor)) {}

accessor_error(const char *Msg, cl_int Err)
: accessor_error(std::string(Msg), Err) {}
Expand All @@ -177,7 +179,7 @@ class __SYCL2020_DEPRECATED(
"use sycl::exception with sycl::errc::nd_range instead.") nd_range_error
: public runtime_error {
public:
nd_range_error() = default;
nd_range_error() : runtime_error(make_error_code(errc::nd_range)) {}

nd_range_error(const char *Msg, cl_int Err)
: nd_range_error(std::string(Msg), Err) {}
Expand All @@ -190,7 +192,7 @@ class __SYCL2020_DEPRECATED(
"use sycl::exception with sycl::errc::event instead.") event_error
: public runtime_error {
public:
event_error() = default;
event_error() : runtime_error(make_error_code(errc::event)) {}

event_error(const char *Msg, cl_int Err)
: event_error(std::string(Msg), Err) {}
Expand All @@ -203,7 +205,8 @@ class __SYCL2020_DEPRECATED(
"use sycl::exception with a sycl::errc enum value instead.")
invalid_parameter_error : public runtime_error {
public:
invalid_parameter_error() = default;
invalid_parameter_error()
: runtime_error(make_error_code(errc::kernel_argument)) {}

invalid_parameter_error(const char *Msg, cl_int Err)
: invalid_parameter_error(std::string(Msg), Err) {}
Expand All @@ -216,7 +219,7 @@ class __SYCL2020_DEPRECATED(
"use sycl::exception with a sycl::errc enum value instead.") device_error
: public exception {
public:
device_error() = default;
device_error() : exception(make_error_code(errc::invalid)) {}

device_error(const char *Msg, cl_int Err)
: device_error(std::string(Msg), Err) {}
Expand All @@ -225,6 +228,8 @@ class __SYCL2020_DEPRECATED(
: 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 cl_int CLErr)
: exception(ec, Msg, CLErr) {}
};
Expand All @@ -233,7 +238,7 @@ class __SYCL2020_DEPRECATED(
"use sycl::exception with a sycl::errc enum value instead.")
compile_program_error : public device_error {
public:
compile_program_error() = default;
compile_program_error() : device_error(make_error_code(errc::build)) {}

compile_program_error(const char *Msg, cl_int Err)
: compile_program_error(std::string(Msg), Err) {}
Expand All @@ -246,7 +251,7 @@ class __SYCL2020_DEPRECATED(
"use sycl::exception with a sycl::errc enum value instead.")
link_program_error : public device_error {
public:
link_program_error() = default;
link_program_error() : device_error(make_error_code(errc::build)) {}

link_program_error(const char *Msg, cl_int Err)
: link_program_error(std::string(Msg), Err) {}
Expand All @@ -259,7 +264,7 @@ class __SYCL2020_DEPRECATED(
"use sycl::exception with a sycl::errc enum value instead.")
invalid_object_error : public device_error {
public:
invalid_object_error() = default;
invalid_object_error() : device_error(make_error_code(errc::invalid)) {}

invalid_object_error(const char *Msg, cl_int Err)
: invalid_object_error(std::string(Msg), Err) {}
Expand All @@ -272,7 +277,8 @@ class __SYCL2020_DEPRECATED(
"use sycl::exception with sycl::errc::memory_allocation instead.")
memory_allocation_error : public device_error {
public:
memory_allocation_error() = default;
memory_allocation_error()
: device_error(make_error_code(errc::memory_allocation)) {}

memory_allocation_error(const char *Msg, cl_int Err)
: memory_allocation_error(std::string(Msg), Err) {}
Expand All @@ -285,7 +291,7 @@ class __SYCL2020_DEPRECATED(
"use sycl::exception with sycl::errc::platform instead.") platform_error
: public device_error {
public:
platform_error() = default;
platform_error() : device_error(make_error_code(errc::platform)) {}

platform_error(const char *Msg, cl_int Err)
: platform_error(std::string(Msg), Err) {}
Expand All @@ -298,7 +304,7 @@ class __SYCL2020_DEPRECATED(
"use sycl::exception with sycl::errc::profiling instead.") profiling_error
: public device_error {
public:
profiling_error() = default;
profiling_error() : device_error(make_error_code(errc::profiling)) {}

profiling_error(const char *Msg, cl_int Err)
: profiling_error(std::string(Msg), Err) {}
Expand All @@ -311,7 +317,8 @@ class __SYCL2020_DEPRECATED(
"use sycl::exception with sycl::errc::feature_not_supported instead.")
feature_not_supported : public device_error {
public:
feature_not_supported() = default;
feature_not_supported()
: device_error(make_error_code(errc::feature_not_supported)) {}

feature_not_supported(const char *Msg, cl_int Err)
: feature_not_supported(std::string(Msg), Err) {}
Expand Down
Loading