[Openmp-commits] [PATCH] D60223: [OpenMP][libomptarget] Add support for target link variables when unified memory is enabled
Gheorghe-Teodor Bercea via Phabricator via Openmp-commits
openmp-commits at lists.llvm.org
Wed Apr 3 11:53:54 PDT 2019
gtbercea created this revision.
gtbercea added reviewers: ABataev, AlexEichenberger.
Herald added subscribers: openmp-commits, jdoerfert, guansong.
Herald added a project: OpenMP.
Target link variables are currently implemented by creating a copy of the variables on the device side and unified memory never gets exploited.
When the prgram uses the:
#pragma omp requires unified_shared_memory
directive in conjunction with a declare target link, the linked variable is no longer allocated on the device and the host version is used instead.
This behavior is overridden by performing an explicit mapping.
A Clang side patch is required.
Repository:
rOMP OpenMP
https://reviews.llvm.org/D60223
Files:
libomptarget/include/omptarget.h
libomptarget/plugins/cuda/src/rtl.cpp
libomptarget/src/device.cpp
libomptarget/src/interface.cpp
libomptarget/src/omptarget.cpp
libomptarget/src/rtl.cpp
Index: libomptarget/src/rtl.cpp
===================================================================
--- libomptarget/src/rtl.cpp
+++ libomptarget/src/rtl.cpp
@@ -177,10 +177,6 @@
DPxPTR(entry->addr));
Device.PendingCtorsDtors[desc].PendingDtors.push_front(entry->addr);
}
-
- if (entry->flags & OMP_DECLARE_TARGET_LINK) {
- DP("The \"link\" attribute is not yet supported!\n");
- }
}
Device.PendingGlobalsMtx.unlock();
}
Index: libomptarget/src/omptarget.cpp
===================================================================
--- libomptarget/src/omptarget.cpp
+++ libomptarget/src/omptarget.cpp
@@ -216,7 +216,8 @@
for (int32_t i = 0; i < arg_num; ++i) {
// Ignore private variables and arrays - there is no mapping for them.
if ((arg_types[i] & OMP_TGT_MAPTYPE_LITERAL) ||
- (arg_types[i] & OMP_TGT_MAPTYPE_PRIVATE))
+ (arg_types[i] & OMP_TGT_MAPTYPE_PRIVATE) ||
+ (arg_types[i] & OMP_TGT_MAPTYPE_USE_HOST_VAR))
continue;
void *HstPtrBegin = args[i];
Index: libomptarget/src/interface.cpp
===================================================================
--- libomptarget/src/interface.cpp
+++ libomptarget/src/interface.cpp
@@ -57,7 +57,7 @@
}
break;
case tgt_default:
- FATAL_MESSAGE0(1, "default offloading policy must switched to "
+ FATAL_MESSAGE0(1, "default offloading policy must switched to "
"mandatory or disabled");
break;
case tgt_mandatory:
Index: libomptarget/src/device.cpp
===================================================================
--- libomptarget/src/device.cpp
+++ libomptarget/src/device.cpp
@@ -152,7 +152,7 @@
// Used by target_data_begin
// Return the target pointer begin (where the data will be moved).
-// Allocate memory if this is the first occurrence if this mapping.
+// Allocate memory if this is the first occurrence of this mapping.
// Increment the reference counter.
// If NULL is returned, then either data allocation failed or the user tried
// to do an illegal mapping.
Index: libomptarget/plugins/cuda/src/rtl.cpp
===================================================================
--- libomptarget/plugins/cuda/src/rtl.cpp
+++ libomptarget/plugins/cuda/src/rtl.cpp
@@ -434,7 +434,18 @@
DP("Entry point " DPxMOD " maps to global %s (" DPxMOD ")\n",
DPxPTR(e - HostBegin), e->name, DPxPTR(cuptr));
+
entry.addr = (void *)cuptr;
+ if (e->flags & OMP_DECLARE_TARGET_LINK) {
+ // By default, we handle declare target link global variables as if
+ // unified memory can be sued. If at target region launch it turns
+ // out that unified memory is not available then this value will
+ // be overwritten.
+ cuMemcpyHtoD(cuptr, e->addr, 8);
+ DP("Copy linked variable host address (" DPxMOD ")"
+ "to device address (" DPxMOD ")\n",
+ DPxPTR(*((void**)e->addr)), DPxPTR(cuptr));
+ }
DeviceInfo.addOffloadEntry(device_id, entry);
Index: libomptarget/include/omptarget.h
===================================================================
--- libomptarget/include/omptarget.h
+++ libomptarget/include/omptarget.h
@@ -47,6 +47,8 @@
OMP_TGT_MAPTYPE_LITERAL = 0x100,
// mapping is implicit
OMP_TGT_MAPTYPE_IMPLICIT = 0x200,
+ /// Target link
+ OMP_TGT_MAPTYPE_USE_HOST_VAR = 0x400,
// member of struct, member given by [16 MSBs] - 1
OMP_TGT_MAPTYPE_MEMBER_OF = 0xffff000000000000
};
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D60223.193555.patch
Type: text/x-patch
Size: 3548 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/openmp-commits/attachments/20190403/9935f805/attachment.bin>
More information about the Openmp-commits
mailing list