Skip to content

Commit cf119df

Browse files
committed
Revert "[OpenMP] [OMPT] [7/8] Invoke tool-supplied callbacks before and after target launch and data transfer operations"
This reverts commit 00ccfcf.
1 parent 74445d6 commit cf119df

14 files changed

+83
-457
lines changed

openmp/libomptarget/include/OmptCallback.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,6 @@
2727
FOREACH_OMPT_NOEMI_EVENT(macro) \
2828
FOREACH_OMPT_EMI_EVENT(macro)
2929

30-
#define performIfOmptInitialized(stmt) \
31-
do { \
32-
if (llvm::omp::target::ompt::Initialized) { \
33-
stmt; \
34-
} \
35-
} while (0)
36-
3730
#define performOmptCallback(CallbackName, ...) \
3831
do { \
3932
if (ompt_callback_##CallbackName##_fn) \
@@ -96,8 +89,6 @@ extern bool Initialized;
9689
} // namespace omp
9790
} // namespace llvm
9891

99-
#else
100-
#define performIfOmptInitialized(stmt)
10192
#endif // OMPT_SUPPORT
10293

10394
#pragma pop_macro("DEBUG_PREFIX")

openmp/libomptarget/src/OmptCallback.cpp

Lines changed: 45 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -35,20 +35,12 @@ FOREACH_OMPT_NOEMI_EVENT(defineOmptCallback)
3535
FOREACH_OMPT_EMI_EVENT(defineOmptCallback)
3636
#undef defineOmptCallback
3737

38-
/// Forward declaration
39-
class LibomptargetRtlFinalizer;
38+
/// Thread local state for target region and associated metadata
39+
thread_local llvm::omp::target::ompt::Interface OmptInterface;
4040

41-
/// Object that will maintain the RTL finalizer from the plugin
42-
LibomptargetRtlFinalizer *LibraryFinalizer = nullptr;
43-
44-
thread_local Interface llvm::omp::target::ompt::RegionInterface;
45-
46-
bool llvm::omp::target::ompt::Initialized = false;
47-
48-
ompt_get_callback_t llvm::omp::target::ompt::lookupCallbackByCode = nullptr;
49-
ompt_function_lookup_t llvm::omp::target::ompt::lookupCallbackByName = nullptr;
50-
ompt_get_target_task_data_t ompt_get_target_task_data_fn = nullptr;
41+
/// Define function pointers
5142
ompt_get_task_data_t ompt_get_task_data_fn = nullptr;
43+
ompt_get_target_task_data_t ompt_get_target_task_data_fn = nullptr;
5244

5345
/// Unique correlation id
5446
static std::atomic<uint64_t> IdCounter(1);
@@ -59,14 +51,14 @@ static uint64_t createId() { return IdCounter.fetch_add(1); }
5951
/// Create a new correlation id and update the operations id
6052
static uint64_t createOpId() {
6153
uint64_t NewId = createId();
62-
RegionInterface.setHostOpId(NewId);
54+
OmptInterface.setHostOpId(NewId);
6355
return NewId;
6456
}
6557

6658
/// Create a new correlation id and update the target region id
6759
static uint64_t createRegionId() {
6860
uint64_t NewId = createId();
69-
RegionInterface.setTargetDataValue(NewId);
61+
OmptInterface.setTargetDataValue(NewId);
7062
return NewId;
7163
}
7264

@@ -76,19 +68,18 @@ void Interface::beginTargetDataAlloc(int64_t DeviceId, void *HstPtrBegin,
7668
if (ompt_callback_target_data_op_emi_fn) {
7769
// HostOpId will be set by the tool. Invoke the tool supplied data op EMI
7870
// callback
79-
ompt_callback_target_data_op_emi_fn(
80-
ompt_scope_begin, TargetTaskData, &TargetData, &TargetRegionOpId,
81-
ompt_target_data_alloc, HstPtrBegin,
82-
/* SrcDeviceNum */ omp_get_initial_device(), /* TgtPtrBegin */ nullptr,
83-
/* TgtDeviceNum */ DeviceId, Size, Code);
71+
ompt_callback_target_data_op_emi_fn(ompt_scope_begin, TargetTaskData,
72+
&TargetData, &TargetRegionOpId,
73+
ompt_target_data_alloc, HstPtrBegin,
74+
DeviceId, /* TgtPtrBegin */ nullptr,
75+
/* TgtDeviceNum */ 0, Size, Code);
8476
} else if (ompt_callback_target_data_op_fn) {
8577
// HostOpId is set by the runtime
8678
HostOpId = createOpId();
8779
// Invoke the tool supplied data op callback
8880
ompt_callback_target_data_op_fn(
8981
TargetData.value, HostOpId, ompt_target_data_alloc, HstPtrBegin,
90-
/* SrcDeviceNum */ omp_get_initial_device(), /* TgtPtrBegin */ nullptr,
91-
/* TgtDeviceNum */ DeviceId, Size, Code);
82+
DeviceId, /* TgtPtrBegin */ nullptr, /* TgtDeviceNum */ 0, Size, Code);
9283
}
9384
}
9485

@@ -98,11 +89,11 @@ void Interface::endTargetDataAlloc(int64_t DeviceId, void *HstPtrBegin,
9889
if (ompt_callback_target_data_op_emi_fn) {
9990
// HostOpId will be set by the tool. Invoke the tool supplied data op EMI
10091
// callback
101-
ompt_callback_target_data_op_emi_fn(
102-
ompt_scope_end, TargetTaskData, &TargetData, &TargetRegionOpId,
103-
ompt_target_data_alloc, HstPtrBegin,
104-
/* SrcDeviceNum */ omp_get_initial_device(), /* TgtPtrBegin */ nullptr,
105-
/* TgtDeviceNum */ DeviceId, Size, Code);
92+
ompt_callback_target_data_op_emi_fn(ompt_scope_end, TargetTaskData,
93+
&TargetData, &TargetRegionOpId,
94+
ompt_target_data_alloc, HstPtrBegin,
95+
DeviceId, /* TgtPtrBegin */ nullptr,
96+
/* TgtDeviceNum */ 0, Size, Code);
10697
}
10798
endTargetDataOperation();
10899
}
@@ -117,16 +108,14 @@ void Interface::beginTargetDataSubmit(int64_t DeviceId, void *TgtPtrBegin,
117108
ompt_callback_target_data_op_emi_fn(
118109
ompt_scope_begin, TargetTaskData, &TargetData, &TargetRegionOpId,
119110
ompt_target_data_transfer_to_device, HstPtrBegin,
120-
/* SrcDeviceNum */ omp_get_initial_device(), TgtPtrBegin, DeviceId,
121-
Size, Code);
111+
/* SrcDeviceNum */ 0, TgtPtrBegin, DeviceId, Size, Code);
122112
} else if (ompt_callback_target_data_op_fn) {
123113
// HostOpId is set by the runtime
124114
HostOpId = createOpId();
125115
// Invoke the tool supplied data op callback
126116
ompt_callback_target_data_op_fn(
127117
TargetData.value, HostOpId, ompt_target_data_transfer_to_device,
128-
HstPtrBegin, /* SrcDeviceNum */ omp_get_initial_device(), TgtPtrBegin,
129-
DeviceId, Size, Code);
118+
HstPtrBegin, /* SrcDeviceNum */ 0, TgtPtrBegin, DeviceId, Size, Code);
130119
}
131120
}
132121

@@ -140,8 +129,7 @@ void Interface::endTargetDataSubmit(int64_t DeviceId, void *TgtPtrBegin,
140129
ompt_callback_target_data_op_emi_fn(
141130
ompt_scope_end, TargetTaskData, &TargetData, &TargetRegionOpId,
142131
ompt_target_data_transfer_to_device, HstPtrBegin,
143-
/* SrcDeviceNum */ omp_get_initial_device(), TgtPtrBegin, DeviceId,
144-
Size, Code);
132+
/* SrcDeviceNum */ 0, TgtPtrBegin, DeviceId, Size, Code);
145133
}
146134
endTargetDataOperation();
147135
}
@@ -155,15 +143,15 @@ void Interface::beginTargetDataDelete(int64_t DeviceId, void *TgtPtrBegin,
155143
ompt_callback_target_data_op_emi_fn(
156144
ompt_scope_begin, TargetTaskData, &TargetData, &TargetRegionOpId,
157145
ompt_target_data_delete, TgtPtrBegin, DeviceId,
158-
/* TgtPtrBegin */ nullptr, /* TgtDeviceNum */ -1, /* Bytes */ 0, Code);
146+
/* TgtPtrBegin */ nullptr, /* TgtDeviceNum */ 0, /* Bytes */ 0, Code);
159147
} else if (ompt_callback_target_data_op_fn) {
160148
// HostOpId is set by the runtime
161149
HostOpId = createOpId();
162150
// Invoke the tool supplied data op callback
163151
ompt_callback_target_data_op_fn(TargetData.value, HostOpId,
164152
ompt_target_data_delete, TgtPtrBegin,
165153
DeviceId, /* TgtPtrBegin */ nullptr,
166-
/* TgtDeviceNum */ -1, /* Bytes */ 0, Code);
154+
/* TgtDeviceNum */ 0, /* Bytes */ 0, Code);
167155
}
168156
}
169157

@@ -176,7 +164,7 @@ void Interface::endTargetDataDelete(int64_t DeviceId, void *TgtPtrBegin,
176164
ompt_callback_target_data_op_emi_fn(
177165
ompt_scope_end, TargetTaskData, &TargetData, &TargetRegionOpId,
178166
ompt_target_data_delete, TgtPtrBegin, DeviceId,
179-
/* TgtPtrBegin */ nullptr, /* TgtDeviceNum */ -1, /* Bytes */ 0, Code);
167+
/* TgtPtrBegin */ nullptr, /* TgtDeviceNum */ 0, /* Bytes */ 0, Code);
180168
}
181169
endTargetDataOperation();
182170
}
@@ -188,19 +176,19 @@ void Interface::beginTargetDataRetrieve(int64_t DeviceId, void *HstPtrBegin,
188176
if (ompt_callback_target_data_op_emi_fn) {
189177
// HostOpId will be set by the tool. Invoke the tool supplied data op EMI
190178
// callback
191-
ompt_callback_target_data_op_emi_fn(
192-
ompt_scope_begin, TargetTaskData, &TargetData, &TargetRegionOpId,
193-
ompt_target_data_transfer_from_device, TgtPtrBegin, DeviceId,
194-
HstPtrBegin,
195-
/* TgtDeviceNum */ omp_get_initial_device(), Size, Code);
179+
ompt_callback_target_data_op_emi_fn(ompt_scope_begin, TargetTaskData,
180+
&TargetData, &TargetRegionOpId,
181+
ompt_target_data_transfer_from_device,
182+
TgtPtrBegin, DeviceId, HstPtrBegin,
183+
/* TgtDeviceNum */ 0, Size, Code);
196184
} else if (ompt_callback_target_data_op_fn) {
197185
// HostOpId is set by the runtime
198186
HostOpId = createOpId();
199187
// Invoke the tool supplied data op callback
200-
ompt_callback_target_data_op_fn(
201-
TargetData.value, HostOpId, ompt_target_data_transfer_from_device,
202-
TgtPtrBegin, DeviceId, HstPtrBegin,
203-
/* TgtDeviceNum */ omp_get_initial_device(), Size, Code);
188+
ompt_callback_target_data_op_fn(TargetData.value, HostOpId,
189+
ompt_target_data_transfer_from_device,
190+
TgtPtrBegin, DeviceId, HstPtrBegin,
191+
/* TgtDeviceNum */ 0, Size, Code);
204192
}
205193
}
206194

@@ -211,11 +199,11 @@ void Interface::endTargetDataRetrieve(int64_t DeviceId, void *HstPtrBegin,
211199
if (ompt_callback_target_data_op_emi_fn) {
212200
// HostOpId will be set by the tool. Invoke the tool supplied data op EMI
213201
// callback
214-
ompt_callback_target_data_op_emi_fn(
215-
ompt_scope_end, TargetTaskData, &TargetData, &TargetRegionOpId,
216-
ompt_target_data_transfer_from_device, TgtPtrBegin, DeviceId,
217-
HstPtrBegin,
218-
/* TgtDeviceNum */ omp_get_initial_device(), Size, Code);
202+
ompt_callback_target_data_op_emi_fn(ompt_scope_end, TargetTaskData,
203+
&TargetData, &TargetRegionOpId,
204+
ompt_target_data_transfer_from_device,
205+
TgtPtrBegin, DeviceId, HstPtrBegin,
206+
/* TgtDeviceNum */ 0, Size, Code);
219207
}
220208
endTargetDataOperation();
221209
}
@@ -242,7 +230,6 @@ void Interface::endTargetSubmit(unsigned int numTeams) {
242230
numTeams);
243231
}
244232
}
245-
246233
void Interface::beginTargetDataEnter(int64_t DeviceId, void *Code) {
247234
beginTargetRegion();
248235
if (ompt_callback_target_emi_fn) {
@@ -404,6 +391,14 @@ class LibomptargetRtlFinalizer {
404391
llvm::SmallVector<ompt_finalize_t> RtlFinalizationFunctions;
405392
};
406393

394+
/// Object that will maintain the RTL finalizer from the plugin
395+
LibomptargetRtlFinalizer *LibraryFinalizer = nullptr;
396+
397+
bool llvm::omp::target::ompt::Initialized = false;
398+
399+
ompt_get_callback_t llvm::omp::target::ompt::lookupCallbackByCode = nullptr;
400+
ompt_function_lookup_t llvm::omp::target::ompt::lookupCallbackByName = nullptr;
401+
407402
int llvm::omp::target::ompt::initializeLibrary(ompt_function_lookup_t lookup,
408403
int initial_device_num,
409404
ompt_data_t *tool_data) {
@@ -423,9 +418,6 @@ int llvm::omp::target::ompt::initializeLibrary(ompt_function_lookup_t lookup,
423418

424419
assert(lookupCallbackByCode && "lookupCallbackByCode should be non-null");
425420
assert(lookupCallbackByName && "lookupCallbackByName should be non-null");
426-
assert(ompt_get_task_data_fn && "ompt_get_task_data_fn should be non-null");
427-
assert(ompt_get_target_task_data_fn &&
428-
"ompt_get_target_task_data_fn should be non-null");
429421
assert(LibraryFinalizer == nullptr &&
430422
"LibraryFinalizer should not be initialized yet");
431423

@@ -442,7 +434,6 @@ void llvm::omp::target::ompt::finalizeLibrary(ompt_data_t *data) {
442434
// with this library
443435
LibraryFinalizer->finalize();
444436
delete LibraryFinalizer;
445-
Initialized = false;
446437
}
447438

448439
void llvm::omp::target::ompt::connectLibrary() {

openmp/libomptarget/src/OmptInterface.h

Lines changed: 2 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,15 @@
1313
#ifndef _OMPTARGET_OMPTINTERFACE_H
1414
#define _OMPTARGET_OMPTINTERFACE_H
1515

16-
#include <functional>
17-
#include <tuple>
18-
19-
#include "OmptCallback.h"
2016
#include "omp-tools.h"
2117

22-
#include "llvm/Support/ErrorHandling.h"
23-
2418
// If target OMPT support is compiled in
2519
#ifdef OMPT_SUPPORT
2620
#define OMPT_IF_BUILT(stmt) stmt
2721
#else
2822
#define OMPT_IF_BUILT(stmt)
2923
#endif
3024

31-
#define OMPT_GET_RETURN_ADDRESS(level) __builtin_return_address(level)
32-
3325
/// Callbacks for target regions require task_data representing the
3426
/// encountering task.
3527
/// Callbacks for target regions and target data ops require
@@ -116,66 +108,6 @@ class Interface {
116108
/// Top-level function for invoking callback after target construct
117109
void endTarget(int64_t DeviceId, void *Code);
118110

119-
// Callback getter: Target data operations
120-
template <ompt_target_data_op_t OpType> auto getCallbacks() {
121-
if constexpr (OpType == ompt_target_data_alloc ||
122-
OpType == ompt_target_data_alloc_async)
123-
return std::make_pair(std::mem_fn(&Interface::beginTargetDataAlloc),
124-
std::mem_fn(&Interface::endTargetDataAlloc));
125-
126-
if constexpr (OpType == ompt_target_data_delete ||
127-
OpType == ompt_target_data_delete_async)
128-
return std::make_pair(std::mem_fn(&Interface::beginTargetDataDelete),
129-
std::mem_fn(&Interface::endTargetDataDelete));
130-
131-
if constexpr (OpType == ompt_target_data_transfer_to_device ||
132-
OpType == ompt_target_data_transfer_to_device_async)
133-
return std::make_pair(std::mem_fn(&Interface::beginTargetDataSubmit),
134-
std::mem_fn(&Interface::endTargetDataSubmit));
135-
136-
if constexpr (OpType == ompt_target_data_transfer_from_device ||
137-
OpType == ompt_target_data_transfer_from_device_async)
138-
return std::make_pair(std::mem_fn(&Interface::beginTargetDataRetrieve),
139-
std::mem_fn(&Interface::endTargetDataRetrieve));
140-
141-
llvm_unreachable("Unhandled target data operation type!");
142-
}
143-
144-
// Callback getter: Target region operations
145-
template <ompt_target_t OpType> auto getCallbacks() {
146-
if constexpr (OpType == ompt_target_enter_data ||
147-
OpType == ompt_target_enter_data_nowait)
148-
return std::make_pair(std::mem_fn(&Interface::beginTargetDataEnter),
149-
std::mem_fn(&Interface::endTargetDataEnter));
150-
151-
if constexpr (OpType == ompt_target_exit_data ||
152-
OpType == ompt_target_exit_data_nowait)
153-
return std::make_pair(std::mem_fn(&Interface::beginTargetDataExit),
154-
std::mem_fn(&Interface::endTargetDataExit));
155-
156-
if constexpr (OpType == ompt_target_update ||
157-
OpType == ompt_target_update_nowait)
158-
return std::make_pair(std::mem_fn(&Interface::beginTargetUpdate),
159-
std::mem_fn(&Interface::endTargetUpdate));
160-
161-
if constexpr (OpType == ompt_target || OpType == ompt_target_nowait)
162-
return std::make_pair(std::mem_fn(&Interface::beginTarget),
163-
std::mem_fn(&Interface::endTarget));
164-
165-
llvm_unreachable("Unknown target region operation type!");
166-
}
167-
168-
// Callback getter: Kernel launch operation
169-
template <ompt_callbacks_t OpType> auto getCallbacks() {
170-
// We use 'ompt_callbacks_t', because no other enum is currently available
171-
// to model a kernel launch / target submit operation.
172-
if constexpr (OpType == ompt_callback_target_submit)
173-
return std::make_pair(std::mem_fn(&Interface::beginTargetSubmit),
174-
std::mem_fn(&Interface::endTargetSubmit));
175-
176-
llvm_unreachable("Unhandled target operation!");
177-
}
178-
179111
/// Setters for target region and target operation correlation ids
180112
void setTargetDataValue(uint64_t DataValue) { TargetData.value = DataValue; }
181113
void setTargetDataPtr(void *DataPtr) { TargetData.ptr = DataPtr; }
@@ -215,50 +147,11 @@ class Interface {
215147
void endTargetRegion();
216148
};
217149

218-
/// Thread local state for target region and associated metadata
219-
extern thread_local Interface RegionInterface;
220-
221-
template <typename FuncTy, typename ArgsTy, size_t... IndexSeq>
222-
void InvokeInterfaceFunction(FuncTy Func, ArgsTy Args,
223-
std::index_sequence<IndexSeq...>) {
224-
std::invoke(Func, RegionInterface, std::get<IndexSeq>(Args)...);
225-
}
226-
227-
template <typename CallbackPairTy, typename... ArgsTy> class InterfaceRAII {
228-
public:
229-
InterfaceRAII(CallbackPairTy Callbacks, ArgsTy... Args)
230-
: Arguments(Args...), beginFunction(std::get<0>(Callbacks)),
231-
endFunction(std::get<1>(Callbacks)) {
232-
performIfOmptInitialized(begin());
233-
}
234-
~InterfaceRAII() { performIfOmptInitialized(end()); }
235-
236-
private:
237-
void begin() {
238-
auto IndexSequence =
239-
std::make_index_sequence<std::tuple_size_v<decltype(Arguments)>>{};
240-
InvokeInterfaceFunction(beginFunction, Arguments, IndexSequence);
241-
}
242-
243-
void end() {
244-
auto IndexSequence =
245-
std::make_index_sequence<std::tuple_size_v<decltype(Arguments)>>{};
246-
InvokeInterfaceFunction(endFunction, Arguments, IndexSequence);
247-
}
248-
249-
std::tuple<ArgsTy...> Arguments;
250-
typename CallbackPairTy::first_type beginFunction;
251-
typename CallbackPairTy::second_type endFunction;
252-
};
253-
254-
// InterfaceRAII's class template argument deduction guide
255-
template <typename CallbackPairTy, typename... ArgsTy>
256-
InterfaceRAII(CallbackPairTy Callbacks, ArgsTy... Args)
257-
-> InterfaceRAII<CallbackPairTy, ArgsTy...>;
258-
259150
} // namespace ompt
260151
} // namespace target
261152
} // namespace omp
262153
} // namespace llvm
263154

155+
extern thread_local llvm::omp::target::ompt::Interface OmptInterface;
156+
264157
#endif // _OMPTARGET_OMPTINTERFACE_H

0 commit comments

Comments
 (0)