42 #include "TpetraCore_config.h"
43 #include "Kokkos_Core.hpp"
44 #include "Teuchos_TestForException.hpp"
52 namespace DeepCopyCounterDetails {
54 bool is_initialized=
true;
56 size_t count_different=0;
57 bool count_active=
false;
59 void kokkosp_begin_deep_copy(Kokkos::Tools::SpaceHandle dst_handle,
const char* dst_name,
const void* dst_ptr,
60 Kokkos::Tools::SpaceHandle src_handle,
const char* src_name,
const void* src_ptr,
64 if(strcmp(dst_handle.name,src_handle.name))
75 DeepCopyCounterDetails::count_active=
true;
76 Kokkos::Tools::Experimental::set_begin_deep_copy_callback(DeepCopyCounterDetails::kokkosp_begin_deep_copy);
80 DeepCopyCounterDetails::count_same=0;
81 DeepCopyCounterDetails::count_different=0;
85 DeepCopyCounterDetails::count_active=
false;
89 return DeepCopyCounterDetails::count_same;
93 return DeepCopyCounterDetails::count_different;
101 namespace FenceCounterDetails {
104 bool is_initialized=
false;
105 bool count_active=
false;
106 std::vector<size_t> count_instance;
107 std::vector<size_t> count_global;
111 void kokkosp_begin_fence(
const char* name,
const uint32_t deviceId,
115 using namespace Kokkos::Tools::Experimental;
116 ExecutionSpaceIdentifier eid = identifier_from_devid(deviceId);
119 int idx = (int) eid.type;
120 if(eid.instance_id == Impl::int_for_synchronization_reason(SpecialSynchronizationCases::GlobalDeviceSynchronization))
123 count_instance[idx]++;
128 std::string get_label(
int i) {
129 using namespace Kokkos::Tools::Experimental;
130 DeviceType i_type = devicetype_from_uint32t(i);
131 std::string device_label;
132 if (i_type == DeviceType::Serial) device_label=
"Serial";
133 else if (i_type == DeviceType::OpenMP) device_label=
"OpenMP";
134 else if (i_type == DeviceType::Cuda) device_label=
"Cuda";
135 else if (i_type == DeviceType::HIP) device_label=
"HIP";
136 else if (i_type == DeviceType::OpenMPTarget) device_label=
"OpenMPTarget";
137 else if (i_type == DeviceType::HPX) device_label=
"HPX";
138 else if (i_type == DeviceType::Threads) device_label=
"Threats";
139 else if (i_type == DeviceType::SYCL) device_label=
"SYCL";
140 else if (i_type == DeviceType::OpenACC) device_label=
"OpenACC";
141 else if (i_type == DeviceType::Unknown) device_label=
"Unknown";
147 using namespace Kokkos::Tools::Experimental;
148 num_devices = (int) DeviceType::Unknown;
149 count_instance.resize(num_devices);
150 count_instance.assign(num_devices,0);
151 count_global.resize(num_devices);
152 count_global.assign(num_devices,0);
162 if(!FenceCounterDetails::is_initialized)
163 FenceCounterDetails::initialize();
164 FenceCounterDetails::count_active=
true;
165 Kokkos::Tools::Experimental::set_begin_fence_callback(FenceCounterDetails::kokkosp_begin_fence);
169 FenceCounterDetails::count_instance.assign(FenceCounterDetails::num_devices,0);
170 FenceCounterDetails::count_global.assign(FenceCounterDetails::num_devices,0);
174 FenceCounterDetails::count_active=
false;
178 using namespace Kokkos::Tools::Experimental;
179 for(
int i=0;i<FenceCounterDetails::num_devices; i++) {
180 std::string device_label = FenceCounterDetails::get_label(i);
182 if(device == device_label)
183 return FenceCounterDetails::count_global[i];
187 TEUCHOS_TEST_FOR_EXCEPTION(1,std::runtime_error,std::string(
"Error: ") + device + std::string(
" is not a device known to Tpetra"));
192 using namespace Kokkos::Tools::Experimental;
193 for(
int i=0;i<FenceCounterDetails::num_devices; i++) {
194 std::string device_label = FenceCounterDetails::get_label(i);
196 if(device == device_label)
197 return FenceCounterDetails::count_instance[i];
201 TEUCHOS_TEST_FOR_EXCEPTION(1,std::runtime_error,std::string(
"Error: ") + device + std::string(
" is not a device known to Tpetra"));
void initialize(int *argc, char ***argv)
Initialize Tpetra.
void reset()
Reset the deep_copy counter.
Declaration of various tools for counting Kokkos calls of various types using the Kokkos Profiling Li...
size_t get_count_same_space()
Query the deep_copy counter for copies in the same space.
size_t get_count_global(const std::string &device)
Query the fence counter for given device, for an Kokkos::fence()
void start()
Start the fence counter.
size_t get_count_different_space()
Query the deep_copy counter for copies between different spaces.
void reset()
Reset the fence counter.
void start()
Start the deep_copy counter.
void stop()
Stop the fence counter.
size_t get_count_instance(const std::string &device)
Query the fence counter for given device, for an exec_space_instance.fence()
void stop()
Stop the deep_copy counter.