Kokkos Core Kernels Package Version of the Day
Loading...
Searching...
No Matches
Kokkos_Profiling_ProfileSection.hpp
1//@HEADER
2// ************************************************************************
3//
4// Kokkos v. 4.0
5// Copyright (2022) National Technology & Engineering
6// Solutions of Sandia, LLC (NTESS).
7//
8// Under the terms of Contract DE-NA0003525 with NTESS,
9// the U.S. Government retains certain rights in this software.
10//
11// Part of Kokkos, under the Apache License v2.0 with LLVM Exceptions.
12// See https://kokkos.org/LICENSE for license information.
13// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
14//
15//@HEADER
16
17#ifndef KOKKOSP_PROFILE_SECTION_HPP
18#define KOKKOSP_PROFILE_SECTION_HPP
19#ifndef KOKKOS_IMPL_PUBLIC_INCLUDE
20#define KOKKOS_IMPL_PUBLIC_INCLUDE
21#define KOKKOS_IMPL_PUBLIC_INCLUDE_PROFILING_PROFILESECTION
22#endif
23
24#include <Kokkos_Macros.hpp>
25#include <impl/Kokkos_Profiling_Interface.hpp>
26#include <impl/Kokkos_Profiling.hpp>
27
28#include <string>
29
30namespace Kokkos {
31namespace Profiling {
32
33class ProfilingSection {
34 public:
35 ProfilingSection(ProfilingSection const&) = delete;
36 ProfilingSection& operator=(ProfilingSection const&) = delete;
37
38 ProfilingSection(const std::string& sectionName) {
39 if (Kokkos::Profiling::profileLibraryLoaded()) {
40 Kokkos::Profiling::createProfileSection(sectionName, &secID);
41 }
42 }
43
44 void start() {
45 if (Kokkos::Profiling::profileLibraryLoaded()) {
46 Kokkos::Profiling::startSection(secID);
47 }
48 }
49
50 void stop() {
51 if (Kokkos::Profiling::profileLibraryLoaded()) {
52 Kokkos::Profiling::stopSection(secID);
53 }
54 }
55
56 ~ProfilingSection() {
57 if (Kokkos::Profiling::profileLibraryLoaded()) {
58 Kokkos::Profiling::destroyProfileSection(secID);
59 }
60 }
61
62 protected:
63 uint32_t secID;
64};
65
66} // namespace Profiling
67} // namespace Kokkos
68
69#ifdef KOKKOS_IMPL_PUBLIC_INCLUDE_NOTDEFINED_CORE
70#undef KOKKOS_IMPL_PUBLIC_INCLUDE
71#undef KOKKOS_IMPL_PUBLIC_INCLUDE_NOTDEFINED_PROFILING_PROFILESECTION
72#endif
73#endif