//===- GenericProfiler.h - GenericProfiler interface for use in Plugins ---===// // // 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 // //===----------------------------------------------------------------------===// // // The GenericProfiler interface allows to implement profiler logic for various // backends, such as OMPT or other tracing mechanisms. // This enables the plugins to be agnostic of the actual high-level language // that is implemented. // //===----------------------------------------------------------------------===// #ifndef OFFLOAD_PLUGIN_COMMON_GENERICPROFILER_H #define OFFLOAD_PLUGIN_COMMON_GENERICPROFILER_H #include #include #include #include #include struct __tgt_async_info; namespace llvm { namespace offload { namespace plugin { struct GenericDeviceTy; class GenericProfilerTy; /// Helper function to unpack a tuple of arguments and call a function with /// them. template void callViaIndexSeq(FunT F, GenericProfilerTy *P, uint64_t StartNanos, uint64_t EndNanos, std::tuple Args, std::index_sequence) { F(P, StartNanos, EndNanos, std::get(Args)...); } /// Helper function to unpack a tuple of arguments and call a function with /// them. template void callViaUnpack(FunT F, GenericProfilerTy *P, uint64_t StartNanos, uint64_t EndNanos, std::tuple Tup) { callViaIndexSeq(F, P, StartNanos, EndNanos, Tup, std::index_sequence_for{}); } /// Abstraction layer to implement different profiler backends. /// /// The plugins call into the GenericProfilerTy to handle the specific events /// with whatever specific backend was instantiated. For now, the supported /// backends are limited to an OMPT implementation. class GenericProfilerTy { public: GenericProfilerTy() = default; virtual ~GenericProfilerTy() = default; /// Returns true if profiling is enabled, false otherwise. virtual bool isProfilingEnabled() { return false; } /// Set the factors which are used to interpolate the device clock compared to /// the host clock. This follows a simple linear interpolation: Slope *