[Openmp-commits] [llvm] [openmp] [Offload] Add logger in Plugin API functions for OpenMP (PR #215582)
Nick Sarnie via Openmp-commits
openmp-commits at lists.llvm.org
Wed Aug 12 11:49:44 PDT 2026
================
@@ -0,0 +1,167 @@
+//===-- Shared/APITrace.h - Tracing of offload API calls --------*- 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
+//
+//===----------------------------------------------------------------------===//
+//
+// Prints one line per offload API call while tracing is enabled:
+//
+// ---> init_device(.DeviceId = 0)-> OFFLOAD_SUCCESS (1053 us)
+//
+// Tracing is off until the runtime above the plugins turns it on, see
+// GenericPluginTy::set_api_trace.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef OMPTARGET_SHARED_API_TRACE_H
+#define OMPTARGET_SHARED_API_TRACE_H
+
+#include "APITypes.h"
+#include "omptarget.h"
+
+#include "llvm/ADT/SmallString.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/raw_ostream.h"
+
+#include <atomic>
+#include <chrono>
+#include <type_traits>
+#include <utility>
+
+namespace llvm::offload::trace {
+
+inline std::atomic<bool> &getTraceEnabledFlag() {
+ static std::atomic<bool> Enabled = false;
----------------
sarnex wrote:
is it safe to have this definition in the header? inlining seems required for correctness here
https://github.com/llvm/llvm-project/pull/215582
More information about the Openmp-commits
mailing list