[Openmp-commits] [llvm] [openmp] [Offload] Add logger in Plugin API functions for OpenMP (PR #215582)

Alex Duran via Openmp-commits openmp-commits at lists.llvm.org
Thu Aug 13 05:09:13 PDT 2026


================
@@ -0,0 +1,162 @@
+//===-- 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 when the OMP_INFOTYPE_API_TRACE bit of
+// LIBOMPTARGET_INFO is set:
+//
+//   ---> init_device(.DeviceId = 0)-> OFFLOAD_SUCCESS (1053 us)
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef OMPTARGET_SHARED_API_TRACE_H
+#define OMPTARGET_SHARED_API_TRACE_H
+
+#include "APITypes.h"
+#include "Debug.h"
+#include "omptarget.h"
+
+#include "llvm/ADT/SmallString.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/raw_ostream.h"
+
+#include <chrono>
+#include <type_traits>
+#include <utility>
+
+namespace llvm::offload::trace {
+
+/// The level is read on every call so that __tgt_set_info_flag can turn tracing
+/// on and off around a region of interest.
+inline bool isTraceEnabled() { return getInfoLevel() & OMP_INFOTYPE_API_TRACE; }
----------------
adurang wrote:

I think it's ok here as it is but could we have a way to disable this at compile-time?
```
#if LIBOFFLOAD_TRACE_PLUGINS
...
#else
inline bool isTraceEnabled() { return false; }
#endif 
```
I think some builds might want to have this only when debug is enabled but if we don't want to gate it together, at least would be nice to be able to control whether it should be enabled or not.

https://github.com/llvm/llvm-project/pull/215582


More information about the Openmp-commits mailing list