diff options
author | Tobias Burnus <tburnus@baylibre.com> | 2025-03-24 16:08:20 +0100 |
---|---|---|
committer | Tobias Burnus <tburnus@baylibre.com> | 2025-03-24 16:08:20 +0100 |
commit | 1c5a375c21a262eb636449f88e671a09e140404e (patch) | |
tree | 194e7fa3f8d4a3b69a5f8f29512b77c805ed3a79 | |
parent | c6e7d9ca72cb424b7af9357d77209eb7dd14621a (diff) | |
download | gcc-1c5a375c21a262eb636449f88e671a09e140404e.zip gcc-1c5a375c21a262eb636449f88e671a09e140404e.tar.gz gcc-1c5a375c21a262eb636449f88e671a09e140404e.tar.bz2 |
libgomp/plugin/plugin-nvptx.c: Fix device used for stream creation
libgomp/ChangeLog:
* plugin/plugin-nvptx.c (GOMP_OFFLOAD_interop): Set context for
stream creation to use the specified device.
-rw-r--r-- | libgomp/plugin/plugin-nvptx.c | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/libgomp/plugin/plugin-nvptx.c b/libgomp/plugin/plugin-nvptx.c index 822c6a4..a5cf859 100644 --- a/libgomp/plugin/plugin-nvptx.c +++ b/libgomp/plugin/plugin-nvptx.c @@ -2483,12 +2483,26 @@ GOMP_OFFLOAD_interop (struct interop_obj_t *obj, int ord, break; } - obj->device_data = ptx_devices[ord]; + struct ptx_device *ptx_dev = obj->device_data = ptx_devices[ord]; if (targetsync) { CUstream stream = NULL; - CUDA_CALL_ASSERT (cuStreamCreate, &stream, CU_STREAM_DEFAULT); + CUdevice cur_ctx_dev; + CUresult res = CUDA_CALL_NOCHECK (cuCtxGetDevice, &cur_ctx_dev); + if (res != CUDA_SUCCESS && res != CUDA_ERROR_INVALID_CONTEXT) + GOMP_PLUGIN_fatal ("cuCtxGetDevice error: %s", cuda_error (res)); + if (res != CUDA_ERROR_INVALID_CONTEXT && ptx_dev->dev == cur_ctx_dev) + CUDA_CALL_ASSERT (cuStreamCreate, &stream, CU_STREAM_DEFAULT); + else + { + CUcontext old_ctx; + assert (ptx_dev->ctx); + CUDA_CALL_ASSERT (cuCtxPushCurrent, ptx_dev->ctx); + CUDA_CALL_ASSERT (cuStreamCreate, &stream, CU_STREAM_DEFAULT); + if (res != CUDA_ERROR_INVALID_CONTEXT) + CUDA_CALL_ASSERT (cuCtxPopCurrent, &old_ctx); + } obj->stream = stream; } } |