Skip to content

Commit 3b42472

Browse files
authored
[SYCL] Make adapter releasing more robust wrt adapter specific errors (#19050)
If `urAdapterRelease` happens to return `UR_RESULT_ERROR_ADAPTER_SPECIFIC` (which is banned by the spec), we can't use `urAdapterGetLastError` to retrieve that error. This change ensures that we don't call it in that situation.
1 parent cc0c3d9 commit 3b42472

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

sycl/source/detail/adapter.hpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ class Adapter {
6868
template <sycl::errc errc = sycl::errc::runtime>
6969
void checkUrResult(ur_result_t ur_result) const {
7070
if (ur_result == UR_RESULT_ERROR_ADAPTER_SPECIFIC) {
71+
assert(!adapterReleased);
7172
const char *message = nullptr;
7273
int32_t adapter_error = 0;
7374
ur_result = call_nocheck<UrApiKind::urAdapterGetLastError>(
@@ -154,8 +155,19 @@ class Adapter {
154155
bool hasBackend(backend Backend) const { return Backend == MBackend; }
155156

156157
void release() {
157-
call<UrApiKind::urAdapterRelease>(MAdapter);
158+
auto Res = call_nocheck<UrApiKind::urAdapterRelease>(MAdapter);
159+
if (Res == UR_RESULT_ERROR_ADAPTER_SPECIFIC) {
160+
// We can't query the adapter for the error message because the adapter
161+
// has been released
162+
throw sycl::exception(
163+
sycl::make_error_code(sycl::errc::runtime),
164+
__SYCL_UR_ERROR_REPORT(MBackend) +
165+
"Adapter failed to be released and reported "
166+
"`UR_RESULT_ERROR_ADAPTER_SPECIFIC`. This should "
167+
"never happen, please file a bug.");
168+
}
158169
this->adapterReleased = true;
170+
checkUrResult(Res);
159171
}
160172

161173
// Return the index of a UR platform.

0 commit comments

Comments
 (0)