aboutsummaryrefslogtreecommitdiff
path: root/openmp/tools/omptest/include/InternalEvent.h
blob: 743fad99ff4a067271069b6ef0c34aa732b0bea6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
//===- InternalEvent.h - Internal event representation ----------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
///
/// \file
/// Declares internal event representations along the default CTOR definition.
///
//===----------------------------------------------------------------------===//

#ifndef OPENMP_TOOLS_OMPTEST_INCLUDE_INTERNALEVENT_H
#define OPENMP_TOOLS_OMPTEST_INCLUDE_INTERNALEVENT_H

#include "InternalEventCommon.h"

#include <cstring>
#include <limits>
#include <omp-tools.h>

#define expectedDefault(TypeName) std::numeric_limits<TypeName>::min()

namespace omptest {

namespace util {

/// String manipulation helper function. Takes up to 8 bytes of data and returns
/// their hexadecimal representation as string. The data can be expanded to the
/// given size in bytes and will by default be prefixed with '0x'.
std::string makeHexString(uint64_t Data, bool IsPointer = true,
                          size_t DataBytes = 0, bool ShowHexBase = true);

} // namespace util

namespace internal {
struct AssertionSyncPoint : public EventBase<AssertionSyncPoint> {
  std::string toString() const override;
  AssertionSyncPoint(const std::string &Name) : Name(Name) {}
  const std::string Name;
};

struct AssertionSuspend : public EventBase<AssertionSuspend> {
  AssertionSuspend() = default;
};

struct ThreadBegin : public EventBase<ThreadBegin> {
  std::string toString() const override;
  ThreadBegin(ompt_thread_t ThreadType) : ThreadType(ThreadType) {}
  ompt_thread_t ThreadType;
};

struct ThreadEnd : public EventBase<ThreadEnd> {
  std::string toString() const override;
  ThreadEnd() = default;
};

struct ParallelBegin : public EventBase<ParallelBegin> {
  std::string toString() const override;
  ParallelBegin(int NumThreads) : NumThreads(NumThreads) {}
  unsigned int NumThreads;
};

struct ParallelEnd : public EventBase<ParallelEnd> {
  std::string toString() const override;
  ParallelEnd(ompt_data_t *ParallelData, ompt_data_t *EncounteringTaskData,
              int Flags, const void *CodeptrRA)
      : ParallelData(ParallelData), EncounteringTaskData(EncounteringTaskData),
        Flags(Flags), CodeptrRA(CodeptrRA) {}
  ompt_data_t *ParallelData;
  ompt_data_t *EncounteringTaskData;
  int Flags;
  const void *CodeptrRA;
};

struct Work : public EventBase<Work> {
  std::string toString() const override;
  Work(ompt_work_t WorkType, ompt_scope_endpoint_t Endpoint,
       ompt_data_t *ParallelData, ompt_data_t *TaskData, uint64_t Count,
       const void *CodeptrRA)
      : WorkType(WorkType), Endpoint(Endpoint), ParallelData(ParallelData),
        TaskData(TaskData), Count(Count), CodeptrRA(CodeptrRA) {}
  ompt_work_t WorkType;
  ompt_scope_endpoint_t Endpoint;
  ompt_data_t *ParallelData;
  ompt_data_t *TaskData;
  uint64_t Count;
  const void *CodeptrRA;
};

struct Dispatch : public EventBase<Dispatch> {
  std::string toString() const override;
  Dispatch(ompt_data_t *ParallelData, ompt_data_t *TaskData,
           ompt_dispatch_t Kind, ompt_data_t Instance)
      : ParallelData(ParallelData), TaskData(TaskData), Kind(Kind),
        Instance(Instance) {}
  ompt_data_t *ParallelData;
  ompt_data_t *TaskData;
  ompt_dispatch_t Kind;
  ompt_data_t Instance;
};

struct TaskCreate : public EventBase<TaskCreate> {
  std::string toString() const override;
  TaskCreate(ompt_data_t *EncounteringTaskData,
             const ompt_frame_t *EncounteringTaskFrame,
             ompt_data_t *NewTaskData, int Flags, int HasDependences,
             const void *CodeptrRA)
      : EncounteringTaskData(EncounteringTaskData),
        EncounteringTaskFrame(EncounteringTaskFrame), NewTaskData(NewTaskData),
        Flags(Flags), HasDependences(HasDependences), CodeptrRA(CodeptrRA) {}
  ompt_data_t *EncounteringTaskData;
  const ompt_frame_t *EncounteringTaskFrame;
  ompt_data_t *NewTaskData;
  int Flags;
  int HasDependences;
  const void *CodeptrRA;
};

struct Dependences : public EventBase<Dependences> {
  Dependences() = default;
};

struct TaskDependence : public EventBase<TaskDependence> {
  TaskDependence() = default;
};

struct TaskSchedule : public EventBase<TaskSchedule> {
  TaskSchedule() = default;
};

struct ImplicitTask : public EventBase<ImplicitTask> {
  std::string toString() const override;
  ImplicitTask(ompt_scope_endpoint_t Endpoint, ompt_data_t *ParallelData,
               ompt_data_t *TaskData, unsigned int ActualParallelism,
               unsigned int Index, int Flags)
      : Endpoint(Endpoint), ParallelData(ParallelData), TaskData(TaskData),
        ActualParallelism(ActualParallelism), Index(Index), Flags(Flags) {}
  ompt_scope_endpoint_t Endpoint;
  ompt_data_t *ParallelData;
  ompt_data_t *TaskData;
  unsigned int ActualParallelism;
  unsigned int Index;
  int Flags;
};

struct Masked : public EventBase<Masked> {
  Masked() = default;
};

struct SyncRegion : public EventBase<SyncRegion> {
  std::string toString() const override;
  SyncRegion(ompt_sync_region_t Kind, ompt_scope_endpoint_t Endpoint,
             ompt_data_t *ParallelData, ompt_data_t *TaskData,
             const void *CodeptrRA)
      : Kind(Kind), Endpoint(Endpoint), ParallelData(ParallelData),
        TaskData(TaskData), CodeptrRA(CodeptrRA) {}
  ompt_sync_region_t Kind;
  ompt_scope_endpoint_t Endpoint;
  ompt_data_t *ParallelData;
  ompt_data_t *TaskData;
  const void *CodeptrRA;
};

struct MutexAcquire : public EventBase<MutexAcquire> {
  MutexAcquire() = default;
};

struct Mutex : public EventBase<Mutex> {
  Mutex() = default;
};

struct NestLock : public EventBase<NestLock> {
  NestLock() = default;
};

struct Flush : public EventBase<Flush> {
  Flush() = default;
};

struct Cancel : public EventBase<Cancel> {
  Cancel() = default;
};

struct Target : public EventBase<Target> {
  std::string toString() const override;
  Target(ompt_target_t Kind, ompt_scope_endpoint_t Endpoint, int DeviceNum,
         ompt_data_t *TaskData, ompt_id_t TargetId, const void *CodeptrRA)
      : Kind(Kind), Endpoint(Endpoint), DeviceNum(DeviceNum),
        TaskData(TaskData), TargetId(TargetId), CodeptrRA(CodeptrRA) {}
  ompt_target_t Kind;
  ompt_scope_endpoint_t Endpoint;
  int DeviceNum;
  ompt_data_t *TaskData;
  ompt_id_t TargetId;
  const void *CodeptrRA;
};

struct TargetEmi : public EventBase<TargetEmi> {
  std::string toString() const override;
  TargetEmi(ompt_target_t Kind, ompt_scope_endpoint_t Endpoint, int DeviceNum,
            ompt_data_t *TaskData, ompt_data_t *TargetTaskData,
            ompt_data_t *TargetData, const void *CodeptrRA)
      : Kind(Kind), Endpoint(Endpoint), DeviceNum(DeviceNum),
        TaskData(TaskData), TargetTaskData(TargetTaskData),
        TargetData(TargetData), CodeptrRA(CodeptrRA) {}
  ompt_target_t Kind;
  ompt_scope_endpoint_t Endpoint;
  int DeviceNum;
  ompt_data_t *TaskData;
  ompt_data_t *TargetTaskData;
  ompt_data_t *TargetData;
  const void *CodeptrRA;
};

struct TargetDataOp : public EventBase<TargetDataOp> {
  std::string toString() const override;
  TargetDataOp(ompt_id_t TargetId, ompt_id_t HostOpId,
               ompt_target_data_op_t OpType, void *SrcAddr, int SrcDeviceNum,
               void *DstAddr, int DstDeviceNum, size_t Bytes,
               const void *CodeptrRA)
      : TargetId(TargetId), HostOpId(HostOpId), OpType(OpType),
        SrcAddr(SrcAddr), SrcDeviceNum(SrcDeviceNum), DstAddr(DstAddr),
        DstDeviceNum(DstDeviceNum), Bytes(Bytes), CodeptrRA(CodeptrRA) {}
  ompt_id_t TargetId;
  ompt_id_t HostOpId;
  ompt_target_data_op_t OpType;
  void *SrcAddr;
  int SrcDeviceNum;
  void *DstAddr;
  int DstDeviceNum;
  size_t Bytes;
  const void *CodeptrRA;
};

struct TargetDataOpEmi : public EventBase<TargetDataOpEmi> {
  std::string toString() const override;
  TargetDataOpEmi(ompt_scope_endpoint_t Endpoint, ompt_data_t *TargetTaskData,
                  ompt_data_t *TargetData, ompt_id_t *HostOpId,
                  ompt_target_data_op_t OpType, void *SrcAddr, int SrcDeviceNum,
                  void *DstAddr, int DstDeviceNum, size_t Bytes,
                  const void *CodeptrRA)
      : Endpoint(Endpoint), TargetTaskData(TargetTaskData),
        TargetData(TargetData), HostOpId(HostOpId), OpType(OpType),
        SrcAddr(SrcAddr), SrcDeviceNum(SrcDeviceNum), DstAddr(DstAddr),
        DstDeviceNum(DstDeviceNum), Bytes(Bytes), CodeptrRA(CodeptrRA) {}
  ompt_scope_endpoint_t Endpoint;
  ompt_data_t *TargetTaskData;
  ompt_data_t *TargetData;
  ompt_id_t *HostOpId;
  ompt_target_data_op_t OpType;
  void *SrcAddr;
  int SrcDeviceNum;
  void *DstAddr;
  int DstDeviceNum;
  size_t Bytes;
  const void *CodeptrRA;
};

struct TargetSubmit : public EventBase<TargetSubmit> {
  std::string toString() const override;
  TargetSubmit(ompt_id_t TargetId, ompt_id_t HostOpId,
               unsigned int RequestedNumTeams)
      : TargetId(TargetId), HostOpId(HostOpId),
        RequestedNumTeams(RequestedNumTeams) {}
  ompt_id_t TargetId;
  ompt_id_t HostOpId;
  unsigned int RequestedNumTeams;
};

struct TargetSubmitEmi : public EventBase<TargetSubmitEmi> {
  std::string toString() const override;
  TargetSubmitEmi(ompt_scope_endpoint_t Endpoint, ompt_data_t *TargetData,
                  ompt_id_t *HostOpId, unsigned int RequestedNumTeams)
      : Endpoint(Endpoint), TargetData(TargetData), HostOpId(HostOpId),
        RequestedNumTeams(RequestedNumTeams) {}
  ompt_scope_endpoint_t Endpoint;
  ompt_data_t *TargetData;
  ompt_id_t *HostOpId;
  unsigned int RequestedNumTeams;
};

struct ControlTool : public EventBase<ControlTool> {
  ControlTool() = default;
};

struct DeviceInitialize : public EventBase<DeviceInitialize> {
  std::string toString() const override;
  DeviceInitialize(int DeviceNum, const char *Type, ompt_device_t *Device,
                   ompt_function_lookup_t LookupFn, const char *DocStr)
      : DeviceNum(DeviceNum), Type(Type), Device(Device), LookupFn(LookupFn),
        DocStr(DocStr) {}
  int DeviceNum;
  const char *Type;
  ompt_device_t *Device;
  ompt_function_lookup_t LookupFn;
  const char *DocStr;
};

struct DeviceFinalize : public EventBase<DeviceFinalize> {
  std::string toString() const override;
  DeviceFinalize(int DeviceNum) : DeviceNum(DeviceNum) {}
  int DeviceNum;
};

struct DeviceLoad : public EventBase<DeviceLoad> {
  std::string toString() const override;
  DeviceLoad(int DeviceNum, const char *Filename, int64_t OffsetInFile,
             void *VmaInFile, size_t Bytes, void *HostAddr, void *DeviceAddr,
             uint64_t ModuleId)
      : DeviceNum(DeviceNum), Filename(Filename), OffsetInFile(OffsetInFile),
        VmaInFile(VmaInFile), Bytes(Bytes), HostAddr(HostAddr),
        DeviceAddr(DeviceAddr), ModuleId(ModuleId) {}
  int DeviceNum;
  const char *Filename;
  int64_t OffsetInFile;
  void *VmaInFile;
  size_t Bytes;
  void *HostAddr;
  void *DeviceAddr;
  uint64_t ModuleId;
};

struct DeviceUnload : public EventBase<DeviceUnload> {
  DeviceUnload() = default;
};

struct BufferRequest : public EventBase<BufferRequest> {
  std::string toString() const override;
  BufferRequest(int DeviceNum, ompt_buffer_t **Buffer, size_t *Bytes)
      : DeviceNum(DeviceNum), Buffer(Buffer), Bytes(Bytes) {}
  int DeviceNum;
  ompt_buffer_t **Buffer;
  size_t *Bytes;
};

struct BufferComplete : public EventBase<BufferComplete> {
  std::string toString() const override;
  BufferComplete(int DeviceNum, ompt_buffer_t *Buffer, size_t Bytes,
                 ompt_buffer_cursor_t Begin, int BufferOwned)
      : DeviceNum(DeviceNum), Buffer(Buffer), Bytes(Bytes), Begin(Begin),
        BufferOwned(BufferOwned) {}
  int DeviceNum;
  ompt_buffer_t *Buffer;
  size_t Bytes;
  ompt_buffer_cursor_t Begin;
  int BufferOwned;
};

struct BufferRecord : public EventBase<BufferRecord> {
  std::string toString() const override;
  BufferRecord(ompt_record_ompt_t *RecordPtr) : RecordPtr(RecordPtr) {
    if (RecordPtr != nullptr)
      Record = *RecordPtr;
    else
      memset(&Record, 0, sizeof(ompt_record_ompt_t));
  }
  ompt_record_ompt_t Record;
  ompt_record_ompt_t *RecordPtr;
};

struct BufferRecordDeallocation : public EventBase<BufferRecordDeallocation> {
  std::string toString() const override;
  BufferRecordDeallocation(ompt_buffer_t *Buffer) : Buffer(Buffer) {}
  ompt_buffer_t *Buffer;
};

// Add specialized event equality operators here.
// Note: Placement of these forward declarations is important as they need to
// take precedence over the following default equality operator definition.
bool operator==(const ParallelBegin &, const ParallelBegin &);
bool operator==(const Work &, const Work &);
bool operator==(const Dispatch &, const Dispatch &);
bool operator==(const ImplicitTask &, const ImplicitTask &);
bool operator==(const SyncRegion &, const SyncRegion &);
bool operator==(const Target &, const Target &);
bool operator==(const TargetEmi &, const TargetEmi &);
bool operator==(const TargetDataOp &, const TargetDataOp &);
bool operator==(const TargetDataOpEmi &, const TargetDataOpEmi &);
bool operator==(const TargetSubmit &, const TargetSubmit &);
bool operator==(const TargetSubmitEmi &, const TargetSubmitEmi &);
bool operator==(const DeviceInitialize &, const DeviceInitialize &);
bool operator==(const DeviceFinalize &, const DeviceFinalize &);
bool operator==(const DeviceLoad &, const DeviceLoad &);
bool operator==(const BufferRequest &, const BufferRequest &);
bool operator==(const BufferComplete &, const BufferComplete &);
bool operator==(const BufferRecord &, const BufferRecord &);

/// Default (fallback) event equality operator definition.
template <typename Event> bool operator==(const Event &, const Event &) {
  return true;
}

// clang-format off
event_type_trait(AssertionSyncPoint)
event_type_trait(AssertionSuspend)
event_type_trait(ThreadBegin)
event_type_trait(ThreadEnd)
event_type_trait(ParallelBegin)
event_type_trait(ParallelEnd)
event_type_trait(Work)
event_type_trait(Dispatch)
event_type_trait(TaskCreate)
event_type_trait(Dependences)
event_type_trait(TaskDependence)
event_type_trait(TaskSchedule)
event_type_trait(ImplicitTask)
event_type_trait(Masked)
event_type_trait(SyncRegion)
event_type_trait(MutexAcquire)
event_type_trait(Mutex)
event_type_trait(NestLock)
event_type_trait(Flush)
event_type_trait(Cancel)
event_type_trait(Target)
event_type_trait(TargetEmi)
event_type_trait(TargetDataOp)
event_type_trait(TargetDataOpEmi)
event_type_trait(TargetSubmit)
event_type_trait(TargetSubmitEmi)
event_type_trait(ControlTool)
event_type_trait(DeviceInitialize)
event_type_trait(DeviceFinalize)
event_type_trait(DeviceLoad)
event_type_trait(DeviceUnload)
event_type_trait(BufferRequest)
event_type_trait(BufferComplete)
event_type_trait(BufferRecord)
event_type_trait(BufferRecordDeallocation)
// clang-format on

} // namespace internal

} // namespace omptest

#endif