Skip to content

Commit ef68270

Browse files
[SYCL][CUDA] Fixes context release and unnamed context scope (#1207)
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 5e7ea06 commit ef68270

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
@@ -1230,11 +1230,14 @@ pi_result cuda_piContextRelease(pi_context ctxt) {
12301230
CUcontext cuCtxt = ctxt->get();
12311231
CUcontext current = nullptr;
12321232
cuCtxGetCurrent(&current);
1233-
if(cuCtxt != current)
1234-
{
1235-
PI_CHECK_ERROR(cuCtxSetCurrent(cuCtxt));
1233+
if (cuCtxt != current) {
1234+
PI_CHECK_ERROR(cuCtxPushCurrent(cuCtxt));
12361235
}
12371236
PI_CHECK_ERROR(cuCtxSynchronize());
1237+
cuCtxGetCurrent(&current);
1238+
if (cuCtxt == current) {
1239+
PI_CHECK_ERROR(cuCtxPopCurrent(&current));
1240+
}
12381241
return PI_CHECK_ERROR(cuCtxDestroy(cuCtxt));
12391242
} else {
12401243
// Primary context is not destroyed, but released
@@ -1305,6 +1308,7 @@ pi_result cuda_piMemRelease(pi_mem memObj) {
13051308
pi_result ret = PI_SUCCESS;
13061309

13071310
try {
1311+
13081312
// Do nothing if there are other references
13091313
if (memObj->decrement_reference_count() > 0) {
13101314
return PI_SUCCESS;
@@ -1315,7 +1319,7 @@ pi_result cuda_piMemRelease(pi_mem memObj) {
13151319

13161320
if (!memObj->is_sub_buffer()) {
13171321

1318-
ScopedContext(uniqueMemObj->get_context());
1322+
ScopedContext active(uniqueMemObj->get_context());
13191323

13201324
switch (uniqueMemObj->allocMode_) {
13211325
case _pi_mem::alloc_mode::classic:

0 commit comments

Comments
 (0)