diff options
Diffstat (limited to 'offload/include')
-rw-r--r-- | offload/include/OpenMP/Mapping.h | 40 | ||||
-rw-r--r-- | offload/include/device.h | 4 | ||||
-rw-r--r-- | offload/include/omptarget.h | 44 |
3 files changed, 64 insertions, 24 deletions
diff --git a/offload/include/OpenMP/Mapping.h b/offload/include/OpenMP/Mapping.h index b9f5c16..93c1e569 100644 --- a/offload/include/OpenMP/Mapping.h +++ b/offload/include/OpenMP/Mapping.h @@ -417,12 +417,42 @@ struct MapperComponentsTy { typedef void (*MapperFuncPtrTy)(void *, void *, void *, int64_t, int64_t, void *); +/// Structure to store information about a single ATTACH map entry. +struct AttachMapInfo { + void *PointerBase; + void *PointeeBegin; + int64_t PointerSize; + int64_t MapType; + map_var_info_t Pointername; + + AttachMapInfo(void *PointerBase, void *PointeeBegin, int64_t Size, + int64_t Type, map_var_info_t Name) + : PointerBase(PointerBase), PointeeBegin(PointeeBegin), PointerSize(Size), + MapType(Type), Pointername(Name) {} +}; + +/// Structure to track ATTACH entries and new allocations across recursive calls +/// (for handling mappers) to targetDataBegin for a given construct. +struct AttachInfoTy { + /// ATTACH map entries for deferred processing. + llvm::SmallVector<AttachMapInfo> AttachEntries; + + /// Key: host pointer, Value: allocation size. + llvm::DenseMap<void *, int64_t> NewAllocations; + + AttachInfoTy() = default; + + // Delete copy constructor and copy assignment operator to prevent copying + AttachInfoTy(const AttachInfoTy &) = delete; + AttachInfoTy &operator=(const AttachInfoTy &) = delete; +}; + // Function pointer type for targetData* functions (targetDataBegin, // targetDataEnd and targetDataUpdate). typedef int (*TargetDataFuncPtrTy)(ident_t *, DeviceTy &, int32_t, void **, void **, int64_t *, int64_t *, map_var_info_t *, void **, AsyncInfoTy &, - bool); + AttachInfoTy *, bool); void dumpTargetPointerMappings(const ident_t *Loc, DeviceTy &Device, bool toStdOut = false); @@ -431,20 +461,26 @@ int targetDataBegin(ident_t *Loc, DeviceTy &Device, int32_t ArgNum, void **ArgsBase, void **Args, int64_t *ArgSizes, int64_t *ArgTypes, map_var_info_t *ArgNames, void **ArgMappers, AsyncInfoTy &AsyncInfo, + AttachInfoTy *AttachInfo = nullptr, bool FromMapper = false); int targetDataEnd(ident_t *Loc, DeviceTy &Device, int32_t ArgNum, void **ArgBases, void **Args, int64_t *ArgSizes, int64_t *ArgTypes, map_var_info_t *ArgNames, void **ArgMappers, AsyncInfoTy &AsyncInfo, - bool FromMapper = false); + AttachInfoTy *AttachInfo = nullptr, bool FromMapper = false); int targetDataUpdate(ident_t *Loc, DeviceTy &Device, int32_t ArgNum, void **ArgsBase, void **Args, int64_t *ArgSizes, int64_t *ArgTypes, map_var_info_t *ArgNames, void **ArgMappers, AsyncInfoTy &AsyncInfo, + AttachInfoTy *AttachInfo = nullptr, bool FromMapper = false); +// Process deferred ATTACH map entries collected during targetDataBegin. +int processAttachEntries(DeviceTy &Device, AttachInfoTy &AttachInfo, + AsyncInfoTy &AsyncInfo); + struct MappingInfoTy { MappingInfoTy(DeviceTy &Device) : Device(Device) {} diff --git a/offload/include/device.h b/offload/include/device.h index f4b10ab..1e85bb1 100644 --- a/offload/include/device.h +++ b/offload/include/device.h @@ -98,6 +98,10 @@ struct DeviceTy { int32_t dataExchange(void *SrcPtr, DeviceTy &DstDev, void *DstPtr, int64_t Size, AsyncInfoTy &AsyncInfo); + // Insert a data fence between previous data operations and the following + // operations if necessary for the device. + int32_t dataFence(AsyncInfoTy &AsyncInfo); + /// Notify the plugin about a new mapping starting at the host address /// \p HstPtr and \p Size bytes. int32_t notifyDataMapped(void *HstPtr, int64_t Size); diff --git a/offload/include/omptarget.h b/offload/include/omptarget.h index 6971780..8fd722b 100644 --- a/offload/include/omptarget.h +++ b/offload/include/omptarget.h @@ -33,9 +33,6 @@ #define OFFLOAD_DEVICE_DEFAULT -1 -// Don't format out enums and structs. -// clang-format off - /// return flags of __tgt_target_XXX public APIs enum __tgt_target_return_t : int { /// successful offload executed on a target device @@ -51,39 +48,42 @@ enum __tgt_target_return_t : int { /// Data attributes for each data reference used in an OpenMP target region. enum tgt_map_type { // No flags - OMP_TGT_MAPTYPE_NONE = 0x000, + OMP_TGT_MAPTYPE_NONE = 0x000, // copy data from host to device - OMP_TGT_MAPTYPE_TO = 0x001, + OMP_TGT_MAPTYPE_TO = 0x001, // copy data from device to host - OMP_TGT_MAPTYPE_FROM = 0x002, + OMP_TGT_MAPTYPE_FROM = 0x002, // copy regardless of the reference count - OMP_TGT_MAPTYPE_ALWAYS = 0x004, + OMP_TGT_MAPTYPE_ALWAYS = 0x004, // force unmapping of data - OMP_TGT_MAPTYPE_DELETE = 0x008, + OMP_TGT_MAPTYPE_DELETE = 0x008, // map the pointer as well as the pointee - OMP_TGT_MAPTYPE_PTR_AND_OBJ = 0x010, + OMP_TGT_MAPTYPE_PTR_AND_OBJ = 0x010, // pass device base address to kernel - OMP_TGT_MAPTYPE_TARGET_PARAM = 0x020, + OMP_TGT_MAPTYPE_TARGET_PARAM = 0x020, // return base device address of mapped data - OMP_TGT_MAPTYPE_RETURN_PARAM = 0x040, + OMP_TGT_MAPTYPE_RETURN_PARAM = 0x040, // private variable - not mapped - OMP_TGT_MAPTYPE_PRIVATE = 0x080, + OMP_TGT_MAPTYPE_PRIVATE = 0x080, // copy by value - not mapped - OMP_TGT_MAPTYPE_LITERAL = 0x100, + OMP_TGT_MAPTYPE_LITERAL = 0x100, // mapping is implicit - OMP_TGT_MAPTYPE_IMPLICIT = 0x200, + OMP_TGT_MAPTYPE_IMPLICIT = 0x200, // copy data to device - OMP_TGT_MAPTYPE_CLOSE = 0x400, + OMP_TGT_MAPTYPE_CLOSE = 0x400, // runtime error if not already allocated - OMP_TGT_MAPTYPE_PRESENT = 0x1000, + OMP_TGT_MAPTYPE_PRESENT = 0x1000, // use a separate reference counter so that the data cannot be unmapped within // the structured region // This is an OpenMP extension for the sake of OpenACC support. - OMP_TGT_MAPTYPE_OMPX_HOLD = 0x2000, + OMP_TGT_MAPTYPE_OMPX_HOLD = 0x2000, + // Attach pointer and pointee, after processing all other maps. + // Applicable to map-entering directives. Does not change ref-count. + OMP_TGT_MAPTYPE_ATTACH = 0x4000, // descriptor for non-contiguous target-update - OMP_TGT_MAPTYPE_NON_CONTIG = 0x100000000000, + OMP_TGT_MAPTYPE_NON_CONTIG = 0x100000000000, // member of struct, member given by [16 MSBs] - 1 - OMP_TGT_MAPTYPE_MEMBER_OF = 0xffff000000000000 + OMP_TGT_MAPTYPE_MEMBER_OF = 0xffff000000000000 }; /// Flags for offload entries. @@ -105,9 +105,9 @@ enum TargetAllocTy : int32_t { TARGET_ALLOC_DEVICE_NON_BLOCKING, }; -inline KernelArgsTy CTorDTorKernelArgs = {1, 0, nullptr, nullptr, - nullptr, nullptr, nullptr, nullptr, - 0, {0,0,0}, {1, 0, 0}, {1, 0, 0}, 0}; +inline KernelArgsTy CTorDTorKernelArgs = { + 1, 0, nullptr, nullptr, nullptr, nullptr, nullptr, + nullptr, 0, {0, 0, 0}, {1, 0, 0}, {1, 0, 0}, 0}; struct DeviceTy; |