Skip to content

Commit e1eefbb

Browse files
committed
updates to build system for LDMS connector
1 parent 3fb4d5c commit e1eefbb

File tree

5 files changed

+520
-0
lines changed

5 files changed

+520
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
option(KokkosTools_ENABLE_LDMS "Enable building LDMS connector" OFF)
2+
3+
if(KokkosTools_ENABLE_LDMS)
4+
# Users must set OVIS_DIR or LDMS_ROOT to the LDMS install prefix
5+
find_package(LDMS REQUIRED)
6+
7+
# Use kp_add_library if available, otherwise fallback to add_library
8+
if(COMMAND kp_add_library)
9+
kp_add_library(kp_ldms_connector kp_kernel_ldms.cpp)
10+
else()
11+
add_library(kp_ldms_connector SHARED kp_kernel_ldms.cpp)
12+
set_target_properties(kp_ldms_connector PROPERTIES OUTPUT_NAME kp_kernel_ldms PREFIX "")
13+
endif()
14+
15+
target_include_directories(kp_ldms_connector PRIVATE ${LDMS_INCLUDE_DIR} ${CMAKE_CURRENT_SOURCE_DIR})
16+
target_link_libraries(kp_ldms_connector PRIVATE LDMS::LDMS)
17+
endif()

profiling/ldms-connector/Makefile

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# User must set the path to OVIS install (required)
2+
ifndef OVIS_DIR
3+
$(error OVIS_DIR is not set. Please set OVIS_DIR to your OVIS installation path)
4+
endif
5+
6+
# User must set the path to Kokkos Tools install (required)
7+
ifndef PATH_TO_KOKKOS_TOOLS_INSTALL
8+
$(error PATH_TO_KOKKOS_TOOLS_INSTALL is not set. Please set PATH_TO_KOKKOS_TOOLS_INSTALL to your Kokkos Tools installation path)
9+
endif
10+
11+
KTO_DIR=${PATH_TO_KOKKOS_TOOLS_INSTALL}/kokkos-tools/
12+
CXX?=g++
13+
CXXFLAGS=-O3 -std=c++11 -g \
14+
-I$(OVIS_DIR)/include/ -I./include -I$(KTO_DIR)/profiling/all/ -I$(KTO_DIR)/common/makefile-only/
15+
16+
SHARED_CXXFLAGS=-shared -fPIC
17+
LDFLAGS=-L$(OVIS_DIR)/lib
18+
19+
# Platform-specific libraries
20+
UNAME_S := $(shell uname -s)
21+
ifeq ($(UNAME_S),Darwin)
22+
LIBS=-lldmsd_stream -lldms
23+
else
24+
LIBS=-lldmsd_stream -lldms -lrt
25+
endif
26+
27+
all: kp_kernel_ldms.so
28+
29+
MAKEFILE_PATH := $(subst Makefile,,$(abspath $(lastword $(MAKEFILE_LIST))))
30+
CXXFLAGS+=-I${MAKEFILE_PATH}
31+
32+
kp_kernel_ldms.so: ${MAKEFILE_PATH}kp_kernel_ldms.cpp ${MAKEFILE_PATH}kp_kernel_info.h
33+
$(CXX) $(SHARED_CXXFLAGS) $(CXXFLAGS) $(LDFLAGS) -o $@ ${MAKEFILE_PATH}kp_kernel_ldms.cpp \
34+
$(LIBS)
35+
36+
.PHONY: all clean
37+
38+
clean:
39+
$(RM) *.so
Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
2+
#ifndef _H_KOKKOSP_KERNEL_INFO
3+
#define _H_KOKKOSP_KERNEL_INFO
4+
5+
#include <stdio.h>
6+
#include <string>
7+
#include <cstring>
8+
#include <unistd.h>
9+
10+
#if defined(__GXX_ABI_VERSION)
11+
#define HAVE_GCC_ABI_DEMANGLE
12+
#endif
13+
14+
#if defined(HAVE_GCC_ABI_DEMANGLE)
15+
#include <cxxabi.h>
16+
#endif // HAVE_GCC_ABI_DEMANGLE
17+
18+
#include "kp_kernel_timer.h"
19+
20+
#include <ldms/ldms.h>
21+
#include <ldms/ldmsd_stream.h>
22+
#include <ovis_util/util.h>
23+
24+
char* demangleName(char* kernelName)
25+
{
26+
#if defined(HAVE_GCC_ABI_DEMANGLE)
27+
int status = -1;
28+
char* demangledKernelName = abi::__cxa_demangle(kernelName, NULL, NULL, &status);
29+
if (status==0) {
30+
free(kernelName);
31+
kernelName = demangledKernelName;
32+
}
33+
#endif // HAVE_GCC_ABI_DEMANGLE
34+
return kernelName;
35+
}
36+
37+
enum KernelExecutionType {
38+
PARALLEL_FOR = 0,
39+
PARALLEL_REDUCE = 1,
40+
PARALLEL_SCAN = 2,
41+
REGION = 3
42+
};
43+
44+
static uint64_t kernel_ex = 0;
45+
static double total_time = 0;
46+
47+
class KernelPerformanceInfo {
48+
public:
49+
50+
KernelPerformanceInfo(std::string kName, KernelExecutionType kernelType, ldms_t* the_ldms,
51+
const char* node_name,
52+
const int rank_no,
53+
const int job_id,
54+
const double job_start,
55+
const uint64_t job_epoch_start,
56+
const uint16_t kernel_nest_level,
57+
const int tool_verbosity,
58+
bool* ldms_global_publish):
59+
kType(kernelType), ldms(the_ldms),
60+
nodename(node_name), rank(rank_no),
61+
jobid(job_id), jobStartTime(job_start),
62+
jobStartEpochTimeMS(job_epoch_start),
63+
nestingLevel(kernel_nest_level),
64+
verbosity(tool_verbosity),
65+
ldms_publish(ldms_global_publish) {
66+
67+
kernelName = (char*) malloc(sizeof(char) * (kName.size() + 1));
68+
strcpy(kernelName, kName.c_str());
69+
70+
callCount = 0;
71+
72+
const char* tool_sample_rate = getenv("KOKKOS_SAMPLER_RATE");
73+
kernelSampleRate = 0;
74+
75+
if (NULL != tool_sample_rate) {
76+
kernelSampleRate = atoi(tool_sample_rate);
77+
} else {
78+
kernelSampleRate = 1;
79+
}
80+
}
81+
82+
~KernelPerformanceInfo() {
83+
free(kernelName);
84+
}
85+
86+
KernelExecutionType getKernelType() {
87+
return kType;
88+
}
89+
90+
void incrementCount() {
91+
callCount++;
92+
kernel_ex++;
93+
}
94+
95+
void addTime(double t) {
96+
timeSq += (t*t);
97+
total_time += t;
98+
}
99+
100+
void addFromTimer() {
101+
const double now = seconds();
102+
const double sample_time = now - startTime;
103+
addTime(sample_time);
104+
incrementCount();
105+
106+
if( (*ldms_publish) ) {
107+
const int buffer_size = (NULL == kernelName) ? 4096 :
108+
( strlen(kernelName) > 3072 ? 2048 + strlen(kernelName) : 4096 );
109+
110+
char* big_buffer = (char*) malloc( sizeof(char) * buffer_size );
111+
112+
double epoch_stamp = (double) jobStartEpochTimeMS;
113+
epoch_stamp += static_cast<double>( now - jobStartTime ) * 1000.0;
114+
epoch_stamp = epoch_stamp / 1000.0;
115+
116+
snprintf( big_buffer, buffer_size, "{ \"job-id\" : %d, \"node-name\" : \"%s\", \"rank\" : %d, \"timestamp\" : \"%.6f\", \"kokkos-perf-data\" : [ { \"name\" : \"%s\", \"type\" : %d, \"current-kernel-count\" : %llu, \"total-kernel-count\" : %llu, \"level\" : %u, \"current-kernel-time\" : %.9f, \"total-kernel-time\" : %.9f } ] }\n",
117+
jobid, nodename, rank, epoch_stamp,
118+
(NULL==kernelName) ? "" : kernelName,
119+
(int) kType, callCount, kernel_ex * kernelSampleRate, nestingLevel, sample_time, total_time );
120+
121+
if( verbosity > 0 ) {
122+
printf("%s", big_buffer);
123+
}
124+
125+
int rc = ldmsd_stream_publish( (*ldms), "kokkos-perf-data", LDMSD_STREAM_JSON,
126+
big_buffer, strlen(big_buffer) + 1);
127+
128+
//int rc = ldmsd_stream_publish( (*ldms), "kokkos-perf-data", LDMSD_STREAM_JSON, big_buffer, strlen(big_buffer) + 1);
129+
// always check your return codes :p
130+
free( big_buffer );
131+
}
132+
}
133+
134+
void startTimer() {
135+
startTime = seconds();
136+
}
137+
138+
uint64_t getCallCount() {
139+
return callCount;
140+
}
141+
142+
double getTime() {
143+
return time;
144+
}
145+
146+
double getTimeSq() {
147+
return timeSq;
148+
}
149+
150+
char* getName() {
151+
return kernelName;
152+
}
153+
154+
155+
private:
156+
char* kernelName;
157+
uint64_t callCount;
158+
double time;
159+
double timeSq;
160+
double startTime;
161+
double jobStartTime;
162+
163+
uint64_t kernelSampleRate;
164+
165+
KernelExecutionType kType;
166+
ldms_t* ldms;
167+
168+
bool* ldms_publish;
169+
const uint16_t nestingLevel;
170+
const char* nodename;
171+
const int rank;
172+
const int jobid;
173+
const int verbosity;
174+
const uint64_t jobStartEpochTimeMS;
175+
};
176+
177+
#endif

0 commit comments

Comments
 (0)