[Openmp-commits] [PATCH] D60884: [OpenMP][libomptarget] Enable usage of unified memory for declare target link variables

Gheorghe-Teodor Bercea via Phabricator via Openmp-commits openmp-commits at lists.llvm.org
Thu Apr 18 12:08:49 PDT 2019

gtbercea created this revision.
gtbercea added reviewers: ABataev, caomhin.
Herald added subscribers: openmp-commits, jdoerfert, guansong.
Herald added a project: OpenMP.
gtbercea added a parent revision: D60223: [OpenMP][libomptarget] Enable requires flags for target libraries. Support for target link variables when unified memory is enabled.

This patch enables the usage of a host variable on the device for declare target link variables when unified memory is available.

  rOMP OpenMP



Index: libomptarget/plugins/cuda/src/rtl.cpp
--- libomptarget/plugins/cuda/src/rtl.cpp
+++ libomptarget/plugins/cuda/src/rtl.cpp
@@ -446,6 +446,16 @@
       DP("Entry point " DPxMOD " maps to global %s (" DPxMOD ")\n",
           DPxPTR(e - HostBegin), e->name, DPxPTR(cuptr));
       entry.addr = (void *)cuptr;
+      if (DeviceInfo.RequiresFlags & OMP_REQ_UNIFIED_SHARED_MEMORY &&
+          e->flags & OMP_DECLARE_TARGET_LINK) {
+        // If unified memory is present any target link variables
+        // can access host addresses directly. There is no longer a
+        // need for device copies.
+        cuMemcpyHtoD(cuptr, e->addr, sizeof(void *));
+        DP("Copy linked variable host address (" DPxMOD ")"
+           "to device address (" DPxMOD ")\n",
+          DPxPTR(*((void**)e->addr)), DPxPTR(cuptr));
+      }
       DeviceInfo.addOffloadEntry(device_id, entry);

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D60884.195799.patch
Type: text/x-patch
Size: 958 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/openmp-commits/attachments/20190418/210cdd65/attachment.bin>

More information about the Openmp-commits mailing list