106 lines · c
1//===-- OpenMP/OMPT/Callback.h - OpenMP Tooling callbacks -------*- 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// Interface used by target-independent runtimes to coordinate registration and10// invocation of OMPT callbacks and initialization / finalization.11//12//===----------------------------------------------------------------------===//13 14#ifndef OFFLOAD_INCLUDE_OPENMP_OMPT_CALLBACK_H15#define OFFLOAD_INCLUDE_OPENMP_OMPT_CALLBACK_H16 17#ifdef OMPT_SUPPORT18 19#include "omp-tools.h"20 21#pragma push_macro("DEBUG_PREFIX")22#undef DEBUG_PREFIX23#define DEBUG_PREFIX "OMPT"24 25#define FOREACH_OMPT_TARGET_CALLBACK(macro) \26 FOREACH_OMPT_DEVICE_EVENT(macro) \27 FOREACH_OMPT_NOEMI_EVENT(macro) \28 FOREACH_OMPT_EMI_EVENT(macro)29 30#define performIfOmptInitialized(stmt) \31 do { \32 if (llvm::omp::target::ompt::Initialized) { \33 stmt; \34 } \35 } while (0)36 37#define performOmptCallback(CallbackName, ...) \38 do { \39 if (ompt_callback_##CallbackName##_fn) \40 ompt_callback_##CallbackName##_fn(__VA_ARGS__); \41 } while (0)42 43/// Function type def used for maintaining unique target region, target44/// operations ids45typedef uint64_t (*IdInterfaceTy)();46 47namespace llvm {48namespace omp {49namespace target {50namespace ompt {51 52#define declareOmptCallback(Name, Type, Code) extern Name##_t Name##_fn;53FOREACH_OMPT_NOEMI_EVENT(declareOmptCallback)54FOREACH_OMPT_EMI_EVENT(declareOmptCallback)55#undef declareOmptCallback56 57/// This function will call an OpenMP API function. Which in turn will lookup a58/// given enum value of type \p ompt_callbacks_t and copy the address of the59/// corresponding callback function into the provided pointer.60/// The pointer to the runtime function is passed during 'initializeLibrary'.61/// \p which the enum value of the requested callback function62/// \p callback the destination pointer where the address shall be copied63extern ompt_get_callback_t lookupCallbackByCode;64 65/// Lookup function to be used by the lower layer (e.g. the plugin). This66/// function has to be provided when actually calling callback functions like67/// 'ompt_callback_device_initialize_fn' (param: 'lookup').68/// The pointer to the runtime function is passed during 'initializeLibrary'.69/// \p InterfaceFunctionName the name of the OMPT callback function to look up70extern ompt_function_lookup_t lookupCallbackByName;71 72/// This is the function called by the higher layer (libomp / libomtarget)73/// responsible for initializing OMPT in this library. This is passed to libomp74/// as part of the OMPT connector object.75/// \p lookup to be used to query callbacks registered with libomp76/// \p initial_device_num initial device num (id) provided by libomp77/// \p tool_data as provided by the tool78int initializeLibrary(ompt_function_lookup_t lookup, int initial_device_num,79 ompt_data_t *tool_data);80 81/// This function is passed to libomp / libomtarget as part of the OMPT82/// connector object. It is called by libomp during finalization of OMPT in83/// libomptarget -OR- by libomptarget during finalization of OMPT in the plugin.84/// \p tool_data as provided by the tool85void finalizeLibrary(ompt_data_t *tool_data);86 87/// This function will connect the \p initializeLibrary and \p finalizeLibrary88/// functions to their respective higher layer.89void connectLibrary();90 91/// OMPT initialization status; false if initializeLibrary has not been executed92extern bool Initialized;93 94} // namespace ompt95} // namespace target96} // namespace omp97} // namespace llvm98 99#pragma pop_macro("DEBUG_PREFIX")100 101#else102#define performIfOmptInitialized(stmt)103#endif // OMPT_SUPPORT104 105#endif // OFFLOAD_INCLUDE_OPENMP_OMPT_CALLBACK_H106