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 }; Index: libomptarget/plugins/cuda/src/rtl.cpp =================================================================== --- libomptarget/plugins/cuda/src/rtl.cpp +++ libomptarget/plugins/cuda/src/rtl.cpp @@ -435,6 +435,16 @@ 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/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/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/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/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(); }