File: OmptCallback.h

package info (click to toggle)
swiftlang 6.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,519,992 kB
  • sloc: cpp: 9,107,863; ansic: 2,040,022; asm: 1,135,751; python: 296,500; objc: 82,456; f90: 60,502; lisp: 34,951; pascal: 19,946; sh: 18,133; perl: 7,482; ml: 4,937; javascript: 4,117; makefile: 3,840; awk: 3,535; xml: 914; fortran: 619; cs: 573; ruby: 573
file content (105 lines) | stat: -rw-r--r-- 4,399 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
//===---- OmptCallback.h - Target independent OMPT callbacks --*- C++ -*---===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// Interface used by target-independent runtimes to coordinate registration and
// invocation of OMPT callbacks and initialization / finalization.
//
//===----------------------------------------------------------------------===//

#ifndef _OMPTCALLBACK_H
#define _OMPTCALLBACK_H

#ifdef OMPT_SUPPORT

#include "omp-tools.h"

#pragma push_macro("DEBUG_PREFIX")
#undef DEBUG_PREFIX
#define DEBUG_PREFIX "OMPT"

#define FOREACH_OMPT_TARGET_CALLBACK(macro)                                    \
  FOREACH_OMPT_DEVICE_EVENT(macro)                                             \
  FOREACH_OMPT_NOEMI_EVENT(macro)                                              \
  FOREACH_OMPT_EMI_EVENT(macro)

#define performIfOmptInitialized(stmt)                                         \
  do {                                                                         \
    if (llvm::omp::target::ompt::Initialized) {                                \
      stmt;                                                                    \
    }                                                                          \
  } while (0)

#define performOmptCallback(CallbackName, ...)                                 \
  do {                                                                         \
    if (ompt_callback_##CallbackName##_fn)                                     \
      ompt_callback_##CallbackName##_fn(__VA_ARGS__);                          \
  } while (0)

/// Function type def used for maintaining unique target region, target
/// operations ids
typedef uint64_t (*IdInterfaceTy)();

namespace llvm {
namespace omp {
namespace target {
namespace ompt {

#define declareOmptCallback(Name, Type, Code) extern Name##_t Name##_fn;
FOREACH_OMPT_NOEMI_EVENT(declareOmptCallback)
FOREACH_OMPT_EMI_EVENT(declareOmptCallback)
#undef declareOmptCallback

/// This function will call an OpenMP API function. Which in turn will lookup a
/// given enum value of type \p ompt_callbacks_t and copy the address of the
/// corresponding callback funtion into the provided pointer.
/// The pointer to the runtime function is passed during 'initializeLibrary'.
/// \p which the enum value of the requested callback function
/// \p callback the destination pointer where the address shall be copied
extern ompt_get_callback_t lookupCallbackByCode;

/// Lookup function to be used by the lower layer (e.g. the plugin). This
/// function has to be provided when actually calling callback functions like
/// 'ompt_callback_device_initialize_fn' (param: 'lookup').
/// The pointer to the runtime function is passed during 'initializeLibrary'.
/// \p InterfaceFunctionName the name of the OMPT callback function to look up
extern ompt_function_lookup_t lookupCallbackByName;

/// This is the function called by the higher layer (libomp / libomtarget)
/// responsible for initializing OMPT in this library. This is passed to libomp
/// as part of the OMPT connector object.
/// \p lookup to be used to query callbacks registered with libomp
/// \p initial_device_num initial device num (id) provided by libomp
/// \p tool_data as provided by the tool
int initializeLibrary(ompt_function_lookup_t lookup, int initial_device_num,
                      ompt_data_t *tool_data);

/// This function is passed to libomp / libomtarget as part of the OMPT
/// connector object. It is called by libomp during finalization of OMPT in
/// libomptarget -OR- by libomptarget during finalization of OMPT in the plugin.
/// \p tool_data as provided by the tool
void finalizeLibrary(ompt_data_t *tool_data);

/// This function will connect the \p initializeLibrary and \p finalizeLibrary
/// functions to their respective higher layer.
void connectLibrary();

/// OMPT initialization status; false if initializeLibrary has not been executed
extern bool Initialized;

} // namespace ompt
} // namespace target
} // namespace omp
} // namespace llvm

#else
#define performIfOmptInitialized(stmt)
#endif // OMPT_SUPPORT

#pragma pop_macro("DEBUG_PREFIX")

#endif // _OMPTCALLBACK_H