Skip to content

Commit

Permalink
tool(space-time-stack): demangle name
Browse files Browse the repository at this point in the history
  • Loading branch information
romintomasetti committed Nov 6, 2023
1 parent 2ddedef commit 1a76dca
Show file tree
Hide file tree
Showing 24 changed files with 351 additions and 237 deletions.
7 changes: 7 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ option(KokkosTools_ENABLE_MPI "Enable MPI support" OFF)
option(KokkosTools_ENABLE_CALIPER "Enable building Caliper library" OFF)
option(KokkosTools_ENABLE_APEX "Enable building Apex library" OFF)
option(KokkosTools_ENABLE_EXAMPLES "Build examples" OFF)
option(KokkosTools_ENABLE_TESTS "Build tests" OFF)
# Advanced settings
option(KokkosTools_REUSE_KOKKOS_COMPILER "Set the compiler and flags based on installed Kokkos settings" OFF)
mark_as_advanced(KokkosTools_REUSE_KOKKOS_COMPILER)
Expand Down Expand Up @@ -263,6 +264,12 @@ if(KokkosTools_ENABLE_EXAMPLES)
endif()
endif()

# Build tests
if(KokkosTools_ENABLE_TESTS)
enable_testing()
add_subdirectory(tests)
endif()

# Install exports
install(TARGETS ${EXPORT_TARGETS} EXPORT ${EXPORT_NAME})
install(EXPORT ${EXPORT_NAME}
Expand Down
1 change: 1 addition & 0 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"CMAKE_BUILD_TYPE" : "Release",
"CMAKE_CXX_STANDARD" : "17",
"KokkosTools_ENABLE_EXAMPLES" : "ON",
"KokkosTools_ENABLE_TESTS" : "ON",
"KokkosTools_ENABLE_SINGLE" : "ON",
"KokkosTools_ENABLE_MPI" : "ON"
}
Expand Down
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
55 changes: 55 additions & 0 deletions common/utils_demangle.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#ifndef KOKKOSTOOLS_COMMON_UTILS_DEMANGLE
#define KOKKOSTOOLS_COMMON_UTILS_DEMANGLE

#include <string>

#if defined(__GXX_ABI_VERSION)
#define HAVE_GCC_ABI_DEMANGLE
#endif

#if defined(HAVE_GCC_ABI_DEMANGLE)
#include <cxxabi.h>
#endif // HAVE_GCC_ABI_DEMANGLE

namespace KokkosTools
{

inline char* demangleName(char* kernelName) {
#if defined(HAVE_GCC_ABI_DEMANGLE)
int status = -1;
char* demangledKernelName =
abi::__cxa_demangle(kernelName, NULL, NULL, &status);
if (status != 0 || 0 == demangledKernelName) {
if (demangledKernelName != NULL) {
free(demangledKernelName);
}
} else {
free(kernelName);
kernelName = demangledKernelName;
}
#endif // HAVE_GCC_ABI_DEMANGLE
return kernelName;
}

inline std::string demangleName(const std::string& mangledName )
{
#if defined(HAVE_GCC_ABI_DEMANGLE)
int status;
char* _demangledName = abi::__cxa_demangle(mangledName.c_str (), 0, 0, &status);
if (status != 0 || 0 == _demangledName) {
if (_demangledName != NULL) {
free (_demangledName);
}
return mangledName;
}
std::string demangledName (_demangledName);
free (_demangledName); // We have to free this before we return!
return demangledName;
#else
return mangledName;
#endif
}

} // namespace KokkosTools

#endif // KOKKOSTOOLS_COMMON_UTILS_DEMANGLE
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
4 changes: 2 additions & 2 deletions profiling/all/impl/Kokkos_Profiling_C_Interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ enum Kokkos_Tools_OptimizationType {
Kokkos_Tools_Maximize
};

struct Kokkos_Tools_OptimzationGoal {
struct Kokkos_Tools_OptimizationGoal {
size_t type_id;
enum Kokkos_Tools_OptimizationType goal;
};
Expand Down Expand Up @@ -218,7 +218,7 @@ typedef void (*Kokkos_Tools_contextBeginFunction)(const size_t);
typedef void (*Kokkos_Tools_contextEndFunction)(
const size_t, struct Kokkos_Tools_VariableValue);
typedef void (*Kokkos_Tools_optimizationGoalDeclarationFunction)(
const size_t, const struct Kokkos_Tools_OptimzationGoal goal);
const size_t, const struct Kokkos_Tools_OptimizationGoal goal);

struct Kokkos_Profiling_EventSet {
Kokkos_Profiling_initFunction init;
Expand Down
2 changes: 1 addition & 1 deletion profiling/all/impl/Kokkos_Profiling_Interface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ using ValueType = Kokkos_Tools_VariableInfo_ValueType;
using CandidateValueType = Kokkos_Tools_VariableInfo_CandidateValueType;
using SetOrRange = Kokkos_Tools_VariableInfo_SetOrRange;
using VariableInfo = Kokkos_Tools_VariableInfo;
using OptimizationGoal = Kokkos_Tools_OptimzationGoal;
using OptimizationGoal = Kokkos_Tools_OptimizationGoal;
using TuningString = Kokkos_Tools_Tuning_String;
using VariableValue = Kokkos_Tools_VariableValue;

Expand Down
Loading

0 comments on commit 1a76dca

Please sign in to comment.