| 1 |
//===- InternalEvent.h - Internal event representation ----------*- C++ -*-===// |
| 2 |
// |
| 3 |
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 |
// See https://llvm.org/LICENSE.txt for license information. |
| 5 |
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 |
// |
| 7 |
//===----------------------------------------------------------------------===// |
| 8 |
/// |
| 9 |
/// \file |
| 10 |
/// Declares internal event representations along the default CTOR definition. |
| 11 |
/// |
| 12 |
//===----------------------------------------------------------------------===// |
| 13 |
|
| 14 |
#ifndef OPENMP_TOOLS_OMPTEST_INCLUDE_INTERNALEVENT_H |
| 15 |
#define OPENMP_TOOLS_OMPTEST_INCLUDE_INTERNALEVENT_H |
| 16 |
|
| 17 |
#include "InternalEventCommon.h" |
| 18 |
|
| 19 |
#include <cstring> |
| 20 |
#include <limits> |
| 21 |
#include <omp-tools.h> |
| 22 |
|
| 23 |
#define expectedDefault(TypeName) std::numeric_limits<TypeName>::min() |
| 24 |
|
| 25 |
namespace omptest { |
| 26 |
|
| 27 |
namespace util { |
| 28 |
|
| 29 |
/// String manipulation helper function. Takes up to 8 bytes of data and returns |
| 30 |
/// their hexadecimal representation as string. The data can be expanded to the |
| 31 |
/// given size in bytes and will by default be prefixed with '0x'. |
| 32 |
std::string makeHexString(uint64_t Data, bool IsPointer = true, |
| 33 |
size_t DataBytes = 0, bool ShowHexBase = true); |
| 34 |
|
| 35 |
} // namespace util |
| 36 |
|
| 37 |
namespace internal { |
| 38 |
struct AssertionSyncPoint : public EventBase<AssertionSyncPoint> { |
| 39 |
std::string toString() const override; |
| 40 |
AssertionSyncPoint(const std::string &Name) : Name(Name) {} |
| 41 |
const std::string Name; |
| 42 |
}; |
| 43 |
|
| 44 |
struct AssertionSuspend : public EventBase<AssertionSuspend> { |
| 45 |
AssertionSuspend() = default; |
| 46 |
}; |
| 47 |
|
| 48 |
struct ThreadBegin : public EventBase<ThreadBegin> { |
| 49 |
std::string toString() const override; |
| 50 |
ThreadBegin(ompt_thread_t ThreadType) : ThreadType(ThreadType) {} |
| 51 |
ompt_thread_t ThreadType; |
| 52 |
}; |
| 53 |
|
| 54 |
struct ThreadEnd : public EventBase<ThreadEnd> { |
| 55 |
std::string toString() const override; |
| 56 |
ThreadEnd() = default; |
| 57 |
}; |
| 58 |
|
| 59 |
struct ParallelBegin : public EventBase<ParallelBegin> { |
| 60 |
std::string toString() const override; |
| 61 |
ParallelBegin(int NumThreads) : NumThreads(NumThreads) {} |
| 62 |
unsigned int NumThreads; |
| 63 |
}; |
| 64 |
|
| 65 |
struct ParallelEnd : public EventBase<ParallelEnd> { |
| 66 |
std::string toString() const override; |
| 67 |
ParallelEnd(ompt_data_t *ParallelData, ompt_data_t *EncounteringTaskData, |
| 68 |
int Flags, const void *CodeptrRA) |
| 69 |
: ParallelData(ParallelData), EncounteringTaskData(EncounteringTaskData), |
| 70 |
Flags(Flags), CodeptrRA(CodeptrRA) {} |
| 71 |
ompt_data_t *ParallelData; |
| 72 |
ompt_data_t *EncounteringTaskData; |
| 73 |
int Flags; |
| 74 |
const void *CodeptrRA; |
| 75 |
}; |
| 76 |
|
| 77 |
struct Work : public EventBase<Work> { |
| 78 |
std::string toString() const override; |
| 79 |
Work(ompt_work_t WorkType, ompt_scope_endpoint_t Endpoint, |
| 80 |
ompt_data_t *ParallelData, ompt_data_t *TaskData, uint64_t Count, |
| 81 |
const void *CodeptrRA) |
| 82 |
: WorkType(WorkType), Endpoint(Endpoint), ParallelData(ParallelData), |
| 83 |
TaskData(TaskData), Count(Count), CodeptrRA(CodeptrRA) {} |
| 84 |
ompt_work_t WorkType; |
| 85 |
ompt_scope_endpoint_t Endpoint; |
| 86 |
ompt_data_t *ParallelData; |
| 87 |
ompt_data_t *TaskData; |
| 88 |
uint64_t Count; |
| 89 |
const void *CodeptrRA; |
| 90 |
}; |
| 91 |
|
| 92 |
struct Dispatch : public EventBase<Dispatch> { |
| 93 |
std::string toString() const override; |
| 94 |
Dispatch(ompt_data_t *ParallelData, ompt_data_t *TaskData, |
| 95 |
ompt_dispatch_t Kind, ompt_data_t Instance) |
| 96 |
: ParallelData(ParallelData), TaskData(TaskData), Kind(Kind), |
| 97 |
Instance(Instance) {} |
| 98 |
ompt_data_t *ParallelData; |
| 99 |
ompt_data_t *TaskData; |
| 100 |
ompt_dispatch_t Kind; |
| 101 |
ompt_data_t Instance; |
| 102 |
}; |
| 103 |
|
| 104 |
struct TaskCreate : public EventBase<TaskCreate> { |
| 105 |
std::string toString() const override; |
| 106 |
TaskCreate(ompt_data_t *EncounteringTaskData, |
| 107 |
const ompt_frame_t *EncounteringTaskFrame, |
| 108 |
ompt_data_t *NewTaskData, int Flags, int HasDependences, |
| 109 |
const void *CodeptrRA) |
| 110 |
: EncounteringTaskData(EncounteringTaskData), |
| 111 |
EncounteringTaskFrame(EncounteringTaskFrame), NewTaskData(NewTaskData), |
| 112 |
Flags(Flags), HasDependences(HasDependences), CodeptrRA(CodeptrRA) {} |
| 113 |
ompt_data_t *EncounteringTaskData; |
| 114 |
const ompt_frame_t *EncounteringTaskFrame; |
| 115 |
ompt_data_t *NewTaskData; |
| 116 |
int Flags; |
| 117 |
int HasDependences; |
| 118 |
const void *CodeptrRA; |
| 119 |
}; |
| 120 |
|
| 121 |
struct Dependences : public EventBase<Dependences> { |
| 122 |
Dependences() = default; |
| 123 |
}; |
| 124 |
|
| 125 |
struct TaskDependence : public EventBase<TaskDependence> { |
| 126 |
TaskDependence() = default; |
| 127 |
}; |
| 128 |
|
| 129 |
struct TaskSchedule : public EventBase<TaskSchedule> { |
| 130 |
TaskSchedule() = default; |
| 131 |
}; |
| 132 |
|
| 133 |
struct ImplicitTask : public EventBase<ImplicitTask> { |
| 134 |
std::string toString() const override; |
| 135 |
ImplicitTask(ompt_scope_endpoint_t Endpoint, ompt_data_t *ParallelData, |
| 136 |
ompt_data_t *TaskData, unsigned int ActualParallelism, |
| 137 |
unsigned int Index, int Flags) |
| 138 |
: Endpoint(Endpoint), ParallelData(ParallelData), TaskData(TaskData), |
| 139 |
ActualParallelism(ActualParallelism), Index(Index), Flags(Flags) {} |
| 140 |
ompt_scope_endpoint_t Endpoint; |
| 141 |
ompt_data_t *ParallelData; |
| 142 |
ompt_data_t *TaskData; |
| 143 |
unsigned int ActualParallelism; |
| 144 |
unsigned int Index; |
| 145 |
int Flags; |
| 146 |
}; |
| 147 |
|
| 148 |
struct Masked : public EventBase<Masked> { |
| 149 |
Masked() = default; |
| 150 |
}; |
| 151 |
|
| 152 |
struct SyncRegion : public EventBase<SyncRegion> { |
| 153 |
std::string toString() const override; |
| 154 |
SyncRegion(ompt_sync_region_t Kind, ompt_scope_endpoint_t Endpoint, |
| 155 |
ompt_data_t *ParallelData, ompt_data_t *TaskData, |
| 156 |
const void *CodeptrRA) |
| 157 |
: Kind(Kind), Endpoint(Endpoint), ParallelData(ParallelData), |
| 158 |
TaskData(TaskData), CodeptrRA(CodeptrRA) {} |
| 159 |
ompt_sync_region_t Kind; |
| 160 |
ompt_scope_endpoint_t Endpoint; |
| 161 |
ompt_data_t *ParallelData; |
| 162 |
ompt_data_t *TaskData; |
| 163 |
const void *CodeptrRA; |
| 164 |
}; |
| 165 |
|
| 166 |
struct MutexAcquire : public EventBase<MutexAcquire> { |
| 167 |
MutexAcquire() = default; |
| 168 |
}; |
| 169 |
|
| 170 |
struct Mutex : public EventBase<Mutex> { |
| 171 |
Mutex() = default; |
| 172 |
}; |
| 173 |
|
| 174 |
struct NestLock : public EventBase<NestLock> { |
| 175 |
NestLock() = default; |
| 176 |
}; |
| 177 |
|
| 178 |
struct Flush : public EventBase<Flush> { |
| 179 |
Flush() = default; |
| 180 |
}; |
| 181 |
|
| 182 |
struct Cancel : public EventBase<Cancel> { |
| 183 |
Cancel() = default; |
| 184 |
}; |
| 185 |
|
| 186 |
struct Target : public EventBase<Target> { |
| 187 |
std::string toString() const override; |
| 188 |
Target(ompt_target_t Kind, ompt_scope_endpoint_t Endpoint, int DeviceNum, |
| 189 |
ompt_data_t *TaskData, ompt_id_t TargetId, const void *CodeptrRA) |
| 190 |
: Kind(Kind), Endpoint(Endpoint), DeviceNum(DeviceNum), |
| 191 |
TaskData(TaskData), TargetId(TargetId), CodeptrRA(CodeptrRA) {} |
| 192 |
ompt_target_t Kind; |
| 193 |
ompt_scope_endpoint_t Endpoint; |
| 194 |
int DeviceNum; |
| 195 |
ompt_data_t *TaskData; |
| 196 |
ompt_id_t TargetId; |
| 197 |
const void *CodeptrRA; |
| 198 |
}; |
| 199 |
|
| 200 |
struct TargetEmi : public EventBase<TargetEmi> { |
| 201 |
std::string toString() const override; |
| 202 |
TargetEmi(ompt_target_t Kind, ompt_scope_endpoint_t Endpoint, int DeviceNum, |
| 203 |
ompt_data_t *TaskData, ompt_data_t *TargetTaskData, |
| 204 |
ompt_data_t *TargetData, const void *CodeptrRA) |
| 205 |
: Kind(Kind), Endpoint(Endpoint), DeviceNum(DeviceNum), |
| 206 |
TaskData(TaskData), TargetTaskData(TargetTaskData), |
| 207 |
TargetData(TargetData), CodeptrRA(CodeptrRA) {} |
| 208 |
ompt_target_t Kind; |
| 209 |
ompt_scope_endpoint_t Endpoint; |
| 210 |
int DeviceNum; |
| 211 |
ompt_data_t *TaskData; |
| 212 |
ompt_data_t *TargetTaskData; |
| 213 |
ompt_data_t *TargetData; |
| 214 |
const void *CodeptrRA; |
| 215 |
}; |
| 216 |
|
| 217 |
struct TargetDataOp : public EventBase<TargetDataOp> { |
| 218 |
std::string toString() const override; |
| 219 |
TargetDataOp(ompt_id_t TargetId, ompt_id_t HostOpId, |
| 220 |
ompt_target_data_op_t OpType, void *SrcAddr, int SrcDeviceNum, |
| 221 |
void *DstAddr, int DstDeviceNum, size_t Bytes, |
| 222 |
const void *CodeptrRA) |
| 223 |
: TargetId(TargetId), HostOpId(HostOpId), OpType(OpType), |
| 224 |
SrcAddr(SrcAddr), SrcDeviceNum(SrcDeviceNum), DstAddr(DstAddr), |
| 225 |
DstDeviceNum(DstDeviceNum), Bytes(Bytes), CodeptrRA(CodeptrRA) {} |
| 226 |
ompt_id_t TargetId; |
| 227 |
ompt_id_t HostOpId; |
| 228 |
ompt_target_data_op_t OpType; |
| 229 |
void *SrcAddr; |
| 230 |
int SrcDeviceNum; |
| 231 |
void *DstAddr; |
| 232 |
int DstDeviceNum; |
| 233 |
size_t Bytes; |
| 234 |
const void *CodeptrRA; |
| 235 |
}; |
| 236 |
|
| 237 |
struct TargetDataOpEmi : public EventBase<TargetDataOpEmi> { |
| 238 |
std::string toString() const override; |
| 239 |
TargetDataOpEmi(ompt_scope_endpoint_t Endpoint, ompt_data_t *TargetTaskData, |
| 240 |
ompt_data_t *TargetData, ompt_id_t *HostOpId, |
| 241 |
ompt_target_data_op_t OpType, void *SrcAddr, int SrcDeviceNum, |
| 242 |
void *DstAddr, int DstDeviceNum, size_t Bytes, |
| 243 |
const void *CodeptrRA) |
| 244 |
: Endpoint(Endpoint), TargetTaskData(TargetTaskData), |
| 245 |
TargetData(TargetData), HostOpId(HostOpId), OpType(OpType), |
| 246 |
SrcAddr(SrcAddr), SrcDeviceNum(SrcDeviceNum), DstAddr(DstAddr), |
| 247 |
DstDeviceNum(DstDeviceNum), Bytes(Bytes), CodeptrRA(CodeptrRA) {} |
| 248 |
ompt_scope_endpoint_t Endpoint; |
| 249 |
ompt_data_t *TargetTaskData; |
| 250 |
ompt_data_t *TargetData; |
| 251 |
ompt_id_t *HostOpId; |
| 252 |
ompt_target_data_op_t OpType; |
| 253 |
void *SrcAddr; |
| 254 |
int SrcDeviceNum; |
| 255 |
void *DstAddr; |
| 256 |
int DstDeviceNum; |
| 257 |
size_t Bytes; |
| 258 |
const void *CodeptrRA; |
| 259 |
}; |
| 260 |
|
| 261 |
struct TargetSubmit : public EventBase<TargetSubmit> { |
| 262 |
std::string toString() const override; |
| 263 |
TargetSubmit(ompt_id_t TargetId, ompt_id_t HostOpId, |
| 264 |
unsigned int RequestedNumTeams) |
| 265 |
: TargetId(TargetId), HostOpId(HostOpId), |
| 266 |
RequestedNumTeams(RequestedNumTeams) {} |
| 267 |
ompt_id_t TargetId; |
| 268 |
ompt_id_t HostOpId; |
| 269 |
unsigned int RequestedNumTeams; |
| 270 |
}; |
| 271 |
|
| 272 |
struct TargetSubmitEmi : public EventBase<TargetSubmitEmi> { |
| 273 |
std::string toString() const override; |
| 274 |
TargetSubmitEmi(ompt_scope_endpoint_t Endpoint, ompt_data_t *TargetData, |
| 275 |
ompt_id_t *HostOpId, unsigned int RequestedNumTeams) |
| 276 |
: Endpoint(Endpoint), TargetData(TargetData), HostOpId(HostOpId), |
| 277 |
RequestedNumTeams(RequestedNumTeams) {} |
| 278 |
ompt_scope_endpoint_t Endpoint; |
| 279 |
ompt_data_t *TargetData; |
| 280 |
ompt_id_t *HostOpId; |
| 281 |
unsigned int RequestedNumTeams; |
| 282 |
}; |
| 283 |
|
| 284 |
struct ControlTool : public EventBase<ControlTool> { |
| 285 |
ControlTool() = default; |
| 286 |
}; |
| 287 |
|
| 288 |
struct DeviceInitialize : public EventBase<DeviceInitialize> { |
| 289 |
std::string toString() const override; |
| 290 |
DeviceInitialize(int DeviceNum, const char *Type, ompt_device_t *Device, |
| 291 |
ompt_function_lookup_t LookupFn, const char *DocStr) |
| 292 |
: DeviceNum(DeviceNum), Type(Type), Device(Device), LookupFn(LookupFn), |
| 293 |
DocStr(DocStr) {} |
| 294 |
int DeviceNum; |
| 295 |
const char *Type; |
| 296 |
ompt_device_t *Device; |
| 297 |
ompt_function_lookup_t LookupFn; |
| 298 |
const char *DocStr; |
| 299 |
}; |
| 300 |
|
| 301 |
struct DeviceFinalize : public EventBase<DeviceFinalize> { |
| 302 |
std::string toString() const override; |
| 303 |
DeviceFinalize(int DeviceNum) : DeviceNum(DeviceNum) {} |
| 304 |
int DeviceNum; |
| 305 |
}; |
| 306 |
|
| 307 |
struct DeviceLoad : public EventBase<DeviceLoad> { |
| 308 |
std::string toString() const override; |
| 309 |
DeviceLoad(int DeviceNum, const char *Filename, int64_t OffsetInFile, |
| 310 |
void *VmaInFile, size_t Bytes, void *HostAddr, void *DeviceAddr, |
| 311 |
uint64_t ModuleId) |
| 312 |
: DeviceNum(DeviceNum), Filename(Filename), OffsetInFile(OffsetInFile), |
| 313 |
VmaInFile(VmaInFile), Bytes(Bytes), HostAddr(HostAddr), |
| 314 |
DeviceAddr(DeviceAddr), ModuleId(ModuleId) {} |
| 315 |
int DeviceNum; |
| 316 |
const char *Filename; |
| 317 |
int64_t OffsetInFile; |
| 318 |
void *VmaInFile; |
| 319 |
size_t Bytes; |
| 320 |
void *HostAddr; |
| 321 |
void *DeviceAddr; |
| 322 |
uint64_t ModuleId; |
| 323 |
}; |
| 324 |
|
| 325 |
struct DeviceUnload : public EventBase<DeviceUnload> { |
| 326 |
DeviceUnload() = default; |
| 327 |
}; |
| 328 |
|
| 329 |
struct BufferRequest : public EventBase<BufferRequest> { |
| 330 |
std::string toString() const override; |
| 331 |
BufferRequest(int DeviceNum, ompt_buffer_t **Buffer, size_t *Bytes) |
| 332 |
: DeviceNum(DeviceNum), Buffer(Buffer), Bytes(Bytes) {} |
| 333 |
int DeviceNum; |
| 334 |
ompt_buffer_t **Buffer; |
| 335 |
size_t *Bytes; |
| 336 |
}; |
| 337 |
|
| 338 |
struct BufferComplete : public EventBase<BufferComplete> { |
| 339 |
std::string toString() const override; |
| 340 |
BufferComplete(int DeviceNum, ompt_buffer_t *Buffer, size_t Bytes, |
| 341 |
ompt_buffer_cursor_t Begin, int BufferOwned) |
| 342 |
: DeviceNum(DeviceNum), Buffer(Buffer), Bytes(Bytes), Begin(Begin), |
| 343 |
BufferOwned(BufferOwned) {} |
| 344 |
int DeviceNum; |
| 345 |
ompt_buffer_t *Buffer; |
| 346 |
size_t Bytes; |
| 347 |
ompt_buffer_cursor_t Begin; |
| 348 |
int BufferOwned; |
| 349 |
}; |
| 350 |
|
| 351 |
struct BufferRecord : public EventBase<BufferRecord> { |
| 352 |
std::string toString() const override; |
| 353 |
BufferRecord(ompt_record_ompt_t *RecordPtr) : RecordPtr(RecordPtr) { |
| 354 |
if (RecordPtr != nullptr) |
| 355 |
Record = *RecordPtr; |
| 356 |
else |
| 357 |
memset(&Record, 0, sizeof(ompt_record_ompt_t)); |
| 358 |
} |
| 359 |
ompt_record_ompt_t Record; |
| 360 |
ompt_record_ompt_t *RecordPtr; |
| 361 |
}; |
| 362 |
|
| 363 |
struct BufferRecordDeallocation : public EventBase<BufferRecordDeallocation> { |
| 364 |
std::string toString() const override; |
| 365 |
BufferRecordDeallocation(ompt_buffer_t *Buffer) : Buffer(Buffer) {} |
| 366 |
ompt_buffer_t *Buffer; |
| 367 |
}; |
| 368 |
|
| 369 |
// Add specialized event equality operators here. |
| 370 |
// Note: Placement of these forward declarations is important as they need to |
| 371 |
// take precedence over the following default equality operator definition. |
| 372 |
bool operator==(const ParallelBegin &, const ParallelBegin &); |
| 373 |
bool operator==(const Work &, const Work &); |
| 374 |
bool operator==(const Dispatch &, const Dispatch &); |
| 375 |
bool operator==(const ImplicitTask &, const ImplicitTask &); |
| 376 |
bool operator==(const SyncRegion &, const SyncRegion &); |
| 377 |
bool operator==(const Target &, const Target &); |
| 378 |
bool operator==(const TargetEmi &, const TargetEmi &); |
| 379 |
bool operator==(const TargetDataOp &, const TargetDataOp &); |
| 380 |
bool operator==(const TargetDataOpEmi &, const TargetDataOpEmi &); |
| 381 |
bool operator==(const TargetSubmit &, const TargetSubmit &); |
| 382 |
bool operator==(const TargetSubmitEmi &, const TargetSubmitEmi &); |
| 383 |
bool operator==(const DeviceInitialize &, const DeviceInitialize &); |
| 384 |
bool operator==(const DeviceFinalize &, const DeviceFinalize &); |
| 385 |
bool operator==(const DeviceLoad &, const DeviceLoad &); |
| 386 |
bool operator==(const BufferRequest &, const BufferRequest &); |
| 387 |
bool operator==(const BufferComplete &, const BufferComplete &); |
| 388 |
bool operator==(const BufferRecord &, const BufferRecord &); |
| 389 |
|
| 390 |
/// Default (fallback) event equality operator definition. |
| 391 |
template <typename Event> bool operator==(const Event &, const Event &) { |
| 392 |
return true; |
| 393 |
} |
| 394 |
|
| 395 |
// clang-format off |
| 396 |
event_type_trait(AssertionSyncPoint) |
| 397 |
event_type_trait(AssertionSuspend) |
| 398 |
event_type_trait(ThreadBegin) |
| 399 |
event_type_trait(ThreadEnd) |
| 400 |
event_type_trait(ParallelBegin) |
| 401 |
event_type_trait(ParallelEnd) |
| 402 |
event_type_trait(Work) |
| 403 |
event_type_trait(Dispatch) |
| 404 |
event_type_trait(TaskCreate) |
| 405 |
event_type_trait(Dependences) |
| 406 |
event_type_trait(TaskDependence) |
| 407 |
event_type_trait(TaskSchedule) |
| 408 |
event_type_trait(ImplicitTask) |
| 409 |
event_type_trait(Masked) |
| 410 |
event_type_trait(SyncRegion) |
| 411 |
event_type_trait(MutexAcquire) |
| 412 |
event_type_trait(Mutex) |
| 413 |
event_type_trait(NestLock) |
| 414 |
event_type_trait(Flush) |
| 415 |
event_type_trait(Cancel) |
| 416 |
event_type_trait(Target) |
| 417 |
event_type_trait(TargetEmi) |
| 418 |
event_type_trait(TargetDataOp) |
| 419 |
event_type_trait(TargetDataOpEmi) |
| 420 |
event_type_trait(TargetSubmit) |
| 421 |
event_type_trait(TargetSubmitEmi) |
| 422 |
event_type_trait(ControlTool) |
| 423 |
event_type_trait(DeviceInitialize) |
| 424 |
event_type_trait(DeviceFinalize) |
| 425 |
event_type_trait(DeviceLoad) |
| 426 |
event_type_trait(DeviceUnload) |
| 427 |
event_type_trait(BufferRequest) |
| 428 |
event_type_trait(BufferComplete) |
| 429 |
event_type_trait(BufferRecord) |
| 430 |
event_type_trait(BufferRecordDeallocation) |
| 431 |
// clang-format on |
| 432 |
|
| 433 |
} // namespace internal |
| 434 |
|
| 435 |
} // namespace omptest |
| 436 |
|
| 437 |
#endif |