Skip to content

[SYCL] Remove default error code value in exception #1150

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
7 changes: 4 additions & 3 deletions sycl/include/CL/sycl/accessor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,8 @@ class image_accessor
template <info::device param>
void checkDeviceFeatureSupported(const device &Device) {
if (!Device.get_info<param>())
throw feature_not_supported("Images are not supported by this device.");
throw feature_not_supported("Images are not supported by this device.",
PI_INVALID_OPERATION);
}

#ifdef __SYCL_DEVICE_ONLY__
Expand All @@ -357,8 +358,8 @@ class image_accessor

sycl::vec<int, Dimensions> getRangeInternal() const {
// TODO: Implement for host.
throw runtime_error(
"image::getRangeInternal() is not implemented for host");
throw runtime_error("image::getRangeInternal() is not implemented for host",
PI_INVALID_OPERATION);
return sycl::vec<int, Dimensions>{1};
}

Expand Down
10 changes: 6 additions & 4 deletions sycl/include/CL/sycl/buffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,13 +180,14 @@ class buffer {
IsSubBuffer(true) {
if (b.is_sub_buffer())
throw cl::sycl::invalid_object_error(
"Cannot create sub buffer from sub buffer.");
"Cannot create sub buffer from sub buffer.", PI_INVALID_VALUE);
if (isOutOfBounds(baseIndex, subRange, b.Range))
throw cl::sycl::invalid_object_error(
"Requested sub-buffer size exceeds the size of the parent buffer");
"Requested sub-buffer size exceeds the size of the parent buffer",
PI_INVALID_VALUE);
if (!isContiguousRegion(baseIndex, subRange, b.Range))
throw cl::sycl::invalid_object_error(
"Requested sub-buffer region is not contiguous");
"Requested sub-buffer region is not contiguous", PI_INVALID_VALUE);
}

template <int N = dimensions, typename = EnableIfOneDimension<N>>
Expand Down Expand Up @@ -282,7 +283,8 @@ class buffer {
throw cl::sycl::invalid_object_error(
"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");
"represented by the type and range of this SYCL buffer",
PI_INVALID_VALUE);

return buffer<ReinterpretT, ReinterpretDim, AllocatorT>(
impl, reinterpretRange, OffsetInBytes, IsSubBuffer);
Expand Down
3 changes: 2 additions & 1 deletion sycl/include/CL/sycl/detail/array.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ template <int dimensions = 1> class array {
ALWAYS_INLINE void check_dimension(int dimension) const {
#ifndef __SYCL_DEVICE_ONLY__
if (dimension >= dimensions || dimension < 0) {
throw cl::sycl::invalid_parameter_error("Index out of range");
throw cl::sycl::invalid_parameter_error("Index out of range",
PI_INVALID_VALUE);
}
#endif
}
Expand Down
6 changes: 4 additions & 2 deletions sycl/include/CL/sycl/detail/cg.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,8 @@ class HostKernel : public HostKernelBase {
for (int I = 0; I < Dims; ++I) {
if (NDRDesc.LocalSize[I] == 0 ||
NDRDesc.GlobalSize[I] % NDRDesc.LocalSize[I] != 0)
throw sycl::nd_range_error("Invalid local size for global size");
throw sycl::nd_range_error("Invalid local size for global size",
PI_INVALID_WORK_GROUP_SIZE);
GroupSize[I] = NDRDesc.GlobalSize[I] / NDRDesc.LocalSize[I];
}

Expand Down Expand Up @@ -320,7 +321,8 @@ class HostKernel : public HostKernelBase {
for (int I = 0; I < Dims; ++I) {
if (NDRDesc.LocalSize[I] == 0 ||
NDRDesc.GlobalSize[I] % NDRDesc.LocalSize[I] != 0)
throw sycl::nd_range_error("Invalid local size for global size");
throw sycl::nd_range_error("Invalid local size for global size",
PI_INVALID_WORK_GROUP_SIZE);
NGroups[I] = NDRDesc.GlobalSize[I] / NDRDesc.LocalSize[I];
}

Expand Down
48 changes: 32 additions & 16 deletions sycl/include/CL/sycl/detail/image_accessor_util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,8 @@ vec<T, 4> readPixel(T *Ptr, const image_channel_order ChannelOrder,
Pixel.x() = Ptr[3]; // r
break;
default:
throw cl::sycl::invalid_parameter_error("Unhandled image channel order");
throw cl::sycl::invalid_parameter_error("Unhandled image channel order",
PI_INVALID_VALUE);
}

return Pixel;
Expand Down Expand Up @@ -265,7 +266,8 @@ void writePixel(const vec<T, 4> Pixel, T *Ptr,
Ptr[3] = Pixel.x(); // r
break;
default:
throw cl::sycl::invalid_parameter_error("Unhandled image channel order");
throw cl::sycl::invalid_parameter_error("Unhandled image channel order",
PI_INVALID_VALUE);
}
}

Expand Down Expand Up @@ -293,7 +295,8 @@ void convertReadData(const vec<ChannelType, 4> PixelData,
// unsigned_int32.
throw cl::sycl::invalid_parameter_error(
"Datatype of read data - cl_uint4 is incompatible with the "
"image_channel_type of the image.");
"image_channel_type of the image.",
PI_INVALID_VALUE);
}
}

Expand All @@ -314,7 +317,8 @@ void convertReadData(const vec<ChannelType, 4> PixelData,
// signed_int32.
throw cl::sycl::invalid_parameter_error(
"Datatype of read data - cl_int4 is incompatible with the "
"image_channel_type of the image.");
"image_channel_type of the image.",
PI_INVALID_VALUE);
}
}

Expand Down Expand Up @@ -395,7 +399,8 @@ void convertReadData(const vec<ChannelType, 4> PixelData,
// and signed/unsigned_int32.
throw cl::sycl::invalid_parameter_error(
"Datatype of read data - cl_float4 is incompatible with the "
"image_channel_type of the image.");
"image_channel_type of the image.",
PI_INVALID_VALUE);
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 @@ -425,7 +430,8 @@ void convertReadData(const vec<ChannelType, 4> PixelData,
// TODO: Missing information in OpenCL spec.
throw cl::sycl::feature_not_supported(
"Currently unsupported datatype conversion from image_channel_type "
"to cl_half4.");
"to cl_half4.",
PI_INVALID_OPERATION);
case image_channel_type::signed_int8:
case image_channel_type::signed_int16:
case image_channel_type::signed_int32:
Expand All @@ -437,14 +443,16 @@ void convertReadData(const vec<ChannelType, 4> PixelData,
// and signed/unsigned_int32.
throw cl::sycl::invalid_parameter_error(
"Datatype to read- cl_half4 is incompatible with the "
"image_channel_type of the image.");
"image_channel_type of the image.",
PI_INVALID_VALUE);
case image_channel_type::fp16:
RetData = PixelData.template convert<cl_half>();
break;
case image_channel_type::fp32:
throw cl::sycl::invalid_parameter_error(
"Datatype to read - cl_half4 is incompatible with the "
"image_channel_type of the image.");
"image_channel_type of the image.",
PI_INVALID_VALUE);
default:
break;
}
Expand Down Expand Up @@ -484,7 +492,8 @@ convertWriteData(const vec<cl_uint, 4> WriteData,
// unsigned_int32.
throw cl::sycl::invalid_parameter_error(
"Datatype of data to write - cl_uint4 is incompatible with the "
"image_channel_type of the image.");
"image_channel_type of the image.",
PI_INVALID_VALUE);
}
}

Expand Down Expand Up @@ -516,7 +525,8 @@ convertWriteData(const vec<cl_int, 4> WriteData,
// signed_int32.
throw cl::sycl::invalid_parameter_error(
"Datatype of data to write - cl_int4 is incompatible with the "
"image_channel_type of the image.");
"image_channel_type of the image.",
PI_INVALID_VALUE);
}
}

Expand Down Expand Up @@ -554,7 +564,8 @@ convertWriteData(const vec<cl_float, 4> WriteData,
// TODO: Missing information in OpenCL spec.
throw cl::sycl::feature_not_supported(
"Currently unsupported datatype conversion from image_channel_type "
"to cl_float4.");
"to cl_float4.",
PI_INVALID_OPERATION);
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 @@ -596,7 +607,8 @@ convertWriteData(const vec<cl_float, 4> WriteData,
// and signed/unsigned_int32.
throw cl::sycl::invalid_parameter_error(
"Datatype of data to write - cl_float4 is incompatible with the "
"image_channel_type of the image.");
"image_channel_type of the image.",
PI_INVALID_VALUE);
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 @@ -624,7 +636,8 @@ convertWriteData(const vec<cl_half, 4> WriteData,
// TODO: Missing information in OpenCL spec.
throw cl::sycl::feature_not_supported(
"Currently unsupported datatype conversion from image_channel_type "
"to cl_half4.");
"to cl_half4.",
PI_INVALID_OPERATION);
case image_channel_type::signed_int8:
case image_channel_type::signed_int16:
case image_channel_type::signed_int32:
Expand All @@ -636,13 +649,15 @@ convertWriteData(const vec<cl_half, 4> WriteData,
// and signed/unsigned_int32.
throw cl::sycl::invalid_parameter_error(
"Datatype of data to write - cl_float4 is incompatible with the "
"image_channel_type of the image.");
"image_channel_type of the image.",
PI_INVALID_VALUE);
case image_channel_type::fp16:
return WriteData.convert<ChannelType>();
case image_channel_type::fp32:
throw cl::sycl::invalid_parameter_error(
"Datatype of data to write - cl_float4 is incompatible with the "
"image_channel_type of the image.");
"image_channel_type of the image.",
PI_INVALID_VALUE);
default:
break;
}
Expand Down Expand Up @@ -1007,7 +1022,8 @@ DataT imageReadSamplerHostImpl(const CoordT &Coords, const sampler &Smpl,
throw cl::sycl::feature_not_supported(
"Sampler used with unsupported configuration of "
"mirrored_repeat/repeat filtering mode with unnormalized "
"coordinates. ");
"coordinates. ",
PI_INVALID_OPERATION);
case addressing_mode::clamp_to_edge:
case addressing_mode::clamp:
case addressing_mode::none:
Expand Down
3 changes: 3 additions & 0 deletions sycl/include/CL/sycl/detail/pi.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ typedef enum {
PI_MISALIGNED_SUB_BUFFER_OFFSET = CL_MISALIGNED_SUB_BUFFER_OFFSET,
PI_BUILD_PROGRAM_FAILURE = CL_BUILD_PROGRAM_FAILURE,
PI_INVALID_WORK_GROUP_SIZE = CL_INVALID_WORK_GROUP_SIZE,
PI_COMPILER_NOT_AVAILABLE = CL_COMPILER_NOT_AVAILABLE,
PI_PROFILING_INFO_NOT_AVAILABLE = CL_PROFILING_INFO_NOT_AVAILABLE,
PI_DEVICE_NOT_FOUND = CL_DEVICE_NOT_FOUND,
PI_ERROR_UNKNOWN = -999
} _pi_result;

Expand Down
5 changes: 3 additions & 2 deletions sycl/include/CL/sycl/detail/sycl_mem_obj_t.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,9 +234,10 @@ class SYCLMemObjT : public SYCLMemObjI {
MHostPtrReadOnly = iterator_to_const_type_t<InputIterator>::value;
setAlign(RequiredAlign);
if (useHostPtr())
throw invalid_parameter_error(
throw runtime_error(
"Buffer constructor from a pair of iterator values does not support "
"use_host_ptr property.");
"use_host_ptr property.",
PI_INVALID_OPERATION);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think PI_INVALID_VALUE is not apt for a invalid_parameter_error.
You have used that in the above file pretty consistently.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no requirement in spec on exception in this case.
Though, for sake of consistency I'd rather change the type of exception to a mere cl::sycl::runtime_error.
Done.


setAlign(RequiredAlign);
MShadowCopy = allocateHostMem();
Expand Down
17 changes: 8 additions & 9 deletions sycl/include/CL/sycl/exception.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
// 4.9.2 Exception Class Interface

#include <CL/sycl/detail/common.hpp>
#include <CL/sycl/detail/pi.h>
#include <CL/sycl/stl.hpp>

#include <exception>
Expand All @@ -37,15 +38,15 @@ class exception: public std::exception {

private:
string_class MMsg;
cl_int MCLErr = CL_SUCCESS;
cl_int MCLErr;
shared_ptr_class<context> MContext;

protected:
exception(const char *Msg, const cl_int CLErr = CL_SUCCESS,
exception(const char *Msg, const cl_int CLErr,
shared_ptr_class<context> Context = nullptr)
: exception(string_class(Msg), CLErr, Context) {}

exception(const string_class &Msg, const cl_int CLErr = CL_SUCCESS,
exception(const string_class &Msg, const cl_int CLErr,
shared_ptr_class<context> Context = nullptr)
: MMsg(Msg + " " + detail::codeToString(CLErr)), MCLErr(CLErr),
MContext(Context) {}
Expand All @@ -55,11 +56,10 @@ class runtime_error : public exception {
public:
runtime_error() = default;

runtime_error(const char *Msg, cl_int Err = CL_SUCCESS)
runtime_error(const char *Msg, cl_int Err)
: runtime_error(string_class(Msg), Err) {}

runtime_error(const string_class &Msg, cl_int Err = CL_SUCCESS)
: exception(Msg, Err) {}
runtime_error(const string_class &Msg, cl_int Err) : exception(Msg, Err) {}
};
class kernel_error : public runtime_error {
using runtime_error::runtime_error;
Expand All @@ -80,11 +80,10 @@ class device_error : public exception {
public:
device_error() = default;

device_error(const char *Msg, cl_int Err = CL_SUCCESS)
device_error(const char *Msg, cl_int Err)
: device_error(string_class(Msg), Err) {}

device_error(const string_class &Msg, cl_int Err = CL_SUCCESS)
: exception(Msg, Err) {}
device_error(const string_class &Msg, cl_int Err) : exception(Msg, Err) {}
};
class compile_program_error : public device_error {
using device_error::device_error;
Expand Down
6 changes: 4 additions & 2 deletions sycl/include/CL/sycl/handler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -296,10 +296,12 @@ class handler {
void verifySyclKernelInvoc(const kernel &SyclKernel) {
if (is_host()) {
throw invalid_object_error(
"This kernel invocation method cannot be used on the host");
"This kernel invocation method cannot be used on the host",
PI_INVALID_DEVICE);
}
if (SyclKernel.is_host()) {
throw invalid_object_error("Invalid kernel type, OpenCL expected");
throw invalid_object_error("Invalid kernel type, OpenCL expected",
PI_INVALID_KERNEL);
}
}

Expand Down
3 changes: 2 additions & 1 deletion sycl/include/CL/sycl/intel/function_pointer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ device_func_ptr_holder_t get_device_func_ptr(FuncType F, const char *FuncName,

if (program_state::linked != P.get_state()) {
throw invalid_parameter_error(
"Program must be built before passing to get_device_func_ptr");
"Program must be built before passing to get_device_func_ptr",
PI_INVALID_OPERATION);
}

return detail::getDeviceFunctionPointerImpl(D, P, FuncName);
Expand Down
Loading