Skip to content

Commit

Permalink
Revert "[OpenMP] [OMPT] [amdgpu] [4/8] Implemented callback registrat…
Browse files Browse the repository at this point in the history
…ion in nextgen plugins"

This reverts commit 8cd1f0d.

It causes issues when OMPT is disabled explicitly and dependences are not set
correctly.
  • Loading branch information
shiltian committed May 2, 2023
1 parent 58295ca commit c7de29e
Show file tree
Hide file tree
Showing 12 changed files with 13 additions and 245 deletions.
16 changes: 2 additions & 14 deletions openmp/libomptarget/include/ompt_device_callbacks.h
Expand Up @@ -49,20 +49,6 @@ class OmptDeviceCallbacksTy {
#undef OmptBindCallback
}

/// Used to find a callback given its name
ompt_interface_fn_t lookupCallback(const char *InterfaceFunctionName) {
#define OmptLookup(Name, Type, Code) \
if (strcmp(InterfaceFunctionName, #Name) == 0) \
return (ompt_interface_fn_t)Name##_fn;

FOREACH_OMPT_TARGET_CALLBACK(OmptLookup);
#undef OmptLookup
return (ompt_interface_fn_t) nullptr;
}

/// Wrapper function to find a callback given its name
static ompt_interface_fn_t doLookup(const char *InterfaceFunctionName);

private:
/// Set to true if callbacks for this library have been initialized
bool Enabled;
Expand All @@ -76,6 +62,8 @@ class OmptDeviceCallbacksTy {
/// Device callbacks object for the library that performs the instantiation
extern OmptDeviceCallbacksTy OmptDeviceCallbacks;

#undef DEBUG_PREFIX

#endif // OMPT_SUPPORT

#endif // _OMPT_DEVICE_CALLBACKS_H
1 change: 0 additions & 1 deletion openmp/libomptarget/plugins-nextgen/CMakeLists.txt
Expand Up @@ -49,7 +49,6 @@ if(CMAKE_SYSTEM_PROCESSOR MATCHES "${tmachine}$")
PRIVATE
elf_common
MemoryManager
OMPT
PluginInterface
${LIBOMPTARGET_DEP_LIBFFI_LIBRARIES}
${OPENMP_PTHREAD_LIB}
Expand Down
1 change: 0 additions & 1 deletion openmp/libomptarget/plugins-nextgen/amdgpu/CMakeLists.txt
Expand Up @@ -82,7 +82,6 @@ add_llvm_library(omptarget.rtl.amdgpu.nextgen SHARED
PRIVATE
elf_common
MemoryManager
OMPT
PluginInterface
${LIBOMPTARGET_DEP_LIBRARIES}
${OPENMP_PTHREAD_LIB}
Expand Down
1 change: 0 additions & 1 deletion openmp/libomptarget/plugins-nextgen/common/CMakeLists.txt
Expand Up @@ -10,5 +10,4 @@
#
##===----------------------------------------------------------------------===##

add_subdirectory(OMPT)
add_subdirectory(PluginInterface)
72 changes: 0 additions & 72 deletions openmp/libomptarget/plugins-nextgen/common/OMPT/CMakeLists.txt

This file was deleted.

83 changes: 0 additions & 83 deletions openmp/libomptarget/plugins-nextgen/common/OMPT/OmptCallback.cpp

This file was deleted.

Expand Up @@ -60,7 +60,6 @@ target_link_libraries(PluginInterface
${llvm_libs}
elf_common
MemoryManager
OMPT
)

# Define the TARGET_NAME and DEBUG_PREFIX.
Expand Down
1 change: 0 additions & 1 deletion openmp/libomptarget/plugins-nextgen/cuda/CMakeLists.txt
Expand Up @@ -36,7 +36,6 @@ add_llvm_library(omptarget.rtl.cuda.nextgen SHARED
LINK_LIBS PRIVATE
elf_common
MemoryManager
OMPT
PluginInterface
${OPENMP_PTHREAD_LIB}

Expand Down
2 changes: 1 addition & 1 deletion openmp/libomptarget/src/CMakeLists.txt
Expand Up @@ -20,7 +20,7 @@ add_llvm_library(omptarget
interface.cpp
interop.cpp
omptarget.cpp
OmptCallback.cpp
ompt_callback.cpp
rtl.cpp
LegacyAPI.cpp

Expand Down
1 change: 0 additions & 1 deletion openmp/libomptarget/src/exports
Expand Up @@ -64,7 +64,6 @@ VERS1.0 {
__tgt_interop_init;
__tgt_interop_use;
__tgt_interop_destroy;
ompt_libomptarget_connect;
local:
*;
};
@@ -1,4 +1,4 @@
//===-- OmptCallback.cpp - Target independent OpenMP target RTL --- C++ -*-===//
//===-- ompt_callback.cpp - Target independent OpenMP target RTL -- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
Expand All @@ -19,47 +19,17 @@

#include "omp-tools.h"

#include "Debug.h"
#include "ompt_connector.h"
#include "ompt_device_callbacks.h"
#include "private.h"

#define fnptr_to_ptr(x) ((void *)(uint64_t)x)

/// Used to indicate whether OMPT was enabled for this library
bool OmptEnabled = false;
bool ompt_enabled = false;
/// Object maintaining all the callbacks for this library
OmptDeviceCallbacksTy OmptDeviceCallbacks;

/// Used to maintain the finalization function that is received
/// from the plugin during connect
class LibomptargetRtlFinalizer {
public:
LibomptargetRtlFinalizer() : RtlFinalization(nullptr) {}
void registerRtl(ompt_finalize_t FinalizationFunction) {
assert((RtlFinalization == nullptr) &&
"RTL finalization may only be registered once");
RtlFinalization = FinalizationFunction;
}
void finalize() {
if (RtlFinalization)
RtlFinalization(nullptr /* tool_data */);
RtlFinalization = nullptr;
}

private:
ompt_finalize_t RtlFinalization;
};

/// Object that will maintain the RTL finalizer from the plugin
static LibomptargetRtlFinalizer LibraryFinalizer;

/// Lookup function to be used by libomptarget library
ompt_interface_fn_t
OmptDeviceCallbacksTy::doLookup(const char *InterfaceFunctionName) {
return OmptDeviceCallbacks.lookupCallback(InterfaceFunctionName);
}

/// This is the function called by the higher layer (libomp) responsible
/// for initializing OMPT in this library. This is passed to libomp
/// as part of the OMPT connector object.
Expand All @@ -70,7 +40,7 @@ static int ompt_libomptarget_initialize(ompt_function_lookup_t lookup,
int initial_device_num,
ompt_data_t *tool_data) {
DP("enter ompt_libomptarget_initialize!\n");
OmptEnabled = true;
ompt_enabled = true;
// The lookup parameter is provided by libomp which already has the
// tool callbacks registered at this point. The registration call
// below causes the same callback functions to be registered in
Expand All @@ -80,14 +50,9 @@ static int ompt_libomptarget_initialize(ompt_function_lookup_t lookup,
return 0;
}

/// This function is passed to libomp as part of the OMPT connector object.
/// It is called by libomp during finalization of OMPT in libomptarget.
static void ompt_libomptarget_finalize(ompt_data_t *data) {
DP("enter ompt_libomptarget_finalize!\n");
// Before disabling OMPT, call the finalizer (of the plugin) that was
// registered with this library
LibraryFinalizer.finalize();
OmptEnabled = false;
ompt_enabled = false;
DP("exit ompt_libomptarget_finalize!\n");
}

Expand All @@ -96,9 +61,11 @@ static void ompt_libomptarget_finalize(ompt_data_t *data) {
*****************************************************************************/
/// Used to initialize callbacks implemented by the tool. This interface
/// will lookup the callbacks table in libomp and assign them to the callbacks
/// maintained in libomptarget.
void InitOmptLibomp() {
DP("OMPT: Enter InitOmptLibomp\n");
/// maintained in libomptarget. Using priority 102 to have this constructor
/// run after the init target library constructor with priority 101 (see
/// rtl.cpp).
__attribute__((constructor(102))) static void ompt_init(void) {
DP("OMPT: Enter ompt_init\n");
// Connect with libomp
static OmptLibraryConnectorTy LibompConnector("libomp");
static ompt_start_tool_result_t OmptResult;
Expand All @@ -114,24 +81,7 @@ void InitOmptLibomp() {

// Now call connect that causes the above init/fini functions to be called
LibompConnector.connect(&OmptResult);
DP("OMPT: Exit InitOmptLibomp\n");
DP("OMPT: Exit ompt_init\n");
}

#endif // OMPT_SUPPORT

extern "C" {
/// Used for connecting libomptarget with a plugin
void ompt_libomptarget_connect(ompt_start_tool_result_t *result) {
DP("OMPT: Enter ompt_libomptarget_connect\n");
if (OmptEnabled && result) {
// Cache the fini function so that it can be invoked on exit
LibraryFinalizer.registerRtl(result->finalize);
// Invoke the provided init function with the lookup function maintained
// in this library so that callbacks maintained by this library are
// retrieved.
result->initialize(OmptDeviceCallbacksTy::doLookup,
0 /* initial_device_num */, nullptr /* tool_data */);
}
DP("OMPT: Leave ompt_libomptarget_connect\n");
}
}
9 changes: 0 additions & 9 deletions openmp/libomptarget/src/rtl.cpp
Expand Up @@ -43,10 +43,6 @@ PluginManager *PM;

static char *ProfileTraceFile = nullptr;

#ifdef OMPT_SUPPORT
extern void InitOmptLibomp();
#endif

__attribute__((constructor(101))) void init() {
DP("Init target library!\n");

Expand All @@ -69,11 +65,6 @@ __attribute__((constructor(101))) void init() {
if (ProfileTraceFile)
timeTraceProfilerInitialize(500 /* us */, "libomptarget");

#ifdef OMPT_SUPPORT
// Initialize OMPT first
InitOmptLibomp();
#endif

PM->RTLs.loadRTLs();
PM->registerDelayedLibraries();
}
Expand Down

0 comments on commit c7de29e

Please sign in to comment.