Skip to content

[OpenMP][NFC] Move mapping related logic into Mapping.h #74009

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 1 commit into from
Dec 1, 2023
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
19 changes: 19 additions & 0 deletions openmp/libomptarget/include/OpenMP/Mapping.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#ifndef OMPTARGET_OPENMP_MAPPING_H
#define OMPTARGET_OPENMP_MAPPING_H

#include "Shared/EnvironmentVar.h"
#include "omptarget.h"

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

using map_var_info_t = void *;

class MappingConfig {

MappingConfig() {
BoolEnvar ForceAtomic = BoolEnvar("LIBOMPTARGET_MAP_FORCE_ATOMIC", true);
UseEventsForAtomicTransfers = ForceAtomic;
}

public:
static const MappingConfig &get() {
static MappingConfig MP;
return MP;
};

/// Flag to indicate if we use events to ensure the atomicity of
/// map clauses or not. Can be modified with an environment variable.
bool UseEventsForAtomicTransfers = true;
};

/// Information about shadow pointers.
struct ShadowPtrInfoTy {
void **HstPtrAddr = nullptr;
Expand Down
7 changes: 0 additions & 7 deletions openmp/libomptarget/include/PluginManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,6 @@ struct PluginAdaptorManagerTy {

/// Struct for the data required to handle plugins
struct PluginManager {
PluginManager(bool UseEventsForAtomicTransfers)
: UseEventsForAtomicTransfers(UseEventsForAtomicTransfers) {}

/// RTLs identified on the host
PluginAdaptorManagerTy RTLs;

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

/// Flag to indicate if we use events to ensure the atomicity of
/// map clauses or not. Can be modified with an environment variable.
const bool UseEventsForAtomicTransfers;

// Work around for plugins that call dlopen on shared libraries that call
// tgt_register_lib during their initialisation. Stash the pointers in a
// vector until the plugins are all initialised and then register them.
Expand Down
2 changes: 1 addition & 1 deletion openmp/libomptarget/src/device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ using namespace llvm::omp::target::ompt;
int HostDataToTargetTy::addEventIfNecessary(DeviceTy &Device,
AsyncInfoTy &AsyncInfo) const {
// First, check if the user disabled atomic map transfer/malloc/dealloc.
if (!PM->UseEventsForAtomicTransfers)
if (!MappingConfig::get().UseEventsForAtomicTransfers)
return OFFLOAD_SUCCESS;

void *Event = getEvent();
Expand Down
14 changes: 1 addition & 13 deletions openmp/libomptarget/src/rtl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,7 @@ extern void ompt::connectLibrary();
__attribute__((constructor(101))) void init() {
DP("Init target library!\n");

bool UseEventsForAtomicTransfers = true;
if (const char *ForceAtomicMap = getenv("LIBOMPTARGET_MAP_FORCE_ATOMIC")) {
std::string ForceAtomicMapStr(ForceAtomicMap);
if (ForceAtomicMapStr == "false" || ForceAtomicMapStr == "FALSE")
UseEventsForAtomicTransfers = false;
else if (ForceAtomicMapStr != "true" && ForceAtomicMapStr != "TRUE")
fprintf(stderr,
"Warning: 'LIBOMPTARGET_MAP_FORCE_ATOMIC' accepts only "
"'true'/'TRUE' or 'false'/'FALSE' as options, '%s' ignored\n",
ForceAtomicMap);
}

PM = new PluginManager(UseEventsForAtomicTransfers);
PM = new PluginManager();

#ifdef OMPT_SUPPORT
// Initialize OMPT first
Expand Down