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