Skip to content

Commit 6cfa921

Browse files
authored
[SYCL][L0] Fix the bug in pi_context::finalize (#2873)
Signed-off-by: Byoungro So <[email protected]>
1 parent 2d9d5ef commit 6cfa921

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

sycl/plugins/level_zero/pi_level_zero.cpp

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -448,12 +448,6 @@ pi_result _pi_context::finalize() {
448448

449449
// Destroy the command list used for initializations
450450
ZE_CALL(zeCommandListDestroy(ZeCommandListInit));
451-
452-
// Destruction of some members of pi_context uses L0 context
453-
// and therefore it must be valid at that point.
454-
// Technically it should be placed to the destructor of pi_context
455-
// but this makes API error handling more complex.
456-
ZE_CALL(zeContextDestroy(ZeContext));
457451
return PI_SUCCESS;
458452
}
459453

@@ -1830,9 +1824,22 @@ pi_result piContextRelease(pi_context Context) {
18301824

18311825
assert(Context);
18321826
if (--(Context->RefCount) == 0) {
1827+
auto ZeContext = Context->ZeContext;
1828+
18331829
// Clean up any live memory associated with Context
18341830
pi_result Result = Context->finalize();
1831+
1832+
// We must delete Context first and then destroy zeContext because
1833+
// Context deallocation requires ZeContext in some member deallocation of
1834+
// pi_context.
18351835
delete Context;
1836+
1837+
// Destruction of some members of pi_context uses L0 context
1838+
// and therefore it must be valid at that point.
1839+
// Technically it should be placed to the destructor of pi_context
1840+
// but this makes API error handling more complex.
1841+
ZE_CALL(zeContextDestroy(ZeContext));
1842+
18361843
return Result;
18371844
}
18381845
return PI_SUCCESS;

0 commit comments

Comments
 (0)