Skip to content

Commit 1034206

Browse files
[SYCL][NFC] Cleanup exception class ABI (#20171)
All changes are made under preview breaking changes macro: - moved most of constructor definitions into the header - dropped legacy internal constructors - moved `stringifyErrorCode` helper into the library and made it non-exported
1 parent 36363e6 commit 1034206

File tree

5 files changed

+139
-100
lines changed

5 files changed

+139
-100
lines changed

sycl/include/sycl/exception.hpp

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,14 @@ __SYCL_EXPORT std::error_code make_error_code(sycl::errc E) noexcept;
5151
__SYCL_EXPORT const std::error_category &sycl_category() noexcept;
5252

5353
namespace detail {
54+
#ifndef __INTEL_PREVIEW_BREAKING_CHANGES
5455
__SYCL_EXPORT const char *stringifyErrorCode(int32_t error);
5556

5657
inline std::string codeToString(int32_t code) {
57-
return std::to_string(code) + " (" + std::string(stringifyErrorCode(code)) + ")";
58+
return std::to_string(code) + " (" + std::string(stringifyErrorCode(code)) +
59+
")";
5860
}
61+
#endif
5962

6063
class __SYCL_EXPORT SYCLCategory : public std::error_category {
6164
public:
@@ -78,17 +81,35 @@ class __SYCL_EXPORT exception : public virtual std::exception {
7881
exception() = default;
7982
virtual ~exception();
8083

81-
exception(std::error_code, const char *Msg);
84+
exception(std::error_code Ec, const char *Msg)
85+
#ifdef __INTEL_PREVIEW_BREAKING_CHANGES
86+
: exception(Ec, nullptr, Msg) {}
87+
#endif
88+
;
8289

8390
exception(std::error_code Ec, const std::string &Msg)
8491
: exception(Ec, nullptr, Msg.c_str()) {}
8592

86-
// new SYCL 2020 constructors
87-
exception(std::error_code);
93+
exception(std::error_code Ec)
94+
#ifdef __INTEL_PREVIEW_BREAKING_CHANGES
95+
: exception(Ec, nullptr, "") {}
96+
#endif
97+
;
98+
8899
exception(int EV, const std::error_category &ECat, const std::string &WhatArg)
89-
: exception(EV, ECat, WhatArg.c_str()) {}
90-
exception(int, const std::error_category &, const char *);
91-
exception(int, const std::error_category &);
100+
: exception(std::error_code(EV, ECat), nullptr, WhatArg.c_str()) {}
101+
102+
exception(int EV, const std::error_category &ECat, const char *WhatArg)
103+
#ifdef __INTEL_PREVIEW_BREAKING_CHANGES
104+
: exception(std::error_code(EV, ECat), nullptr, WhatArg) {}
105+
#endif
106+
;
107+
108+
exception(int EV, const std::error_category &ECat)
109+
#ifdef __INTEL_PREVIEW_BREAKING_CHANGES
110+
: exception(std::error_code(EV, ECat), nullptr, "") {}
111+
#endif
112+
;
92113

93114
// context.hpp depends on exception.hpp but we can't define these ctors in
94115
// exception.hpp while context is still an incomplete type.
@@ -119,6 +140,7 @@ class __SYCL_EXPORT exception : public virtual std::exception {
119140
std::error_code MErrC = make_error_code(sycl::errc::invalid);
120141

121142
protected:
143+
#ifndef __INTEL_PREVIEW_BREAKING_CHANGES
122144
// base constructors used by SYCL 1.2.1 exception subclasses
123145
exception(std::error_code Ec, const char *Msg, const int32_t PIErr)
124146
: exception(Ec, std::string(Msg), PIErr) {}
@@ -127,6 +149,7 @@ class __SYCL_EXPORT exception : public virtual std::exception {
127149
: exception(Ec, nullptr, Msg + " " + detail::codeToString(URErr)) {
128150
MErr = URErr;
129151
}
152+
#endif
130153

131154
// base constructor for all SYCL 2020 constructors
132155
// exception(context *, std::error_code, const std::string);

sycl/source/detail/kernel_impl.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <sycl/detail/common.hpp>
1616
#include <sycl/detail/ur.hpp>
1717
#include <sycl/device.hpp>
18+
#include <sycl/exception.hpp>
1819
#include <sycl/ext/oneapi/experimental/root_group.hpp>
1920
#include <sycl/info/info_desc.hpp>
2021
#include <sycl/queue.hpp>

sycl/source/detail/ur.cpp

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,98 @@ ur_program_metadata_t mapDeviceBinaryPropertyToProgramMetadata(
439439
}
440440

441441
} // namespace ur
442+
443+
const char *stringifyErrorCode(int32_t error) {
444+
switch (error) {
445+
#define _UR_ERRC(NAME) \
446+
case NAME: \
447+
return #NAME;
448+
// TODO: bring back old code specific messages?
449+
#define _UR_ERRC_WITH_MSG(NAME, MSG) \
450+
case NAME: \
451+
return MSG;
452+
_UR_ERRC(UR_RESULT_SUCCESS)
453+
_UR_ERRC(UR_RESULT_ERROR_INVALID_OPERATION)
454+
_UR_ERRC(UR_RESULT_ERROR_INVALID_QUEUE_PROPERTIES)
455+
_UR_ERRC(UR_RESULT_ERROR_INVALID_QUEUE)
456+
_UR_ERRC(UR_RESULT_ERROR_INVALID_VALUE)
457+
_UR_ERRC(UR_RESULT_ERROR_INVALID_CONTEXT)
458+
_UR_ERRC(UR_RESULT_ERROR_INVALID_PLATFORM)
459+
_UR_ERRC(UR_RESULT_ERROR_INVALID_BINARY)
460+
_UR_ERRC(UR_RESULT_ERROR_INVALID_PROGRAM)
461+
_UR_ERRC(UR_RESULT_ERROR_INVALID_SAMPLER)
462+
_UR_ERRC(UR_RESULT_ERROR_INVALID_BUFFER_SIZE)
463+
_UR_ERRC(UR_RESULT_ERROR_INVALID_MEM_OBJECT)
464+
_UR_ERRC(UR_RESULT_ERROR_INVALID_EVENT)
465+
_UR_ERRC(UR_RESULT_ERROR_INVALID_EVENT_WAIT_LIST)
466+
_UR_ERRC(UR_RESULT_ERROR_MISALIGNED_SUB_BUFFER_OFFSET)
467+
_UR_ERRC(UR_RESULT_ERROR_INVALID_WORK_GROUP_SIZE)
468+
_UR_ERRC(UR_RESULT_ERROR_COMPILER_NOT_AVAILABLE)
469+
_UR_ERRC(UR_RESULT_ERROR_PROFILING_INFO_NOT_AVAILABLE)
470+
_UR_ERRC(UR_RESULT_ERROR_DEVICE_NOT_FOUND)
471+
_UR_ERRC(UR_RESULT_ERROR_INVALID_DEVICE)
472+
_UR_ERRC(UR_RESULT_ERROR_DEVICE_LOST)
473+
_UR_ERRC(UR_RESULT_ERROR_DEVICE_REQUIRES_RESET)
474+
_UR_ERRC(UR_RESULT_ERROR_DEVICE_IN_LOW_POWER_STATE)
475+
_UR_ERRC(UR_RESULT_ERROR_DEVICE_PARTITION_FAILED)
476+
_UR_ERRC(UR_RESULT_ERROR_INVALID_DEVICE_PARTITION_COUNT)
477+
_UR_ERRC(UR_RESULT_ERROR_INVALID_WORK_ITEM_SIZE)
478+
_UR_ERRC(UR_RESULT_ERROR_INVALID_WORK_DIMENSION)
479+
_UR_ERRC(UR_RESULT_ERROR_INVALID_KERNEL)
480+
_UR_ERRC(UR_RESULT_ERROR_INVALID_KERNEL_NAME)
481+
_UR_ERRC(UR_RESULT_ERROR_INVALID_KERNEL_ARGUMENT_INDEX)
482+
_UR_ERRC(UR_RESULT_ERROR_INVALID_KERNEL_ARGUMENT_SIZE)
483+
_UR_ERRC(UR_RESULT_ERROR_INVALID_KERNEL_ATTRIBUTE_VALUE)
484+
_UR_ERRC(UR_RESULT_ERROR_INVALID_IMAGE_SIZE)
485+
_UR_ERRC(UR_RESULT_ERROR_INVALID_IMAGE_FORMAT_DESCRIPTOR)
486+
_UR_ERRC(UR_RESULT_ERROR_MEM_OBJECT_ALLOCATION_FAILURE)
487+
_UR_ERRC(UR_RESULT_ERROR_INVALID_PROGRAM_EXECUTABLE)
488+
_UR_ERRC(UR_RESULT_ERROR_UNINITIALIZED)
489+
_UR_ERRC(UR_RESULT_ERROR_OUT_OF_HOST_MEMORY)
490+
_UR_ERRC(UR_RESULT_ERROR_OUT_OF_DEVICE_MEMORY)
491+
_UR_ERRC(UR_RESULT_ERROR_OUT_OF_RESOURCES)
492+
_UR_ERRC(UR_RESULT_ERROR_PROGRAM_BUILD_FAILURE)
493+
_UR_ERRC(UR_RESULT_ERROR_PROGRAM_LINK_FAILURE)
494+
_UR_ERRC(UR_RESULT_ERROR_UNSUPPORTED_VERSION)
495+
_UR_ERRC(UR_RESULT_ERROR_UNSUPPORTED_FEATURE)
496+
_UR_ERRC(UR_RESULT_ERROR_INVALID_ARGUMENT)
497+
_UR_ERRC(UR_RESULT_ERROR_INVALID_NULL_HANDLE)
498+
_UR_ERRC(UR_RESULT_ERROR_HANDLE_OBJECT_IN_USE)
499+
_UR_ERRC(UR_RESULT_ERROR_INVALID_NULL_POINTER)
500+
_UR_ERRC(UR_RESULT_ERROR_INVALID_SIZE)
501+
_UR_ERRC(UR_RESULT_ERROR_UNSUPPORTED_SIZE)
502+
_UR_ERRC(UR_RESULT_ERROR_UNSUPPORTED_ALIGNMENT)
503+
_UR_ERRC(UR_RESULT_ERROR_INVALID_SYNCHRONIZATION_OBJECT)
504+
_UR_ERRC(UR_RESULT_ERROR_INVALID_ENUMERATION)
505+
_UR_ERRC(UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION)
506+
_UR_ERRC(UR_RESULT_ERROR_UNSUPPORTED_IMAGE_FORMAT)
507+
_UR_ERRC(UR_RESULT_ERROR_INVALID_NATIVE_BINARY)
508+
_UR_ERRC(UR_RESULT_ERROR_INVALID_GLOBAL_NAME)
509+
_UR_ERRC(UR_RESULT_ERROR_FUNCTION_ADDRESS_NOT_AVAILABLE)
510+
_UR_ERRC(UR_RESULT_ERROR_INVALID_GROUP_SIZE_DIMENSION)
511+
_UR_ERRC(UR_RESULT_ERROR_INVALID_GLOBAL_WIDTH_DIMENSION)
512+
_UR_ERRC(UR_RESULT_ERROR_PROGRAM_UNLINKED)
513+
_UR_ERRC(UR_RESULT_ERROR_OVERLAPPING_REGIONS)
514+
_UR_ERRC(UR_RESULT_ERROR_INVALID_HOST_PTR)
515+
_UR_ERRC(UR_RESULT_ERROR_INVALID_USM_SIZE)
516+
_UR_ERRC(UR_RESULT_ERROR_OBJECT_ALLOCATION_FAILURE)
517+
_UR_ERRC(UR_RESULT_ERROR_ADAPTER_SPECIFIC)
518+
_UR_ERRC(UR_RESULT_ERROR_LAYER_NOT_PRESENT)
519+
_UR_ERRC(UR_RESULT_ERROR_IN_EVENT_LIST_EXEC_STATUS)
520+
_UR_ERRC(UR_RESULT_ERROR_DEVICE_NOT_AVAILABLE)
521+
_UR_ERRC(UR_RESULT_ERROR_INVALID_COMMAND_BUFFER_EXP)
522+
_UR_ERRC(UR_RESULT_ERROR_INVALID_COMMAND_BUFFER_SYNC_POINT_EXP)
523+
_UR_ERRC(UR_RESULT_ERROR_INVALID_COMMAND_BUFFER_SYNC_POINT_WAIT_LIST_EXP)
524+
_UR_ERRC(UR_RESULT_ERROR_INVALID_COMMAND_BUFFER_COMMAND_HANDLE_EXP)
525+
_UR_ERRC(UR_RESULT_ERROR_UNKNOWN)
526+
#undef _UR_ERRC
527+
#undef _UR_ERRC_WITH_MSG
528+
529+
default:
530+
return "Unknown error code";
531+
}
532+
}
533+
442534
} // namespace detail
443535
} // namespace _V1
444536
} // namespace sycl

sycl/source/detail/ur.hpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
#include <ur_api.h>
1818

19+
#include <sycl/detail/export.hpp>
20+
1921
#include <memory>
2022
#include <string>
2123
#include <vector>
@@ -26,6 +28,18 @@ enum class backend : char;
2628
namespace detail {
2729
class adapter_impl;
2830

31+
#ifndef __INTEL_PREVIEW_BREAKING_CHANGES
32+
__SYCL_EXPORT
33+
#endif
34+
const char *stringifyErrorCode(int32_t error);
35+
36+
#ifdef __INTEL_PREVIEW_BREAKING_CHANGES
37+
inline std::string codeToString(int32_t code) {
38+
return std::to_string(code) + " (" + std::string(stringifyErrorCode(code)) +
39+
")";
40+
}
41+
#endif
42+
2943
namespace ur {
3044
void *getURLoaderLibrary();
3145

sycl/source/exception.cpp

Lines changed: 2 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
namespace sycl {
1818
inline namespace _V1 {
1919

20+
#ifndef __INTEL_PREVIEW_BREAKING_CHANGES
2021
exception::exception(std::error_code EC, const char *Msg)
2122
: exception(EC, nullptr, Msg) {}
2223

@@ -29,6 +30,7 @@ exception::exception(int EV, const std::error_category &ECat,
2930

3031
exception::exception(int EV, const std::error_category &ECat)
3132
: exception({EV, ECat}, nullptr, "") {}
33+
#endif
3234

3335
// protected base constructor for all SYCL 2020 constructors
3436
exception::exception(std::error_code EC, std::shared_ptr<context> SharedPtrCtx,
@@ -66,98 +68,5 @@ std::error_code make_error_code(sycl::errc Err) noexcept {
6668
return {static_cast<int>(Err), sycl_category()};
6769
}
6870

69-
namespace detail {
70-
__SYCL_EXPORT const char *stringifyErrorCode(int32_t error) {
71-
switch (error) {
72-
#define _UR_ERRC(NAME) \
73-
case NAME: \
74-
return #NAME;
75-
// TODO: bring back old code specific messages?
76-
#define _UR_ERRC_WITH_MSG(NAME, MSG) \
77-
case NAME: \
78-
return MSG;
79-
_UR_ERRC(UR_RESULT_SUCCESS)
80-
_UR_ERRC(UR_RESULT_ERROR_INVALID_OPERATION)
81-
_UR_ERRC(UR_RESULT_ERROR_INVALID_QUEUE_PROPERTIES)
82-
_UR_ERRC(UR_RESULT_ERROR_INVALID_QUEUE)
83-
_UR_ERRC(UR_RESULT_ERROR_INVALID_VALUE)
84-
_UR_ERRC(UR_RESULT_ERROR_INVALID_CONTEXT)
85-
_UR_ERRC(UR_RESULT_ERROR_INVALID_PLATFORM)
86-
_UR_ERRC(UR_RESULT_ERROR_INVALID_BINARY)
87-
_UR_ERRC(UR_RESULT_ERROR_INVALID_PROGRAM)
88-
_UR_ERRC(UR_RESULT_ERROR_INVALID_SAMPLER)
89-
_UR_ERRC(UR_RESULT_ERROR_INVALID_BUFFER_SIZE)
90-
_UR_ERRC(UR_RESULT_ERROR_INVALID_MEM_OBJECT)
91-
_UR_ERRC(UR_RESULT_ERROR_INVALID_EVENT)
92-
_UR_ERRC(UR_RESULT_ERROR_INVALID_EVENT_WAIT_LIST)
93-
_UR_ERRC(UR_RESULT_ERROR_MISALIGNED_SUB_BUFFER_OFFSET)
94-
_UR_ERRC(UR_RESULT_ERROR_INVALID_WORK_GROUP_SIZE)
95-
_UR_ERRC(UR_RESULT_ERROR_COMPILER_NOT_AVAILABLE)
96-
_UR_ERRC(UR_RESULT_ERROR_PROFILING_INFO_NOT_AVAILABLE)
97-
_UR_ERRC(UR_RESULT_ERROR_DEVICE_NOT_FOUND)
98-
_UR_ERRC(UR_RESULT_ERROR_INVALID_DEVICE)
99-
_UR_ERRC(UR_RESULT_ERROR_DEVICE_LOST)
100-
_UR_ERRC(UR_RESULT_ERROR_DEVICE_REQUIRES_RESET)
101-
_UR_ERRC(UR_RESULT_ERROR_DEVICE_IN_LOW_POWER_STATE)
102-
_UR_ERRC(UR_RESULT_ERROR_DEVICE_PARTITION_FAILED)
103-
_UR_ERRC(UR_RESULT_ERROR_INVALID_DEVICE_PARTITION_COUNT)
104-
_UR_ERRC(UR_RESULT_ERROR_INVALID_WORK_ITEM_SIZE)
105-
_UR_ERRC(UR_RESULT_ERROR_INVALID_WORK_DIMENSION)
106-
_UR_ERRC(UR_RESULT_ERROR_INVALID_KERNEL)
107-
_UR_ERRC(UR_RESULT_ERROR_INVALID_KERNEL_NAME)
108-
_UR_ERRC(UR_RESULT_ERROR_INVALID_KERNEL_ARGUMENT_INDEX)
109-
_UR_ERRC(UR_RESULT_ERROR_INVALID_KERNEL_ARGUMENT_SIZE)
110-
_UR_ERRC(UR_RESULT_ERROR_INVALID_KERNEL_ATTRIBUTE_VALUE)
111-
_UR_ERRC(UR_RESULT_ERROR_INVALID_IMAGE_SIZE)
112-
_UR_ERRC(UR_RESULT_ERROR_INVALID_IMAGE_FORMAT_DESCRIPTOR)
113-
_UR_ERRC(UR_RESULT_ERROR_MEM_OBJECT_ALLOCATION_FAILURE)
114-
_UR_ERRC(UR_RESULT_ERROR_INVALID_PROGRAM_EXECUTABLE)
115-
_UR_ERRC(UR_RESULT_ERROR_UNINITIALIZED)
116-
_UR_ERRC(UR_RESULT_ERROR_OUT_OF_HOST_MEMORY)
117-
_UR_ERRC(UR_RESULT_ERROR_OUT_OF_DEVICE_MEMORY)
118-
_UR_ERRC(UR_RESULT_ERROR_OUT_OF_RESOURCES)
119-
_UR_ERRC(UR_RESULT_ERROR_PROGRAM_BUILD_FAILURE)
120-
_UR_ERRC(UR_RESULT_ERROR_PROGRAM_LINK_FAILURE)
121-
_UR_ERRC(UR_RESULT_ERROR_UNSUPPORTED_VERSION)
122-
_UR_ERRC(UR_RESULT_ERROR_UNSUPPORTED_FEATURE)
123-
_UR_ERRC(UR_RESULT_ERROR_INVALID_ARGUMENT)
124-
_UR_ERRC(UR_RESULT_ERROR_INVALID_NULL_HANDLE)
125-
_UR_ERRC(UR_RESULT_ERROR_HANDLE_OBJECT_IN_USE)
126-
_UR_ERRC(UR_RESULT_ERROR_INVALID_NULL_POINTER)
127-
_UR_ERRC(UR_RESULT_ERROR_INVALID_SIZE)
128-
_UR_ERRC(UR_RESULT_ERROR_UNSUPPORTED_SIZE)
129-
_UR_ERRC(UR_RESULT_ERROR_UNSUPPORTED_ALIGNMENT)
130-
_UR_ERRC(UR_RESULT_ERROR_INVALID_SYNCHRONIZATION_OBJECT)
131-
_UR_ERRC(UR_RESULT_ERROR_INVALID_ENUMERATION)
132-
_UR_ERRC(UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION)
133-
_UR_ERRC(UR_RESULT_ERROR_UNSUPPORTED_IMAGE_FORMAT)
134-
_UR_ERRC(UR_RESULT_ERROR_INVALID_NATIVE_BINARY)
135-
_UR_ERRC(UR_RESULT_ERROR_INVALID_GLOBAL_NAME)
136-
_UR_ERRC(UR_RESULT_ERROR_FUNCTION_ADDRESS_NOT_AVAILABLE)
137-
_UR_ERRC(UR_RESULT_ERROR_INVALID_GROUP_SIZE_DIMENSION)
138-
_UR_ERRC(UR_RESULT_ERROR_INVALID_GLOBAL_WIDTH_DIMENSION)
139-
_UR_ERRC(UR_RESULT_ERROR_PROGRAM_UNLINKED)
140-
_UR_ERRC(UR_RESULT_ERROR_OVERLAPPING_REGIONS)
141-
_UR_ERRC(UR_RESULT_ERROR_INVALID_HOST_PTR)
142-
_UR_ERRC(UR_RESULT_ERROR_INVALID_USM_SIZE)
143-
_UR_ERRC(UR_RESULT_ERROR_OBJECT_ALLOCATION_FAILURE)
144-
_UR_ERRC(UR_RESULT_ERROR_ADAPTER_SPECIFIC)
145-
_UR_ERRC(UR_RESULT_ERROR_LAYER_NOT_PRESENT)
146-
_UR_ERRC(UR_RESULT_ERROR_IN_EVENT_LIST_EXEC_STATUS)
147-
_UR_ERRC(UR_RESULT_ERROR_DEVICE_NOT_AVAILABLE)
148-
_UR_ERRC(UR_RESULT_ERROR_INVALID_COMMAND_BUFFER_EXP)
149-
_UR_ERRC(UR_RESULT_ERROR_INVALID_COMMAND_BUFFER_SYNC_POINT_EXP)
150-
_UR_ERRC(UR_RESULT_ERROR_INVALID_COMMAND_BUFFER_SYNC_POINT_WAIT_LIST_EXP)
151-
_UR_ERRC(UR_RESULT_ERROR_INVALID_COMMAND_BUFFER_COMMAND_HANDLE_EXP)
152-
_UR_ERRC(UR_RESULT_ERROR_UNKNOWN)
153-
#undef _UR_ERRC
154-
#undef _UR_ERRC_WITH_MSG
155-
156-
default:
157-
return "Unknown error code";
158-
}
159-
}
160-
} // namespace detail
161-
16271
} // namespace _V1
16372
} // namespace sycl

0 commit comments

Comments
 (0)