Skip to content

Commit 51fc854

Browse files
authored
[OpenMP][NFC] Move mapping related logic into Mapping.h (#74009)
1 parent 071855d commit 51fc854

File tree

4 files changed

+21
-21
lines changed

4 files changed

+21
-21
lines changed

openmp/libomptarget/include/OpenMP/Mapping.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#ifndef OMPTARGET_OPENMP_MAPPING_H
1414
#define OMPTARGET_OPENMP_MAPPING_H
1515

16+
#include "Shared/EnvironmentVar.h"
1617
#include "omptarget.h"
1718

1819
#include <cstdint>
@@ -26,6 +27,24 @@ class AsyncInfoTy;
2627

2728
using map_var_info_t = void *;
2829

30+
class MappingConfig {
31+
32+
MappingConfig() {
33+
BoolEnvar ForceAtomic = BoolEnvar("LIBOMPTARGET_MAP_FORCE_ATOMIC", true);
34+
UseEventsForAtomicTransfers = ForceAtomic;
35+
}
36+
37+
public:
38+
static const MappingConfig &get() {
39+
static MappingConfig MP;
40+
return MP;
41+
};
42+
43+
/// Flag to indicate if we use events to ensure the atomicity of
44+
/// map clauses or not. Can be modified with an environment variable.
45+
bool UseEventsForAtomicTransfers = true;
46+
};
47+
2948
/// Information about shadow pointers.
3049
struct ShadowPtrInfoTy {
3150
void **HstPtrAddr = nullptr;

openmp/libomptarget/include/PluginManager.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,6 @@ struct PluginAdaptorManagerTy {
9393

9494
/// Struct for the data required to handle plugins
9595
struct PluginManager {
96-
PluginManager(bool UseEventsForAtomicTransfers)
97-
: UseEventsForAtomicTransfers(UseEventsForAtomicTransfers) {}
98-
9996
/// RTLs identified on the host
10097
PluginAdaptorManagerTy RTLs;
10198

@@ -121,10 +118,6 @@ struct PluginManager {
121118
kmp_target_offload_kind_t TargetOffloadPolicy = tgt_default;
122119
std::mutex TargetOffloadMtx; ///< For TargetOffloadPolicy
123120

124-
/// Flag to indicate if we use events to ensure the atomicity of
125-
/// map clauses or not. Can be modified with an environment variable.
126-
const bool UseEventsForAtomicTransfers;
127-
128121
// Work around for plugins that call dlopen on shared libraries that call
129122
// tgt_register_lib during their initialisation. Stash the pointers in a
130123
// vector until the plugins are all initialised and then register them.

openmp/libomptarget/src/device.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ using namespace llvm::omp::target::ompt;
3535
int HostDataToTargetTy::addEventIfNecessary(DeviceTy &Device,
3636
AsyncInfoTy &AsyncInfo) const {
3737
// First, check if the user disabled atomic map transfer/malloc/dealloc.
38-
if (!PM->UseEventsForAtomicTransfers)
38+
if (!MappingConfig::get().UseEventsForAtomicTransfers)
3939
return OFFLOAD_SUCCESS;
4040

4141
void *Event = getEvent();

openmp/libomptarget/src/rtl.cpp

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -48,19 +48,7 @@ extern void ompt::connectLibrary();
4848
__attribute__((constructor(101))) void init() {
4949
DP("Init target library!\n");
5050

51-
bool UseEventsForAtomicTransfers = true;
52-
if (const char *ForceAtomicMap = getenv("LIBOMPTARGET_MAP_FORCE_ATOMIC")) {
53-
std::string ForceAtomicMapStr(ForceAtomicMap);
54-
if (ForceAtomicMapStr == "false" || ForceAtomicMapStr == "FALSE")
55-
UseEventsForAtomicTransfers = false;
56-
else if (ForceAtomicMapStr != "true" && ForceAtomicMapStr != "TRUE")
57-
fprintf(stderr,
58-
"Warning: 'LIBOMPTARGET_MAP_FORCE_ATOMIC' accepts only "
59-
"'true'/'TRUE' or 'false'/'FALSE' as options, '%s' ignored\n",
60-
ForceAtomicMap);
61-
}
62-
63-
PM = new PluginManager(UseEventsForAtomicTransfers);
51+
PM = new PluginManager();
6452

6553
#ifdef OMPT_SUPPORT
6654
// Initialize OMPT first

0 commit comments

Comments
 (0)