-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tool(space-time-stack): demangle name
- Loading branch information
1 parent
2ddedef
commit b12c60a
Showing
16 changed files
with
245 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.