Skip to content

Commit 6042d3a

Browse files
authored
[SYCL][ROCm] Fix context destruction on AMD (#4104)
What this piece of code is doing is making the context being destroyed "current" by pushing it, so that it can be synchronized, and then popping it. However on AMD the synchronization is not supported, nor necessary, so these steps can be skipped. In addition this was causing issues because on AMD it uses a single context under the hood so `hipCtxt == current` is always true, which means that this piece of code was popping the context without pushing it first which would return an error code. Simply skipping this step on AMD should be fine.
1 parent af2bf96 commit 6042d3a

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

sycl/plugins/rocm/pi_rocm.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1696,17 +1696,20 @@ pi_result rocm_piContextRelease(pi_context ctxt) {
16961696

16971697
if (!ctxt->is_primary()) {
16981698
hipCtx_t hipCtxt = ctxt->get();
1699+
// hipCtxSynchronize is not supported for AMD platform so we can just
1700+
// destroy the context, for NVIDIA make sure it's synchronized.
1701+
#if defined(__HIP_PLATFORM_NVIDIA__)
16991702
hipCtx_t current = nullptr;
17001703
PI_CHECK_ERROR(hipCtxGetCurrent(&current));
17011704
if (hipCtxt != current) {
17021705
PI_CHECK_ERROR(hipCtxPushCurrent(hipCtxt));
17031706
}
1704-
// hipErrorNotSupported this API
1705-
// PI_CHECK_ERROR(hipCtxSynchronize());
1707+
PI_CHECK_ERROR(hipCtxSynchronize());
17061708
PI_CHECK_ERROR(hipCtxGetCurrent(&current));
17071709
if (hipCtxt == current) {
17081710
PI_CHECK_ERROR(hipCtxPopCurrent(&current));
17091711
}
1712+
#endif
17101713
return PI_CHECK_ERROR(hipCtxDestroy(hipCtxt));
17111714
} else {
17121715
// Primary context is not destroyed, but released

0 commit comments

Comments
 (0)