Skip to content

[SYCL][CUDA] Fixes context release and unnamed context scope #1207

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions sycl/plugins/cuda/pi_cuda.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1178,11 +1178,14 @@ pi_result cuda_piContextRelease(pi_context ctxt) {
CUcontext cuCtxt = ctxt->get();
CUcontext current = nullptr;
cuCtxGetCurrent(&current);
if(cuCtxt != current)
{
PI_CHECK_ERROR(cuCtxSetCurrent(cuCtxt));
if (cuCtxt != current) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, explain what the problem is in the commits message and add a test.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Description has been added to both the commit and this PR. The bugs that this fixes are some odd corner cases and are difficult to test.

PI_CHECK_ERROR(cuCtxPushCurrent(cuCtxt));
}
PI_CHECK_ERROR(cuCtxSynchronize());
cuCtxGetCurrent(&current);
if (cuCtxt == current) {
PI_CHECK_ERROR(cuCtxPopCurrent(&current));
}
return PI_CHECK_ERROR(cuCtxDestroy(cuCtxt));
} else {
// Primary context is not destroyed, but released
Expand Down Expand Up @@ -1253,6 +1256,7 @@ pi_result cuda_piMemRelease(pi_mem memObj) {
pi_result ret = PI_SUCCESS;

try {

// Do nothing if there are other references
if (memObj->decrement_reference_count() > 0) {
return PI_SUCCESS;
Expand All @@ -1263,7 +1267,7 @@ pi_result cuda_piMemRelease(pi_mem memObj) {

if (!memObj->is_sub_buffer()) {

ScopedContext(uniqueMemObj->get_context());
ScopedContext active(uniqueMemObj->get_context());

switch (uniqueMemObj->allocMode_) {
case _pi_mem::alloc_mode::classic:
Expand Down