1//===---------- OmptCallback.cpp - Generic OMPT 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// OMPT support for PluginInterface
10//
11//===----------------------------------------------------------------------===//
12
13#ifdef OMPT_SUPPORT
14
15#include "llvm/Support/DynamicLibrary.h"
16
17#include <cstdlib>
18#include <cstring>
19#include <memory>
20
21#include "Shared/Debug.h"
22
23#include "OpenMP/OMPT/Callback.h"
24#include "OpenMP/OMPT/Connector.h"
25
26using namespace llvm::omp::target::ompt;
27
28bool llvm::omp::target::ompt::Initialized = false;
29
30ompt_get_callback_t llvm::omp::target::ompt::lookupCallbackByCode = nullptr;
31ompt_function_lookup_t llvm::omp::target::ompt::lookupCallbackByName = nullptr;
32
33int llvm::omp::target::ompt::initializeLibrary(ompt_function_lookup_t lookup,
34 int initial_device_num,
35 ompt_data_t *tool_data) {
36 DP("OMPT: Executing initializeLibrary (libomptarget)\n");
37#define bindOmptFunctionName(OmptFunction, DestinationFunction) \
38 if (lookup) \
39 DestinationFunction = (OmptFunction##_t)lookup(#OmptFunction); \
40 DP("OMPT: initializeLibrary (libomptarget) bound %s=%p\n", \
41 #DestinationFunction, ((void *)(uint64_t)DestinationFunction));
42
43 bindOmptFunctionName(ompt_get_callback, lookupCallbackByCode);
44#undef bindOmptFunctionName
45
46 // Store pointer of 'ompt_libomp_target_fn_lookup' for use by the plugin
47 lookupCallbackByName = lookup;
48
49 Initialized = true;
50
51 return 0;
52}
53
54void llvm::omp::target::ompt::finalizeLibrary(ompt_data_t *tool_data) {
55 DP("OMPT: Executing finalizeLibrary (libomptarget)\n");
56}
57
58void llvm::omp::target::ompt::connectLibrary() {
59 DP("OMPT: Entering connectLibrary (libomptarget)\n");
60 /// Connect plugin instance with libomptarget
61 OmptLibraryConnectorTy LibomptargetConnector("libomptarget");
62 ompt_start_tool_result_t OmptResult;
63
64 // Initialize OmptResult with the init and fini functions that will be
65 // called by the connector
66 OmptResult.initialize = ompt::initializeLibrary;
67 OmptResult.finalize = ompt::finalizeLibrary;
68 OmptResult.tool_data.value = 0;
69
70 // Now call connect that causes the above init/fini functions to be called
71 LibomptargetConnector.connect(&OmptResult);
72 DP("OMPT: Exiting connectLibrary (libomptarget)\n");
73}
74
75#endif
76

source code of offload/plugins-nextgen/common/OMPT/OmptCallback.cpp