@@ -35,12 +35,20 @@ FOREACH_OMPT_NOEMI_EVENT(defineOmptCallback)
35
35
FOREACH_OMPT_EMI_EVENT(defineOmptCallback)
36
36
#undef defineOmptCallback
37
37
38
- // / Thread local state for target region and associated metadata
39
- thread_local llvm::omp::target::ompt::Interface OmptInterface ;
38
+ // / Forward declaration
39
+ class LibomptargetRtlFinalizer ;
40
40
41
- // / Define function pointers
42
- ompt_get_task_data_t ompt_get_task_data_fn = nullptr ;
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 ;
43
50
ompt_get_target_task_data_t ompt_get_target_task_data_fn = nullptr ;
51
+ ompt_get_task_data_t ompt_get_task_data_fn = nullptr ;
44
52
45
53
// / Unique correlation id
46
54
static std::atomic<uint64_t > IdCounter (1 );
@@ -51,14 +59,14 @@ static uint64_t createId() { return IdCounter.fetch_add(1); }
51
59
// / Create a new correlation id and update the operations id
52
60
static uint64_t createOpId () {
53
61
uint64_t NewId = createId ();
54
- OmptInterface .setHostOpId (NewId);
62
+ RegionInterface .setHostOpId (NewId);
55
63
return NewId;
56
64
}
57
65
58
66
// / Create a new correlation id and update the target region id
59
67
static uint64_t createRegionId () {
60
68
uint64_t NewId = createId ();
61
- OmptInterface .setTargetDataValue (NewId);
69
+ RegionInterface .setTargetDataValue (NewId);
62
70
return NewId;
63
71
}
64
72
@@ -68,18 +76,19 @@ void Interface::beginTargetDataAlloc(int64_t DeviceId, void *HstPtrBegin,
68
76
if (ompt_callback_target_data_op_emi_fn) {
69
77
// HostOpId will be set by the tool. Invoke the tool supplied data op EMI
70
78
// callback
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);
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);
76
84
} else if (ompt_callback_target_data_op_fn) {
77
85
// HostOpId is set by the runtime
78
86
HostOpId = createOpId ();
79
87
// Invoke the tool supplied data op callback
80
88
ompt_callback_target_data_op_fn (
81
89
TargetData.value , HostOpId, ompt_target_data_alloc, HstPtrBegin,
82
- DeviceId, /* TgtPtrBegin */ nullptr , /* TgtDeviceNum */ 0 , Size, Code);
90
+ /* SrcDeviceNum */ omp_get_initial_device (), /* TgtPtrBegin */ nullptr ,
91
+ /* TgtDeviceNum */ DeviceId, Size, Code);
83
92
}
84
93
}
85
94
@@ -89,11 +98,11 @@ void Interface::endTargetDataAlloc(int64_t DeviceId, void *HstPtrBegin,
89
98
if (ompt_callback_target_data_op_emi_fn) {
90
99
// HostOpId will be set by the tool. Invoke the tool supplied data op EMI
91
100
// callback
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);
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);
97
106
}
98
107
endTargetDataOperation ();
99
108
}
@@ -108,14 +117,16 @@ void Interface::beginTargetDataSubmit(int64_t DeviceId, void *TgtPtrBegin,
108
117
ompt_callback_target_data_op_emi_fn (
109
118
ompt_scope_begin, TargetTaskData, &TargetData, &TargetRegionOpId,
110
119
ompt_target_data_transfer_to_device, HstPtrBegin,
111
- /* SrcDeviceNum */ 0 , TgtPtrBegin, DeviceId, Size, Code);
120
+ /* SrcDeviceNum */ omp_get_initial_device (), TgtPtrBegin, DeviceId,
121
+ Size, Code);
112
122
} else if (ompt_callback_target_data_op_fn) {
113
123
// HostOpId is set by the runtime
114
124
HostOpId = createOpId ();
115
125
// Invoke the tool supplied data op callback
116
126
ompt_callback_target_data_op_fn (
117
127
TargetData.value , HostOpId, ompt_target_data_transfer_to_device,
118
- HstPtrBegin, /* SrcDeviceNum */ 0 , TgtPtrBegin, DeviceId, Size, Code);
128
+ HstPtrBegin, /* SrcDeviceNum */ omp_get_initial_device (), TgtPtrBegin,
129
+ DeviceId, Size, Code);
119
130
}
120
131
}
121
132
@@ -129,7 +140,8 @@ void Interface::endTargetDataSubmit(int64_t DeviceId, void *TgtPtrBegin,
129
140
ompt_callback_target_data_op_emi_fn (
130
141
ompt_scope_end, TargetTaskData, &TargetData, &TargetRegionOpId,
131
142
ompt_target_data_transfer_to_device, HstPtrBegin,
132
- /* SrcDeviceNum */ 0 , TgtPtrBegin, DeviceId, Size, Code);
143
+ /* SrcDeviceNum */ omp_get_initial_device (), TgtPtrBegin, DeviceId,
144
+ Size, Code);
133
145
}
134
146
endTargetDataOperation ();
135
147
}
@@ -143,15 +155,15 @@ void Interface::beginTargetDataDelete(int64_t DeviceId, void *TgtPtrBegin,
143
155
ompt_callback_target_data_op_emi_fn (
144
156
ompt_scope_begin, TargetTaskData, &TargetData, &TargetRegionOpId,
145
157
ompt_target_data_delete, TgtPtrBegin, DeviceId,
146
- /* TgtPtrBegin */ nullptr , /* TgtDeviceNum */ 0 , /* Bytes */ 0 , Code);
158
+ /* TgtPtrBegin */ nullptr , /* TgtDeviceNum */ - 1 , /* Bytes */ 0 , Code);
147
159
} else if (ompt_callback_target_data_op_fn) {
148
160
// HostOpId is set by the runtime
149
161
HostOpId = createOpId ();
150
162
// Invoke the tool supplied data op callback
151
163
ompt_callback_target_data_op_fn (TargetData.value , HostOpId,
152
164
ompt_target_data_delete, TgtPtrBegin,
153
165
DeviceId, /* TgtPtrBegin */ nullptr ,
154
- /* TgtDeviceNum */ 0 , /* Bytes */ 0 , Code);
166
+ /* TgtDeviceNum */ - 1 , /* Bytes */ 0 , Code);
155
167
}
156
168
}
157
169
@@ -164,7 +176,7 @@ void Interface::endTargetDataDelete(int64_t DeviceId, void *TgtPtrBegin,
164
176
ompt_callback_target_data_op_emi_fn (
165
177
ompt_scope_end, TargetTaskData, &TargetData, &TargetRegionOpId,
166
178
ompt_target_data_delete, TgtPtrBegin, DeviceId,
167
- /* TgtPtrBegin */ nullptr , /* TgtDeviceNum */ 0 , /* Bytes */ 0 , Code);
179
+ /* TgtPtrBegin */ nullptr , /* TgtDeviceNum */ - 1 , /* Bytes */ 0 , Code);
168
180
}
169
181
endTargetDataOperation ();
170
182
}
@@ -176,19 +188,19 @@ void Interface::beginTargetDataRetrieve(int64_t DeviceId, void *HstPtrBegin,
176
188
if (ompt_callback_target_data_op_emi_fn) {
177
189
// HostOpId will be set by the tool. Invoke the tool supplied data op EMI
178
190
// callback
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);
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);
184
196
} else if (ompt_callback_target_data_op_fn) {
185
197
// HostOpId is set by the runtime
186
198
HostOpId = createOpId ();
187
199
// Invoke the tool supplied data op callback
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);
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);
192
204
}
193
205
}
194
206
@@ -199,11 +211,11 @@ void Interface::endTargetDataRetrieve(int64_t DeviceId, void *HstPtrBegin,
199
211
if (ompt_callback_target_data_op_emi_fn) {
200
212
// HostOpId will be set by the tool. Invoke the tool supplied data op EMI
201
213
// callback
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);
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);
207
219
}
208
220
endTargetDataOperation ();
209
221
}
@@ -230,6 +242,7 @@ void Interface::endTargetSubmit(unsigned int numTeams) {
230
242
numTeams);
231
243
}
232
244
}
245
+
233
246
void Interface::beginTargetDataEnter (int64_t DeviceId, void *Code) {
234
247
beginTargetRegion ();
235
248
if (ompt_callback_target_emi_fn) {
@@ -391,14 +404,6 @@ class LibomptargetRtlFinalizer {
391
404
llvm::SmallVector<ompt_finalize_t > RtlFinalizationFunctions;
392
405
};
393
406
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
-
402
407
int llvm::omp::target::ompt::initializeLibrary (ompt_function_lookup_t lookup,
403
408
int initial_device_num,
404
409
ompt_data_t *tool_data) {
@@ -418,6 +423,9 @@ int llvm::omp::target::ompt::initializeLibrary(ompt_function_lookup_t lookup,
418
423
419
424
assert (lookupCallbackByCode && " lookupCallbackByCode should be non-null" );
420
425
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" );
421
429
assert (LibraryFinalizer == nullptr &&
422
430
" LibraryFinalizer should not be initialized yet" );
423
431
@@ -434,6 +442,7 @@ void llvm::omp::target::ompt::finalizeLibrary(ompt_data_t *data) {
434
442
// with this library
435
443
LibraryFinalizer->finalize ();
436
444
delete LibraryFinalizer;
445
+ Initialized = false ;
437
446
}
438
447
439
448
void llvm::omp::target::ompt::connectLibrary () {
0 commit comments