Skip to content

[OpenMP] Add OpenMP extension API to dump mapping tables #85381

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

Merged
merged 3 commits into from
Mar 18, 2024
Merged
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
3 changes: 2 additions & 1 deletion openmp/libomptarget/include/OpenMP/Mapping.h
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,8 @@ typedef int (*TargetDataFuncPtrTy)(ident_t *, DeviceTy &, int32_t, void **,
map_var_info_t *, void **, AsyncInfoTy &,
bool);

void dumpTargetPointerMappings(const ident_t *Loc, DeviceTy &Device);
void dumpTargetPointerMappings(const ident_t *Loc, DeviceTy &Device,
bool toStdOut = false);

int targetDataBegin(ident_t *Loc, DeviceTy &Device, int32_t ArgNum,
void **ArgsBase, void **Args, int64_t *ArgSizes,
Expand Down
17 changes: 14 additions & 3 deletions openmp/libomptarget/include/Shared/Debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,12 @@ inline uint32_t getDebugLevel() {
} while (0)

/// Print a generic information string used if LIBOMPTARGET_INFO=1
#define INFO_MESSAGE(_num, ...) \
#define INFO_MESSAGE(_num, ...) INFO_MESSAGE_TO(stderr, _num, __VA_ARGS__)

#define INFO_MESSAGE_TO(_stdDst, _num, ...) \
do { \
fprintf(stderr, GETNAME(TARGET_NAME) " device %d info: ", (int)_num); \
fprintf(stderr, __VA_ARGS__); \
fprintf(_stdDst, GETNAME(TARGET_NAME) " device %d info: ", (int)_num); \
fprintf(_stdDst, __VA_ARGS__); \
} while (0)

// Debugging messages
Expand Down Expand Up @@ -187,4 +189,13 @@ inline uint32_t getDebugLevel() {
} \
} while (false)

#define DUMP_INFO(toStdOut, _flags, _id, ...) \
do { \
if (toStdOut) { \
INFO_MESSAGE_TO(stdout, _id, __VA_ARGS__); \
} else { \
INFO(_flags, _id, __VA_ARGS__); \
} \
} while (false)

#endif // OMPTARGET_SHARED_DEBUG_H
1 change: 1 addition & 0 deletions openmp/libomptarget/include/omptarget.h
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ struct __tgt_target_non_contig {
extern "C" {
#endif

void ompx_dump_mapping_tables(void);
int omp_get_num_devices(void);
int omp_get_device_num(void);
int omp_get_initial_device(void);
Expand Down
8 changes: 8 additions & 0 deletions openmp/libomptarget/src/OpenMP/API.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "rtl.h"

#include "OpenMP/InternalTypes.h"
#include "OpenMP/Mapping.h"
#include "OpenMP/OMPT/Interface.h"
#include "OpenMP/omp.h"
#include "Shared/Profile.h"
Expand All @@ -27,6 +28,13 @@
#include <cstring>
#include <mutex>

EXTERN void ompx_dump_mapping_tables() {
ident_t Loc = {0, 0, 0, 0, ";libomptarget;libomptarget;0;0;;"};
auto ExclusiveDevicesAccessor = PM->getExclusiveDevicesAccessor();
for (auto &Device : PM->devices(ExclusiveDevicesAccessor))
dumpTargetPointerMappings(&Loc, Device, true);
}

#ifdef OMPT_SUPPORT
using namespace llvm::omp::target::ompt;
#endif
Expand Down
33 changes: 19 additions & 14 deletions openmp/libomptarget/src/OpenMP/Mapping.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,33 @@
#include "device.h"

/// Dump a table of all the host-target pointer pairs on failure
void dumpTargetPointerMappings(const ident_t *Loc, DeviceTy &Device) {
void dumpTargetPointerMappings(const ident_t *Loc, DeviceTy &Device,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yeah, this should be ToStdOut.

bool toStdOut) {
MappingInfoTy::HDTTMapAccessorTy HDTTMap =
Device.getMappingInfo().HostDataToTargetMap.getExclusiveAccessor();
if (HDTTMap->empty())
if (HDTTMap->empty()) {
DUMP_INFO(toStdOut, OMP_INFOTYPE_ALL, Device.DeviceID,
"OpenMP Host-Device pointer mappings table empty\n");
return;
}

SourceInfo Kernel(Loc);
INFO(OMP_INFOTYPE_ALL, Device.DeviceID,
"OpenMP Host-Device pointer mappings after block at %s:%d:%d:\n",
Kernel.getFilename(), Kernel.getLine(), Kernel.getColumn());
INFO(OMP_INFOTYPE_ALL, Device.DeviceID, "%-18s %-18s %s %s %s %s\n",
"Host Ptr", "Target Ptr", "Size (B)", "DynRefCount", "HoldRefCount",
"Declaration");
DUMP_INFO(toStdOut, OMP_INFOTYPE_ALL, Device.DeviceID,
"OpenMP Host-Device pointer mappings after block at %s:%d:%d:\n",
Kernel.getFilename(), Kernel.getLine(), Kernel.getColumn());
DUMP_INFO(toStdOut, OMP_INFOTYPE_ALL, Device.DeviceID,
"%-18s %-18s %s %s %s %s\n", "Host Ptr", "Target Ptr", "Size (B)",
"DynRefCount", "HoldRefCount", "Declaration");
for (const auto &It : *HDTTMap) {
HostDataToTargetTy &HDTT = *It.HDTT;
SourceInfo Info(HDTT.HstPtrName);
INFO(OMP_INFOTYPE_ALL, Device.DeviceID,
DPxMOD " " DPxMOD " %-8" PRIuPTR " %-11s %-12s %s at %s:%d:%d\n",
DPxPTR(HDTT.HstPtrBegin), DPxPTR(HDTT.TgtPtrBegin),
HDTT.HstPtrEnd - HDTT.HstPtrBegin, HDTT.dynRefCountToStr().c_str(),
HDTT.holdRefCountToStr().c_str(), Info.getName(), Info.getFilename(),
Info.getLine(), Info.getColumn());
DUMP_INFO(toStdOut, OMP_INFOTYPE_ALL, Device.DeviceID,
DPxMOD " " DPxMOD " %-8" PRIuPTR " %-11s %-12s %s at %s:%d:%d\n",
DPxPTR(HDTT.HstPtrBegin), DPxPTR(HDTT.TgtPtrBegin),
HDTT.HstPtrEnd - HDTT.HstPtrBegin,
HDTT.dynRefCountToStr().c_str(), HDTT.holdRefCountToStr().c_str(),
Info.getName(), Info.getFilename(), Info.getLine(),
Info.getColumn());
}
}

Expand Down
1 change: 1 addition & 0 deletions openmp/libomptarget/src/exports
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ VERS1.0 {
__tgt_push_mapper_component;
__kmpc_push_target_tripcount;
__kmpc_push_target_tripcount_mapper;
ompx_dump_mapping_tables;
omp_get_mapped_ptr;
omp_get_num_devices;
omp_get_device_num;
Expand Down
40 changes: 40 additions & 0 deletions openmp/libomptarget/test/api/ompx_dump_mapping_tables.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// RUN: %libomptarget-compilexx-run-and-check-generic

#include <cstdio>
#include <omp.h>

#define N 10

int main() {
int *a = new int[N]; // mapped and released from device 0
int *b = new int[N]; // mapped to device 2

// clang-format off
// CHECK: Mapping tables after target enter data:
// CHECK-NEXT: omptarget device 0 info: OpenMP Host-Device pointer mappings after block
// CHECK-NEXT: omptarget device 0 info: Host Ptr Target Ptr Size (B) DynRefCount HoldRefCount Declaration
// CHECK-NEXT: omptarget device 0 info: {{(0x[0-9a-f]{16})}} {{(0x[0-9a-f]{16})}}
// CHECK-NEXT: omptarget device 1 info: OpenMP Host-Device pointer mappings table empty
// CHECK-NEXT: omptarget device 2 info: OpenMP Host-Device pointer mappings after block
// CHECK-NEXT: omptarget device 2 info: Host Ptr Target Ptr Size (B) DynRefCount HoldRefCount Declaration
// CHECK-NEXT: omptarget device 2 info: {{(0x[0-9a-f]{16})}} {{(0x[0-9a-f]{16})}}
// clang-format on
#pragma omp target enter data device(0) map(to : a[ : N])
#pragma omp target enter data device(2) map(to : b[ : N])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have only 1 device in the buildbots, so this will fail.

printf("Mapping tables after target enter data:\n");
ompx_dump_mapping_tables();

// clang-format off
// CHECK: Mapping tables after target exit data for a:
// CHECK-NEXT: omptarget device 0 info: OpenMP Host-Device pointer mappings table empty
// CHECK-NEXT: omptarget device 1 info: OpenMP Host-Device pointer mappings table empty
// CHECK-NEXT: omptarget device 2 info: OpenMP Host-Device pointer mappings after block
// CHECK-NEXT: omptarget device 2 info: Host Ptr Target Ptr Size (B) DynRefCount HoldRefCount Declaration
// CHECK-NEXT: omptarget device 2 info: {{(0x[0-9a-f]{16})}} {{(0x[0-9a-f]{16})}}
// clang-format on
#pragma omp target exit data device(0) map(release : a[ : N])
printf("\nMapping tables after target exit data for a:\n");
ompx_dump_mapping_tables();

return 0;
}
2 changes: 2 additions & 0 deletions openmp/runtime/src/include/omp.h.var
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@
/* OpenMP 5.1 interop */
typedef intptr_t omp_intptr_t;

extern void __KAI_KMPC_CONVENTION ompx_dump_mapping_tables(void);

/* 0..omp_get_num_interop_properties()-1 are reserved for implementation-defined properties */
typedef enum omp_interop_property {
omp_ipr_fr_id = -1,
Expand Down