Skip to content

Commit 9ae0b35

Browse files
author
Steffen Larsen
committed
[SYCL][CUDA] Fixes context release and unnamed context scope
This PR fixes the following bugs: 1 Some times upon deletion, the deleted context would stay on the CUDA context stack and cause subsequent CUDA operations to fail. To fix this the context stack is now checked after destruction and if the dead context is still there it is removed. 2 In one location a ScopedContext was created without being assigned to a variable and would therefore die immediately. It should now live for the entirety of the surrounding scope. Signed-off-by: Steffen Larsen <[email protected]>
1 parent c220eb8 commit 9ae0b35

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

sycl/plugins/cuda/pi_cuda.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1178,11 +1178,14 @@ pi_result cuda_piContextRelease(pi_context ctxt) {
11781178
CUcontext cuCtxt = ctxt->get();
11791179
CUcontext current = nullptr;
11801180
cuCtxGetCurrent(&current);
1181-
if(cuCtxt != current)
1182-
{
1183-
PI_CHECK_ERROR(cuCtxSetCurrent(cuCtxt));
1181+
if (cuCtxt != current) {
1182+
PI_CHECK_ERROR(cuCtxPushCurrent(cuCtxt));
11841183
}
11851184
PI_CHECK_ERROR(cuCtxSynchronize());
1185+
cuCtxGetCurrent(&current);
1186+
if (cuCtxt == current) {
1187+
PI_CHECK_ERROR(cuCtxPopCurrent(&current));
1188+
}
11861189
return PI_CHECK_ERROR(cuCtxDestroy(cuCtxt));
11871190
} else {
11881191
// Primary context is not destroyed, but released
@@ -1253,6 +1256,7 @@ pi_result cuda_piMemRelease(pi_mem memObj) {
12531256
pi_result ret = PI_SUCCESS;
12541257

12551258
try {
1259+
12561260
// Do nothing if there are other references
12571261
if (memObj->decrement_reference_count() > 0) {
12581262
return PI_SUCCESS;
@@ -1263,7 +1267,7 @@ pi_result cuda_piMemRelease(pi_mem memObj) {
12631267

12641268
if (!memObj->is_sub_buffer()) {
12651269

1266-
ScopedContext(uniqueMemObj->get_context());
1270+
ScopedContext active(uniqueMemObj->get_context());
12671271

12681272
switch (uniqueMemObj->allocMode_) {
12691273
case _pi_mem::alloc_mode::classic:

0 commit comments

Comments
 (0)