Skip to content

Commit 65fd8ab

Browse files
mhalkronlieb
authored andcommitted
[NFC][offload][OMPT] Cleanup of OMPT internals
Removed OmptCallbacks.cpp since relevant contents were duplicated. Because of the static linking there should be no change in functionality. This commit is meant to replace the following upstream PR: llvm#109005 Change-Id: Iddc56ae559f7387056bdcf2d6b8860ab9fc5956a
1 parent b0c4093 commit 65fd8ab

File tree

6 files changed

+39
-147
lines changed

6 files changed

+39
-147
lines changed

offload/include/OmptCommonDefs.h

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
#ifndef OPENMP_LIBOMPTARGET_INCLUDE_OMPTCOMMONDEFS_H
14-
#define OPENMP_LIBOMPTARGET_INCLUDE_OMPTCOMMONDEFS_H
13+
#ifndef OFFLOAD_INCLUDE_OMPTCOMMONDEFS_H
14+
#define OFFLOAD_INCLUDE_OMPTCOMMONDEFS_H
1515

1616
#ifdef OMPT_SUPPORT
1717

@@ -47,14 +47,13 @@
4747

4848
#define OMPT_API_ROUTINE static
4949

50-
#define OMPT_CALLBACK_AVAILABLE(fn) \
51-
(llvm::omp::target::ompt::CallbacksInitialized && fn)
50+
#define OMPT_CALLBACK_AVAILABLE(fn) (llvm::omp::target::ompt::Initialized && fn)
5251

5352
#define OMPT_IF_BUILT(stmt) stmt
5453

5554
#define OMPT_IF_ENABLED(stmts) \
5655
do { \
57-
if (llvm::omp::target::ompt::CallbacksInitialized) { \
56+
if (llvm::omp::target::ompt::Initialized) { \
5857
stmts \
5958
} \
6059
} while (0)
@@ -80,7 +79,7 @@
8079

8180
#define performIfOmptInitialized(stmt) \
8281
do { \
83-
if (llvm::omp::target::ompt::CallbacksInitialized) { \
82+
if (llvm::omp::target::ompt::Initialized) { \
8483
stmt; \
8584
} \
8685
} while (0)
@@ -125,4 +124,4 @@ typedef uint64_t (*IdInterfaceTy)();
125124
#define OMPT_IF_TRACING_ENABLED(stmts)
126125
#endif // OMPT_SUPPORT
127126

128-
#endif // OPENMP_LIBOMPTARGET_INCLUDE_OMPTCOMMONDEFS_H
127+
#endif // OFFLOAD_INCLUDE_OMPTCOMMONDEFS_H

offload/include/OpenMP/OMPT/Callback.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
//
1212
//===----------------------------------------------------------------------===//
1313

14-
#ifndef OMPTARGET_OPENMP_OMPT_CALLBACK_H
15-
#define OMPTARGET_OPENMP_OMPT_CALLBACK_H
14+
#ifndef OFFLOAD_INCLUDE_OPENMP_OMPT_CALLBACK_H
15+
#define OFFLOAD_INCLUDE_OPENMP_OMPT_CALLBACK_H
1616

1717
#ifdef OMPT_SUPPORT
1818

@@ -67,7 +67,7 @@ void finalizeLibrary(ompt_data_t *tool_data);
6767
void connectLibrary();
6868

6969
/// OMPT initialization status; false if initializeLibrary has not been executed
70-
extern bool CallbacksInitialized;
70+
extern bool Initialized;
7171

7272
} // namespace ompt
7373
} // namespace target
@@ -78,4 +78,4 @@ extern bool CallbacksInitialized;
7878

7979
#endif // OMPT_SUPPORT
8080

81-
#endif // OMPTARGET_OPENMP_OMPT_CALLBACK_H
81+
#endif // OFFLOAD_INCLUDE_OPENMP_OMPT_CALLBACK_H

offload/include/OpenMP/OMPT/Interface.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
#ifndef OPENMP_LIBOMPTARGET_SRC_OMPTINTERFACE_H
14-
#define OPENMP_LIBOMPTARGET_SRC_OMPTINTERFACE_H
13+
#ifndef OFFLOAD_INCLUDE_OPENMP_OMPT_INTERFACE_H
14+
#define OFFLOAD_INCLUDE_OPENMP_OMPT_INTERFACE_H
1515

1616
// Only provide functionality if target OMPT support is enabled
1717
#ifdef OMPT_SUPPORT
@@ -44,9 +44,9 @@ namespace ompt {
4444

4545
/// Function pointers that will be used to track task_data and
4646
/// target_task_data.
47-
extern ompt_get_task_data_t ompt_get_task_data_fn;
48-
extern ompt_get_target_task_data_t ompt_get_target_task_data_fn;
49-
extern ompt_set_frame_enter_t ompt_set_frame_enter_fn;
47+
static ompt_get_task_data_t ompt_get_task_data_fn;
48+
static ompt_get_target_task_data_t ompt_get_target_task_data_fn;
49+
static ompt_set_frame_enter_t ompt_set_frame_enter_fn;
5050

5151
/// OMPT global tracing status. Indicates if at least one device is traced.
5252
extern bool TracingActive;
@@ -567,4 +567,4 @@ class ReturnAddressSetterRAII {
567567

568568
#endif // OMPT_SUPPORT
569569

570-
#endif // OPENMP_LIBOMPTARGET_SRC_OMPTINTERFACE_H
570+
#endif // OFFLOAD_INCLUDE_OPENMP_OMPT_INTERFACE_H

offload/plugins-nextgen/common/OMPT/OmptCallback.cpp

Lines changed: 0 additions & 83 deletions
This file was deleted.

offload/plugins-nextgen/common/src/PluginInterface.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -919,7 +919,7 @@ GenericDeviceTy::GenericDeviceTy(GenericPluginTy &Plugin, int32_t DeviceId,
919919
OmptInitialized.store(false);
920920
// Bind the callbacks to this device's member functions
921921
#define bindOmptCallback(Name, Type, Code) \
922-
if (ompt::CallbacksInitialized && ompt::lookupCallbackByCode) { \
922+
if (ompt::Initialized && ompt::lookupCallbackByCode) { \
923923
ompt::lookupCallbackByCode((ompt_callbacks_t)(Code), \
924924
((ompt_callback_t *)&(Name##_fn))); \
925925
DP("class bound %s=%p\n", #Name, ((void *)(uint64_t)Name##_fn)); \
@@ -929,7 +929,7 @@ GenericDeviceTy::GenericDeviceTy(GenericPluginTy &Plugin, int32_t DeviceId,
929929
#undef bindOmptCallback
930930

931931
#define bindOmptTracingFunction(FunctionName) \
932-
if (ompt::CallbacksInitialized && ompt::lookupDeviceTracingFn) { \
932+
if (ompt::Initialized && ompt::lookupDeviceTracingFn) { \
933933
FunctionName##_fn = ompt::lookupDeviceTracingFn(#FunctionName); \
934934
DP("device tracing fn bound %s=%p\n", #FunctionName, \
935935
((void *)(uint64_t)FunctionName##_fn)); \
@@ -948,7 +948,7 @@ Error GenericDeviceTy::init(GenericPluginTy &Plugin) {
948948
#ifdef OMPT_SUPPORT
949949
auto DevicePtr = reinterpret_cast<ompt_device_t *>(this);
950950
ompt::setDeviceId(DevicePtr, Plugin.getUserId(DeviceId));
951-
if (ompt::CallbacksInitialized) {
951+
if (ompt::Initialized) {
952952
bool ExpectedStatus = false;
953953
if (OmptInitialized.compare_exchange_strong(ExpectedStatus, true))
954954
performOmptCallback(device_initialize, Plugin.getUserId(DeviceId),
@@ -1060,7 +1060,7 @@ Error GenericDeviceTy::deinit(GenericPluginTy &Plugin) {
10601060
return Err;
10611061

10621062
#ifdef OMPT_SUPPORT
1063-
if (ompt::CallbacksInitialized) {
1063+
if (ompt::Initialized) {
10641064
bool ExpectedStatus = true;
10651065
if (OmptInitialized.compare_exchange_strong(ExpectedStatus, false))
10661066
performOmptCallback(device_finalize, Plugin.getUserId(DeviceId));
@@ -1119,7 +1119,7 @@ GenericDeviceTy::loadBinary(GenericPluginTy &Plugin,
11191119
return std::move(Err);
11201120

11211121
#ifdef OMPT_SUPPORT
1122-
if (ompt::CallbacksInitialized) {
1122+
if (ompt::Initialized) {
11231123
size_t Bytes =
11241124
utils::getPtrDiff(InputTgtImage->ImageEnd, InputTgtImage->ImageStart);
11251125
performOmptCallback(

offload/src/OpenMP/OMPT/Callback.cpp

Lines changed: 18 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,7 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
#ifndef OMPT_SUPPORT
14-
15-
extern "C" {
16-
/// Dummy definition when OMPT is disabled
17-
void ompt_libomptarget_connect() {}
18-
}
19-
20-
#else // OMPT_SUPPORT is set
13+
#ifdef OMPT_SUPPORT
2114

2215
#include <atomic>
2316
#include <cassert>
@@ -27,27 +20,28 @@ void ompt_libomptarget_connect() {}
2720
#include <mutex>
2821
#include <thread>
2922

30-
#pragma push_macro("DEBUG_PREFIX")
3123
#include "Shared/Debug.h"
3224

3325
#include "OpenMP/OMPT/Callback.h"
3426
#include "OpenMP/OMPT/Connector.h"
3527
#include "OpenMP/OMPT/Interface.h"
3628

3729
#include "llvm/Support/DynamicLibrary.h"
30+
#include "llvm/Support/ErrorHandling.h"
3831

32+
#pragma push_macro("DEBUG_PREFIX")
3933
#undef DEBUG_PREFIX
4034
#define DEBUG_PREFIX "OMPT"
4135

42-
using namespace llvm::omp::target::ompt;
43-
4436
// Define OMPT callback functions (bound to actual callbacks later on)
4537
#define defineOmptCallback(Name, Type, Code) \
4638
Name##_t llvm::omp::target::ompt::Name##_fn = nullptr;
4739
FOREACH_OMPT_NOEMI_EVENT(defineOmptCallback)
4840
FOREACH_OMPT_EMI_EVENT(defineOmptCallback)
4941
#undef defineOmptCallback
5042

43+
using namespace llvm::omp::target::ompt;
44+
5145
/// Forward declaration
5246
class LibomptargetRtlFinalizer;
5347

@@ -58,15 +52,13 @@ thread_local Interface llvm::omp::target::ompt::RegionInterface;
5852

5953
thread_local void *llvm::omp::target::ompt::ReturnAddress = nullptr;
6054

61-
bool llvm::omp::target::ompt::CallbacksInitialized = false;
55+
bool llvm::omp::target::ompt::Initialized = false;
6256

6357
ompt_get_callback_t llvm::omp::target::ompt::lookupCallbackByCode = nullptr;
6458
ompt_function_lookup_t llvm::omp::target::ompt::lookupCallbackByName = nullptr;
65-
ompt_get_target_task_data_t
66-
llvm::omp::target::ompt::ompt_get_target_task_data_fn = nullptr;
67-
ompt_get_task_data_t llvm::omp::target::ompt::ompt_get_task_data_fn = nullptr;
68-
ompt_set_frame_enter_t llvm::omp::target::ompt::ompt_set_frame_enter_fn =
69-
nullptr;
59+
ompt_get_target_task_data_t ompt_get_target_task_data_fn = nullptr;
60+
ompt_get_task_data_t ompt_get_task_data_fn = nullptr;
61+
ompt_set_frame_enter_t ompt_set_frame_enter_fn = nullptr;
7062

7163
/// Unique correlation id
7264
static std::atomic<uint64_t> IdCounter(1);
@@ -482,10 +474,11 @@ class LibomptargetRtlFinalizer {
482474
int llvm::omp::target::ompt::initializeLibrary(ompt_function_lookup_t lookup,
483475
int initial_device_num,
484476
ompt_data_t *tool_data) {
485-
DP("Executing initializeLibrary (libomp)\n");
477+
DP("Executing initializeLibrary\n");
486478
#define bindOmptFunctionName(OmptFunction, DestinationFunction) \
487-
DestinationFunction = (OmptFunction##_t)lookup(#OmptFunction); \
488-
DP("initializeLibrary (libomp) bound %s=%p\n", #DestinationFunction, \
479+
if (lookup) \
480+
DestinationFunction = (OmptFunction##_t)lookup(#OmptFunction); \
481+
DP("initializeLibrary bound %s=%p\n", #DestinationFunction, \
489482
((void *)(uint64_t)DestinationFunction));
490483

491484
bindOmptFunctionName(ompt_get_callback, lookupCallbackByCode);
@@ -509,22 +502,22 @@ int llvm::omp::target::ompt::initializeLibrary(ompt_function_lookup_t lookup,
509502

510503
LibraryFinalizer = new LibomptargetRtlFinalizer();
511504

512-
CallbacksInitialized = true;
505+
Initialized = true;
513506

514507
return 0;
515508
}
516509

517510
void llvm::omp::target::ompt::finalizeLibrary(ompt_data_t *data) {
518-
DP("Executing finalizeLibrary (libomp)\n");
511+
DP("Executing finalizeLibrary\n");
519512
// Before disabling OMPT, call the (plugin) finalizations that were registered
520513
// with this library
521514
LibraryFinalizer->finalize();
522515
delete LibraryFinalizer;
523-
CallbacksInitialized = false;
516+
Initialized = false;
524517
}
525518

526519
void llvm::omp::target::ompt::connectLibrary() {
527-
DP("Entering connectLibrary (libomp)\n");
520+
DP("Entering connectLibrary\n");
528521
// Connect with libomp
529522
static OmptLibraryConnectorTy LibompConnector("libomp");
530523
static ompt_start_tool_result_t OmptResult;
@@ -547,24 +540,7 @@ void llvm::omp::target::ompt::connectLibrary() {
547540
FOREACH_OMPT_EMI_EVENT(bindOmptCallback)
548541
#undef bindOmptCallback
549542

550-
DP("Exiting connectLibrary (libomp)\n");
551-
}
552-
553-
extern "C" {
554-
/// Used for connecting libomptarget with a plugin
555-
void ompt_libomptarget_connect(ompt_start_tool_result_t *result) {
556-
DP("Enter ompt_libomptarget_connect\n");
557-
if (CallbacksInitialized && result && LibraryFinalizer) {
558-
// Cache each fini function, so that they can be invoked on exit
559-
LibraryFinalizer->registerRtl(result->finalize);
560-
// Invoke the provided init function with the lookup function maintained
561-
// in this library so that callbacks maintained by this library are
562-
// retrieved.
563-
result->initialize(lookupCallbackByName,
564-
/*initial_device_num=*/0, /*tool_data=*/nullptr);
565-
}
566-
DP("Leave ompt_libomptarget_connect\n");
567-
}
543+
DP("Exiting connectLibrary\n");
568544
}
569545

570546
#pragma pop_macro("DEBUG_PREFIX")

0 commit comments

Comments
 (0)