11#include "TpetraCore_config.h"
12#include "Kokkos_Core.hpp"
13#include "Teuchos_TestForException.hpp"
21namespace DeepCopyCounterDetails {
23bool is_initialized =
true;
25size_t count_different = 0;
26bool count_active =
false;
28void kokkosp_begin_deep_copy(Kokkos::Tools::SpaceHandle dst_handle,
const char *dst_name,
const void *dst_ptr,
29 Kokkos::Tools::SpaceHandle src_handle,
const char *src_name,
const void *src_ptr,
32 if (strcmp(dst_handle.name, src_handle.name))
42 DeepCopyCounterDetails::count_active =
true;
43 Kokkos::Tools::Experimental::set_begin_deep_copy_callback(DeepCopyCounterDetails::kokkosp_begin_deep_copy);
47 DeepCopyCounterDetails::count_same = 0;
48 DeepCopyCounterDetails::count_different = 0;
52 DeepCopyCounterDetails::count_active =
false;
56 return DeepCopyCounterDetails::count_same;
60 return DeepCopyCounterDetails::count_different;
65namespace FenceCounterDetails {
68bool is_initialized =
false;
69bool count_active =
false;
70std::vector<size_t> count_instance;
71std::vector<size_t> count_global;
77 using namespace Kokkos::Tools::Experimental;
85 count_instance[idx]++;
89std::string get_label(
int i) {
90 using namespace Kokkos::Tools::Experimental;
91 DeviceType i_type = devicetype_from_uint32t(i);
92 std::string device_label;
93 if (i_type == DeviceType::Serial)
94 device_label =
"Serial";
95 else if (i_type == DeviceType::OpenMP)
96 device_label =
"OpenMP";
97 else if (i_type == DeviceType::Cuda)
98 device_label =
"Cuda";
99 else if (i_type == DeviceType::HIP)
100 device_label =
"HIP";
101 else if (i_type == DeviceType::OpenMPTarget)
102 device_label =
"OpenMPTarget";
103 else if (i_type == DeviceType::HPX)
104 device_label =
"HPX";
105 else if (i_type == DeviceType::Threads)
106 device_label =
"Threats";
107 else if (i_type == DeviceType::SYCL)
108 device_label =
"SYCL";
109 else if (i_type == DeviceType::OpenACC)
110 device_label =
"OpenACC";
111 else if (i_type == DeviceType::Unknown)
112 device_label =
"Unknown";
118 using namespace Kokkos::Tools::Experimental;
119 num_devices = (int)DeviceType::Unknown;
120 count_instance.resize(num_devices);
121 count_instance.assign(num_devices, 0);
122 count_global.resize(num_devices);
123 count_global.assign(num_devices, 0);
124 is_initialized =
true;
130 if (!FenceCounterDetails::is_initialized)
131 FenceCounterDetails::initialize();
132 FenceCounterDetails::count_active =
true;
133 Kokkos::Tools::Experimental::set_begin_fence_callback(FenceCounterDetails::kokkosp_begin_fence);
137 FenceCounterDetails::count_instance.assign(FenceCounterDetails::num_devices, 0);
138 FenceCounterDetails::count_global.assign(FenceCounterDetails::num_devices, 0);
142 FenceCounterDetails::count_active =
false;
146 using namespace Kokkos::Tools::Experimental;
147 for (
int i = 0;
i < FenceCounterDetails::num_devices;
i++) {
148 std::string
device_label = FenceCounterDetails::get_label(
i);
151 return FenceCounterDetails::count_global[
i];
159 using namespace Kokkos::Tools::Experimental;
160 for (
int i = 0;
i < FenceCounterDetails::num_devices;
i++) {
161 std::string
device_label = FenceCounterDetails::get_label(
i);
164 return FenceCounterDetails::count_instance[
i];
171namespace KokkosRegionCounterDetails {
172std::vector<std::string> regions;
174void push_region_callback(
const char *label) { regions.push_back(label); }
175static_assert(std::is_same_v<
decltype(&push_region_callback),
177 "Unexpected Kokkos profiling interface API. This is an internal "
178 "Tpetra developer error, please report this.");
183 Kokkos::Tools::Experimental::set_push_region_callback(
184 KokkosRegionCounterDetails::push_region_callback);
188 KokkosRegionCounterDetails::regions.clear();
192 Kokkos::Tools::Experimental::set_push_region_callback(
nullptr);
198 for (
const auto &
region : KokkosRegionCounterDetails::regions) {
205 for (
const auto &
region : KokkosRegionCounterDetails::regions) {
211 for (
const auto &
region : KokkosRegionCounterDetails::regions) {
Declaration of various tools for counting Kokkos calls of various types using the Kokkos Profiling Li...
Struct that holds views of the contents of a CrsMatrix.
Implementation details of Tpetra.
size_t get_count_different_space()
Query the deep_copy counter for copies between different spaces.
size_t get_count_same_space()
Query the deep_copy counter for copies in the same space.
void stop()
Stop the deep_copy counter.
void start()
Start the deep_copy counter.
void reset()
Reset the deep_copy counter.
size_t get_count_instance(const std::string &device)
Query the fence counter for given device, for an exec_space_instance.fence()
size_t get_count_global(const std::string &device)
Query the fence counter for given device, for an Kokkos::fence()
void reset()
Reset the fence counter.
void start()
Start the fence counter.
void stop()
Stop the fence counter.
void reset()
Reset the counter.
void dump_regions(std::ostream &os)
Print all observed region labels, separated by newline.
size_t get_count_region_contains(const std::string &substr)
How many regions containing substr have been seen.
void stop()
Stop the counter.
void start()
Start the counter.
Namespace Tpetra contains the class and methods constituting the Tpetra library.
void initialize(int *argc, char ***argv)
Initialize Tpetra.