Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tool(space-time-stack): demangle name #218

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions common/FrameType.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#ifndef KOKKOSTOOLS_COMMON_FRAMETYPE_HPP
#define KOKKOSTOOLS_COMMON_FRAMETYPE_HPP

#include <ostream>
#include <string>

namespace KokkosTools {

enum FrameType {
PARALLEL_FOR = 0,
PARALLEL_REDUCE = 1,
PARALLEL_SCAN = 2,
REGION = 3,
COPY = 4
};

//! A @ref FrameType::REGION is not a kernel.
inline constexpr bool is_a_kernel(const FrameType type) {
switch (type) {
case PARALLEL_FOR : return true;
case PARALLEL_REDUCE: return true;
case PARALLEL_SCAN : return true;
case REGION : return false;
case COPY : return true;
default: throw type;
}
}

inline std::string to_string(const FrameType t) {
switch (t) {
case PARALLEL_FOR : return "PARALLEL_FOR";
case PARALLEL_REDUCE: return "PARALLEL_REDUCE";
case PARALLEL_SCAN : return "PARALLEL_SCAN";
case REGION : return "REGION";
case COPY : return "COPY";
default: throw t;
}
}

inline std::ostream &operator<<(std::ostream &os, const FrameType kind) {
switch (kind) {
case PARALLEL_FOR : os << "[for]"; break;
case PARALLEL_REDUCE: os << "[reduce]"; break;
case PARALLEL_SCAN : os << "[scan]"; break;
case REGION : os << "[region]"; break;
case COPY : os << "[copy]"; break;
};
return os;
}

} // namespace KokkosTools

#endif // KOKKOSTOOLS_COMMON_FRAMETYPE_HPP
67 changes: 67 additions & 0 deletions common/SpaceHandle.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#ifndef KOKKOSTOOLS_COMMON_SPACEHANDLE_HPP
#define KOKKOSTOOLS_COMMON_SPACEHANDLE_HPP

#include "impl/Kokkos_Profiling_C_Interface.h"

#include <ostream>
#include <string>

namespace KokkosTools
{
//! A @c Kokkos space type has a unique name.
using SpaceHandle = Kokkos_Profiling_SpaceHandle;

//! Supported @c Kokkos spaces.
enum Space {
HOST = 0,
CUDA = 1,
HIP = 2,
SYCL = 3,
OMPT = 4
};

//! Number of supported spaces (size of @ref Space).
constexpr size_t NSPACES = 5;

//! Get @ref Space from @ref SpaceHandle.
Space get_space(SpaceHandle const& handle)
{
switch(handle.name[0])
{
// Only 'CUDA' space starts with 'C'.
case 'C':
return Space::CUDA;
// Only 'SYCL' space starts with 'S'.
case 'S':
return Space::SYCL;
// Only 'OpenMPTarget' starts with 'O'.
case 'O':
return Space::OMPT;
// Otherwise, it's either 'HIP' or 'HOST'.
case 'H':
if(handle.name[1] == 'I') return Space::HIP;
else return Space::HOST;
default:
std::abort();
}
}

//! Get the name of a @ref Space.
const char* get_space_name(const Space space) {
switch (space) {
case Space::HOST: return "HOST";
case Space::CUDA: return "CUDA";
case Space::SYCL: return "SYCL";
case Space::OMPT: return "OpenMPTarget";
case Space::HIP : return "HIP";
}
std::abort();
}

std::ostream& operator<<(std::ostream& out, const Space space) {
return out << get_space_name(space);
}

} // namespace KokkosTools

#endif // KOKKOSTOOLS_COMMON_SPACEHANDLE_HPP
35 changes: 35 additions & 0 deletions common/utils_time.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#ifndef KOKKOSTOOLS_COMMON_UTILS_TIME_HPP
#define KOKKOSTOOLS_COMMON_UTILS_TIME_HPP

#include <chrono>
#include <sys/time.h>

namespace KokkosTools
{
struct Now {
using impl_t = std::chrono::time_point<std::chrono::high_resolution_clock>;
impl_t impl;
};

inline Now now() {
Now t;
t.impl = std::chrono::high_resolution_clock::now();
return t;
}

inline uint64_t operator-(Now b, Now a) {
return std::chrono::duration_cast<std::chrono::nanoseconds>(b.impl - a.impl)
.count();
}

//! @todo Use @c chrono instead.
inline double seconds() {
struct timeval now;
gettimeofday(&now, NULL);

return (double)(now.tv_sec + (now.tv_usec * 1.0e-6));
}

} // namespace KokkosTools

#endif // KOKKOSTOOLS_COMMON_UTILS_TIME_HPP
7 changes: 4 additions & 3 deletions debugging/kernel-logger/kp_kernel_logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@
#include <limits>
#include <cstring>

#include "../../common/SpaceHandle.hpp"

std::vector<std::string> regions;
static uint64_t uniqID;
struct SpaceHandle {
char name[64];
};

using SpaceHandle = KokkosTools::SpaceHandle;

void kokkosp_print_region_stack_indent(const int level) {
printf("KokkosP: ");
Expand Down
71 changes: 14 additions & 57 deletions profiling/chrome-tracing/kp_chrome_tracing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
#include <unistd.h>

#include "kp_core.hpp"
#include "../../common/FrameType.hpp"
#include "../../common/SpaceHandle.hpp"
#include "../../common/utils_time.hpp"

#if USE_MPI
#include <mpi.h>
Expand All @@ -42,60 +45,14 @@
namespace KokkosTools {
namespace ChromeTracing {

enum Space { SPACE_HOST, SPACE_CUDA };

Space get_space(SpaceHandle const &handle) {
switch (handle.name[0]) {
case 'H': return SPACE_HOST;
case 'C': return SPACE_CUDA;
}
abort();
return SPACE_HOST;
}

struct Now {
typedef std::chrono::time_point<std::chrono::high_resolution_clock> Impl;
Impl impl;
};

Now now() {
Now t;
t.impl = std::chrono::high_resolution_clock::now();
return t;
}

uint64_t operator-(Now b, Now a) {
return std::chrono::duration_cast<std::chrono::nanoseconds>(b.impl - a.impl)
.count();
}

enum StackKind {
STACK_FOR,
STACK_REDUCE,
STACK_SCAN,
STACK_REGION,
STACK_COPY
};

std::ostream &operator<<(std::ostream &os, StackKind kind) {
switch (kind) {
case STACK_FOR: os << "[for]"; break;
case STACK_REDUCE: os << "[reduce]"; break;
case STACK_SCAN: os << "[scan]"; break;
case STACK_REGION: os << "[region]"; break;
case STACK_COPY: os << "[copy]"; break;
};
return os;
}

struct StackNode {
std::string name;
StackKind kind;
FrameType kind;
int rank;
double total_runtime;
Now start_time;
Now base_time;
StackNode(std::string &&name_in, StackKind kind_in, int r, Now b)
StackNode(std::string &&name_in, FrameType kind_in, int r, Now b)
: name(std::move(name_in)),
kind(kind_in),
rank(r),
Expand Down Expand Up @@ -144,7 +101,7 @@ struct State {
}

~State() { outfile << "]\n"; }
void begin_frame(const char *name, StackKind kind) {
void begin_frame(const char *name, FrameType kind) {
std::string name_str(name);
current_stack.emplace_back(std::move(name_str), kind, my_mpi_rank,
my_base_time);
Expand All @@ -163,27 +120,27 @@ struct State {
current_stack.pop_back();
}

std::uint64_t begin_kernel(const char *name, StackKind kind) {
std::uint64_t begin_kernel(const char *name, FrameType kind) {
begin_frame(name, kind);
return 0;
}
void end_kernel(std::uint64_t) { end_frame(); }
void push_region(const char *name) { begin_frame(name, STACK_REGION); }
void push_region(const char *name) { begin_frame(name, FrameType::REGION); }
void pop_region() { end_frame(); }
void begin_deep_copy(Space dst, const char *dst_name, const void *, Space src,
const char *src_name, const void *, std::uint64_t len) {
std::string frame_name;
frame_name += dst_name;
frame_name += " SPACE ";
frame_name += (dst == SPACE_HOST) ? 'H' : 'D';
frame_name += (dst == Space::HOST) ? 'H' : 'D';
frame_name += " COPYFROM ";
frame_name += src_name;
frame_name += " SPACE ";
frame_name += (src == SPACE_HOST) ? 'H' : 'D';
frame_name += (src == Space::HOST) ? 'H' : 'D';
frame_name += " LENGTH ";
frame_name += std::to_string(len);
frame_name += " ";
begin_frame(frame_name.c_str(), STACK_COPY);
begin_frame(frame_name.c_str(), FrameType::COPY);
}
void end_deep_copy() { end_frame(); }
};
Expand All @@ -206,19 +163,19 @@ void kokkosp_finalize_library() {
void kokkosp_begin_parallel_for(const char *name, std::uint32_t devid,
std::uint64_t *kernid) {
(void)devid;
*kernid = global_state->begin_kernel(name, STACK_FOR);
*kernid = global_state->begin_kernel(name, FrameType::PARALLEL_FOR);
}

void kokkosp_begin_parallel_reduce(const char *name, std::uint32_t devid,
std::uint64_t *kernid) {
(void)devid;
*kernid = global_state->begin_kernel(name, STACK_REDUCE);
*kernid = global_state->begin_kernel(name, FrameType::PARALLEL_REDUCE);
}

void kokkosp_begin_parallel_scan(const char *name, std::uint32_t devid,
std::uint64_t *kernid) {
(void)devid;
*kernid = global_state->begin_kernel(name, STACK_SCAN);
*kernid = global_state->begin_kernel(name, FrameType::PARALLEL_SCAN);
}

void kokkosp_end_parallel_for(std::uint64_t kernid) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ void kokkosp_init_library(
} // end kokkosp_init_library

KernelNVTXFocusedConnectorInfo* getFocusedConnectorInfo(
const char* name, KernelExecutionType kType) {
const char* name, FrameType kType) {
std::string nameStr(name);
auto kDomain = domain_map.find(nameStr);
currentKernel = NULL;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,17 @@
#include <sys/time.h>
#include <cstring>

#include "../../common/FrameType.hpp"

#include "nvToolsExt.h"

namespace KokkosTools {
namespace NVTXFocusedConnector {

enum KernelExecutionType {
PARALLEL_FOR = 0,
PARALLEL_REDUCE = 1,
PARALLEL_SCAN = 2
};

class KernelNVTXFocusedConnectorInfo {
public:
KernelNVTXFocusedConnectorInfo(std::string kName,
KernelExecutionType kernelType) {
FrameType kernelType) {
domainNameHandle = kName;
char* domainName = (char*)malloc(sizeof(char*) * (32 + kName.size()));

Expand Down
6 changes: 3 additions & 3 deletions profiling/papi-connector/kp_papi_connector_domain.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@
#include <sys/time.h>
#include <cstring>

#include "../../common/SpaceHandle.hpp"

#include "papi.h"

struct SpaceHandle {
char name[64];
};
using SpaceHandle = KokkosTools::SpaceHandle;

/* stack for parallel_for */
std::stack<std::string> parallel_for_name;
Expand Down
12 changes: 2 additions & 10 deletions profiling/simple-kernel-timer/kp_json_writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,16 @@
#include <fstream>
#include <iostream>

#include "../../common/FrameType.hpp"
#include "kp_shared.h"

using namespace KokkosTools;
using namespace KokkosTools::KernelTimer;

bool is_region(KernelPerformanceInfo const& kp) {
return kp.getKernelType() == REGION;
}

inline std::string to_string(KernelExecutionType t) {
switch (t) {
case PARALLEL_FOR: return "\"PARALLEL_FOR\"";
case PARALLEL_REDUCE: return "\"PARALLEL_REDUCE\"";
case PARALLEL_SCAN: return "\"PARALLEL_SCAN\"";
case REGION: return "\"REGION\"";
default: throw t;
}
}

inline void write_json(std::ostream& os, KernelPerformanceInfo const& kp,
std::string indent = "") {
os << indent << "{\n";
Expand Down
Loading
Loading