12using clk = std::chrono::steady_clock;
13struct Rec {
double t = 0;
long n = 0; };
14std::map<std::string, Rec> recs;
15struct Fr { std::string n; clk::time_point t;
double cov = 0; };
18std::uint64_t nextId = 0;
19std::map<std::uint64_t, std::pair<std::string, clk::time_point>> open;
20void begin(
const char* name, std::uint64_t*
id) { *
id = nextId++; open[*id] = {name, clk::now()}; }
21void end(std::uint64_t
id) {
22 auto it = open.find(
id);
if (it == open.end())
return;
23 auto& r = recs[it->second.first];
24 const double d = std::chrono::duration<double>(clk::now() - it->second.second).count();
25 r.t += d; ++r.n; open.erase(it);
if (!stack.empty()) stack.back().cov += d;
31 const char* r = std::getenv(
"OMPI_COMM_WORLD_RANK");
32 if (r && std::atoi(r) != 0)
return;
33 std::vector<std::pair<std::string, Rec>> v(recs.begin(), recs.end());
34 std::sort(v.begin(), v.end(), [](
auto& a,
auto& b) { return a.second.t > b.second.t; });
35 double tot = 0;
for (
auto& x : v) tot += x.second.t;
36 std::fprintf(stderr,
"KTIMER total_kernel_s=%.4f\n", tot);
38 for (
auto& x : v) {
if (k++ >= 400)
break; std::fprintf(stderr,
"KT %9.4f s %8ld %s\n", x.second.t, x.second.n, x.first.c_str()); }
48 if (stack.empty())
return;
49 const double d = std::chrono::duration<double>(clk::now() - stack.back().t).count();
50 auto& r = recs[stack.back().n]; r.t += d; ++r.n;
51 auto& x = recs[
"XHOST " + stack.back().n.substr(7)]; x.t += d - stack.back().cov; ++x.n;
52 stack.pop_back();
if (!stack.empty()) stack.back().cov += d;
54void kokkosp_begin_deep_copy(
void*,
const char*,
const void*,
void*,
const char*,
const void*,
const std::uint64_t) { dcT = clk::now(); }
55void kokkosp_end_deep_copy() {
const double d = std::chrono::duration<double>(clk::now() - dcT).count();
auto& r = recs[
"deep_copy(all)"]; r.t += d; ++r.n;
if (!stack.empty()) stack.back().cov += d; }
void kokkosp_end_parallel_for(const std::uint64_t id)
void kokkosp_begin_parallel_reduce(const char *n, const std::uint32_t, std::uint64_t *id)
void kokkosp_init_library(const int, const std::uint64_t, const std::uint32_t, void *)
void kokkosp_end_deep_copy()
void kokkosp_begin_deep_copy(void *, const char *, const void *, void *, const char *, const void *, const std::uint64_t)
void kokkosp_end_parallel_scan(const std::uint64_t id)
void kokkosp_begin_parallel_for(const char *n, const std::uint32_t, std::uint64_t *id)
void kokkosp_end_parallel_reduce(const std::uint64_t id)
void kokkosp_pop_profile_region()
void kokkosp_finalize_library()
void kokkosp_begin_parallel_scan(const char *n, const std::uint32_t, std::uint64_t *id)
void kokkosp_push_profile_region(const char *n)