| 1 |
//===- OmptAssertEvent.h - Assertion event declarations ---------*- 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 |
/// Contains assertion event constructors, for generally all observable events. |
| 11 |
/// This includes user-generated events, like synchronization. |
| 12 |
/// |
| 13 |
//===----------------------------------------------------------------------===// |
| 14 |
|
| 15 |
#ifndef OPENMP_TOOLS_OMPTEST_INCLUDE_OMPTASSERTEVENT_H |
| 16 |
#define OPENMP_TOOLS_OMPTEST_INCLUDE_OMPTASSERTEVENT_H |
| 17 |
|
| 18 |
#include "InternalEvent.h" |
| 19 |
#include "omp-tools.h" |
| 20 |
|
| 21 |
#include <cassert> |
| 22 |
#include <limits> |
| 23 |
#include <memory> |
| 24 |
#include <string> |
| 25 |
|
| 26 |
namespace omptest { |
| 27 |
|
| 28 |
enum class ObserveState { Generated, Always, Never }; |
| 29 |
|
| 30 |
/// Helper function, returning an ObserveState string representation |
| 31 |
const char *to_string(ObserveState State); |
| 32 |
|
| 33 |
/// Assertion event struct, provides statically callable CTORs. |
| 34 |
struct OmptAssertEvent { |
| 35 |
static OmptAssertEvent AssertionSyncPoint(const std::string &Name, |
| 36 |
const std::string &Group, |
| 37 |
const ObserveState &Expected, |
| 38 |
const std::string &SyncPointName); |
| 39 |
|
| 40 |
static OmptAssertEvent AssertionSuspend(const std::string &Name, |
| 41 |
const std::string &Group, |
| 42 |
const ObserveState &Expected); |
| 43 |
|
| 44 |
static OmptAssertEvent ThreadBegin(const std::string &Name, |
| 45 |
const std::string &Group, |
| 46 |
const ObserveState &Expected, |
| 47 |
ompt_thread_t ThreadType); |
| 48 |
|
| 49 |
static OmptAssertEvent ThreadEnd(const std::string &Name, |
| 50 |
const std::string &Group, |
| 51 |
const ObserveState &Expected); |
| 52 |
|
| 53 |
static OmptAssertEvent ParallelBegin(const std::string &Name, |
| 54 |
const std::string &Group, |
| 55 |
const ObserveState &Expected, |
| 56 |
int NumThreads); |
| 57 |
|
| 58 |
static OmptAssertEvent ParallelEnd( |
| 59 |
const std::string &Name, const std::string &Group, |
| 60 |
const ObserveState &Expected, |
| 61 |
ompt_data_t *ParallelData = expectedDefault(ompt_data_t *), |
| 62 |
ompt_data_t *EncounteringTaskData = expectedDefault(ompt_data_t *), |
| 63 |
int Flags = expectedDefault(int), |
| 64 |
const void *CodeptrRA = expectedDefault(const void *)); |
| 65 |
|
| 66 |
static OmptAssertEvent |
| 67 |
Work(const std::string &Name, const std::string &Group, |
| 68 |
const ObserveState &Expected, ompt_work_t WorkType, |
| 69 |
ompt_scope_endpoint_t Endpoint, |
| 70 |
ompt_data_t *ParallelData = expectedDefault(ompt_data_t *), |
| 71 |
ompt_data_t *TaskData = expectedDefault(ompt_data_t *), |
| 72 |
uint64_t Count = expectedDefault(uint64_t), |
| 73 |
const void *CodeptrRA = expectedDefault(const void *)); |
| 74 |
|
| 75 |
static OmptAssertEvent |
| 76 |
Dispatch(const std::string &Name, const std::string &Group, |
| 77 |
const ObserveState &Expected, |
| 78 |
ompt_data_t *ParallelData = expectedDefault(ompt_data_t *), |
| 79 |
ompt_data_t *TaskData = expectedDefault(ompt_data_t *), |
| 80 |
ompt_dispatch_t Kind = expectedDefault(ompt_dispatch_t), |
| 81 |
ompt_data_t Instance = expectedDefault(ompt_data_t)); |
| 82 |
|
| 83 |
static OmptAssertEvent |
| 84 |
TaskCreate(const std::string &Name, const std::string &Group, |
| 85 |
const ObserveState &Expected, |
| 86 |
ompt_data_t *EncounteringTaskData = expectedDefault(ompt_data_t *), |
| 87 |
const ompt_frame_t *EncounteringTaskFrame = |
| 88 |
expectedDefault(ompt_frame_t *), |
| 89 |
ompt_data_t *NewTaskData = expectedDefault(ompt_data_t *), |
| 90 |
int Flags = expectedDefault(int), |
| 91 |
int HasDependences = expectedDefault(int), |
| 92 |
const void *CodeptrRA = expectedDefault(const void *)); |
| 93 |
|
| 94 |
static OmptAssertEvent TaskSchedule(const std::string &Name, |
| 95 |
const std::string &Group, |
| 96 |
const ObserveState &Expected); |
| 97 |
|
| 98 |
static OmptAssertEvent |
| 99 |
ImplicitTask(const std::string &Name, const std::string &Group, |
| 100 |
const ObserveState &Expected, ompt_scope_endpoint_t Endpoint, |
| 101 |
ompt_data_t *ParallelData = expectedDefault(ompt_data_t *), |
| 102 |
ompt_data_t *TaskData = expectedDefault(ompt_data_t *), |
| 103 |
unsigned int ActualParallelism = expectedDefault(unsigned int), |
| 104 |
unsigned int Index = expectedDefault(unsigned int), |
| 105 |
int Flags = expectedDefault(int)); |
| 106 |
|
| 107 |
static OmptAssertEvent |
| 108 |
SyncRegion(const std::string &Name, const std::string &Group, |
| 109 |
const ObserveState &Expected, ompt_sync_region_t Kind, |
| 110 |
ompt_scope_endpoint_t Endpoint, |
| 111 |
ompt_data_t *ParallelData = expectedDefault(ompt_data_t *), |
| 112 |
ompt_data_t *TaskData = expectedDefault(ompt_data_t *), |
| 113 |
const void *CodeptrRA = expectedDefault(const void *)); |
| 114 |
|
| 115 |
static OmptAssertEvent |
| 116 |
Target(const std::string &Name, const std::string &Group, |
| 117 |
const ObserveState &Expected, ompt_target_t Kind, |
| 118 |
ompt_scope_endpoint_t Endpoint, int DeviceNum = expectedDefault(int), |
| 119 |
ompt_data_t *TaskData = expectedDefault(ompt_data_t *), |
| 120 |
ompt_id_t TargetId = expectedDefault(ompt_id_t), |
| 121 |
const void *CodeptrRA = expectedDefault(void *)); |
| 122 |
|
| 123 |
static OmptAssertEvent |
| 124 |
TargetEmi(const std::string &Name, const std::string &Group, |
| 125 |
const ObserveState &Expected, ompt_target_t Kind, |
| 126 |
ompt_scope_endpoint_t Endpoint, |
| 127 |
int DeviceNum = expectedDefault(int), |
| 128 |
ompt_data_t *TaskData = expectedDefault(ompt_data_t *), |
| 129 |
ompt_data_t *TargetTaskData = expectedDefault(ompt_data_t *), |
| 130 |
ompt_data_t *TargetData = expectedDefault(ompt_data_t *), |
| 131 |
const void *CodeptrRA = expectedDefault(void *)); |
| 132 |
|
| 133 |
static OmptAssertEvent |
| 134 |
TargetDataOp(const std::string &Name, const std::string &Group, |
| 135 |
const ObserveState &Expected, ompt_id_t TargetId, |
| 136 |
ompt_id_t HostOpId, ompt_target_data_op_t OpType, void *SrcAddr, |
| 137 |
int SrcDeviceNum, void *DstAddr, int DstDeviceNum, size_t Bytes, |
| 138 |
const void *CodeptrRA); |
| 139 |
|
| 140 |
static OmptAssertEvent |
| 141 |
TargetDataOp(const std::string &Name, const std::string &Group, |
| 142 |
const ObserveState &Expected, ompt_target_data_op_t OpType, |
| 143 |
size_t Bytes = expectedDefault(size_t), |
| 144 |
void *SrcAddr = expectedDefault(void *), |
| 145 |
void *DstAddr = expectedDefault(void *), |
| 146 |
int SrcDeviceNum = expectedDefault(int), |
| 147 |
int DstDeviceNum = expectedDefault(int), |
| 148 |
ompt_id_t TargetId = expectedDefault(ompt_id_t), |
| 149 |
ompt_id_t HostOpId = expectedDefault(ompt_id_t), |
| 150 |
const void *CodeptrRA = expectedDefault(void *)); |
| 151 |
|
| 152 |
static OmptAssertEvent |
| 153 |
TargetDataOpEmi(const std::string &Name, const std::string &Group, |
| 154 |
const ObserveState &Expected, ompt_scope_endpoint_t Endpoint, |
| 155 |
ompt_data_t *TargetTaskData, ompt_data_t *TargetData, |
| 156 |
ompt_id_t *HostOpId, ompt_target_data_op_t OpType, |
| 157 |
void *SrcAddr, int SrcDeviceNum, void *DstAddr, |
| 158 |
int DstDeviceNum, size_t Bytes, const void *CodeptrRA); |
| 159 |
|
| 160 |
static OmptAssertEvent |
| 161 |
TargetDataOpEmi(const std::string &Name, const std::string &Group, |
| 162 |
const ObserveState &Expected, ompt_target_data_op_t OpType, |
| 163 |
ompt_scope_endpoint_t Endpoint, |
| 164 |
size_t Bytes = expectedDefault(size_t), |
| 165 |
void *SrcAddr = expectedDefault(void *), |
| 166 |
void *DstAddr = expectedDefault(void *), |
| 167 |
int SrcDeviceNum = expectedDefault(int), |
| 168 |
int DstDeviceNum = expectedDefault(int), |
| 169 |
ompt_data_t *TargetTaskData = expectedDefault(ompt_data_t *), |
| 170 |
ompt_data_t *TargetData = expectedDefault(ompt_data_t *), |
| 171 |
ompt_id_t *HostOpId = expectedDefault(ompt_id_t *), |
| 172 |
const void *CodeptrRA = expectedDefault(void *)); |
| 173 |
|
| 174 |
static OmptAssertEvent TargetSubmit(const std::string &Name, |
| 175 |
const std::string &Group, |
| 176 |
const ObserveState &Expected, |
| 177 |
ompt_id_t TargetId, ompt_id_t HostOpId, |
| 178 |
unsigned int RequestedNumTeams); |
| 179 |
|
| 180 |
static OmptAssertEvent |
| 181 |
TargetSubmit(const std::string &Name, const std::string &Group, |
| 182 |
const ObserveState &Expected, unsigned int RequestedNumTeams, |
| 183 |
ompt_id_t TargetId = expectedDefault(ompt_id_t), |
| 184 |
ompt_id_t HostOpId = expectedDefault(ompt_id_t)); |
| 185 |
|
| 186 |
static OmptAssertEvent |
| 187 |
TargetSubmitEmi(const std::string &Name, const std::string &Group, |
| 188 |
const ObserveState &Expected, ompt_scope_endpoint_t Endpoint, |
| 189 |
ompt_data_t *TargetData, ompt_id_t *HostOpId, |
| 190 |
unsigned int RequestedNumTeams); |
| 191 |
|
| 192 |
static OmptAssertEvent |
| 193 |
TargetSubmitEmi(const std::string &Name, const std::string &Group, |
| 194 |
const ObserveState &Expected, unsigned int RequestedNumTeams, |
| 195 |
ompt_scope_endpoint_t Endpoint, |
| 196 |
ompt_data_t *TargetData = expectedDefault(ompt_data_t *), |
| 197 |
ompt_id_t *HostOpId = expectedDefault(ompt_id_t *)); |
| 198 |
|
| 199 |
static OmptAssertEvent ControlTool(const std::string &Name, |
| 200 |
const std::string &Group, |
| 201 |
const ObserveState &Expected); |
| 202 |
|
| 203 |
static OmptAssertEvent DeviceInitialize( |
| 204 |
const std::string &Name, const std::string &Group, |
| 205 |
const ObserveState &Expected, int DeviceNum, |
| 206 |
const char *Type = expectedDefault(const char *), |
| 207 |
ompt_device_t *Device = expectedDefault(ompt_device_t *), |
| 208 |
ompt_function_lookup_t LookupFn = expectedDefault(ompt_function_lookup_t), |
| 209 |
const char *DocumentationStr = expectedDefault(const char *)); |
| 210 |
|
| 211 |
static OmptAssertEvent DeviceFinalize(const std::string &Name, |
| 212 |
const std::string &Group, |
| 213 |
const ObserveState &Expected, |
| 214 |
int DeviceNum); |
| 215 |
|
| 216 |
static OmptAssertEvent |
| 217 |
DeviceLoad(const std::string &Name, const std::string &Group, |
| 218 |
const ObserveState &Expected, int DeviceNum, |
| 219 |
const char *Filename = expectedDefault(const char *), |
| 220 |
int64_t OffsetInFile = expectedDefault(int64_t), |
| 221 |
void *VmaInFile = expectedDefault(void *), |
| 222 |
size_t Bytes = expectedDefault(size_t), |
| 223 |
void *HostAddr = expectedDefault(void *), |
| 224 |
void *DeviceAddr = expectedDefault(void *), |
| 225 |
uint64_t ModuleId = expectedDefault(int64_t)); |
| 226 |
|
| 227 |
static OmptAssertEvent DeviceUnload(const std::string &Name, |
| 228 |
const std::string &Group, |
| 229 |
const ObserveState &Expected); |
| 230 |
|
| 231 |
static OmptAssertEvent BufferRequest(const std::string &Name, |
| 232 |
const std::string &Group, |
| 233 |
const ObserveState &Expected, |
| 234 |
int DeviceNum, ompt_buffer_t **Buffer, |
| 235 |
size_t *Bytes); |
| 236 |
|
| 237 |
static OmptAssertEvent |
| 238 |
BufferComplete(const std::string &Name, const std::string &Group, |
| 239 |
const ObserveState &Expected, int DeviceNum, |
| 240 |
ompt_buffer_t *Buffer, size_t Bytes, |
| 241 |
ompt_buffer_cursor_t Begin, int BufferOwned); |
| 242 |
|
| 243 |
static OmptAssertEvent BufferRecord(const std::string &Name, |
| 244 |
const std::string &Group, |
| 245 |
const ObserveState &Expected, |
| 246 |
ompt_record_ompt_t *Record); |
| 247 |
|
| 248 |
/// Handle type = ompt_record_target_t |
| 249 |
static OmptAssertEvent |
| 250 |
BufferRecord(const std::string &Name, const std::string &Group, |
| 251 |
const ObserveState &Expected, ompt_callbacks_t Type, |
| 252 |
ompt_target_t Kind, ompt_scope_endpoint_t Endpoint, |
| 253 |
int DeviceNum = expectedDefault(int), |
| 254 |
ompt_id_t TaskId = expectedDefault(ompt_id_t), |
| 255 |
ompt_id_t TargetId = expectedDefault(ompt_id_t), |
| 256 |
const void *CodeptrRA = expectedDefault(void *)); |
| 257 |
|
| 258 |
/// Handle type = ompt_callback_target_data_op |
| 259 |
static OmptAssertEvent |
| 260 |
BufferRecord(const std::string &Name, const std::string &Group, |
| 261 |
const ObserveState &Expected, ompt_callbacks_t Type, |
| 262 |
ompt_target_data_op_t OpType, size_t Bytes, |
| 263 |
std::pair<ompt_device_time_t, ompt_device_time_t> Timeframe, |
| 264 |
void *SrcAddr = expectedDefault(void *), |
| 265 |
void *DstAddr = expectedDefault(void *), |
| 266 |
int SrcDeviceNum = expectedDefault(int), |
| 267 |
int DstDeviceNum = expectedDefault(int), |
| 268 |
ompt_id_t TargetId = expectedDefault(ompt_id_t), |
| 269 |
ompt_id_t HostOpId = expectedDefault(ompt_id_t), |
| 270 |
const void *CodeptrRA = expectedDefault(void *)); |
| 271 |
|
| 272 |
/// Handle type = ompt_callback_target_data_op |
| 273 |
static OmptAssertEvent BufferRecord( |
| 274 |
const std::string &Name, const std::string &Group, |
| 275 |
const ObserveState &Expected, ompt_callbacks_t Type, |
| 276 |
ompt_target_data_op_t OpType, size_t Bytes = expectedDefault(size_t), |
| 277 |
ompt_device_time_t MinimumTimeDelta = expectedDefault(ompt_device_time_t), |
| 278 |
void *SrcAddr = expectedDefault(void *), |
| 279 |
void *DstAddr = expectedDefault(void *), |
| 280 |
int SrcDeviceNum = expectedDefault(int), |
| 281 |
int DstDeviceNum = expectedDefault(int), |
| 282 |
ompt_id_t TargetId = expectedDefault(ompt_id_t), |
| 283 |
ompt_id_t HostOpId = expectedDefault(ompt_id_t), |
| 284 |
const void *CodeptrRA = expectedDefault(void *)); |
| 285 |
|
| 286 |
/// Handle type = ompt_callback_target_submit |
| 287 |
static OmptAssertEvent |
| 288 |
BufferRecord(const std::string &Name, const std::string &Group, |
| 289 |
const ObserveState &Expected, ompt_callbacks_t Type, |
| 290 |
std::pair<ompt_device_time_t, ompt_device_time_t> Timeframe, |
| 291 |
unsigned int RequestedNumTeams = expectedDefault(unsigned int), |
| 292 |
unsigned int GrantedNumTeams = expectedDefault(unsigned int), |
| 293 |
ompt_id_t TargetId = expectedDefault(ompt_id_t), |
| 294 |
ompt_id_t HostOpId = expectedDefault(ompt_id_t)); |
| 295 |
|
| 296 |
/// Handle type = ompt_callback_target_submit |
| 297 |
/// Note: This will also act as the simplest default CTOR |
| 298 |
static OmptAssertEvent BufferRecord( |
| 299 |
const std::string &Name, const std::string &Group, |
| 300 |
const ObserveState &Expected, ompt_callbacks_t Type, |
| 301 |
ompt_device_time_t MinimumTimeDelta = expectedDefault(ompt_device_time_t), |
| 302 |
unsigned int RequestedNumTeams = expectedDefault(unsigned int), |
| 303 |
unsigned int GrantedNumTeams = expectedDefault(unsigned int), |
| 304 |
ompt_id_t TargetId = expectedDefault(ompt_id_t), |
| 305 |
ompt_id_t HostOpId = expectedDefault(ompt_id_t)); |
| 306 |
|
| 307 |
static OmptAssertEvent BufferRecordDeallocation(const std::string &Name, |
| 308 |
const std::string &Group, |
| 309 |
const ObserveState &Expected, |
| 310 |
ompt_buffer_t *Buffer); |
| 311 |
|
| 312 |
/// Allow move construction (due to std::unique_ptr) |
| 313 |
OmptAssertEvent(OmptAssertEvent &&o) = default; |
| 314 |
OmptAssertEvent &operator=(OmptAssertEvent &&o) = default; |
| 315 |
|
| 316 |
/// Get the event's name |
| 317 |
std::string getEventName() const; |
| 318 |
|
| 319 |
/// Get the event's group name |
| 320 |
std::string getEventGroup() const; |
| 321 |
|
| 322 |
/// Get the event's expected observation state |
| 323 |
ObserveState getEventExpectedState() const; |
| 324 |
|
| 325 |
/// Return the actual event type enum value |
| 326 |
internal::EventTy getEventType() const; |
| 327 |
|
| 328 |
/// Get a pointer to the internal event |
| 329 |
internal::InternalEvent *getEvent() const; |
| 330 |
|
| 331 |
/// Make events comparable |
| 332 |
friend bool operator==(const OmptAssertEvent &A, const OmptAssertEvent &B); |
| 333 |
|
| 334 |
/// Returns the string representation of the event |
| 335 |
std::string toString(bool PrefixEventName = false) const; |
| 336 |
|
| 337 |
private: |
| 338 |
OmptAssertEvent(const std::string &Name, const std::string &Group, |
| 339 |
const ObserveState &Expected, internal::InternalEvent *IE); |
| 340 |
OmptAssertEvent(const OmptAssertEvent &o) = delete; |
| 341 |
|
| 342 |
/// Determine the event name. Either it is provided directly or determined |
| 343 |
/// from the calling function's name. |
| 344 |
static std::string getName(const std::string &Name, |
| 345 |
const char *Caller = __builtin_FUNCTION()) { |
| 346 |
std::string EName = Name; |
| 347 |
if (EName.empty()) |
| 348 |
EName.append(Caller).append(" (auto generated)"); |
| 349 |
|
| 350 |
return EName; |
| 351 |
} |
| 352 |
|
| 353 |
/// Determine the event name. Either it is provided directly or "default". |
| 354 |
static std::string getGroup(const std::string &Group) { |
| 355 |
if (Group.empty()) |
| 356 |
return "default"; |
| 357 |
|
| 358 |
return Group; |
| 359 |
} |
| 360 |
|
| 361 |
std::string Name; |
| 362 |
std::string Group; |
| 363 |
ObserveState ExpectedState; |
| 364 |
std::unique_ptr<internal::InternalEvent> TheEvent; |
| 365 |
}; |
| 366 |
|
| 367 |
/// POD type, which holds the target region id, corresponding to an event group. |
| 368 |
struct AssertEventGroup { |
| 369 |
AssertEventGroup(uint64_t TargetRegion) : TargetRegion(TargetRegion) {} |
| 370 |
uint64_t TargetRegion; |
| 371 |
}; |
| 372 |
|
| 373 |
bool operator==(const OmptAssertEvent &A, const OmptAssertEvent &B); |
| 374 |
|
| 375 |
} // namespace omptest |
| 376 |
|
| 377 |
#endif |