1 //===---- OmptCallback.h - Target independent OMPT callbacks --*- C++ -*---===//
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
7 //===----------------------------------------------------------------------===//
9 // Interface used by target-independent runtimes to coordinate registration and
10 // invocation of OMPT callbacks and initialization / finalization.
12 //===----------------------------------------------------------------------===//
14 #ifndef _OMPTCALLBACK_H
15 #define _OMPTCALLBACK_H
19 #include "omp-tools.h"
21 #pragma push_macro("DEBUG_PREFIX")
23 #define DEBUG_PREFIX "OMPT"
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)
30 #define performIfOmptInitialized(stmt) \
32 if (llvm::omp::target::ompt::Initialized) { \
37 #define performOmptCallback(CallbackName, ...) \
39 if (ompt_callback_##CallbackName##_fn) \
40 ompt_callback_##CallbackName##_fn(__VA_ARGS__); \
43 /// Function type def used for maintaining unique target region, target
45 typedef uint64_t (*IdInterfaceTy
)();
52 #define declareOmptCallback(Name, Type, Code) extern Name##_t Name##_fn;
53 FOREACH_OMPT_NOEMI_EVENT(declareOmptCallback
)
54 FOREACH_OMPT_EMI_EVENT(declareOmptCallback
)
55 #undef declareOmptCallback
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 funtion 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
63 extern ompt_get_callback_t lookupCallbackByCode
;
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
70 extern ompt_function_lookup_t lookupCallbackByName
;
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
78 int initializeLibrary(ompt_function_lookup_t lookup
, int initial_device_num
,
79 ompt_data_t
*tool_data
);
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
85 void finalizeLibrary(ompt_data_t
*tool_data
);
87 /// This function will connect the \p initializeLibrary and \p finalizeLibrary
88 /// functions to their respective higher layer.
89 void connectLibrary();
91 /// OMPT initialization status; false if initializeLibrary has not been executed
92 extern bool Initialized
;
99 #pragma pop_macro("DEBUG_PREFIX")
102 #define performIfOmptInitialized(stmt)
103 #endif // OMPT_SUPPORT
105 #endif // _OMPTCALLBACK_H