brintos

brintos / llvm-project-archived public Read only

0
0
Text · 6.5 KiB · 40076c3 Raw
166 lines · c
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-exception6//7//===----------------------------------------------------------------------===//8///9/// \file10/// This file provides the OMPT callback handling declarations.11///12//===----------------------------------------------------------------------===//13 14#ifndef OPENMP_TOOLS_OMPTEST_INCLUDE_OMPTCALLBACKHANDLER_H15#define OPENMP_TOOLS_OMPTEST_INCLUDE_OMPTCALLBACKHANDLER_H16 17#include "OmptAssertEvent.h"18#include "OmptAsserter.h"19 20#include "omp-tools.h"21 22#include <vector>23 24namespace omptest {25 26/// Handler class to do whatever is needed to be done when a callback is invoked27/// by the OMP runtime28/// Supports a RecordAndReplay mechanism in which all OMPT events are recorded29/// and then replayed. This is so that a test can assert on, e.g., a device30/// initialize event, even though this would occur before a unit test is31/// actually executed.32class OmptCallbackHandler {33public:34  ~OmptCallbackHandler() = default;35 36  /// Singleton handler37  static OmptCallbackHandler &get();38 39  /// Subscribe a listener to be notified for OMPT events40  void subscribe(OmptListener *Listener);41 42  /// Remove all subscribers43  void clearSubscribers();44 45  /// When the record and replay mechanism is enabled this replays all OMPT46  /// events47  void replay();48 49  /// Special asserter callback which checks that upon encountering the50  /// 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 implementation134  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 145private:146  /// Wrapper around emplace_back for potential additional logging / checking or147  /// so148  void recordEvent(OmptAssertEvent &&Event);149 150  /// Listeners to be notified151  std::vector<OmptListener *> Subscribers;152 153  /// Toggle if OMPT events should notify subscribers immediately or not154  bool RecordAndReplay{false};155 156  /// Recorded events in Record and Replay mode157  std::vector<OmptAssertEvent> RecordedEvents;158};159 160} // namespace omptest161 162// Pointer to global callback handler163extern omptest::OmptCallbackHandler *Handler;164 165#endif166