Skip to content
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

[NFC][offload][OMPT] Cleanup of OMPT internals #109005

Merged
merged 1 commit into from
Sep 23, 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
6 changes: 3 additions & 3 deletions offload/include/OpenMP/OMPT/Callback.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
//
//===----------------------------------------------------------------------===//

#ifndef OMPTARGET_OPENMP_OMPT_CALLBACK_H
#define OMPTARGET_OPENMP_OMPT_CALLBACK_H
#ifndef OFFLOAD_INCLUDE_OPENMP_OMPT_CALLBACK_H
#define OFFLOAD_INCLUDE_OPENMP_OMPT_CALLBACK_H

#ifdef OMPT_SUPPORT

Expand Down Expand Up @@ -102,4 +102,4 @@ extern bool Initialized;
#define performIfOmptInitialized(stmt)
#endif // OMPT_SUPPORT

#endif // OMPTARGET_OPENMP_OMPT_CALLBACK_H
#endif // OFFLOAD_INCLUDE_OPENMP_OMPT_CALLBACK_H
12 changes: 6 additions & 6 deletions offload/include/OpenMP/OMPT/Interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@
//
//===----------------------------------------------------------------------===//

#ifndef _OMPTARGET_OMPTINTERFACE_H
#define _OMPTARGET_OMPTINTERFACE_H
#ifndef OFFLOAD_INCLUDE_OPENMP_OMPT_INTERFACE_H
#define OFFLOAD_INCLUDE_OPENMP_OMPT_INTERFACE_H

// Only provide functionality if target OMPT support is enabled
#ifdef OMPT_SUPPORT
#include <functional>
#include <tuple>

#include "Callback.h"
#include "omp-tools.h"

#include "llvm/Support/ErrorHandling.h"

#include <functional>
#include <tuple>

#define OMPT_IF_BUILT(stmt) stmt

/// Callbacks for target regions require task_data representing the
Expand Down Expand Up @@ -326,4 +326,4 @@ class ReturnAddressSetterRAII {
#define OMPT_IF_BUILT(stmt)
#endif

#endif // _OMPTARGET_OMPTINTERFACE_H
#endif // OFFLOAD_INCLUDE_OPENMP_OMPT_INTERFACE_H
6 changes: 0 additions & 6 deletions offload/plugins-nextgen/common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,6 @@ elseif(${LIBOMPTARGET_GPU_LIBC_SUPPORT})
endif()
endif()

# If we have OMPT enabled include it in the list of sources.
if (OMPT_TARGET_DEFAULT AND LIBOMPTARGET_OMPT_SUPPORT)
target_sources(PluginCommon PRIVATE OMPT/OmptCallback.cpp)
target_include_directories(PluginCommon PRIVATE OMPT)
endif()

# Define the TARGET_NAME and DEBUG_PREFIX.
target_compile_definitions(PluginCommon PRIVATE
TARGET_NAME="PluginInterface"
Expand Down
75 changes: 0 additions & 75 deletions offload/plugins-nextgen/common/OMPT/OmptCallback.cpp

This file was deleted.

54 changes: 16 additions & 38 deletions offload/src/OpenMP/OMPT/Callback.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,7 @@
//
//===----------------------------------------------------------------------===//

#ifndef OMPT_SUPPORT

extern "C" {
/// Dummy definition when OMPT is disabled
void ompt_libomptarget_connect() {}
}

#else // OMPT_SUPPORT is set
#ifdef OMPT_SUPPORT

#include <cstdlib>
#include <cstring>
Expand All @@ -34,15 +27,15 @@ void ompt_libomptarget_connect() {}
#undef DEBUG_PREFIX
#define DEBUG_PREFIX "OMPT"

using namespace llvm::omp::target::ompt;

// Define OMPT callback functions (bound to actual callbacks later on)
#define defineOmptCallback(Name, Type, Code) \
Name##_t llvm::omp::target::ompt::Name##_fn = nullptr;
FOREACH_OMPT_NOEMI_EVENT(defineOmptCallback)
FOREACH_OMPT_EMI_EVENT(defineOmptCallback)
#undef defineOmptCallback

using namespace llvm::omp::target::ompt;

/// Forward declaration
class LibomptargetRtlFinalizer;

Expand Down Expand Up @@ -226,26 +219,26 @@ void Interface::endTargetDataRetrieve(int64_t SrcDeviceId, void *SrcPtrBegin,
endTargetDataOperation();
}

void Interface::beginTargetSubmit(unsigned int numTeams) {
void Interface::beginTargetSubmit(unsigned int NumTeams) {
if (ompt_callback_target_submit_emi_fn) {
// HostOpId is set by the tool. Invoke the tool supplied target submit EMI
// callback
ompt_callback_target_submit_emi_fn(ompt_scope_begin, &TargetData, &HostOpId,
numTeams);
NumTeams);
} else if (ompt_callback_target_submit_fn) {
// HostOpId is set by the runtime
HostOpId = createOpId();
ompt_callback_target_submit_fn(TargetData.value, HostOpId, numTeams);
ompt_callback_target_submit_fn(TargetData.value, HostOpId, NumTeams);
}
}

void Interface::endTargetSubmit(unsigned int numTeams) {
void Interface::endTargetSubmit(unsigned int NumTeams) {
// Only EMI callback handles end scope
if (ompt_callback_target_submit_emi_fn) {
// HostOpId is set by the tool. Invoke the tool supplied target submit EMI
// callback
ompt_callback_target_submit_emi_fn(ompt_scope_end, &TargetData, &HostOpId,
numTeams);
NumTeams);
}
}

Expand Down Expand Up @@ -458,7 +451,7 @@ class LibomptargetRtlFinalizer {

void finalize() {
for (auto FinalizationFunction : RtlFinalizationFunctions)
FinalizationFunction(/* tool_data */ nullptr);
FinalizationFunction(/*tool_data=*/nullptr);
RtlFinalizationFunctions.clear();
}

Expand All @@ -469,10 +462,11 @@ class LibomptargetRtlFinalizer {
int llvm::omp::target::ompt::initializeLibrary(ompt_function_lookup_t lookup,
int initial_device_num,
ompt_data_t *tool_data) {
DP("Executing initializeLibrary (libomp)\n");
DP("Executing initializeLibrary\n");
#define bindOmptFunctionName(OmptFunction, DestinationFunction) \
DestinationFunction = (OmptFunction##_t)lookup(#OmptFunction); \
DP("initializeLibrary (libomp) bound %s=%p\n", #DestinationFunction, \
if (lookup) \
DestinationFunction = (OmptFunction##_t)lookup(#OmptFunction); \
DP("initializeLibrary bound %s=%p\n", #DestinationFunction, \
((void *)(uint64_t)DestinationFunction));

bindOmptFunctionName(ompt_get_callback, lookupCallbackByCode);
Expand All @@ -499,7 +493,7 @@ int llvm::omp::target::ompt::initializeLibrary(ompt_function_lookup_t lookup,
}

void llvm::omp::target::ompt::finalizeLibrary(ompt_data_t *data) {
DP("Executing finalizeLibrary (libomp)\n");
DP("Executing finalizeLibrary\n");
// Before disabling OMPT, call the (plugin) finalizations that were registered
// with this library
LibraryFinalizer->finalize();
Expand All @@ -508,7 +502,7 @@ void llvm::omp::target::ompt::finalizeLibrary(ompt_data_t *data) {
}

void llvm::omp::target::ompt::connectLibrary() {
DP("Entering connectLibrary (libomp)\n");
DP("Entering connectLibrary\n");
// Connect with libomp
static OmptLibraryConnectorTy LibompConnector("libomp");
static ompt_start_tool_result_t OmptResult;
Expand All @@ -531,23 +525,7 @@ void llvm::omp::target::ompt::connectLibrary() {
FOREACH_OMPT_EMI_EVENT(bindOmptCallback)
#undef bindOmptCallback

DP("Exiting connectLibrary (libomp)\n");
DP("Exiting connectLibrary\n");
}

extern "C" {
/// Used for connecting libomptarget with a plugin
void ompt_libomptarget_connect(ompt_start_tool_result_t *result) {
DP("Enter ompt_libomptarget_connect\n");
if (Initialized && result && LibraryFinalizer) {
// Cache each fini function, so that they 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(lookupCallbackByName,
/* initial_device_num */ 0, /* tool_data */ nullptr);
}
DP("Leave ompt_libomptarget_connect\n");
}
}
#endif // OMPT_SUPPORT
1 change: 0 additions & 1 deletion offload/src/exports
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ VERS1.0 {
__tgt_interop_init;
__tgt_interop_use;
__tgt_interop_destroy;
ompt_libomptarget_connect;
__llvmPushCallConfiguration;
__llvmPopCallConfiguration;
llvmLaunchKernel;
Expand Down
Loading