Skip to content

Commit 04ee17c

Browse files
authored
[SYCL] Remove default error code value in exception (#1150)
Signed-off-by: Sergey Kanaev <[email protected]>
1 parent 065c22e commit 04ee17c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+327
-194
lines changed

sycl/include/CL/sycl/accessor.hpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,8 @@ class image_accessor
336336
template <info::device param>
337337
void checkDeviceFeatureSupported(const device &Device) {
338338
if (!Device.get_info<param>())
339-
throw feature_not_supported("Images are not supported by this device.");
339+
throw feature_not_supported("Images are not supported by this device.",
340+
PI_INVALID_OPERATION);
340341
}
341342

342343
#ifdef __SYCL_DEVICE_ONLY__
@@ -357,8 +358,8 @@ class image_accessor
357358

358359
sycl::vec<int, Dimensions> getRangeInternal() const {
359360
// TODO: Implement for host.
360-
throw runtime_error(
361-
"image::getRangeInternal() is not implemented for host");
361+
throw runtime_error("image::getRangeInternal() is not implemented for host",
362+
PI_INVALID_OPERATION);
362363
return sycl::vec<int, Dimensions>{1};
363364
}
364365

sycl/include/CL/sycl/buffer.hpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -180,13 +180,14 @@ class buffer {
180180
IsSubBuffer(true) {
181181
if (b.is_sub_buffer())
182182
throw cl::sycl::invalid_object_error(
183-
"Cannot create sub buffer from sub buffer.");
183+
"Cannot create sub buffer from sub buffer.", PI_INVALID_VALUE);
184184
if (isOutOfBounds(baseIndex, subRange, b.Range))
185185
throw cl::sycl::invalid_object_error(
186-
"Requested sub-buffer size exceeds the size of the parent buffer");
186+
"Requested sub-buffer size exceeds the size of the parent buffer",
187+
PI_INVALID_VALUE);
187188
if (!isContiguousRegion(baseIndex, subRange, b.Range))
188189
throw cl::sycl::invalid_object_error(
189-
"Requested sub-buffer region is not contiguous");
190+
"Requested sub-buffer region is not contiguous", PI_INVALID_VALUE);
190191
}
191192

192193
template <int N = dimensions, typename = EnableIfOneDimension<N>>
@@ -282,7 +283,8 @@ class buffer {
282283
throw cl::sycl::invalid_object_error(
283284
"Total size in bytes represented by the type and range of the "
284285
"reinterpreted SYCL buffer does not equal the total size in bytes "
285-
"represented by the type and range of this SYCL buffer");
286+
"represented by the type and range of this SYCL buffer",
287+
PI_INVALID_VALUE);
286288

287289
return buffer<ReinterpretT, ReinterpretDim, AllocatorT>(
288290
impl, reinterpretRange, OffsetInBytes, IsSubBuffer);

sycl/include/CL/sycl/detail/array.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,8 @@ template <int dimensions = 1> class array {
111111
ALWAYS_INLINE void check_dimension(int dimension) const {
112112
#ifndef __SYCL_DEVICE_ONLY__
113113
if (dimension >= dimensions || dimension < 0) {
114-
throw cl::sycl::invalid_parameter_error("Index out of range");
114+
throw cl::sycl::invalid_parameter_error("Index out of range",
115+
PI_INVALID_VALUE);
115116
}
116117
#endif
117118
}

sycl/include/CL/sycl/detail/cg.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,8 @@ class HostKernel : public HostKernelBase {
279279
for (int I = 0; I < Dims; ++I) {
280280
if (NDRDesc.LocalSize[I] == 0 ||
281281
NDRDesc.GlobalSize[I] % NDRDesc.LocalSize[I] != 0)
282-
throw sycl::nd_range_error("Invalid local size for global size");
282+
throw sycl::nd_range_error("Invalid local size for global size",
283+
PI_INVALID_WORK_GROUP_SIZE);
283284
GroupSize[I] = NDRDesc.GlobalSize[I] / NDRDesc.LocalSize[I];
284285
}
285286

@@ -320,7 +321,8 @@ class HostKernel : public HostKernelBase {
320321
for (int I = 0; I < Dims; ++I) {
321322
if (NDRDesc.LocalSize[I] == 0 ||
322323
NDRDesc.GlobalSize[I] % NDRDesc.LocalSize[I] != 0)
323-
throw sycl::nd_range_error("Invalid local size for global size");
324+
throw sycl::nd_range_error("Invalid local size for global size",
325+
PI_INVALID_WORK_GROUP_SIZE);
324326
NGroups[I] = NDRDesc.GlobalSize[I] / NDRDesc.LocalSize[I];
325327
}
326328

sycl/include/CL/sycl/detail/image_accessor_util.hpp

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,8 @@ vec<T, 4> readPixel(T *Ptr, const image_channel_order ChannelOrder,
193193
Pixel.x() = Ptr[3]; // r
194194
break;
195195
default:
196-
throw cl::sycl::invalid_parameter_error("Unhandled image channel order");
196+
throw cl::sycl::invalid_parameter_error("Unhandled image channel order",
197+
PI_INVALID_VALUE);
197198
}
198199

199200
return Pixel;
@@ -265,7 +266,8 @@ void writePixel(const vec<T, 4> Pixel, T *Ptr,
265266
Ptr[3] = Pixel.x(); // r
266267
break;
267268
default:
268-
throw cl::sycl::invalid_parameter_error("Unhandled image channel order");
269+
throw cl::sycl::invalid_parameter_error("Unhandled image channel order",
270+
PI_INVALID_VALUE);
269271
}
270272
}
271273

@@ -293,7 +295,8 @@ void convertReadData(const vec<ChannelType, 4> PixelData,
293295
// unsigned_int32.
294296
throw cl::sycl::invalid_parameter_error(
295297
"Datatype of read data - cl_uint4 is incompatible with the "
296-
"image_channel_type of the image.");
298+
"image_channel_type of the image.",
299+
PI_INVALID_VALUE);
297300
}
298301
}
299302

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

@@ -395,7 +399,8 @@ void convertReadData(const vec<ChannelType, 4> PixelData,
395399
// and signed/unsigned_int32.
396400
throw cl::sycl::invalid_parameter_error(
397401
"Datatype of read data - cl_float4 is incompatible with the "
398-
"image_channel_type of the image.");
402+
"image_channel_type of the image.",
403+
PI_INVALID_VALUE);
399404
case image_channel_type::fp16:
400405
// Host has conversion from float to half with accuracy as required in
401406
// section 8.3.2 OpenCL spec.
@@ -425,7 +430,8 @@ void convertReadData(const vec<ChannelType, 4> PixelData,
425430
// TODO: Missing information in OpenCL spec.
426431
throw cl::sycl::feature_not_supported(
427432
"Currently unsupported datatype conversion from image_channel_type "
428-
"to cl_half4.");
433+
"to cl_half4.",
434+
PI_INVALID_OPERATION);
429435
case image_channel_type::signed_int8:
430436
case image_channel_type::signed_int16:
431437
case image_channel_type::signed_int32:
@@ -437,14 +443,16 @@ void convertReadData(const vec<ChannelType, 4> PixelData,
437443
// and signed/unsigned_int32.
438444
throw cl::sycl::invalid_parameter_error(
439445
"Datatype to read- cl_half4 is incompatible with the "
440-
"image_channel_type of the image.");
446+
"image_channel_type of the image.",
447+
PI_INVALID_VALUE);
441448
case image_channel_type::fp16:
442449
RetData = PixelData.template convert<cl_half>();
443450
break;
444451
case image_channel_type::fp32:
445452
throw cl::sycl::invalid_parameter_error(
446453
"Datatype to read - cl_half4 is incompatible with the "
447-
"image_channel_type of the image.");
454+
"image_channel_type of the image.",
455+
PI_INVALID_VALUE);
448456
default:
449457
break;
450458
}
@@ -484,7 +492,8 @@ convertWriteData(const vec<cl_uint, 4> WriteData,
484492
// unsigned_int32.
485493
throw cl::sycl::invalid_parameter_error(
486494
"Datatype of data to write - cl_uint4 is incompatible with the "
487-
"image_channel_type of the image.");
495+
"image_channel_type of the image.",
496+
PI_INVALID_VALUE);
488497
}
489498
}
490499

@@ -516,7 +525,8 @@ convertWriteData(const vec<cl_int, 4> WriteData,
516525
// signed_int32.
517526
throw cl::sycl::invalid_parameter_error(
518527
"Datatype of data to write - cl_int4 is incompatible with the "
519-
"image_channel_type of the image.");
528+
"image_channel_type of the image.",
529+
PI_INVALID_VALUE);
520530
}
521531
}
522532

@@ -554,7 +564,8 @@ convertWriteData(const vec<cl_float, 4> WriteData,
554564
// TODO: Missing information in OpenCL spec.
555565
throw cl::sycl::feature_not_supported(
556566
"Currently unsupported datatype conversion from image_channel_type "
557-
"to cl_float4.");
567+
"to cl_float4.",
568+
PI_INVALID_OPERATION);
558569
case image_channel_type::unorm_short_555:
559570
// TODO: Missing information in OpenCL spec.
560571
// Check if the below code is correct after the spec is updated.
@@ -596,7 +607,8 @@ convertWriteData(const vec<cl_float, 4> WriteData,
596607
// and signed/unsigned_int32.
597608
throw cl::sycl::invalid_parameter_error(
598609
"Datatype of data to write - cl_float4 is incompatible with the "
599-
"image_channel_type of the image.");
610+
"image_channel_type of the image.",
611+
PI_INVALID_VALUE);
600612
case image_channel_type::fp16:
601613
// Host has conversion from float to half with accuracy as required in
602614
// section 8.3.2 OpenCL spec.
@@ -624,7 +636,8 @@ convertWriteData(const vec<cl_half, 4> WriteData,
624636
// TODO: Missing information in OpenCL spec.
625637
throw cl::sycl::feature_not_supported(
626638
"Currently unsupported datatype conversion from image_channel_type "
627-
"to cl_half4.");
639+
"to cl_half4.",
640+
PI_INVALID_OPERATION);
628641
case image_channel_type::signed_int8:
629642
case image_channel_type::signed_int16:
630643
case image_channel_type::signed_int32:
@@ -636,13 +649,15 @@ convertWriteData(const vec<cl_half, 4> WriteData,
636649
// and signed/unsigned_int32.
637650
throw cl::sycl::invalid_parameter_error(
638651
"Datatype of data to write - cl_float4 is incompatible with the "
639-
"image_channel_type of the image.");
652+
"image_channel_type of the image.",
653+
PI_INVALID_VALUE);
640654
case image_channel_type::fp16:
641655
return WriteData.convert<ChannelType>();
642656
case image_channel_type::fp32:
643657
throw cl::sycl::invalid_parameter_error(
644658
"Datatype of data to write - cl_float4 is incompatible with the "
645-
"image_channel_type of the image.");
659+
"image_channel_type of the image.",
660+
PI_INVALID_VALUE);
646661
default:
647662
break;
648663
}
@@ -1007,7 +1022,8 @@ DataT imageReadSamplerHostImpl(const CoordT &Coords, const sampler &Smpl,
10071022
throw cl::sycl::feature_not_supported(
10081023
"Sampler used with unsupported configuration of "
10091024
"mirrored_repeat/repeat filtering mode with unnormalized "
1010-
"coordinates. ");
1025+
"coordinates. ",
1026+
PI_INVALID_OPERATION);
10111027
case addressing_mode::clamp_to_edge:
10121028
case addressing_mode::clamp:
10131029
case addressing_mode::none:

sycl/include/CL/sycl/detail/pi.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ typedef enum {
7373
PI_MISALIGNED_SUB_BUFFER_OFFSET = CL_MISALIGNED_SUB_BUFFER_OFFSET,
7474
PI_BUILD_PROGRAM_FAILURE = CL_BUILD_PROGRAM_FAILURE,
7575
PI_INVALID_WORK_GROUP_SIZE = CL_INVALID_WORK_GROUP_SIZE,
76+
PI_COMPILER_NOT_AVAILABLE = CL_COMPILER_NOT_AVAILABLE,
77+
PI_PROFILING_INFO_NOT_AVAILABLE = CL_PROFILING_INFO_NOT_AVAILABLE,
78+
PI_DEVICE_NOT_FOUND = CL_DEVICE_NOT_FOUND,
7679
PI_ERROR_UNKNOWN = -999
7780
} _pi_result;
7881

sycl/include/CL/sycl/detail/sycl_mem_obj_t.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,9 +234,10 @@ class SYCLMemObjT : public SYCLMemObjI {
234234
MHostPtrReadOnly = iterator_to_const_type_t<InputIterator>::value;
235235
setAlign(RequiredAlign);
236236
if (useHostPtr())
237-
throw invalid_parameter_error(
237+
throw runtime_error(
238238
"Buffer constructor from a pair of iterator values does not support "
239-
"use_host_ptr property.");
239+
"use_host_ptr property.",
240+
PI_INVALID_OPERATION);
240241

241242
setAlign(RequiredAlign);
242243
MShadowCopy = allocateHostMem();

sycl/include/CL/sycl/exception.hpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
// 4.9.2 Exception Class Interface
1212

1313
#include <CL/sycl/detail/common.hpp>
14+
#include <CL/sycl/detail/pi.h>
1415
#include <CL/sycl/stl.hpp>
1516

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

3839
private:
3940
string_class MMsg;
40-
cl_int MCLErr = CL_SUCCESS;
41+
cl_int MCLErr;
4142
shared_ptr_class<context> MContext;
4243

4344
protected:
44-
exception(const char *Msg, const cl_int CLErr = CL_SUCCESS,
45+
exception(const char *Msg, const cl_int CLErr,
4546
shared_ptr_class<context> Context = nullptr)
4647
: exception(string_class(Msg), CLErr, Context) {}
4748

48-
exception(const string_class &Msg, const cl_int CLErr = CL_SUCCESS,
49+
exception(const string_class &Msg, const cl_int CLErr,
4950
shared_ptr_class<context> Context = nullptr)
5051
: MMsg(Msg + " " + detail::codeToString(CLErr)), MCLErr(CLErr),
5152
MContext(Context) {}
@@ -55,11 +56,10 @@ class runtime_error : public exception {
5556
public:
5657
runtime_error() = default;
5758

58-
runtime_error(const char *Msg, cl_int Err = CL_SUCCESS)
59+
runtime_error(const char *Msg, cl_int Err)
5960
: runtime_error(string_class(Msg), Err) {}
6061

61-
runtime_error(const string_class &Msg, cl_int Err = CL_SUCCESS)
62-
: exception(Msg, Err) {}
62+
runtime_error(const string_class &Msg, cl_int Err) : exception(Msg, Err) {}
6363
};
6464
class kernel_error : public runtime_error {
6565
using runtime_error::runtime_error;
@@ -80,11 +80,10 @@ class device_error : public exception {
8080
public:
8181
device_error() = default;
8282

83-
device_error(const char *Msg, cl_int Err = CL_SUCCESS)
83+
device_error(const char *Msg, cl_int Err)
8484
: device_error(string_class(Msg), Err) {}
8585

86-
device_error(const string_class &Msg, cl_int Err = CL_SUCCESS)
87-
: exception(Msg, Err) {}
86+
device_error(const string_class &Msg, cl_int Err) : exception(Msg, Err) {}
8887
};
8988
class compile_program_error : public device_error {
9089
using device_error::device_error;

sycl/include/CL/sycl/handler.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,10 +296,12 @@ class handler {
296296
void verifySyclKernelInvoc(const kernel &SyclKernel) {
297297
if (is_host()) {
298298
throw invalid_object_error(
299-
"This kernel invocation method cannot be used on the host");
299+
"This kernel invocation method cannot be used on the host",
300+
PI_INVALID_DEVICE);
300301
}
301302
if (SyclKernel.is_host()) {
302-
throw invalid_object_error("Invalid kernel type, OpenCL expected");
303+
throw invalid_object_error("Invalid kernel type, OpenCL expected",
304+
PI_INVALID_KERNEL);
303305
}
304306
}
305307

sycl/include/CL/sycl/intel/function_pointer.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ device_func_ptr_holder_t get_device_func_ptr(FuncType F, const char *FuncName,
7676

7777
if (program_state::linked != P.get_state()) {
7878
throw invalid_parameter_error(
79-
"Program must be built before passing to get_device_func_ptr");
79+
"Program must be built before passing to get_device_func_ptr",
80+
PI_INVALID_OPERATION);
8081
}
8182

8283
return detail::getDeviceFunctionPointerImpl(D, P, FuncName);

0 commit comments

Comments
 (0)