Skip to content

[WIP][Offload] Introduce ATTACH map-type support for pointer attachment. #149036

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 38 additions & 2 deletions offload/include/OpenMP/Mapping.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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) {}

Expand Down
3 changes: 3 additions & 0 deletions offload/include/omptarget.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ enum tgt_map_type {
// the structured region
// This is an OpenMP extension for the sake of OpenACC support.
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,
// member of struct, member given by [16 MSBs] - 1
Expand Down
23 changes: 19 additions & 4 deletions offload/libomptarget/interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,12 +165,27 @@ targetData(ident_t *Loc, int64_t DeviceId, int32_t ArgNum, void **ArgsBase,
OMPT_GET_RETURN_ADDRESS);)

int Rc = OFFLOAD_SUCCESS;

// Only allocate AttachInfo for targetDataBegin
AttachInfoTy *AttachInfo = nullptr;
if (TargetDataFunction == targetDataBegin)
AttachInfo = new AttachInfoTy();

Rc = TargetDataFunction(Loc, *DeviceOrErr, ArgNum, ArgsBase, Args, ArgSizes,
ArgTypes, ArgNames, ArgMappers, AsyncInfo,
false /*FromMapper=*/);
ArgTypes, ArgNames, ArgMappers, AsyncInfo, AttachInfo,
/*FromMapper=*/false);

if (Rc == OFFLOAD_SUCCESS)
Rc = AsyncInfo.synchronize();
if (Rc == OFFLOAD_SUCCESS) {
// Process deferred ATTACH entries BEFORE synchronization
if (AttachInfo && !AttachInfo->AttachEntries.empty())
Rc = processAttachEntries(*DeviceOrErr, *AttachInfo, AsyncInfo);

if (Rc == OFFLOAD_SUCCESS)
Rc = AsyncInfo.synchronize();
}

if (AttachInfo)
delete AttachInfo;

handleTargetOutcome(Rc == OFFLOAD_SUCCESS, Loc);
}
Expand Down
Loading
Loading