[Openmp-commits] [PATCH] D34804: [OpenMP] libomptarget / CUDA plugin: Check for existing CUDA context before new context creation
George Rokos via Phabricator via Openmp-commits
openmp-commits at lists.llvm.org
Wed Jun 28 20:27:36 PDT 2017
grokos created this revision.
grokos added a project: OpenMP.
This commit checks for an existing CUDA context (using cuCtxGetCurrent), before creating a new context. If an existing context exists, no new context is created. This change ensures that all allocations made in the program interacting with the openmp offload library are visible in the device context; especially important for CUDA managed allocations (using cudaMallocManaged).
For the existing version, if a context exists, the cuCtxCreate call fails, and hence all further allocations crash.
Thanks to Hashim Sharif, University of Illinois at Urbana, for spotting the problem and submitting the original patch.
Repository:
rL LLVM
https://reviews.llvm.org/D34804
Files:
libomptarget/plugins/cuda/src/rtl.cpp
Index: libomptarget/plugins/cuda/src/rtl.cpp
===================================================================
--- libomptarget/plugins/cuda/src/rtl.cpp
+++ libomptarget/plugins/cuda/src/rtl.cpp
@@ -253,9 +253,13 @@
return OFFLOAD_FAIL;
}
- // Create the context and save it to use whenever this device is selected.
- err = cuCtxCreate(&DeviceInfo.Contexts[device_id], CU_CTX_SCHED_BLOCKING_SYNC,
+ err = cuCtxGetCurrent(&DeviceInfo.Contexts[device_id]);
+ if(DeviceInfo.Contexts[device_id] == NULL){
+ // Create the context and save it to use whenever this device is selected.
+ err = cuCtxCreate(&DeviceInfo.Contexts[device_id], CU_CTX_SCHED_BLOCKING_SYNC,
cuDevice);
+ }
+
if (err != CUDA_SUCCESS) {
DP("Error when creating a CUDA context\n");
CUDA_ERR_STRING(err);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D34804.104586.patch
Type: text/x-patch
Size: 828 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/openmp-commits/attachments/20170629/c081ba13/attachment.bin>
More information about the Openmp-commits
mailing list