Skip to content

Commit 2d757cd

Browse files
tool(space-time-stack): demangle name
1 parent 2ddedef commit 2d757cd

26 files changed

+360
-242
lines changed

CMakeLists.txt

+7
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ option(KokkosTools_ENABLE_MPI "Enable MPI support" OFF)
4545
option(KokkosTools_ENABLE_CALIPER "Enable building Caliper library" OFF)
4646
option(KokkosTools_ENABLE_APEX "Enable building Apex library" OFF)
4747
option(KokkosTools_ENABLE_EXAMPLES "Build examples" OFF)
48+
option(KokkosTools_ENABLE_TESTS "Build tests" OFF)
4849
# Advanced settings
4950
option(KokkosTools_REUSE_KOKKOS_COMPILER "Set the compiler and flags based on installed Kokkos settings" OFF)
5051
mark_as_advanced(KokkosTools_REUSE_KOKKOS_COMPILER)
@@ -263,6 +264,12 @@ if(KokkosTools_ENABLE_EXAMPLES)
263264
endif()
264265
endif()
265266

267+
# Build tests
268+
if(KokkosTools_ENABLE_TESTS)
269+
enable_testing()
270+
add_subdirectory(tests)
271+
endif()
272+
266273
# Install exports
267274
install(TARGETS ${EXPORT_TARGETS} EXPORT ${EXPORT_NAME})
268275
install(EXPORT ${EXPORT_NAME}

CMakePresets.json

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"CMAKE_BUILD_TYPE" : "Release",
99
"CMAKE_CXX_STANDARD" : "17",
1010
"KokkosTools_ENABLE_EXAMPLES" : "ON",
11+
"KokkosTools_ENABLE_TESTS" : "ON",
1112
"KokkosTools_ENABLE_SINGLE" : "ON",
1213
"KokkosTools_ENABLE_MPI" : "ON"
1314
}

common/FrameType.hpp

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#ifndef KOKKOSTOOLS_COMMON_FRAMETYPE_HPP
2+
#define KOKKOSTOOLS_COMMON_FRAMETYPE_HPP
3+
4+
#include <ostream>
5+
#include <string>
6+
7+
namespace KokkosTools {
8+
9+
enum FrameType {
10+
PARALLEL_FOR = 0,
11+
PARALLEL_REDUCE = 1,
12+
PARALLEL_SCAN = 2,
13+
REGION = 3,
14+
COPY = 4
15+
};
16+
17+
//! A @ref FrameType::REGION is not a kernel.
18+
inline constexpr bool is_a_kernel(const FrameType type) {
19+
switch (type) {
20+
case PARALLEL_FOR : return true;
21+
case PARALLEL_REDUCE: return true;
22+
case PARALLEL_SCAN : return true;
23+
case REGION : return false;
24+
case COPY : return true;
25+
default: throw type;
26+
}
27+
}
28+
29+
inline std::string to_string(const FrameType t) {
30+
switch (t) {
31+
case PARALLEL_FOR : return "PARALLEL_FOR";
32+
case PARALLEL_REDUCE: return "PARALLEL_REDUCE";
33+
case PARALLEL_SCAN : return "PARALLEL_SCAN";
34+
case REGION : return "REGION";
35+
case COPY : return "COPY";
36+
default: throw t;
37+
}
38+
}
39+
40+
inline std::ostream &operator<<(std::ostream &os, const FrameType kind) {
41+
switch (kind) {
42+
case PARALLEL_FOR : os << "[for]"; break;
43+
case PARALLEL_REDUCE: os << "[reduce]"; break;
44+
case PARALLEL_SCAN : os << "[scan]"; break;
45+
case REGION : os << "[region]"; break;
46+
case COPY : os << "[copy]"; break;
47+
};
48+
return os;
49+
}
50+
51+
} // namespace KokkosTools
52+
53+
#endif // KOKKOSTOOLS_COMMON_FRAMETYPE_HPP

common/SpaceHandle.hpp

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#ifndef KOKKOSTOOLS_COMMON_SPACEHANDLE_HPP
2+
#define KOKKOSTOOLS_COMMON_SPACEHANDLE_HPP
3+
4+
#include "impl/Kokkos_Profiling_C_Interface.h"
5+
6+
#include <ostream>
7+
#include <string>
8+
9+
namespace KokkosTools
10+
{
11+
//! A @c Kokkos space type has a unique name.
12+
using SpaceHandle = Kokkos_Profiling_SpaceHandle;
13+
14+
//! Supported @c Kokkos spaces.
15+
enum Space {
16+
HOST = 0,
17+
CUDA = 1,
18+
HIP = 2,
19+
SYCL = 3,
20+
OMPT = 4
21+
};
22+
23+
//! Number of supported spaces (size of @ref Space).
24+
constexpr size_t NSPACES = 5;
25+
26+
//! Get @ref Space from @ref SpaceHandle.
27+
Space get_space(SpaceHandle const& handle)
28+
{
29+
switch(handle.name[0])
30+
{
31+
// Only 'CUDA' space starts with 'C'.
32+
case 'C':
33+
return Space::CUDA;
34+
// Only 'SYCL' space starts with 'S'.
35+
case 'S':
36+
return Space::SYCL;
37+
// Only 'OpenMPTarget' starts with 'O'.
38+
case 'O':
39+
return Space::OMPT;
40+
// Otherwise, it's either 'HIP' or 'HOST'.
41+
case 'H':
42+
if(handle.name[1] == 'I') return Space::HIP;
43+
else return Space::HOST;
44+
default:
45+
std::abort();
46+
}
47+
}
48+
49+
//! Get the name of a @ref Space.
50+
const char* get_space_name(const Space space) {
51+
switch (space) {
52+
case Space::HOST: return "HOST";
53+
case Space::CUDA: return "CUDA";
54+
case Space::SYCL: return "SYCL";
55+
case Space::OMPT: return "OpenMPTarget";
56+
case Space::HIP : return "HIP";
57+
}
58+
std::abort();
59+
}
60+
61+
std::ostream& operator<<(std::ostream& out, const Space space) {
62+
return out << get_space_name(space);
63+
}
64+
65+
} // namespace KokkosTools
66+
67+
#endif // KOKKOSTOOLS_COMMON_SPACEHANDLE_HPP

common/utils_demangle.hpp

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#ifndef KOKKOSTOOLS_COMMON_UTILS_DEMANGLE
2+
#define KOKKOSTOOLS_COMMON_UTILS_DEMANGLE
3+
4+
#include <string>
5+
6+
#if defined(__GXX_ABI_VERSION)
7+
#define HAVE_GCC_ABI_DEMANGLE
8+
#endif
9+
10+
#if defined(HAVE_GCC_ABI_DEMANGLE)
11+
#include <cxxabi.h>
12+
#endif // HAVE_GCC_ABI_DEMANGLE
13+
14+
namespace KokkosTools
15+
{
16+
17+
inline char* demangleName(char* kernelName) {
18+
#if defined(HAVE_GCC_ABI_DEMANGLE)
19+
int status = -1;
20+
char* demangledKernelName =
21+
abi::__cxa_demangle(kernelName, NULL, NULL, &status);
22+
if (status != 0 || 0 == demangledKernelName) {
23+
if (demangledKernelName != NULL) {
24+
free(demangledKernelName);
25+
}
26+
} else {
27+
free(kernelName);
28+
kernelName = demangledKernelName;
29+
}
30+
#endif // HAVE_GCC_ABI_DEMANGLE
31+
return kernelName;
32+
}
33+
34+
inline std::string demangleName(const std::string& mangledName )
35+
{
36+
#if defined(HAVE_GCC_ABI_DEMANGLE)
37+
int status;
38+
char* _demangledName = abi::__cxa_demangle(mangledName.c_str (), 0, 0, &status);
39+
if (status != 0 || 0 == _demangledName) {
40+
if (_demangledName != NULL) {
41+
free (_demangledName);
42+
}
43+
return mangledName;
44+
}
45+
std::string demangledName (_demangledName);
46+
free (_demangledName); // We have to free this before we return!
47+
return demangledName;
48+
#else
49+
return mangledName;
50+
#endif
51+
}
52+
53+
} // namespace KokkosTools
54+
55+
#endif // KOKKOSTOOLS_COMMON_UTILS_DEMANGLE

common/utils_time.hpp

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#ifndef KOKKOSTOOLS_COMMON_UTILS_TIME_HPP
2+
#define KOKKOSTOOLS_COMMON_UTILS_TIME_HPP
3+
4+
#include <chrono>
5+
#include <sys/time.h>
6+
7+
namespace KokkosTools
8+
{
9+
struct Now {
10+
using impl_t = std::chrono::time_point<std::chrono::high_resolution_clock>;
11+
impl_t impl;
12+
};
13+
14+
inline Now now() {
15+
Now t;
16+
t.impl = std::chrono::high_resolution_clock::now();
17+
return t;
18+
}
19+
20+
inline uint64_t operator-(Now b, Now a) {
21+
return std::chrono::duration_cast<std::chrono::nanoseconds>(b.impl - a.impl)
22+
.count();
23+
}
24+
25+
//! @todo Use @c chrono instead.
26+
inline double seconds() {
27+
struct timeval now;
28+
gettimeofday(&now, NULL);
29+
30+
return (double)(now.tv_sec + (now.tv_usec * 1.0e-6));
31+
}
32+
33+
} // namespace KokkosTools
34+
35+
#endif // KOKKOSTOOLS_COMMON_UTILS_TIME_HPP

debugging/kernel-logger/kp_kernel_logger.cpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,12 @@
2121
#include <limits>
2222
#include <cstring>
2323

24+
#include "../../common/SpaceHandle.hpp"
25+
2426
std::vector<std::string> regions;
2527
static uint64_t uniqID;
26-
struct SpaceHandle {
27-
char name[64];
28-
};
28+
29+
using SpaceHandle = KokkosTools::SpaceHandle;
2930

3031
void kokkosp_print_region_stack_indent(const int level) {
3132
printf("KokkosP: ");

profiling/all/impl/Kokkos_Profiling_C_Interface.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ enum Kokkos_Tools_OptimizationType {
152152
Kokkos_Tools_Maximize
153153
};
154154

155-
struct Kokkos_Tools_OptimzationGoal {
155+
struct Kokkos_Tools_OptimizationGoal {
156156
size_t type_id;
157157
enum Kokkos_Tools_OptimizationType goal;
158158
};
@@ -218,7 +218,7 @@ typedef void (*Kokkos_Tools_contextBeginFunction)(const size_t);
218218
typedef void (*Kokkos_Tools_contextEndFunction)(
219219
const size_t, struct Kokkos_Tools_VariableValue);
220220
typedef void (*Kokkos_Tools_optimizationGoalDeclarationFunction)(
221-
const size_t, const struct Kokkos_Tools_OptimzationGoal goal);
221+
const size_t, const struct Kokkos_Tools_OptimizationGoal goal);
222222

223223
struct Kokkos_Profiling_EventSet {
224224
Kokkos_Profiling_initFunction init;

profiling/all/impl/Kokkos_Profiling_Interface.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ using ValueType = Kokkos_Tools_VariableInfo_ValueType;
220220
using CandidateValueType = Kokkos_Tools_VariableInfo_CandidateValueType;
221221
using SetOrRange = Kokkos_Tools_VariableInfo_SetOrRange;
222222
using VariableInfo = Kokkos_Tools_VariableInfo;
223-
using OptimizationGoal = Kokkos_Tools_OptimzationGoal;
223+
using OptimizationGoal = Kokkos_Tools_OptimizationGoal;
224224
using TuningString = Kokkos_Tools_Tuning_String;
225225
using VariableValue = Kokkos_Tools_VariableValue;
226226

0 commit comments

Comments
 (0)