[llvm-branch-commits] [llvm] [Offload][OMPT] Add OMPT Profiler to offload. (PR #229410)
Jan Patrick Lehr via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Wed Oct 7 15:51:13 PDT 2026
https://github.com/jplehr updated https://github.com/llvm/llvm-project/pull/229410
>From d9534f33c8a4e172c08f891f9709e35b4ead69ad Mon Sep 17 00:00:00 2001
From: JP Lehr <JanPatrick.Lehr at amd.com>
Date: Thu, 2 Apr 2026 07:40:01 -0500
Subject: [PATCH 1/4] [Offload][OMPT] Add OMPT profiler implementation
Add the OMPT-specific profiler types and plugin tracing implementation without compiling or activating them yet. The existing callback path remains authoritative until the tracing interface and orchestration dependencies are available.
Assisted-by: Claude Code
---
offload/include/OpenMP/OMPT/OmptCommonDefs.h | 127 +++++++
offload/include/OpenMP/OMPT/OmptEventInfoTy.h | 39 +++
offload/plugins-nextgen/common/CMakeLists.txt | 5 +
.../common/OMPT/OmptDeviceTracing.h | 134 ++++++++
.../common/OMPT/OmptProfiler.cpp | 156 +++++++++
.../common/OMPT/OmptProfiler.h | 179 ++++++++++
.../common/OMPT/OmptTracing.cpp | 318 ++++++++++++++++++
7 files changed, 958 insertions(+)
create mode 100644 offload/include/OpenMP/OMPT/OmptCommonDefs.h
create mode 100644 offload/include/OpenMP/OMPT/OmptEventInfoTy.h
create mode 100644 offload/plugins-nextgen/common/OMPT/OmptDeviceTracing.h
create mode 100644 offload/plugins-nextgen/common/OMPT/OmptProfiler.cpp
create mode 100644 offload/plugins-nextgen/common/OMPT/OmptProfiler.h
create mode 100644 offload/plugins-nextgen/common/OMPT/OmptTracing.cpp
diff --git a/offload/include/OpenMP/OMPT/OmptCommonDefs.h b/offload/include/OpenMP/OMPT/OmptCommonDefs.h
new file mode 100644
index 00000000000000..5391658e802629
--- /dev/null
+++ b/offload/include/OpenMP/OMPT/OmptCommonDefs.h
@@ -0,0 +1,127 @@
+//===------ OmptCommonDefs.h - Common definitions for OMPT --*- 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
+//
+//===----------------------------------------------------------------------===//
+//
+// Common defines and typedefs for OMPT callback and tracing functionality.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef OFFLOAD_INCLUDE_OMPTCOMMONDEFS_H
+#define OFFLOAD_INCLUDE_OMPTCOMMONDEFS_H
+
+#ifdef OMPT_SUPPORT
+
+#include "omp-tools.h"
+
+#pragma push_macro("DEBUG_PREFIX")
+#undef DEBUG_PREFIX
+#define DEBUG_PREFIX "OMPT"
+
+#define FUNCPTR_TO_PTR(x) ((void *)(uint64_t)x)
+
+#define FOREACH_OMPT_TARGET_CALLBACK(macro) \
+ FOREACH_OMPT_DEVICE_EVENT(macro) \
+ FOREACH_OMPT_NOEMI_EVENT(macro) \
+ FOREACH_OMPT_EMI_EVENT(macro)
+
+// Common device tracing functions
+#define FOREACH_OMPT_DEVICE_TRACING_FN_COMMON(macro) \
+ macro(ompt_set_trace_ompt) macro(ompt_start_trace) macro(ompt_flush_trace) \
+ macro(ompt_stop_trace) macro(ompt_advance_buffer_cursor) \
+ macro(ompt_get_record_type)
+
+// Supported device tracing entry points
+#define FOREACH_OMPT_DEVICE_TRACING_FN(macro) \
+ FOREACH_OMPT_DEVICE_TRACING_FN_COMMON(macro) \
+ macro(ompt_get_record_ompt) macro(ompt_get_device_time) \
+ macro(ompt_translate_time)
+
+// Device tracing functionalities, which are also e.g. coupled to mutexes
+#define FOREACH_OMPT_DEVICE_TRACING_FN_IMPLEMENTAIONS(macro) \
+ FOREACH_OMPT_DEVICE_TRACING_FN_COMMON(macro) \
+ macro(ompt_set_timestamp) macro(ompt_set_granted_teams)
+
+#define OMPT_API_ROUTINE static
+
+#define OMPT_CALLBACK_AVAILABLE(fn) (llvm::omp::target::ompt::Initialized && fn)
+
+#define OMPT_IF_BUILT(stmt) stmt
+
+#define OMPT_IF_ENABLED(stmts) \
+ do { \
+ if (llvm::omp::target::ompt::Initialized) { \
+ stmts \
+ } \
+ } while (0)
+
+#define OMPT_IF_TRACING_ENABLED(stmts) \
+ do { \
+ if (llvm::omp::target::ompt::TracingActive) { \
+ stmts \
+ } \
+ } while (0)
+
+#define OMPT_FRAME_FLAGS (ompt_frame_runtime | OMPT_FRAME_POSITION_DEFAULT)
+
+#if (__PPC64__ | __arm__)
+#define OMPT_GET_FRAME_ADDRESS(level) __builtin_frame_address(level)
+#define OMPT_FRAME_POSITION_DEFAULT ompt_frame_cfa
+#else
+#define OMPT_GET_FRAME_ADDRESS(level) __builtin_frame_address(level)
+#define OMPT_FRAME_POSITION_DEFAULT ompt_frame_framepointer
+#endif
+
+#define OMPT_PTR_UNKNOWN ((void *)0)
+
+#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)
+
+typedef ompt_set_result_t (*libomptarget_ompt_set_trace_ompt_t)(
+ int Device, unsigned int Enable, unsigned int EventTy);
+typedef int (*libomptarget_ompt_start_trace_t)(int,
+ ompt_callback_buffer_request_t,
+ ompt_callback_buffer_complete_t);
+typedef int (*libomptarget_ompt_flush_trace_t)(int);
+typedef int (*libomptarget_ompt_stop_trace_t)(int);
+typedef int (*libomptarget_ompt_advance_buffer_cursor_t)(
+ ompt_device_t *, ompt_buffer_t *, size_t, ompt_buffer_cursor_t,
+ ompt_buffer_cursor_t *);
+typedef ompt_get_record_ompt_t libomptarget_ompt_get_record_ompt_t;
+typedef ompt_device_time_t (*libomptarget_ompt_get_device_time_t)(
+ ompt_device_t *);
+typedef ompt_translate_time_t libomptarget_ompt_translate_time_t;
+typedef ompt_device_time_t (*libomptarget_ompt_get_device_time_t)(
+ ompt_device_t *);
+typedef ompt_record_t (*libomptarget_ompt_get_record_type_t)(
+ ompt_buffer_t *, ompt_buffer_cursor_t);
+typedef void (*libomptarget_ompt_set_timestamp_t)(uint64_t start, uint64_t end);
+typedef void (*libomptarget_ompt_set_granted_teams_t)(uint32_t);
+
+/// Function type def used for maintaining unique target region, target
+/// operations ids
+typedef uint64_t (*IdInterfaceTy)();
+
+#pragma pop_macro("DEBUG_PREFIX")
+
+#else
+#define performIfOmptInitialized(stmt)
+#define OMPT_IF_BUILT(stmt)
+#define OMPT_IF_ENABLED(stmts)
+#define OMPT_IF_TRACING_ENABLED(stmts)
+#endif // OMPT_SUPPORT
+
+#endif // OFFLOAD_INCLUDE_OMPTCOMMONDEFS_H
diff --git a/offload/include/OpenMP/OMPT/OmptEventInfoTy.h b/offload/include/OpenMP/OMPT/OmptEventInfoTy.h
new file mode 100644
index 00000000000000..7124b3a3ff501b
--- /dev/null
+++ b/offload/include/OpenMP/OMPT/OmptEventInfoTy.h
@@ -0,0 +1,39 @@
+//===- OmptEventInfoTy.h - OMPT specific trace record data ------*- 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
+//
+//===----------------------------------------------------------------------===//
+//
+// Data structure used to communicate OMPT specific profiler data from the
+// high-level libomptarget into the vendor-specific plugins
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef OFFLOAD_INCLUDE_OPENMP_OMPT_OMPTEVENTINFOTY_H
+#define OFFLOAD_INCLUDE_OPENMP_OMPT_OMPTEVENTINFOTY_H
+
+#include "Shared/Debug.h"
+
+struct ompt_record_ompt_t;
+
+namespace llvm {
+namespace omp {
+namespace target {
+namespace ompt {
+
+/// Holds info needed to fill asynchronous trace records
+struct OmptEventInfoTy {
+ /// The granted number of teams at runtime
+ uint64_t NumTeams;
+ /// Pointer to the actual buffer storage location
+ ompt_record_ompt_t *TraceRecord;
+};
+
+} // namespace ompt
+} // namespace target
+} // namespace omp
+} // namespace llvm
+
+#endif // OFFLOAD_INCLUDE_OPENMP_OMPT_OMPTEVENTINFOTY_H
diff --git a/offload/plugins-nextgen/common/CMakeLists.txt b/offload/plugins-nextgen/common/CMakeLists.txt
index 19ce102309a724..556b8ddf3311ca 100644
--- a/offload/plugins-nextgen/common/CMakeLists.txt
+++ b/offload/plugins-nextgen/common/CMakeLists.txt
@@ -37,6 +37,11 @@ endif()
include(FindLibcCommonUtils)
target_link_libraries(PluginCommon PRIVATE llvm-libc-common-utilities)
+if (TARGET flang_rt.runtime.static)
+ target_link_libraries(PluginCommon PRIVATE flang_rt.runtime.static)
+ target_compile_definitions(PluginCommon PRIVATE OFFLOAD_HAS_FLANG_RT)
+endif()
+
# Define the TARGET_NAME and DEBUG_PREFIX.
target_compile_definitions(PluginCommon PRIVATE
TARGET_NAME=PluginInterface
diff --git a/offload/plugins-nextgen/common/OMPT/OmptDeviceTracing.h b/offload/plugins-nextgen/common/OMPT/OmptDeviceTracing.h
new file mode 100644
index 00000000000000..4ffd1976e97307
--- /dev/null
+++ b/offload/plugins-nextgen/common/OMPT/OmptDeviceTracing.h
@@ -0,0 +1,134 @@
+//===- OmptDeviceTracing.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 tracing functionality.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef OPENMP_LIBOMPTARGET_PLUGINS_NEXTGEN_COMMON_OMPTDEVICETRACING_H
+#define OPENMP_LIBOMPTARGET_PLUGINS_NEXTGEN_COMMON_OMPTDEVICETRACING_H
+
+#ifdef OMPT_SUPPORT
+
+#include "OpenMP/OMPT/OmptCommonDefs.h"
+
+#include "llvm/Support/DynamicLibrary.h"
+
+#include <map>
+#include <memory>
+#include <mutex>
+
+#pragma push_macro("DEBUG_PREFIX")
+#undef DEBUG_PREFIX
+#define DEBUG_PREFIX "OMPT"
+
+extern void setOmptAsyncCopyProfile(bool Enable);
+extern void setGlobalOmptKernelProfile(void *Device, int Enable);
+extern uint64_t getSystemTimestampInNs();
+
+namespace llvm {
+namespace omp {
+namespace target {
+namespace ompt {
+
+// Declare OMPT device tracing function entry points
+#define declareOmptTracingFn(Name) extern libomptarget_##Name##_t Name##_fn;
+FOREACH_OMPT_DEVICE_TRACING_FN_IMPLEMENTAIONS(declareOmptTracingFn)
+#undef declareOmptTracingFn
+
+// Declare OMPT device tracing function mutexes
+#define declareOmptTracingFnMutex(Name) extern std::mutex Name##_mutex;
+FOREACH_OMPT_DEVICE_TRACING_FN_IMPLEMENTAIONS(declareOmptTracingFnMutex)
+#undef declareOmptTracingFnMutex
+
+extern std::mutex DeviceIdWritingMutex;
+
+/// Activate tracing on the given device
+void enableDeviceTracing(int DeviceId);
+
+/// Deactivate tracing on the given device
+void disableDeviceTracing(int DeviceId);
+
+/// Set 'start' and 'stop' in trace records
+void setOmptTimestamp(uint64_t StartTime, uint64_t EndTime);
+
+/// Set the linear function correlation between host and device clocks
+void setOmptHostToDeviceRate(double Slope, double Offset);
+
+/// Set / store the number of granted teams in trace records
+void setOmptGrantedNumTeams(uint64_t NumTeams);
+
+/// Lookup the given device pointer and return its RTL device ID
+int getDeviceId(ompt_device_t *Device);
+
+/// Map the given device pointer to the given DeviceId
+void setDeviceId(ompt_device_t *Device, int32_t DeviceId);
+
+/// Rempve the given device pointer from the current mapping
+void removeDeviceId(ompt_device_t *Device);
+
+/// Check whether the provided device is currently traced.
+bool isTracedDevice(int32_t DeviceId);
+
+/// Provide name based lookup for the device tracing functions
+extern ompt_interface_fn_t
+lookupDeviceTracingFn(const char *InterfaceFunctionName);
+
+/// Host to device linear clock correlation
+extern double HostToDeviceSlope;
+
+/// Host to device constant clock offset
+extern double HostToDeviceOffset;
+
+/// Mapping of device pointers to their corresponding RTL device ID
+extern std::map<ompt_device_t *, int32_t> Devices;
+
+/// Mapping of RTL device IDs to their currently enabled tracing event types.
+/// Note: Event type '0' (bit position) indicates if this device is traced.
+extern std::map<int32_t, uint64_t> TracedDevices;
+
+/// OMPT global tracing status. Indicates if at least one device is traced.
+extern bool TracingActive;
+
+/// Parent library pointer
+extern std::shared_ptr<llvm::sys::DynamicLibrary> ParentLibrary;
+
+/// Get the parent library by pointer. If it is not already set, it will set the
+/// parent library pointer.
+std::shared_ptr<llvm::sys::DynamicLibrary> getParentLibrary();
+
+/// Set the parent library by filename
+void setParentLibrary(const char *Filename);
+
+/// Search for FuncName inside the parent library and assign to FuncPtr.
+/// IMPORTANT: This function assumes that the *caller* holds the respective lock
+/// for FuncPtr.
+template <typename FT>
+void ensureFuncPtrLoaded(const std::string &FuncName, FT *FuncPtr) {
+ if (*FuncPtr == nullptr) {
+ if ((ParentLibrary == nullptr && getParentLibrary() == nullptr) ||
+ !ParentLibrary->isValid())
+ return;
+ void *SymbolPtr = ParentLibrary->getAddressOfSymbol(FuncName.c_str());
+ if (SymbolPtr == nullptr)
+ return;
+ *FuncPtr = reinterpret_cast<FT>(SymbolPtr);
+ }
+}
+
+} // namespace ompt
+} // namespace target
+} // namespace omp
+} // namespace llvm
+
+#pragma pop_macro("DEBUG_PREFIX")
+
+#endif // OMPT_SUPPORT
+
+#endif // OPENMP_LIBOMPTARGET_PLUGINS_NEXTGEN_COMMON_OMPTDEVICETRACING_H
diff --git a/offload/plugins-nextgen/common/OMPT/OmptProfiler.cpp b/offload/plugins-nextgen/common/OMPT/OmptProfiler.cpp
new file mode 100644
index 00000000000000..9e8a0960b97119
--- /dev/null
+++ b/offload/plugins-nextgen/common/OMPT/OmptProfiler.cpp
@@ -0,0 +1,156 @@
+//===- OmptProfiler.cpp - OMPT impl of GenericProfilerTy --------*- 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
+//
+//===----------------------------------------------------------------------===//
+//
+// Implementation of OmptProfilerTy
+//
+//===----------------------------------------------------------------------===//
+
+#include "OmptProfiler.h"
+#include "OpenMP/OMPT/Interface.h"
+#include "PluginInterface.h"
+#include "Shared/Debug.h"
+
+#include <memory>
+
+using namespace llvm::omp::target;
+
+void ompt::OmptProfilerTy::handleInit(plugin::GenericDeviceTy *Device,
+ plugin::GenericPluginTy *Plugin) {
+ auto DeviceId = Device->getDeviceId();
+ auto DevicePtr = reinterpret_cast<ompt_device_t *>(Device);
+ ompt::setDeviceId(DevicePtr, Plugin->getUserId(DeviceId));
+
+ if (ompt::Initialized) {
+ bool ExpectedStatus = false;
+ if (OmptInitialized.compare_exchange_strong(ExpectedStatus, true))
+ performOmptCallback(device_initialize, Plugin->getUserId(DeviceId),
+ /*type=*/Device->getComputeUnitKind().c_str(),
+ /*device=*/DevicePtr,
+ /*lookup=*/ompt::lookupDeviceTracingFn,
+ /*documentation=*/nullptr);
+ }
+}
+
+void ompt::OmptProfilerTy::handleDeinit(
+ plugin::GenericDeviceTy *Device, target::plugin::GenericPluginTy *Plugin) {
+ auto DeviceId = Device->getDeviceId();
+
+ if (ompt::Initialized) {
+ bool ExpectedStatus = true;
+ if (OmptInitialized.compare_exchange_strong(ExpectedStatus, false))
+ performOmptCallback(device_finalize, Plugin->getUserId(DeviceId));
+ }
+ ompt::removeDeviceId(reinterpret_cast<ompt_device_t *>(Device));
+}
+
+void ompt::OmptProfilerTy::handleLoadBinary(plugin::GenericDeviceTy *Device,
+ plugin::GenericPluginTy *Plugin,
+ const StringRef InputTgtImage) {
+
+ if (!ompt::Initialized)
+ return;
+
+ auto DeviceId = Device->getDeviceId();
+ size_t Bytes = InputTgtImage.size();
+ performOmptCallback(
+ device_load, Plugin->getUserId(DeviceId),
+ /*FileName=*/nullptr, /*FileOffset=*/0, /*VmaInFile=*/nullptr,
+ /*ImgSize=*/Bytes,
+ /*HostAddr=*/const_cast<unsigned char *>(InputTgtImage.bytes_begin()),
+ /*DeviceAddr=*/nullptr, /* FIXME: ModuleId */ 0);
+}
+
+void ompt::OmptProfilerTy::handleDataAlloc(uint64_t StartNanos,
+ uint64_t EndNanos, void *HostPtr,
+ uint64_t Size, void *Data) {
+ ompt::setOmptTimestamp(StartNanos, EndNanos);
+}
+
+void ompt::OmptProfilerTy::handleDataDelete(uint64_t StartNanos,
+ uint64_t EndNanos, void *TgtPtr,
+ void *Data) {
+ ompt::setOmptTimestamp(StartNanos, EndNanos);
+}
+
+void ompt::OmptProfilerTy::handlePreKernelLaunch(
+ plugin::GenericDeviceTy *Device, uint32_t NumBlocks[3],
+ __tgt_async_info *AI) {
+ if (!ompt::isTracedDevice(
+ ompt::getDeviceId(reinterpret_cast<ompt_device_t *>(Device))))
+ return;
+
+ if (AI->ProfilerData == nullptr)
+ return;
+
+ auto ProfilerSpecificData =
+ reinterpret_cast<ompt::OmptEventInfoTy *>(AI->ProfilerData);
+ assert(ProfilerSpecificData && "Invalid ProfilerSpecificData");
+ // Set number of granted teams for OMPT
+ setOmptGrantedNumTeams(NumBlocks[0]);
+ ProfilerSpecificData->NumTeams = NumBlocks[0];
+}
+
+void ompt::OmptProfilerTy::handleKernelCompletion(uint64_t StartNanos,
+ uint64_t EndNanos,
+ void *Data) {
+
+ if (!isProfilingEnabled())
+ return;
+
+ /// Empty data means no tracing in OMPT
+ /// offload/include/OpenMP/OMPT/Interface.h line 492
+ if (!Data)
+ return;
+
+ ODBG(ODT_Tool) << "OMPT-Async: Time kernel for asynchronous execution: Start "
+ << StartNanos << " End " << EndNanos;
+
+ auto OmptEventInfo = reinterpret_cast<ompt::OmptEventInfoTy *>(Data);
+ assert(OmptEventInfo && "Invalid OmptEventInfo");
+ assert(OmptEventInfo->TraceRecord && "Invalid TraceRecord");
+
+ ompt::RegionInterface.stopTargetSubmitTraceAsync(OmptEventInfo->TraceRecord,
+ OmptEventInfo->NumTeams,
+ StartNanos, EndNanos);
+
+ // Done processing, our responsibility to free the memory
+ freeProfilerDataEntry(OmptEventInfo);
+}
+
+void ompt::OmptProfilerTy::handleDataTransfer(uint64_t StartNanos,
+ uint64_t EndNanos, void *Data) {
+
+ if (!isProfilingEnabled())
+ return;
+
+ /// Empty data means no tracing in OMPT
+ /// offload/include/OpenMP/OMPT/Interface.h line 492
+ if (!Data)
+ return;
+
+ ODBG(ODT_Tool) << "OMPT-Async: Time data for asynchronous execution: Start "
+ << StartNanos << " End " << EndNanos;
+
+ auto OmptEventInfo = reinterpret_cast<ompt::OmptEventInfoTy *>(Data);
+ assert(OmptEventInfo && "Invalid OmptEventInfo");
+ assert(OmptEventInfo->TraceRecord && "Invalid TraceRecord");
+
+ ompt::RegionInterface.stopTargetDataMovementTraceAsync(
+ OmptEventInfo->TraceRecord, StartNanos, EndNanos);
+
+ // Done processing, our responsibility to free the memory
+ freeProfilerDataEntry(OmptEventInfo);
+}
+
+bool ompt::OmptProfilerTy::isProfilingEnabled() { return ompt::TracingActive; }
+
+void ompt::OmptProfilerTy::setTimeConversionFactorsImpl(double Slope,
+ double Offset) {
+ ODBG(ODT_Tool) << "Using Time Slope: " << Slope << " and Offset: " << Offset;
+ setOmptHostToDeviceRate(Slope, Offset);
+}
diff --git a/offload/plugins-nextgen/common/OMPT/OmptProfiler.h b/offload/plugins-nextgen/common/OMPT/OmptProfiler.h
new file mode 100644
index 00000000000000..5376fa145134a1
--- /dev/null
+++ b/offload/plugins-nextgen/common/OMPT/OmptProfiler.h
@@ -0,0 +1,179 @@
+//===- OmptProfiler.h - OMPT specific impl of GenericProfilerTy -*- 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
+//
+//===----------------------------------------------------------------------===//
+//
+// OMPT specific implementation of the GenericProfilerTy class.
+// This class uses the already existing implementation of OMPT to invoke
+// callbacks and perform tracing.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef OFFLOAD_PLUGINS_NEXTGEN_COMMON_OMPT_OMPTPROFILERTY_H
+#define OFFLOAD_PLUGINS_NEXTGEN_COMMON_OMPT_OMPTPROFILERTY_H
+
+#include "GenericProfiler.h"
+
+#include "OmptDeviceTracing.h"
+#include "OpenMP/OMPT/Callback.h"
+#include "OpenMP/OMPT/OmptEventInfoTy.h"
+#include "OpenMP/OMPT/OmptTracingBuffer.h"
+#include "Shared/Debug.h"
+#include "omp-tools.h"
+
+#include <functional>
+#include <memory>
+#include <mutex>
+#include <tuple>
+
+#pragma push_macro("DEBUG_PREFIX")
+#undef DEBUG_PREFIX
+#define DEBUG_PREFIX "OMPT"
+
+extern uint64_t getSystemTimestampInNs();
+
+using namespace llvm::omp::target::debug;
+
+namespace llvm {
+namespace omp {
+namespace target {
+namespace plugin {
+struct GenericDeviceTy;
+struct GenericPluginTy;
+class GenericProfilerTy;
+
+} // namespace plugin
+
+namespace ompt {
+
+// From Callback.h / Callback.cpp
+extern bool Initialized;
+
+/**
+ * Implements an OMPT backend for the Profiler interface used in the plugins.
+ *
+ * Forwards / Implements the different generic hooks with OMPT semantics.
+ */
+class OmptProfilerTy : public plugin::GenericProfilerTy {
+public:
+ /** Public members **/
+ OmptProfilerTy() {
+
+ OmptInitialized.store(false);
+ // Bind the callbacks to this device's member functions
+#define bindOmptCallback(Name, Type, Code) \
+ if (ompt::Initialized && ompt::lookupCallbackByCode) { \
+ ompt::lookupCallbackByCode((ompt_callbacks_t)(Code), \
+ ((ompt_callback_t *)&(Name##_fn))); \
+ ODBG(ODT_Tool) << "class bound " << #Name << "=" \
+ << ((void *)(uint64_t)Name##_fn); \
+ }
+
+ FOREACH_OMPT_DEVICE_EVENT(bindOmptCallback);
+#undef bindOmptCallback
+
+#define bindOmptTracingFunction(FunctionName) \
+ if (ompt::Initialized && ompt::lookupDeviceTracingFn) { \
+ FunctionName##_fn = ompt::lookupDeviceTracingFn(#FunctionName); \
+ ODBG(ODT_Tool) << "device tracing fn bound " << #FunctionName << "=" \
+ << ((void *)(uint64_t)FunctionName##_fn); \
+ }
+
+ FOREACH_OMPT_DEVICE_TRACING_FN_COMMON(bindOmptTracingFunction);
+#undef bindOmptTracingFunction
+ }
+
+ bool isProfilingEnabled() override;
+
+ void handleInit(plugin::GenericDeviceTy *Device,
+ plugin::GenericPluginTy *Plugin) override;
+
+ void handleDeinit(plugin::GenericDeviceTy *Device,
+ plugin::GenericPluginTy *Plugin) override;
+
+ void handleLoadBinary(plugin::GenericDeviceTy *Device,
+ plugin::GenericPluginTy *Plugin,
+ const StringRef InputTgtImage) override;
+
+ void handleDataAlloc(uint64_t StartNanos, uint64_t EndNanos, void *HostPtr,
+ uint64_t Size, void *Data) override;
+ void handleDataDelete(uint64_t StartNanos, uint64_t EndNanos, void *TgtPtr,
+ void *Data) override;
+
+ void handlePreKernelLaunch(plugin::GenericDeviceTy *Device,
+ uint32_t NumBlocks[3],
+ __tgt_async_info *AI) override;
+
+ void handleKernelCompletion(uint64_t StartNanos, uint64_t EndNanos,
+ void *Data) override;
+
+ void handleDataTransfer(uint64_t StartNanos, uint64_t EndNanos,
+ void *Data) override;
+
+ void setTimeConversionFactorsImpl(double Slope, double Offset) override;
+
+ void *getProfilerSpecificData() override {
+ // TODO: This is ID is not used currently
+ uint64_t Id = OmptProfDataId.fetch_add(1);
+ {
+ std::scoped_lock<std::mutex> Lock(ProfilerDataMutex);
+ ProfilerData[Id] = std::make_unique<OmptEventInfoTy>();
+ return ProfilerData[Id].get();
+ }
+ }
+
+ void freeProfilerDataEntry(OmptEventInfoTy *DataPtr) {
+ std::scoped_lock<std::mutex> Lock(ProfilerDataMutex);
+
+ for (auto &Entry : ProfilerData)
+ if (Entry.second.get() == DataPtr) {
+ ProfilerData.erase(Entry.first);
+ break;
+ }
+ }
+
+ /// The trace records handed out here point into buffers owned by the trace
+ /// buffer manager, so the profiler owns it to bind both lifetimes.
+ OmptTracingBufferMgr *getTraceRecordManager() override {
+ return TraceRecordManager.get();
+ }
+
+private:
+ /// Trace buffer manager whose records the ProfilerData entries refer to.
+ std::unique_ptr<OmptTracingBufferMgr> TraceRecordManager =
+ std::make_unique<OmptTracingBufferMgr>();
+
+ /// Holds a unique ID for each allocation of OmptEventInfoTy
+ std::atomic<uint64_t> OmptProfDataId{0};
+
+ /// Holds memory used to store OMPT specific data and pass it down from
+ /// libomptarget into the plugins.
+ std::map<uint64_t, std::unique_ptr<OmptEventInfoTy>> ProfilerData;
+
+ /// Lock to guard STL ProfilerData map
+ std::mutex ProfilerDataMutex;
+
+ /// OMPT callback functions
+#define defineOmptCallback(Name, Type, Code) Name##_t Name##_fn = nullptr;
+ FOREACH_OMPT_DEVICE_EVENT(defineOmptCallback)
+#undef defineOmptCallback
+
+ /// OMPT device tracing functions
+#define defineOmptTracingFunction(Name) ompt_interface_fn_t Name##_fn = nullptr;
+ FOREACH_OMPT_DEVICE_TRACING_FN_COMMON(defineOmptTracingFunction);
+#undef defineOmptTracingFunction
+
+ /// Internal representation for OMPT device (initialize & finalize)
+ std::atomic<bool> OmptInitialized;
+};
+} // namespace ompt
+} // namespace target
+} // namespace omp
+} // namespace llvm
+
+#pragma pop_macro("DEBUG_PREFIX")
+
+#endif
diff --git a/offload/plugins-nextgen/common/OMPT/OmptTracing.cpp b/offload/plugins-nextgen/common/OMPT/OmptTracing.cpp
new file mode 100644
index 00000000000000..7a8e312b3d4768
--- /dev/null
+++ b/offload/plugins-nextgen/common/OMPT/OmptTracing.cpp
@@ -0,0 +1,318 @@
+//===-- OmptTracing.cpp - Target independent OpenMP target RTL --- 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
+//
+//===----------------------------------------------------------------------===//
+//
+// Implementation of OMPT tracing interfaces for PluginInterface
+//
+//===----------------------------------------------------------------------===//
+
+#ifdef OMPT_SUPPORT
+
+#include "OmptDeviceTracing.h"
+#include "Shared/Debug.h"
+#include "omp-tools.h"
+
+#include "llvm/Support/DynamicLibrary.h"
+
+#include <atomic>
+#include <cassert>
+#include <cstdlib>
+#include <cstring>
+#include <memory>
+#include <mutex>
+
+#pragma push_macro("DEBUG_PREFIX")
+#undef DEBUG_PREFIX
+#define DEBUG_PREFIX "OMPT"
+
+// Define OMPT device tracing function entry points
+#define defineOmptTracingFn(Name) \
+ libomptarget_##Name##_t llvm::omp::target::ompt::Name##_fn = nullptr;
+FOREACH_OMPT_DEVICE_TRACING_FN_IMPLEMENTAIONS(defineOmptTracingFn)
+#undef defineOmptTracingFn
+
+// Define OMPT device tracing function mutexes
+#define defineOmptTracingFnMutex(Name) \
+ std::mutex llvm::omp::target::ompt::Name##_mutex;
+FOREACH_OMPT_DEVICE_TRACING_FN_IMPLEMENTAIONS(defineOmptTracingFnMutex)
+#undef defineOmptTracingFnMutex
+
+std::mutex llvm::omp::target::ompt::DeviceIdWritingMutex;
+
+using namespace llvm::omp::target::ompt;
+using namespace llvm::omp::target::debug;
+
+std::shared_ptr<llvm::sys::DynamicLibrary>
+ llvm::omp::target::ompt::ParentLibrary(nullptr);
+
+double llvm::omp::target::ompt::HostToDeviceSlope = .0;
+double llvm::omp::target::ompt::HostToDeviceOffset = .0;
+
+std::map<ompt_device_t *, int32_t> llvm::omp::target::ompt::Devices;
+
+std::shared_ptr<llvm::sys::DynamicLibrary>
+llvm::omp::target::ompt::getParentLibrary() {
+ static bool ParentLibraryAssigned = false;
+ if (!ParentLibraryAssigned) {
+ setParentLibrary("libomptarget.so");
+ ParentLibraryAssigned = true;
+ }
+ return ParentLibrary;
+}
+
+void llvm::omp::target::ompt::setParentLibrary(const char *Filename) {
+ if (ParentLibrary)
+ return;
+ std::string ErrorMsg;
+ ParentLibrary = std::make_shared<llvm::sys::DynamicLibrary>(
+ llvm::sys::DynamicLibrary::getPermanentLibrary(Filename, &ErrorMsg));
+ if ((ParentLibrary == nullptr) || (!ParentLibrary->isValid()))
+ REPORT() << "Failed to set parent library: " << ErrorMsg.c_str();
+}
+
+int llvm::omp::target::ompt::getDeviceId(ompt_device_t *Device) {
+ // Block other threads, which might trigger an erase (for the same device)
+ std::unique_lock<std::mutex> Lock(DeviceIdWritingMutex);
+ auto DeviceIterator = Devices.find(Device);
+ if (Device == nullptr || DeviceIterator == Devices.end()) {
+ REPORT() << "Failed to get ID for Device=" << Device;
+ return -1;
+ }
+ return DeviceIterator->second;
+}
+
+void llvm::omp::target::ompt::setDeviceId(ompt_device_t *Device,
+ int32_t DeviceId) {
+ assert(Device && "Mapping device ID to nullptr is not allowed");
+ if (Device == nullptr || DeviceId < 0) {
+ REPORT() << "Failed to set ID=%d for Device=" << DeviceId << Device;
+ return;
+ }
+ std::unique_lock<std::mutex> Lock(DeviceIdWritingMutex);
+ auto DeviceIterator = Devices.find(Device);
+ if (DeviceIterator != Devices.end()) {
+ auto CurrentDeviceId = DeviceIterator->second;
+ if (DeviceId == CurrentDeviceId) {
+ REPORT() << "Tried to duplicate OMPT Device= " << Device
+ << " ID=" << DeviceId;
+ } else {
+ REPORT() << "Tried to overwrite OMPT Device=" << Device
+ << " (ID=" << CurrentDeviceId << " with new ID=" << DeviceId;
+ }
+ return;
+ }
+ Devices.emplace(Device, DeviceId);
+}
+
+void llvm::omp::target::ompt::removeDeviceId(ompt_device_t *Device) {
+ int DeviceId = getDeviceId(Device);
+ if (DeviceId < 0) {
+ REPORT() << "Tried to remove Device= " << Device << " ID=" << DeviceId;
+ return;
+ }
+ std::unique_lock<std::mutex> Lock(DeviceIdWritingMutex);
+ Devices.erase(Device);
+ TracedDevices.erase(DeviceId);
+}
+
+OMPT_API_ROUTINE ompt_set_result_t ompt_set_trace_ompt(ompt_device_t *Device,
+ unsigned int Enable,
+ unsigned int EventTy) {
+ ODBG(ODT_Tool) << "Executing ompt_set_trace_ompt";
+
+ int DeviceId = getDeviceId(Device);
+ if (DeviceId < 0) {
+ REPORT() << "Failed to set trace events for Device=" << Device
+ << " (Unknown device) [Enable=" << Enable
+ << " EventTy=" << EventTy;
+ return ompt_set_never;
+ }
+
+ std::unique_lock<std::mutex> Lock(ompt_set_trace_ompt_mutex);
+ ensureFuncPtrLoaded<libomptarget_ompt_set_trace_ompt_t>(
+ "libomptarget_ompt_set_trace_ompt", &ompt_set_trace_ompt_fn);
+ assert(ompt_set_trace_ompt_fn && "libomptarget_ompt_set_trace_ompt loaded");
+ return ompt_set_trace_ompt_fn(DeviceId, Enable, EventTy);
+}
+
+OMPT_API_ROUTINE int
+ompt_start_trace(ompt_device_t *Device, ompt_callback_buffer_request_t Request,
+ ompt_callback_buffer_complete_t Complete) {
+ ODBG(ODT_Tool) << "Executing ompt_start_trace";
+
+ int DeviceId = getDeviceId(Device);
+ if (DeviceId < 0) {
+ REPORT() << "Failed to start trace for Device=" << Device
+ << " (Unknown device";
+ // Indicate failure
+ return 0;
+ }
+
+ {
+ // Protect the function pointer
+ std::unique_lock<std::mutex> Lock(ompt_start_trace_mutex);
+
+ if (Request && Complete) {
+ llvm::omp::target::ompt::enableDeviceTracing(DeviceId);
+ // Enable asynchronous memory copy profiling
+ setOmptAsyncCopyProfile(/*Enable=*/true);
+ // Enable queue dispatch profiling
+ if (DeviceId >= 0)
+ setGlobalOmptKernelProfile(Device, /*Enable=*/1);
+ else
+ REPORT() << "May not enable kernel profiling for invalid device id="
+ << DeviceId;
+ }
+
+ // Call libomptarget specific function
+ ensureFuncPtrLoaded<libomptarget_ompt_start_trace_t>(
+ "libomptarget_ompt_start_trace", &ompt_start_trace_fn);
+ assert(ompt_start_trace_fn && "libomptarget_ompt_start_trace loaded");
+ }
+ return ompt_start_trace_fn(DeviceId, Request, Complete);
+}
+
+OMPT_API_ROUTINE int ompt_flush_trace(ompt_device_t *Device) {
+ ODBG(ODT_Tool) << "Executing ompt_flush_trace";
+
+ std::unique_lock<std::mutex> Lock(ompt_flush_trace_mutex);
+ ensureFuncPtrLoaded<libomptarget_ompt_flush_trace_t>(
+ "libomptarget_ompt_flush_trace", &ompt_flush_trace_fn);
+ assert(ompt_flush_trace_fn && "libomptarget_ompt_flush_trace loaded");
+ return ompt_flush_trace_fn(getDeviceId(Device));
+}
+
+OMPT_API_ROUTINE int ompt_stop_trace(ompt_device_t *Device) {
+ ODBG(ODT_Tool) << "Executing ompt_stop_trace";
+
+ int DeviceId = getDeviceId(Device);
+ if (DeviceId < 0) {
+ REPORT() << "Failed to stop trace for Device=" << Device
+ << " (Unknown device)";
+ // Indicate failure
+ return 0;
+ }
+
+ {
+ // Protect the function pointer
+ std::unique_lock<std::mutex> Lock(ompt_stop_trace_mutex);
+ llvm::omp::target::ompt::disableDeviceTracing(DeviceId);
+ // Disable asynchronous memory copy profiling
+ setOmptAsyncCopyProfile(/*Enable=*/false);
+ // Disable queue dispatch profiling
+ if (DeviceId >= 0)
+ setGlobalOmptKernelProfile(Device, /*Enable=*/0);
+ else
+ REPORT() << "May not disable kernel profiling for invalid device id="
+ << DeviceId;
+ ensureFuncPtrLoaded<libomptarget_ompt_stop_trace_t>(
+ "libomptarget_ompt_stop_trace", &ompt_stop_trace_fn);
+ assert(ompt_stop_trace_fn && "libomptarget_ompt_stop_trace loaded");
+ }
+ return ompt_stop_trace_fn(DeviceId);
+}
+
+OMPT_API_ROUTINE ompt_record_ompt_t *
+ompt_get_record_ompt(ompt_buffer_t *Buffer, ompt_buffer_cursor_t CurrentPos) {
+ // TODO In debug mode, get the metadata associated with this buffer
+ // and assert that there are enough bytes for the current record
+
+ // Currently, no synchronization required since a disjoint set of
+ // trace records is handed over to a thread.
+
+ // Note that CurrentPos can be nullptr. In that case, we return
+ // nullptr. The tool has to handle that properly.
+ return (ompt_record_ompt_t *)CurrentPos;
+}
+
+OMPT_API_ROUTINE int ompt_advance_buffer_cursor(ompt_device_t *Device,
+ ompt_buffer_t *Buffer,
+ size_t Size,
+ ompt_buffer_cursor_t CurrentPos,
+ ompt_buffer_cursor_t *NextPos) {
+ // Note: The input parameter size is unused here. It refers to the
+ // bytes returned in the corresponding callback.
+ // Advance can be called concurrently, so synchronize setting the
+ // function pointer. The actual libomptarget function does not need
+ // to be synchronized since it must be working on logically disjoint
+ // buffers.
+ std::unique_lock<std::mutex> Lock(ompt_advance_buffer_cursor_mutex);
+ ensureFuncPtrLoaded<libomptarget_ompt_advance_buffer_cursor_t>(
+ "libomptarget_ompt_advance_buffer_cursor",
+ &ompt_advance_buffer_cursor_fn);
+ assert(ompt_advance_buffer_cursor_fn &&
+ "libomptarget_ompt_advance_buffer_cursor loaded");
+ return ompt_advance_buffer_cursor_fn(Device, Buffer, Size, CurrentPos,
+ NextPos);
+}
+
+OMPT_API_ROUTINE ompt_record_t
+ompt_get_record_type(ompt_buffer_t *Buffer, ompt_buffer_cursor_t CurrentPos) {
+ std::unique_lock<std::mutex> Lock(ompt_get_record_type_mutex);
+ ensureFuncPtrLoaded<libomptarget_ompt_get_record_type_t>(
+ "libomptarget_ompt_get_record_type", &ompt_get_record_type_fn);
+ assert(ompt_get_record_type_fn && "libomptarget_ompt_get_record_type loaded");
+ return ompt_get_record_type_fn(Buffer, CurrentPos);
+}
+
+OMPT_API_ROUTINE ompt_device_time_t
+ompt_get_device_time(ompt_device_t *Device) {
+ ODBG(ODT_Tool) << "Executing ompt_get_device_time";
+ return getSystemTimestampInNs();
+}
+
+OMPT_API_ROUTINE double ompt_translate_time(ompt_device_t *Device,
+ ompt_device_time_t DeviceTime) {
+ // Translate a device time to a meaningful timepoint in host time
+ // We do not need to account for clock-skew / drift. So simple linear
+ // translation using the host to device rate we obtained.
+ double TranslatedTime = DeviceTime * HostToDeviceSlope + HostToDeviceOffset;
+ ODBG(ODT_Tool) << "D2H translated time: " << TranslatedTime;
+
+ return TranslatedTime;
+}
+
+void llvm::omp::target::ompt::setOmptTimestamp(uint64_t StartTime,
+ uint64_t EndTime) {
+ std::unique_lock<std::mutex> Lock(ompt_set_timestamp_mutex);
+ ensureFuncPtrLoaded<libomptarget_ompt_set_timestamp_t>(
+ "libomptarget_ompt_set_timestamp", &ompt_set_timestamp_fn);
+ // No need to hold a lock
+ ompt_set_timestamp_fn(StartTime, EndTime);
+}
+
+void llvm::omp::target::ompt::setOmptHostToDeviceRate(double Slope,
+ double Offset) {
+ HostToDeviceSlope = Slope;
+ HostToDeviceOffset = Offset;
+}
+
+void llvm::omp::target::ompt::setOmptGrantedNumTeams(uint64_t NumTeams) {
+ std::unique_lock<std::mutex> Lock(ompt_set_granted_teams_mutex);
+ ensureFuncPtrLoaded<libomptarget_ompt_set_granted_teams_t>(
+ "libomptarget_ompt_set_granted_teams", &ompt_set_granted_teams_fn);
+ // No need to hold a lock
+ ompt_set_granted_teams_fn(NumTeams);
+}
+
+ompt_interface_fn_t llvm::omp::target::ompt::lookupDeviceTracingFn(
+ const char *InterfaceFunctionName) {
+#define compareAgainst(AvailableFunction) \
+ if (strcmp(InterfaceFunctionName, #AvailableFunction) == 0) \
+ return (ompt_interface_fn_t)AvailableFunction;
+
+ FOREACH_OMPT_DEVICE_TRACING_FN(compareAgainst);
+#undef compareAgainst
+
+ ODBG(ODT_Tool) << "Warning: Could not find requested function "
+ << InterfaceFunctionName;
+ return (ompt_interface_fn_t) nullptr;
+}
+
+#pragma pop_macro("DEBUG_PREFIX")
+
+#endif // OMPT_SUPPORT
>From d280e72072741acfa0d0b53ef412bdc0696e1dcf Mon Sep 17 00:00:00 2001
From: JP Lehr <JanPatrick.Lehr at amd.com>
Date: Fri, 25 Sep 2026 06:25:25 -0500
Subject: [PATCH 2/4] [Offload][OMPT] Call device tracing entry points directly
The plugin-side tracing code reached the libomptarget-side entry points by
dlopen'ing "libomptarget.so" and dlsym'ing each libomptarget_ompt_* symbol
on first use. That indirection dates back to when libomptarget and the
plugins were separate shared objects. They are not: PluginOmpt is linked
into omptarget itself, so the library was dlopen'ing itself to look up its
own symbols. The callback path was already converted to direct calls; the
tracing path should never have reintroduced the pattern.
Declare the entry points in OmptCommonDefs.h and call them directly. This
removes ParentLibrary, ensureFuncPtrLoaded(), the generated function
pointers, and the libomptarget_ompt_*_t typedefs (two of which were
duplicates, and three of which were never used).
Calling directly also means the symbols no longer have to be exported, so
no version script entry is needed for them.
The per-entry-point mutexes are left untouched here: they currently wrap
the calls themselves, so keeping them preserves the existing locking
behavior exactly. Reducing them is a separate change.
Co-Authored-By: Claude Opus 4.6 <noreply at anthropic.com>
---
offload/include/OpenMP/OMPT/OmptCommonDefs.h | 41 ++++-----
.../common/OMPT/OmptDeviceTracing.h | 34 -------
.../common/OMPT/OmptTracing.cpp | 88 +++----------------
3 files changed, 34 insertions(+), 129 deletions(-)
diff --git a/offload/include/OpenMP/OMPT/OmptCommonDefs.h b/offload/include/OpenMP/OMPT/OmptCommonDefs.h
index 5391658e802629..8ab2ba10a86933 100644
--- a/offload/include/OpenMP/OMPT/OmptCommonDefs.h
+++ b/offload/include/OpenMP/OMPT/OmptCommonDefs.h
@@ -90,26 +90,27 @@
ompt_callback_##CallbackName##_fn(__VA_ARGS__); \
} while (0)
-typedef ompt_set_result_t (*libomptarget_ompt_set_trace_ompt_t)(
- int Device, unsigned int Enable, unsigned int EventTy);
-typedef int (*libomptarget_ompt_start_trace_t)(int,
- ompt_callback_buffer_request_t,
- ompt_callback_buffer_complete_t);
-typedef int (*libomptarget_ompt_flush_trace_t)(int);
-typedef int (*libomptarget_ompt_stop_trace_t)(int);
-typedef int (*libomptarget_ompt_advance_buffer_cursor_t)(
- ompt_device_t *, ompt_buffer_t *, size_t, ompt_buffer_cursor_t,
- ompt_buffer_cursor_t *);
-typedef ompt_get_record_ompt_t libomptarget_ompt_get_record_ompt_t;
-typedef ompt_device_time_t (*libomptarget_ompt_get_device_time_t)(
- ompt_device_t *);
-typedef ompt_translate_time_t libomptarget_ompt_translate_time_t;
-typedef ompt_device_time_t (*libomptarget_ompt_get_device_time_t)(
- ompt_device_t *);
-typedef ompt_record_t (*libomptarget_ompt_get_record_type_t)(
- ompt_buffer_t *, ompt_buffer_cursor_t);
-typedef void (*libomptarget_ompt_set_timestamp_t)(uint64_t start, uint64_t end);
-typedef void (*libomptarget_ompt_set_granted_teams_t)(uint32_t);
+/// Device-independent OMPT tracing entry points, implemented by libomptarget
+/// and linked into the same library as their plugin-side callers.
+extern "C" {
+ompt_set_result_t libomptarget_ompt_set_trace_ompt(int DeviceId,
+ unsigned int Enable,
+ unsigned int EventTy);
+int libomptarget_ompt_start_trace(int DeviceId,
+ ompt_callback_buffer_request_t Request,
+ ompt_callback_buffer_complete_t Complete);
+int libomptarget_ompt_flush_trace(int DeviceId);
+int libomptarget_ompt_stop_trace(int DeviceId);
+int libomptarget_ompt_advance_buffer_cursor(ompt_device_t *Device,
+ ompt_buffer_t *Buffer, size_t Size,
+ ompt_buffer_cursor_t CurrentPos,
+ ompt_buffer_cursor_t *NextPos);
+ompt_record_t
+libomptarget_ompt_get_record_type(ompt_buffer_t *Buffer,
+ ompt_buffer_cursor_t CurrentPos);
+void libomptarget_ompt_set_granted_teams(uint32_t NumTeams);
+void libomptarget_ompt_set_timestamp(uint64_t Start, uint64_t Stop);
+} // extern "C"
/// Function type def used for maintaining unique target region, target
/// operations ids
diff --git a/offload/plugins-nextgen/common/OMPT/OmptDeviceTracing.h b/offload/plugins-nextgen/common/OMPT/OmptDeviceTracing.h
index 4ffd1976e97307..adc3695b139876 100644
--- a/offload/plugins-nextgen/common/OMPT/OmptDeviceTracing.h
+++ b/offload/plugins-nextgen/common/OMPT/OmptDeviceTracing.h
@@ -18,10 +18,7 @@
#include "OpenMP/OMPT/OmptCommonDefs.h"
-#include "llvm/Support/DynamicLibrary.h"
-
#include <map>
-#include <memory>
#include <mutex>
#pragma push_macro("DEBUG_PREFIX")
@@ -37,11 +34,6 @@ namespace omp {
namespace target {
namespace ompt {
-// Declare OMPT device tracing function entry points
-#define declareOmptTracingFn(Name) extern libomptarget_##Name##_t Name##_fn;
-FOREACH_OMPT_DEVICE_TRACING_FN_IMPLEMENTAIONS(declareOmptTracingFn)
-#undef declareOmptTracingFn
-
// Declare OMPT device tracing function mutexes
#define declareOmptTracingFnMutex(Name) extern std::mutex Name##_mutex;
FOREACH_OMPT_DEVICE_TRACING_FN_IMPLEMENTAIONS(declareOmptTracingFnMutex)
@@ -96,32 +88,6 @@ extern std::map<int32_t, uint64_t> TracedDevices;
/// OMPT global tracing status. Indicates if at least one device is traced.
extern bool TracingActive;
-/// Parent library pointer
-extern std::shared_ptr<llvm::sys::DynamicLibrary> ParentLibrary;
-
-/// Get the parent library by pointer. If it is not already set, it will set the
-/// parent library pointer.
-std::shared_ptr<llvm::sys::DynamicLibrary> getParentLibrary();
-
-/// Set the parent library by filename
-void setParentLibrary(const char *Filename);
-
-/// Search for FuncName inside the parent library and assign to FuncPtr.
-/// IMPORTANT: This function assumes that the *caller* holds the respective lock
-/// for FuncPtr.
-template <typename FT>
-void ensureFuncPtrLoaded(const std::string &FuncName, FT *FuncPtr) {
- if (*FuncPtr == nullptr) {
- if ((ParentLibrary == nullptr && getParentLibrary() == nullptr) ||
- !ParentLibrary->isValid())
- return;
- void *SymbolPtr = ParentLibrary->getAddressOfSymbol(FuncName.c_str());
- if (SymbolPtr == nullptr)
- return;
- *FuncPtr = reinterpret_cast<FT>(SymbolPtr);
- }
-}
-
} // namespace ompt
} // namespace target
} // namespace omp
diff --git a/offload/plugins-nextgen/common/OMPT/OmptTracing.cpp b/offload/plugins-nextgen/common/OMPT/OmptTracing.cpp
index 7a8e312b3d4768..426a4e006e326b 100644
--- a/offload/plugins-nextgen/common/OMPT/OmptTracing.cpp
+++ b/offload/plugins-nextgen/common/OMPT/OmptTracing.cpp
@@ -16,25 +16,16 @@
#include "Shared/Debug.h"
#include "omp-tools.h"
-#include "llvm/Support/DynamicLibrary.h"
-
#include <atomic>
#include <cassert>
#include <cstdlib>
#include <cstring>
-#include <memory>
#include <mutex>
#pragma push_macro("DEBUG_PREFIX")
#undef DEBUG_PREFIX
#define DEBUG_PREFIX "OMPT"
-// Define OMPT device tracing function entry points
-#define defineOmptTracingFn(Name) \
- libomptarget_##Name##_t llvm::omp::target::ompt::Name##_fn = nullptr;
-FOREACH_OMPT_DEVICE_TRACING_FN_IMPLEMENTAIONS(defineOmptTracingFn)
-#undef defineOmptTracingFn
-
// Define OMPT device tracing function mutexes
#define defineOmptTracingFnMutex(Name) \
std::mutex llvm::omp::target::ompt::Name##_mutex;
@@ -46,34 +37,11 @@ std::mutex llvm::omp::target::ompt::DeviceIdWritingMutex;
using namespace llvm::omp::target::ompt;
using namespace llvm::omp::target::debug;
-std::shared_ptr<llvm::sys::DynamicLibrary>
- llvm::omp::target::ompt::ParentLibrary(nullptr);
-
double llvm::omp::target::ompt::HostToDeviceSlope = .0;
double llvm::omp::target::ompt::HostToDeviceOffset = .0;
std::map<ompt_device_t *, int32_t> llvm::omp::target::ompt::Devices;
-std::shared_ptr<llvm::sys::DynamicLibrary>
-llvm::omp::target::ompt::getParentLibrary() {
- static bool ParentLibraryAssigned = false;
- if (!ParentLibraryAssigned) {
- setParentLibrary("libomptarget.so");
- ParentLibraryAssigned = true;
- }
- return ParentLibrary;
-}
-
-void llvm::omp::target::ompt::setParentLibrary(const char *Filename) {
- if (ParentLibrary)
- return;
- std::string ErrorMsg;
- ParentLibrary = std::make_shared<llvm::sys::DynamicLibrary>(
- llvm::sys::DynamicLibrary::getPermanentLibrary(Filename, &ErrorMsg));
- if ((ParentLibrary == nullptr) || (!ParentLibrary->isValid()))
- REPORT() << "Failed to set parent library: " << ErrorMsg.c_str();
-}
-
int llvm::omp::target::ompt::getDeviceId(ompt_device_t *Device) {
// Block other threads, which might trigger an erase (for the same device)
std::unique_lock<std::mutex> Lock(DeviceIdWritingMutex);
@@ -133,10 +101,7 @@ OMPT_API_ROUTINE ompt_set_result_t ompt_set_trace_ompt(ompt_device_t *Device,
}
std::unique_lock<std::mutex> Lock(ompt_set_trace_ompt_mutex);
- ensureFuncPtrLoaded<libomptarget_ompt_set_trace_ompt_t>(
- "libomptarget_ompt_set_trace_ompt", &ompt_set_trace_ompt_fn);
- assert(ompt_set_trace_ompt_fn && "libomptarget_ompt_set_trace_ompt loaded");
- return ompt_set_trace_ompt_fn(DeviceId, Enable, EventTy);
+ return libomptarget_ompt_set_trace_ompt(DeviceId, Enable, EventTy);
}
OMPT_API_ROUTINE int
@@ -153,7 +118,7 @@ ompt_start_trace(ompt_device_t *Device, ompt_callback_buffer_request_t Request,
}
{
- // Protect the function pointer
+ // Serialize enabling the device-side profiling sources
std::unique_lock<std::mutex> Lock(ompt_start_trace_mutex);
if (Request && Complete) {
@@ -167,23 +132,15 @@ ompt_start_trace(ompt_device_t *Device, ompt_callback_buffer_request_t Request,
REPORT() << "May not enable kernel profiling for invalid device id="
<< DeviceId;
}
-
- // Call libomptarget specific function
- ensureFuncPtrLoaded<libomptarget_ompt_start_trace_t>(
- "libomptarget_ompt_start_trace", &ompt_start_trace_fn);
- assert(ompt_start_trace_fn && "libomptarget_ompt_start_trace loaded");
}
- return ompt_start_trace_fn(DeviceId, Request, Complete);
+ return libomptarget_ompt_start_trace(DeviceId, Request, Complete);
}
OMPT_API_ROUTINE int ompt_flush_trace(ompt_device_t *Device) {
ODBG(ODT_Tool) << "Executing ompt_flush_trace";
std::unique_lock<std::mutex> Lock(ompt_flush_trace_mutex);
- ensureFuncPtrLoaded<libomptarget_ompt_flush_trace_t>(
- "libomptarget_ompt_flush_trace", &ompt_flush_trace_fn);
- assert(ompt_flush_trace_fn && "libomptarget_ompt_flush_trace loaded");
- return ompt_flush_trace_fn(getDeviceId(Device));
+ return libomptarget_ompt_flush_trace(getDeviceId(Device));
}
OMPT_API_ROUTINE int ompt_stop_trace(ompt_device_t *Device) {
@@ -198,7 +155,7 @@ OMPT_API_ROUTINE int ompt_stop_trace(ompt_device_t *Device) {
}
{
- // Protect the function pointer
+ // Serialize disabling the device-side profiling sources
std::unique_lock<std::mutex> Lock(ompt_stop_trace_mutex);
llvm::omp::target::ompt::disableDeviceTracing(DeviceId);
// Disable asynchronous memory copy profiling
@@ -209,11 +166,8 @@ OMPT_API_ROUTINE int ompt_stop_trace(ompt_device_t *Device) {
else
REPORT() << "May not disable kernel profiling for invalid device id="
<< DeviceId;
- ensureFuncPtrLoaded<libomptarget_ompt_stop_trace_t>(
- "libomptarget_ompt_stop_trace", &ompt_stop_trace_fn);
- assert(ompt_stop_trace_fn && "libomptarget_ompt_stop_trace loaded");
}
- return ompt_stop_trace_fn(DeviceId);
+ return libomptarget_ompt_stop_trace(DeviceId);
}
OMPT_API_ROUTINE ompt_record_ompt_t *
@@ -236,27 +190,17 @@ OMPT_API_ROUTINE int ompt_advance_buffer_cursor(ompt_device_t *Device,
ompt_buffer_cursor_t *NextPos) {
// Note: The input parameter size is unused here. It refers to the
// bytes returned in the corresponding callback.
- // Advance can be called concurrently, so synchronize setting the
- // function pointer. The actual libomptarget function does not need
- // to be synchronized since it must be working on logically disjoint
- // buffers.
+ // The libomptarget function does not need to be synchronized since it must
+ // be working on logically disjoint buffers.
std::unique_lock<std::mutex> Lock(ompt_advance_buffer_cursor_mutex);
- ensureFuncPtrLoaded<libomptarget_ompt_advance_buffer_cursor_t>(
- "libomptarget_ompt_advance_buffer_cursor",
- &ompt_advance_buffer_cursor_fn);
- assert(ompt_advance_buffer_cursor_fn &&
- "libomptarget_ompt_advance_buffer_cursor loaded");
- return ompt_advance_buffer_cursor_fn(Device, Buffer, Size, CurrentPos,
- NextPos);
+ return libomptarget_ompt_advance_buffer_cursor(Device, Buffer, Size,
+ CurrentPos, NextPos);
}
OMPT_API_ROUTINE ompt_record_t
ompt_get_record_type(ompt_buffer_t *Buffer, ompt_buffer_cursor_t CurrentPos) {
std::unique_lock<std::mutex> Lock(ompt_get_record_type_mutex);
- ensureFuncPtrLoaded<libomptarget_ompt_get_record_type_t>(
- "libomptarget_ompt_get_record_type", &ompt_get_record_type_fn);
- assert(ompt_get_record_type_fn && "libomptarget_ompt_get_record_type loaded");
- return ompt_get_record_type_fn(Buffer, CurrentPos);
+ return libomptarget_ompt_get_record_type(Buffer, CurrentPos);
}
OMPT_API_ROUTINE ompt_device_time_t
@@ -279,10 +223,7 @@ OMPT_API_ROUTINE double ompt_translate_time(ompt_device_t *Device,
void llvm::omp::target::ompt::setOmptTimestamp(uint64_t StartTime,
uint64_t EndTime) {
std::unique_lock<std::mutex> Lock(ompt_set_timestamp_mutex);
- ensureFuncPtrLoaded<libomptarget_ompt_set_timestamp_t>(
- "libomptarget_ompt_set_timestamp", &ompt_set_timestamp_fn);
- // No need to hold a lock
- ompt_set_timestamp_fn(StartTime, EndTime);
+ libomptarget_ompt_set_timestamp(StartTime, EndTime);
}
void llvm::omp::target::ompt::setOmptHostToDeviceRate(double Slope,
@@ -293,10 +234,7 @@ void llvm::omp::target::ompt::setOmptHostToDeviceRate(double Slope,
void llvm::omp::target::ompt::setOmptGrantedNumTeams(uint64_t NumTeams) {
std::unique_lock<std::mutex> Lock(ompt_set_granted_teams_mutex);
- ensureFuncPtrLoaded<libomptarget_ompt_set_granted_teams_t>(
- "libomptarget_ompt_set_granted_teams", &ompt_set_granted_teams_fn);
- // No need to hold a lock
- ompt_set_granted_teams_fn(NumTeams);
+ libomptarget_ompt_set_granted_teams(NumTeams);
}
ompt_interface_fn_t llvm::omp::target::ompt::lookupDeviceTracingFn(
>From 85a7717102e236a639eeb5c7a74b6011528710d7 Mon Sep 17 00:00:00 2001
From: JP Lehr <JanPatrick.Lehr at amd.com>
Date: Tue, 29 Sep 2026 06:48:58 -0500
Subject: [PATCH 3/4] [Offload][OMPT] Replace generic profiler data hooks with
OMPT API
GenericProfilerTy no longer exposes getProfilerSpecificData() or
getTraceRecordManager(), so OmptProfilerTy provides the OMPT-specific
entry points directly: trackAsyncRecord() creates the event info that
carries a trace record into the plugins, and getOmptProfiler() gives
libomptarget typed access to the process-wide profiler. Keeping the
OMPT types out of the generic interface lets the plugins stay agnostic
of the profiling backend.
The buffer manager member moves back out until the tracing buffer
infrastructure exists later in the series.
Assisted-by: Claude Code
---
.../common/OMPT/OmptProfiler.cpp | 8 ++---
.../common/OMPT/OmptProfiler.h | 31 +++++++++----------
2 files changed, 18 insertions(+), 21 deletions(-)
diff --git a/offload/plugins-nextgen/common/OMPT/OmptProfiler.cpp b/offload/plugins-nextgen/common/OMPT/OmptProfiler.cpp
index 9e8a0960b97119..b25346bdc53562 100644
--- a/offload/plugins-nextgen/common/OMPT/OmptProfiler.cpp
+++ b/offload/plugins-nextgen/common/OMPT/OmptProfiler.cpp
@@ -102,8 +102,8 @@ void ompt::OmptProfilerTy::handleKernelCompletion(uint64_t StartNanos,
if (!isProfilingEnabled())
return;
- /// Empty data means no tracing in OMPT
- /// offload/include/OpenMP/OMPT/Interface.h line 492
+ // Null data means no trace record was assigned for this event, see
+ // TracerInterfaceRAII in OpenMP/OMPT/Interface.h.
if (!Data)
return;
@@ -128,8 +128,8 @@ void ompt::OmptProfilerTy::handleDataTransfer(uint64_t StartNanos,
if (!isProfilingEnabled())
return;
- /// Empty data means no tracing in OMPT
- /// offload/include/OpenMP/OMPT/Interface.h line 492
+ // Null data means no trace record was assigned for this event, see
+ // TracerInterfaceRAII in OpenMP/OMPT/Interface.h.
if (!Data)
return;
diff --git a/offload/plugins-nextgen/common/OMPT/OmptProfiler.h b/offload/plugins-nextgen/common/OMPT/OmptProfiler.h
index 5376fa145134a1..e33e41257c6372 100644
--- a/offload/plugins-nextgen/common/OMPT/OmptProfiler.h
+++ b/offload/plugins-nextgen/common/OMPT/OmptProfiler.h
@@ -20,7 +20,6 @@
#include "OmptDeviceTracing.h"
#include "OpenMP/OMPT/Callback.h"
#include "OpenMP/OMPT/OmptEventInfoTy.h"
-#include "OpenMP/OMPT/OmptTracingBuffer.h"
#include "Shared/Debug.h"
#include "omp-tools.h"
@@ -115,14 +114,18 @@ class OmptProfilerTy : public plugin::GenericProfilerTy {
void setTimeConversionFactorsImpl(double Slope, double Offset) override;
- void *getProfilerSpecificData() override {
+ /// Allocate the event info that carries \p Record into the plugins for
+ /// asynchronous completion. The profiler owns the returned object and frees
+ /// it via freeProfilerDataEntry once the plugin completed the record.
+ OmptEventInfoTy *trackAsyncRecord(ompt_record_ompt_t *Record) {
// TODO: This is ID is not used currently
uint64_t Id = OmptProfDataId.fetch_add(1);
- {
- std::scoped_lock<std::mutex> Lock(ProfilerDataMutex);
- ProfilerData[Id] = std::make_unique<OmptEventInfoTy>();
- return ProfilerData[Id].get();
- }
+ std::scoped_lock<std::mutex> Lock(ProfilerDataMutex);
+ auto &Info = ProfilerData[Id];
+ Info = std::make_unique<OmptEventInfoTy>();
+ Info->TraceRecord = Record;
+ Info->NumTeams = 0;
+ return Info.get();
}
void freeProfilerDataEntry(OmptEventInfoTy *DataPtr) {
@@ -135,17 +138,7 @@ class OmptProfilerTy : public plugin::GenericProfilerTy {
}
}
- /// The trace records handed out here point into buffers owned by the trace
- /// buffer manager, so the profiler owns it to bind both lifetimes.
- OmptTracingBufferMgr *getTraceRecordManager() override {
- return TraceRecordManager.get();
- }
-
private:
- /// Trace buffer manager whose records the ProfilerData entries refer to.
- std::unique_ptr<OmptTracingBufferMgr> TraceRecordManager =
- std::make_unique<OmptTracingBufferMgr>();
-
/// Holds a unique ID for each allocation of OmptEventInfoTy
std::atomic<uint64_t> OmptProfDataId{0};
@@ -169,6 +162,10 @@ class OmptProfilerTy : public plugin::GenericProfilerTy {
/// Internal representation for OMPT device (initialize & finalize)
std::atomic<bool> OmptInitialized;
};
+
+/// Process-wide OMPT profiler owned by libomptarget; nullptr before it has
+/// been created.
+OmptProfilerTy *getOmptProfiler();
} // namespace ompt
} // namespace target
} // namespace omp
>From eb6dc653dc0160ef101fccc915151fc66a1cc12e Mon Sep 17 00:00:00 2001
From: JP Lehr <JanPatrick.Lehr at amd.com>
Date: Tue, 29 Sep 2026 06:49:34 -0500
Subject: [PATCH 4/4] [Offload][OMPT] Drop device lifecycle handling from
OmptProfilerTy
Since #221726, libomptarget emits the device_initialize,
device_finalize and device_load callbacks itself, and GenericProfilerTy
no longer has the hooks the plugins used to report these events. The
overrides were left without callers and still used
GenericPluginTy::getUserId(), which #221726 removed, so the file would
not compile once it is built. Remove them together with the per-profiler
callback copies and the initialization flag only they used.
Assisted-by: Claude Code
---
.../common/OMPT/OmptProfiler.cpp | 46 ----------------
.../common/OMPT/OmptProfiler.h | 54 -------------------
2 files changed, 100 deletions(-)
diff --git a/offload/plugins-nextgen/common/OMPT/OmptProfiler.cpp b/offload/plugins-nextgen/common/OMPT/OmptProfiler.cpp
index b25346bdc53562..d74e6e3b9b82ac 100644
--- a/offload/plugins-nextgen/common/OMPT/OmptProfiler.cpp
+++ b/offload/plugins-nextgen/common/OMPT/OmptProfiler.cpp
@@ -19,52 +19,6 @@
using namespace llvm::omp::target;
-void ompt::OmptProfilerTy::handleInit(plugin::GenericDeviceTy *Device,
- plugin::GenericPluginTy *Plugin) {
- auto DeviceId = Device->getDeviceId();
- auto DevicePtr = reinterpret_cast<ompt_device_t *>(Device);
- ompt::setDeviceId(DevicePtr, Plugin->getUserId(DeviceId));
-
- if (ompt::Initialized) {
- bool ExpectedStatus = false;
- if (OmptInitialized.compare_exchange_strong(ExpectedStatus, true))
- performOmptCallback(device_initialize, Plugin->getUserId(DeviceId),
- /*type=*/Device->getComputeUnitKind().c_str(),
- /*device=*/DevicePtr,
- /*lookup=*/ompt::lookupDeviceTracingFn,
- /*documentation=*/nullptr);
- }
-}
-
-void ompt::OmptProfilerTy::handleDeinit(
- plugin::GenericDeviceTy *Device, target::plugin::GenericPluginTy *Plugin) {
- auto DeviceId = Device->getDeviceId();
-
- if (ompt::Initialized) {
- bool ExpectedStatus = true;
- if (OmptInitialized.compare_exchange_strong(ExpectedStatus, false))
- performOmptCallback(device_finalize, Plugin->getUserId(DeviceId));
- }
- ompt::removeDeviceId(reinterpret_cast<ompt_device_t *>(Device));
-}
-
-void ompt::OmptProfilerTy::handleLoadBinary(plugin::GenericDeviceTy *Device,
- plugin::GenericPluginTy *Plugin,
- const StringRef InputTgtImage) {
-
- if (!ompt::Initialized)
- return;
-
- auto DeviceId = Device->getDeviceId();
- size_t Bytes = InputTgtImage.size();
- performOmptCallback(
- device_load, Plugin->getUserId(DeviceId),
- /*FileName=*/nullptr, /*FileOffset=*/0, /*VmaInFile=*/nullptr,
- /*ImgSize=*/Bytes,
- /*HostAddr=*/const_cast<unsigned char *>(InputTgtImage.bytes_begin()),
- /*DeviceAddr=*/nullptr, /* FIXME: ModuleId */ 0);
-}
-
void ompt::OmptProfilerTy::handleDataAlloc(uint64_t StartNanos,
uint64_t EndNanos, void *HostPtr,
uint64_t Size, void *Data) {
diff --git a/offload/plugins-nextgen/common/OMPT/OmptProfiler.h b/offload/plugins-nextgen/common/OMPT/OmptProfiler.h
index e33e41257c6372..4c2c90e3f385ad 100644
--- a/offload/plugins-nextgen/common/OMPT/OmptProfiler.h
+++ b/offload/plugins-nextgen/common/OMPT/OmptProfiler.h
@@ -41,16 +41,12 @@ namespace omp {
namespace target {
namespace plugin {
struct GenericDeviceTy;
-struct GenericPluginTy;
class GenericProfilerTy;
} // namespace plugin
namespace ompt {
-// From Callback.h / Callback.cpp
-extern bool Initialized;
-
/**
* Implements an OMPT backend for the Profiler interface used in the plugins.
*
@@ -58,45 +54,8 @@ extern bool Initialized;
*/
class OmptProfilerTy : public plugin::GenericProfilerTy {
public:
- /** Public members **/
- OmptProfilerTy() {
-
- OmptInitialized.store(false);
- // Bind the callbacks to this device's member functions
-#define bindOmptCallback(Name, Type, Code) \
- if (ompt::Initialized && ompt::lookupCallbackByCode) { \
- ompt::lookupCallbackByCode((ompt_callbacks_t)(Code), \
- ((ompt_callback_t *)&(Name##_fn))); \
- ODBG(ODT_Tool) << "class bound " << #Name << "=" \
- << ((void *)(uint64_t)Name##_fn); \
- }
-
- FOREACH_OMPT_DEVICE_EVENT(bindOmptCallback);
-#undef bindOmptCallback
-
-#define bindOmptTracingFunction(FunctionName) \
- if (ompt::Initialized && ompt::lookupDeviceTracingFn) { \
- FunctionName##_fn = ompt::lookupDeviceTracingFn(#FunctionName); \
- ODBG(ODT_Tool) << "device tracing fn bound " << #FunctionName << "=" \
- << ((void *)(uint64_t)FunctionName##_fn); \
- }
-
- FOREACH_OMPT_DEVICE_TRACING_FN_COMMON(bindOmptTracingFunction);
-#undef bindOmptTracingFunction
- }
-
bool isProfilingEnabled() override;
- void handleInit(plugin::GenericDeviceTy *Device,
- plugin::GenericPluginTy *Plugin) override;
-
- void handleDeinit(plugin::GenericDeviceTy *Device,
- plugin::GenericPluginTy *Plugin) override;
-
- void handleLoadBinary(plugin::GenericDeviceTy *Device,
- plugin::GenericPluginTy *Plugin,
- const StringRef InputTgtImage) override;
-
void handleDataAlloc(uint64_t StartNanos, uint64_t EndNanos, void *HostPtr,
uint64_t Size, void *Data) override;
void handleDataDelete(uint64_t StartNanos, uint64_t EndNanos, void *TgtPtr,
@@ -148,19 +107,6 @@ class OmptProfilerTy : public plugin::GenericProfilerTy {
/// Lock to guard STL ProfilerData map
std::mutex ProfilerDataMutex;
-
- /// OMPT callback functions
-#define defineOmptCallback(Name, Type, Code) Name##_t Name##_fn = nullptr;
- FOREACH_OMPT_DEVICE_EVENT(defineOmptCallback)
-#undef defineOmptCallback
-
- /// OMPT device tracing functions
-#define defineOmptTracingFunction(Name) ompt_interface_fn_t Name##_fn = nullptr;
- FOREACH_OMPT_DEVICE_TRACING_FN_COMMON(defineOmptTracingFunction);
-#undef defineOmptTracingFunction
-
- /// Internal representation for OMPT device (initialize & finalize)
- std::atomic<bool> OmptInitialized;
};
/// Process-wide OMPT profiler owned by libomptarget; nullptr before it has
More information about the llvm-branch-commits
mailing list