Skip to content

Commit 26d1473

Browse files
adapt to sycl 2020 exceptions
1 parent d48a5fb commit 26d1473

File tree

5 files changed

+54
-76
lines changed

5 files changed

+54
-76
lines changed

sycl/source/backend.cpp

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ static const PluginPtr &getPlugin(backend Backend) {
3838
case backend::ext_oneapi_cuda:
3939
return pi::getPlugin<backend::ext_oneapi_cuda>();
4040
default:
41-
throw sycl::runtime_error{"getPlugin: Unsupported backend",
42-
PI_ERROR_INVALID_OPERATION};
41+
throw sycl::exception(sycl::errc::runtime, "getPlugin: Unsupported backend");
4342
}
4443
}
4544

@@ -196,21 +195,15 @@ make_kernel_bundle(pi_native_handle NativeHandle, const context &TargetContext,
196195
case (PI_PROGRAM_BINARY_TYPE_COMPILED_OBJECT):
197196
case (PI_PROGRAM_BINARY_TYPE_LIBRARY):
198197
if (State == bundle_state::input)
199-
// TODO SYCL2020 exception
200-
throw sycl::runtime_error(errc::invalid,
201-
"Program and kernel_bundle state mismatch",
202-
PI_ERROR_INVALID_VALUE);
198+
throw sycl::exception(sycl::errc::runtime, "Program and kernel_bundle state mismatch");
203199
if (State == bundle_state::executable)
204200
Plugin->call<errc::build, PiApiKind::piProgramLink>(
205201
ContextImpl->getHandleRef(), 1, &Dev, nullptr, 1, &PiProgram,
206202
nullptr, nullptr, &PiProgram);
207203
break;
208204
case (PI_PROGRAM_BINARY_TYPE_EXECUTABLE):
209205
if (State == bundle_state::input || State == bundle_state::object)
210-
// TODO SYCL2020 exception
211-
throw sycl::runtime_error(errc::invalid,
212-
"Program and kernel_bundle state mismatch",
213-
PI_ERROR_INVALID_VALUE);
206+
throw sycl::exception(sycl::errc::runtime, "Program and kernel_bundle state mismatch");
214207
break;
215208
}
216209
}
@@ -264,9 +257,7 @@ kernel make_kernel(const context &TargetContext,
264257
pi::PiProgram PiProgram = nullptr;
265258
if (Backend == backend::ext_oneapi_level_zero) {
266259
if (KernelBundleImpl->size() != 1)
267-
throw sycl::runtime_error{
268-
"make_kernel: kernel_bundle must have single program image",
269-
PI_ERROR_INVALID_PROGRAM};
260+
throw sycl::exception(sycl::errc::runtime, "make_kernel: kernel_bundle must have single program image");
270261

271262
const device_image<bundle_state::executable> &DeviceImage =
272263
*KernelBundle.begin();

sycl/source/detail/allowlist.cpp

Lines changed: 28 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,11 @@ AllowListParsedT parseAllowList(const std::string &AllowListRaw) {
7272
const char DelimiterBtwDeviceDescs = '|';
7373

7474
if (AllowListRaw.find(DelimiterBtwKeyAndValue, KeyStart) == std::string::npos)
75-
throw sycl::runtime_error("SYCL_DEVICE_ALLOWLIST has incorrect format. For "
76-
"details, please refer to "
77-
"https://github.com/intel/llvm/blob/sycl/sycl/"
78-
"doc/EnvironmentVariables.md",
79-
PI_ERROR_INVALID_VALUE);
75+
throw sycl::exception(sycl::errc::runtime,
76+
"SYCL_DEVICE_ALLOWLIST has incorrect format. For "
77+
"details, please refer to "
78+
"https://github.com/intel/llvm/blob/sycl/sycl/"
79+
"doc/EnvironmentVariables.md");
8080

8181
const std::string &DeprecatedKeyNameDeviceName = DeviceNameKeyName;
8282
const std::string &DeprecatedKeyNamePlatformName = PlatformNameKeyName;
@@ -95,12 +95,11 @@ AllowListParsedT parseAllowList(const std::string &AllowListRaw) {
9595
if (std::find(SupportedAllowListKeyNames.begin(),
9696
SupportedAllowListKeyNames.end(),
9797
Key) == SupportedAllowListKeyNames.end()) {
98-
throw sycl::runtime_error(
98+
throw sycl::exception(sycl::errc::runtime,
9999
"Unrecognized key in SYCL_DEVICE_ALLOWLIST. For details, please "
100100
"refer to "
101101
"https://github.com/intel/llvm/blob/sycl/sycl/doc/"
102-
"EnvironmentVariables.md",
103-
PI_ERROR_INVALID_VALUE);
102+
"EnvironmentVariables.md");
104103
}
105104

106105
if (Key == DeprecatedKeyNameDeviceName) {
@@ -149,13 +148,12 @@ AllowListParsedT parseAllowList(const std::string &AllowListRaw) {
149148
break;
150149
}
151150
if (!ValueIsValid)
152-
throw sycl::runtime_error(
151+
throw sycl::exception( sycl::errc::runtime,
153152
"Value " + Value + " for key " + Key +
154153
" is not valid in "
155154
"SYCL_DEVICE_ALLOWLIST. For details, please refer to "
156155
"https://github.com/intel/llvm/blob/sycl/sycl/doc/"
157-
"EnvironmentVariables.md",
158-
PI_ERROR_INVALID_VALUE);
156+
"EnvironmentVariables.md");
159157
}
160158
};
161159

@@ -168,14 +166,14 @@ AllowListParsedT parseAllowList(const std::string &AllowListRaw) {
168166
if (Key == DeviceVendorIdKeyName) {
169167
// DeviceVendorId should have hex format
170168
if (!std::regex_match(Value, std::regex("0[xX][0-9a-fA-F]+"))) {
171-
throw sycl::runtime_error(
169+
throw sycl::exception(
170+
sycl::errc::runtime,
172171
"Value " + Value + " for key " + Key +
173172
" is not valid in "
174173
"SYCL_DEVICE_ALLOWLIST. It should have the hex format. For "
175174
"details, please refer to "
176175
"https://github.com/intel/llvm/blob/sycl/sycl/doc/"
177-
"EnvironmentVariables.md",
178-
PI_ERROR_INVALID_VALUE);
176+
"EnvironmentVariables.md");
179177
}
180178
}
181179
}
@@ -187,11 +185,11 @@ AllowListParsedT parseAllowList(const std::string &AllowListRaw) {
187185
// TODO: can be changed to string_view::starts_with after switching
188186
// DPC++ RT to C++20
189187
if (Prefix != AllowListRaw.substr(ValueStart, Prefix.length())) {
190-
throw sycl::runtime_error("Key " + Key +
191-
" of SYCL_DEVICE_ALLOWLIST should have "
192-
"value which starts with " +
193-
Prefix,
194-
PI_ERROR_INVALID_VALUE);
188+
throw sycl::exception(sycl::errc::runtime,
189+
"Key " + Key +
190+
" of SYCL_DEVICE_ALLOWLIST should have "
191+
"value which starts with " +
192+
Prefix);
195193
}
196194
// cut off prefix from the value
197195
ValueStart += Prefix.length();
@@ -205,12 +203,11 @@ AllowListParsedT parseAllowList(const std::string &AllowListRaw) {
205203
// if it is the last iteration and next 2 symbols are not a postfix,
206204
// throw exception
207205
if (ValueEnd == AllowListRaw.length() - Postfix.length())
208-
throw sycl::runtime_error(
209-
"Key " + Key +
210-
" of SYCL_DEVICE_ALLOWLIST should have "
211-
"value which ends with " +
212-
Postfix,
213-
PI_ERROR_INVALID_VALUE);
206+
throw sycl::exception(sycl::errc::runtime,
207+
"Key " + Key +
208+
" of SYCL_DEVICE_ALLOWLIST should have "
209+
"value which ends with " +
210+
Postfix);
214211
}
215212
size_t NextExpectedDelimiterPos = ValueEnd + Postfix.length();
216213
// if it is not the end of the string, check that symbol next to a
@@ -219,13 +216,13 @@ AllowListParsedT parseAllowList(const std::string &AllowListRaw) {
219216
(AllowListRaw[NextExpectedDelimiterPos] !=
220217
DelimiterBtwItemsInDeviceDesc) &&
221218
(AllowListRaw[NextExpectedDelimiterPos] != DelimiterBtwDeviceDescs))
222-
throw sycl::runtime_error(
219+
throw sycl::exception(
220+
sycl::errc::runtime,
223221
"Unexpected symbol on position " +
224222
std::to_string(NextExpectedDelimiterPos) + ": " +
225223
AllowListRaw[NextExpectedDelimiterPos] +
226224
". Should be either " + DelimiterBtwItemsInDeviceDesc +
227-
" or " + DelimiterBtwDeviceDescs,
228-
PI_ERROR_INVALID_VALUE);
225+
" or " + DelimiterBtwDeviceDescs);
229226

230227
if (AllowListRaw[NextExpectedDelimiterPos] == DelimiterBtwDeviceDescs)
231228
ShouldAllocateNewDeviceDescMap = true;
@@ -241,10 +238,9 @@ AllowListParsedT parseAllowList(const std::string &AllowListRaw) {
241238
// add key and value to the map
242239
DeviceDescMap.emplace(Key, Value);
243240
} else
244-
throw sycl::runtime_error("Re-definition of key " + Key +
245-
" is not allowed in "
246-
"SYCL_DEVICE_ALLOWLIST",
247-
PI_ERROR_INVALID_VALUE);
241+
throw sycl::exception(sycl::errc::runtime, "Re-definition of key " + Key +
242+
" is not allowed in "
243+
"SYCL_DEVICE_ALLOWLIST");
248244

249245
KeyStart = ValueEnd;
250246
if (KeyStart != std::string::npos)

sycl/source/detail/event_impl.cpp

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -127,21 +127,15 @@ event_impl::event_impl(RT::PiEvent Event, const context &SyclContext)
127127
MIsFlushed(true), MState(HES_Complete) {
128128

129129
if (MContext->is_host()) {
130-
throw sycl::invalid_parameter_error(
131-
"The syclContext must match the OpenCL context associated with the "
132-
"clEvent.",
133-
PI_ERROR_INVALID_CONTEXT);
130+
throw sycl::exception(sycl::errc::invalid, "The syclContext must match the OpenCL context associated with the clEvent.");
134131
}
135132

136133
RT::PiContext TempContext;
137134
getPlugin()->call<PiApiKind::piEventGetInfo>(MEvent, PI_EVENT_INFO_CONTEXT,
138135
sizeof(RT::PiContext),
139136
&TempContext, nullptr);
140137
if (MContext->getHandleRef() != TempContext) {
141-
throw sycl::invalid_parameter_error(
142-
"The syclContext must match the OpenCL context associated with the "
143-
"clEvent.",
144-
PI_ERROR_INVALID_CONTEXT);
138+
throw sycl::exception(sycl::errc::invalid, "The syclContext must match the OpenCL context associated with the clEvent.");
145139
}
146140
}
147141

@@ -157,7 +151,7 @@ event_impl::event_impl(const QueueImplPtr &Queue)
157151
if (Queue->has_property<property::queue::enable_profiling>()) {
158152
MHostProfilingInfo.reset(new HostProfilingInfo());
159153
if (!MHostProfilingInfo)
160-
throw runtime_error("Out of host memory", PI_ERROR_OUT_OF_HOST_MEMORY);
154+
throw sycl::exception(sycl::errc::runtime, "Out of host memory");
161155
}
162156
return;
163157
}
@@ -287,8 +281,7 @@ event_impl::get_profiling_info<info::event_profiling::command_start>() {
287281
return 0;
288282
}
289283
if (!MHostProfilingInfo)
290-
throw invalid_object_error("Profiling info is not available.",
291-
PI_ERROR_PROFILING_INFO_NOT_AVAILABLE);
284+
throw sycl::exception(0,sycl::errc::invalid, "Profiling info is not available.");
292285
return MHostProfilingInfo->getStartTime();
293286
}
294287

@@ -302,8 +295,7 @@ uint64_t event_impl::get_profiling_info<info::event_profiling::command_end>() {
302295
return 0;
303296
}
304297
if (!MHostProfilingInfo)
305-
throw invalid_object_error("Profiling info is not available.",
306-
PI_ERROR_PROFILING_INFO_NOT_AVAILABLE);
298+
throw sycl::exception(sycl::errc::invalid, "Profiling info is not available.");
307299
return MHostProfilingInfo->getEndTime();
308300
}
309301

sycl/source/detail/scheduler/commands.cpp

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1526,8 +1526,7 @@ AllocaCommandBase *ExecCGCommand::getAllocaForReq(Requirement *Req) {
15261526
if (Dep.MDepRequirement == Req)
15271527
return Dep.MAllocaCmd;
15281528
}
1529-
throw runtime_error("Alloca for command not found",
1530-
PI_ERROR_INVALID_OPERATION);
1529+
throw sycl::exception(sycl::errc::runtime,"Alloca for command not found");
15311530
}
15321531

15331532
std::vector<std::shared_ptr<const void>>
@@ -2230,10 +2229,10 @@ static pi_result SetKernelParamsAndLaunch(
22302229
}
22312230
case kernel_param_kind_t::kind_specialization_constants_buffer: {
22322231
if (Queue->is_host()) {
2233-
throw sycl::feature_not_supported(
2232+
throw sycl::exception(
2233+
sycl::errc::feature_not_supported,
22342234
"SYCL2020 specialization constants are not yet supported on host "
2235-
"device",
2236-
PI_ERROR_INVALID_OPERATION);
2235+
"device");
22372236
}
22382237
assert(DeviceImageImpl != nullptr);
22392238
RT::PiMem SpecConstsBuffer = DeviceImageImpl->get_spec_const_buffer_ref();
@@ -2245,7 +2244,7 @@ static pi_result SetKernelParamsAndLaunch(
22452244
break;
22462245
}
22472246
case kernel_param_kind_t::kind_invalid:
2248-
throw runtime_error("Invalid kernel param kind", PI_ERROR_INVALID_VALUE);
2247+
throw sycl::exception(sycl::errc::runtime, "Invalid kernel param kind");
22492248
break;
22502249
}
22512250
};
@@ -2492,8 +2491,8 @@ pi_int32 ExecCGCommand::enqueueImp() {
24922491
switch (MCommandGroup->getType()) {
24932492

24942493
case CG::CGTYPE::UpdateHost: {
2495-
throw runtime_error("Update host should be handled by the Scheduler.",
2496-
PI_ERROR_INVALID_OPERATION);
2494+
throw sycl::exception(sycl::errc::runtime,
2495+
"Update host should be handled by the Scheduler.");
24972496
}
24982497
case CG::CGTYPE::CopyAccToPtr: {
24992498
CGCopy *Copy = (CGCopy *)MCommandGroup.get();
@@ -2631,13 +2630,13 @@ pi_int32 ExecCGCommand::enqueueImp() {
26312630

26322631
switch (Error) {
26332632
case PI_ERROR_INVALID_OPERATION:
2634-
throw sycl::runtime_error(
2635-
"Device doesn't support run_on_host_intel tasks.", Error);
2633+
throw sycl::exception(sycl::errc::runtime,
2634+
"Device doesn't support run_on_host_intel tasks.");
26362635
case PI_SUCCESS:
26372636
return Error;
26382637
default:
2639-
throw sycl::runtime_error("Enqueueing run_on_host_intel task has failed.",
2640-
Error);
2638+
throw sycl::exception(sycl::errc::runtime,
2639+
"Enqueueing run_on_host_intel task has failed.");
26412640
}
26422641
}
26432642
case CG::CGTYPE::Kernel: {
@@ -2795,7 +2794,7 @@ pi_int32 ExecCGCommand::enqueueImp() {
27952794
break;
27962795
}
27972796
default:
2798-
throw runtime_error("Unsupported arg type", PI_ERROR_INVALID_VALUE);
2797+
throw sycl::exception(sycl::errc::runtime, "Unsupported arg type");
27992798
}
28002799
}
28012800

@@ -2822,9 +2821,9 @@ pi_int32 ExecCGCommand::enqueueImp() {
28222821
assert(false &&
28232822
"Can't get memory object due to no allocation available");
28242823

2825-
throw runtime_error(
2826-
"Can't get memory object due to no allocation available",
2827-
PI_ERROR_INVALID_MEM_OBJECT);
2824+
throw sycl::exception(
2825+
sycl::errc::runtime,
2826+
"Can't get memory object due to no allocation available");
28282827
};
28292828
std::for_each(std::begin(HandlerReq), std::end(HandlerReq), ReqToMemConv);
28302829
std::sort(std::begin(ReqToMem), std::end(ReqToMem));
@@ -2902,7 +2901,7 @@ pi_int32 ExecCGCommand::enqueueImp() {
29022901
typeSize, RawEvents, Event, read);
29032902
}
29042903
case CG::CGTYPE::None:
2905-
throw runtime_error("CG type not implemented.", PI_ERROR_INVALID_OPERATION);
2904+
throw sycl::exception(sycl::errc::runtime, "CG type not implemented.");
29062905
}
29072906
return PI_ERROR_INVALID_OPERATION;
29082907
}

sycl/source/exception.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ bool exception::has_context() const noexcept { return (MContext != nullptr); }
7979

8080
context exception::get_context() const {
8181
if (!has_context())
82-
throw invalid_object_error();
82+
throw sycl::exception(sycl::errc::invalid);
8383

8484
return *MContext;
8585
}

0 commit comments

Comments
 (0)