Kokkos Core Kernels Package  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
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.hpp>
26 
27 #include <string>
28 
29 namespace Kokkos::Profiling {
30 
31 class [[nodiscard]] ProfilingSection {
32  uint32_t sectionID;
33 
34  public:
35  ProfilingSection(ProfilingSection const&) = delete;
36  ProfilingSection& operator=(ProfilingSection const&) = delete;
37 
38 #if defined(__has_cpp_attribute) && __has_cpp_attribute(nodiscard) >= 201907
39  [[nodiscard]]
40 #endif
41  explicit ProfilingSection(const std::string& sectionName) {
42  Kokkos::Profiling::createProfileSection(sectionName, &sectionID);
43  }
44 
45  void start() { Kokkos::Profiling::startSection(sectionID); }
46 
47  void stop() { Kokkos::Profiling::stopSection(sectionID); }
48 
49  ~ProfilingSection() { Kokkos::Profiling::destroyProfileSection(sectionID); }
50 };
51 
52 } // namespace Kokkos::Profiling
53 
54 #ifdef KOKKOS_IMPL_PUBLIC_INCLUDE_NOTDEFINED_CORE
55 #undef KOKKOS_IMPL_PUBLIC_INCLUDE
56 #undef KOKKOS_IMPL_PUBLIC_INCLUDE_NOTDEFINED_PROFILING_PROFILESECTION
57 #endif
58 #endif