Debian Codegraph @

openmp/tools/omptest/include/OmptCallbackHandler.h

raw
1 //===- OmptCallbackHandler.h - Callback reception and handling --*- 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 /// This file provides the OMPT callback handling declarations.
11 ///
12 //===----------------------------------------------------------------------===//
13
14 #ifndef OPENMP_TOOLS_OMPTEST_INCLUDE_OMPTCALLBACKHANDLER_H
15 #define OPENMP_TOOLS_OMPTEST_INCLUDE_OMPTCALLBACKHANDLER_H
16
17 #include "OmptAssertEvent.h"
18 #include "OmptAsserter.h"
19
20 #include "omp-tools.h"
21
22 #include <vector>
23
24 namespace omptest {
25
26 /// Handler class to do whatever is needed to be done when a callback is invoked
27 /// by the OMP runtime
28 /// Supports a RecordAndReplay mechanism in which all OMPT events are recorded
29 /// and then replayed. This is so that a test can assert on, e.g., a device
30 /// initialize event, even though this would occur before a unit test is
31 /// actually executed.
32 class OmptCallbackHandler {
33 public:
34 ~OmptCallbackHandler() = default;
35
36 /// Singleton handler
37 static OmptCallbackHandler &get();
38
39 /// Subscribe a listener to be notified for OMPT events
40 void subscribe(OmptListener *Listener);
41
42 /// Remove all subscribers
43 void clearSubscribers();
44
45 /// When the record and replay mechanism is enabled this replays all OMPT
46 /// events
47 void replay();
48
49 /// Special asserter callback which checks that upon encountering the
50 /// synchronization point, all expected events have been processed. That is:
51 /// there are currently no remaining expected events for any asserter.
52 void handleAssertionSyncPoint(const std::string &SyncPointName);
53
54 void handleThreadBegin(ompt_thread_t ThreadType, ompt_data_t *ThreadData);
55
56 void handleThreadEnd(ompt_data_t *ThreadData);
57
58 void handleTaskCreate(ompt_data_t *EncounteringTaskData,
59 const ompt_frame_t *EncounteringTaskFrame,
60 ompt_data_t *NewTaskData, int Flags, int HasDependences,
61 const void *CodeptrRA);
62
63 void handleTaskSchedule(ompt_data_t *PriorTaskData,
64 ompt_task_status_t PriorTaskStatus,
65 ompt_data_t *NextTaskData);
66
67 void handleImplicitTask(ompt_scope_endpoint_t Endpoint,
68 ompt_data_t *ParallelData, ompt_data_t *TaskData,
69 unsigned int ActualParallelism, unsigned int Index,
70 int Flags);
71
72 void handleParallelBegin(ompt_data_t *EncounteringTaskData,
73 const ompt_frame_t *EncounteringTaskFrame,
74 ompt_data_t *ParallelData,
75 unsigned int RequestedParallelism, int Flags,
76 const void *CodeptrRA);
77
78 void handleParallelEnd(ompt_data_t *ParallelData,
79 ompt_data_t *EncounteringTaskData, int Flags,
80 const void *CodeptrRA);
81
82 void handleDeviceInitialize(int DeviceNum, const char *Type,
83 ompt_device_t *Device,
84 ompt_function_lookup_t LookupFn,
85 const char *DocumentationStr);
86
87 void handleDeviceFinalize(int DeviceNum);
88
89 void handleTarget(ompt_target_t Kind, ompt_scope_endpoint_t Endpoint,
90 int DeviceNum, ompt_data_t *TaskData, ompt_id_t TargetId,
91 const void *CodeptrRA);
92
93 void handleTargetEmi(ompt_target_t Kind, ompt_scope_endpoint_t Endpoint,
94 int DeviceNum, ompt_data_t *TaskData,
95 ompt_data_t *TargetTaskData, ompt_data_t *TargetData,
96 const void *CodeptrRA);
97
98 void handleTargetSubmit(ompt_id_t TargetId, ompt_id_t HostOpId,
99 unsigned int RequestedNumTeams);
100
101 void handleTargetSubmitEmi(ompt_scope_endpoint_t Endpoint,
102 ompt_data_t *TargetData, ompt_id_t *HostOpId,
103 unsigned int RequestedNumTeams);
104
105 void handleTargetDataOp(ompt_id_t TargetId, ompt_id_t HostOpId,
106 ompt_target_data_op_t OpType, void *SrcAddr,
107 int SrcDeviceNum, void *DstAddr, int DstDeviceNum,
108 size_t Bytes, const void *CodeptrRA);
109
110 void handleTargetDataOpEmi(ompt_scope_endpoint_t Endpoint,
111 ompt_data_t *TargetTaskData,
112 ompt_data_t *TargetData, ompt_id_t *HostOpId,
113 ompt_target_data_op_t OpType, void *SrcAddr,
114 int SrcDeviceNum, void *DstAddr, int DstDeviceNum,
115 size_t Bytes, const void *CodeptrRA);
116
117 void handleDeviceLoad(int DeviceNum, const char *Filename,
118 int64_t OffsetInFile, void *VmaInFile, size_t Bytes,
119 void *HostAddr, void *DeviceAddr, uint64_t ModuleId);
120
121 void handleDeviceUnload(int DeviceNum, uint64_t ModuleId);
122
123 void handleBufferRequest(int DeviceNum, ompt_buffer_t **Buffer,
124 size_t *Bytes);
125
126 void handleBufferComplete(int DeviceNum, ompt_buffer_t *Buffer, size_t Bytes,
127 ompt_buffer_cursor_t Begin, int BufferOwned);
128
129 void handleBufferRecord(ompt_record_ompt_t *Record);
130
131 void handleBufferRecordDeallocation(ompt_buffer_t *Buffer);
132
133 /// Not needed for a conforming minimal OMPT implementation
134 void handleWork(ompt_work_t WorkType, ompt_scope_endpoint_t Endpoint,
135 ompt_data_t *ParallelData, ompt_data_t *TaskData,
136 uint64_t Count, const void *CodeptrRA);
137
138 void handleDispatch(ompt_data_t *ParallelData, ompt_data_t *TaskData,
139 ompt_dispatch_t Kind, ompt_data_t Instance);
140
141 void handleSyncRegion(ompt_sync_region_t Kind, ompt_scope_endpoint_t Endpoint,
142 ompt_data_t *ParallelData, ompt_data_t *TaskData,
143 const void *CodeptrRA);
144
145 private:
146 /// Wrapper around emplace_back for potential additional logging / checking or
147 /// so
148 void recordEvent(OmptAssertEvent &&Event);
149
150 /// Listeners to be notified
151 std::vector<OmptListener *> Subscribers;
152
153 /// Toggle if OMPT events should notify subscribers immediately or not
154 bool RecordAndReplay{false};
155
156 /// Recorded events in Record and Replay mode
157 std::vector<OmptAssertEvent> RecordedEvents;
158 };
159
160 } // namespace omptest
161
162 // Pointer to global callback handler
163 extern omptest::OmptCallbackHandler *Handler;
164
165 #endif