Please use GitHub pull requests for new patches. Avoid migrating existing patches. Phabricator shutdown timeline
Changeset View
Changeset View
Standalone View
Standalone View
openmp/libomptarget/src/rtl.cpp
//===----------- rtl.cpp - Target independent OpenMP target RTL -----------===// | //===----------- rtl.cpp - Target independent OpenMP target RTL -----------===// | ||||
// | // | ||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||||
// See https://llvm.org/LICENSE.txt for license information. | // See https://llvm.org/LICENSE.txt for license information. | ||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||||
// | // | ||||
//===----------------------------------------------------------------------===// | //===----------------------------------------------------------------------===// | ||||
// | // | ||||
// Functionality for handling RTL plugins. | // Functionality for handling RTL plugins. | ||||
// | // | ||||
//===----------------------------------------------------------------------===// | //===----------------------------------------------------------------------===// | ||||
#include "llvm/Object/OffloadBinary.h" | #include "llvm/Object/OffloadBinary.h" | ||||
#include "llvm/ADT/ScopeExit.h" | |||||
#include "device.h" | #include "device.h" | ||||
#include "private.h" | #include "private.h" | ||||
#include "rtl.h" | #include "rtl.h" | ||||
#include "Utilities.h" | #include "Utilities.h" | ||||
#include <atomic> | |||||
#include <cassert> | #include <cassert> | ||||
#include <cstdlib> | #include <cstdlib> | ||||
#include <cstring> | #include <cstring> | ||||
#include <mutex> | #include <mutex> | ||||
#include <string> | #include <string> | ||||
#include <thread> | |||||
using namespace llvm; | using namespace llvm; | ||||
using namespace llvm::sys; | using namespace llvm::sys; | ||||
using namespace llvm::omp::target; | using namespace llvm::omp::target; | ||||
// List of all plugins that can support offloading. | // List of all plugins that can support offloading. | ||||
static const char *RTLNames[] = { | static const char *RTLNames[] = { | ||||
/* PowerPC target */ "libomptarget.rtl.ppc64", | /* PowerPC target */ "libomptarget.rtl.ppc64", | ||||
▲ Show 20 Lines • Show All 41 Lines • ▼ Show 20 Lines | if (ProfileTraceFile) { | ||||
if (auto E = timeTraceProfilerWrite(ProfileTraceFile, "-")) | if (auto E = timeTraceProfilerWrite(ProfileTraceFile, "-")) | ||||
fprintf(stderr, "Error writing out the time trace\n"); | fprintf(stderr, "Error writing out the time trace\n"); | ||||
timeTraceProfilerCleanup(); | timeTraceProfilerCleanup(); | ||||
} | } | ||||
} | } | ||||
void RTLsTy::loadRTLs() { | void RTLsTy::loadRTLs() { | ||||
LoadingThread.store(std::this_thread::get_id()); | |||||
const auto ResetOnExit = llvm::make_scope_exit([this] { | |||||
LoadingThread.store(std::thread::id{}); | |||||
runDelayedRegistrations(); | |||||
}); | |||||
// Parse environment variable OMP_TARGET_OFFLOAD (if set) | // Parse environment variable OMP_TARGET_OFFLOAD (if set) | ||||
PM->TargetOffloadPolicy = | PM->TargetOffloadPolicy = | ||||
(kmp_target_offload_kind_t)__kmpc_get_target_offload(); | (kmp_target_offload_kind_t)__kmpc_get_target_offload(); | ||||
if (PM->TargetOffloadPolicy == tgt_disabled) { | if (PM->TargetOffloadPolicy == tgt_disabled) { | ||||
return; | return; | ||||
} | } | ||||
DP("Loading RTLs...\n"); | DP("Loading RTLs...\n"); | ||||
Show All 17 Lines | for (const char *Name : RTLNames) { | ||||
if (!attemptLoadRTL(BaseRTLName + ".so", RTL)) | if (!attemptLoadRTL(BaseRTLName + ".so", RTL)) | ||||
AllRTLs.pop_back(); | AllRTLs.pop_back(); | ||||
} | } | ||||
DP("RTLs loaded!\n"); | DP("RTLs loaded!\n"); | ||||
} | } | ||||
void RTLsTy::registerToAllRTLs(__tgt_bin_desc* Desc) { | |||||
for (auto &RTL : PM->RTLs.AllRTLs) { | |||||
if (RTL.register_lib) { | |||||
if ((*RTL.register_lib)(Desc) != OFFLOAD_SUCCESS) { | |||||
DP("Could not register library with %s", RTL.RTLName.c_str()); | |||||
} | |||||
} | |||||
} | |||||
} | |||||
bool RTLsTy::delayRegistration(__tgt_bin_desc* DelayedDesc) { | |||||
if(LoadingThread.load() != std::this_thread::get_id()) | |||||
return false; | |||||
DelayedDescs.insert(DelayedDesc); | |||||
return true; | |||||
} | |||||
bool RTLsTy::cancelDelayedRegistration(__tgt_bin_desc* DelayedDesc) { | |||||
if(LoadingThread.load() != std::this_thread::get_id()) | |||||
return false; | |||||
DelayedDescs.erase(DelayedDesc); | |||||
return true; | |||||
} | |||||
void RTLsTy::runDelayedRegistrations() { | |||||
for (auto* Desc: DelayedDescs) { | |||||
registerToAllRTLs(Desc); | |||||
registerLib(Desc); | |||||
} | |||||
DelayedDescs.clear(); | |||||
} | |||||
bool RTLsTy::attemptLoadRTL(const std::string &RTLName, RTLInfoTy &RTL) { | bool RTLsTy::attemptLoadRTL(const std::string &RTLName, RTLInfoTy &RTL) { | ||||
const char *Name = RTLName.c_str(); | const char *Name = RTLName.c_str(); | ||||
DP("Loading library '%s'...\n", Name); | DP("Loading library '%s'...\n", Name); | ||||
std::string ErrMsg; | std::string ErrMsg; | ||||
auto DynLibrary = std::make_unique<sys::DynamicLibrary>( | auto DynLibrary = std::make_unique<sys::DynamicLibrary>( | ||||
sys::DynamicLibrary::getPermanentLibrary(Name, &ErrMsg)); | sys::DynamicLibrary::getPermanentLibrary(Name, &ErrMsg)); | ||||
▲ Show 20 Lines • Show All 474 Lines • Show Last 20 Lines |