Warning: This file is not a C or C++ file. It does not have highlighting.

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-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// Interface used by target-independent runtimes to coordinate registration and
10// invocation of OMPT callbacks and initialization / finalization.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef OFFLOAD_INCLUDE_OPENMP_OMPT_CALLBACK_H
15#define OFFLOAD_INCLUDE_OPENMP_OMPT_CALLBACK_H
16
17#ifdef OMPT_SUPPORT
18
19#include "omp-tools.h"
20
21#pragma push_macro("DEBUG_PREFIX")
22#undef DEBUG_PREFIX
23#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, target
44/// operations ids
45typedef 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 declareOmptCallback
56
57/// This function will call an OpenMP API function. Which in turn will lookup a
58/// given enum value of type \p ompt_callbacks_t and copy the address of the
59/// 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 function
62/// \p callback the destination pointer where the address shall be copied
63extern ompt_get_callback_t lookupCallbackByCode;
64
65/// Lookup function to be used by the lower layer (e.g. the plugin). This
66/// function has to be provided when actually calling callback functions like
67/// '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 up
70extern 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 libomp
74/// as part of the OMPT connector object.
75/// \p lookup to be used to query callbacks registered with libomp
76/// \p initial_device_num initial device num (id) provided by libomp
77/// \p tool_data as provided by the tool
78int 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 OMPT
82/// connector object. It is called by libomp during finalization of OMPT in
83/// libomptarget -OR- by libomptarget during finalization of OMPT in the plugin.
84/// \p tool_data as provided by the tool
85void finalizeLibrary(ompt_data_t *tool_data);
86
87/// This function will connect the \p initializeLibrary and \p finalizeLibrary
88/// functions to their respective higher layer.
89void connectLibrary();
90
91/// OMPT initialization status; false if initializeLibrary has not been executed
92extern bool Initialized;
93
94} // namespace ompt
95} // namespace target
96} // namespace omp
97} // namespace llvm
98
99#pragma pop_macro("DEBUG_PREFIX")
100
101#else
102#define performIfOmptInitialized(stmt)
103#endif // OMPT_SUPPORT
104
105#endif // OFFLOAD_INCLUDE_OPENMP_OMPT_CALLBACK_H
106

Warning: This file is not a C or C++ file. It does not have highlighting.

source code of offload/include/OpenMP/OMPT/Callback.h