Skip to content

Commit 28072a8

Browse files
committed
#2302: Update interface to PAPI metrics
1 parent bab57b7 commit 28072a8

File tree

8 files changed

+102
-57
lines changed

8 files changed

+102
-57
lines changed

ci/build_cpp.sh

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,10 @@ else
8080
cd "${source_dir}/lib"
8181
git clone https://github.com/icl-utk-edu/papi.git
8282
cd papi/src
83-
./configure --prefix=${source_dir}/lib/papi/install
84-
make && make install
83+
export PAPI_BUILD=${build_dir}/papi
84+
mkdir -p "$PAPI_BUILD"
85+
CC="${CC:-cc}" F77="${F77:-gfortran}" ./configure --prefix=${PAPI_BUILD}/install
86+
make -j ${dashj} && make install
8587
fi
8688

8789
if test "${VT_ZOLTAN_ENABLED:-0}" -eq 1
@@ -132,6 +134,7 @@ cmake -G "${CMAKE_GENERATOR:-Ninja}" \
132134
-DCMAKE_C_COMPILER="${CC:-cc}" \
133135
-DCMAKE_EXE_LINKER_FLAGS="${CMAKE_EXE_LINKER_FLAGS:-}" \
134136
-Dcheckpoint_ROOT="$CHECKPOINT_BUILD/install" \
137+
-Dpapi_ROOT="${build_dir}/papi/install" \
135138
-DCMAKE_PREFIX_PATH="${CMAKE_PREFIX_PATH:-}" \
136139
-DCMAKE_INSTALL_PREFIX="$VT_BUILD/install" \
137140
-Dvt_ci_build="${VT_CI_BUILD:-0}" \

cmake/FindPAPI.cmake

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
# Set minimum CMake version
22
cmake_minimum_required(VERSION 3.23 FATAL_ERROR)
33

4-
set(PAPI_ROOT "${CMAKE_SOURCE_DIR}/lib/papi/install")
54

65
# Find the PAPI include directory and library
7-
find_path(PAPI_INCLUDE_DIR NAMES papi.h HINTS ${PAPI_ROOT}/include)
8-
find_library(PAPI_LIBRARY NAMES papi HINTS ${PAPI_ROOT}/lib)
6+
message(STATUS "Finding PAPI, PAPI_BUILD_ROOT: ${papi_ROOT}")
7+
find_path(PAPI_INCLUDE_DIR NAMES papi.h HINTS ${papi_ROOT}/include)
8+
find_library(PAPI_LIBRARY NAMES papi HINTS ${papi_ROOT}/lib)
99

1010
include(FindPackageHandleStandardArgs)
1111
find_package_handle_standard_args(PAPI DEFAULT_MSG PAPI_LIBRARY PAPI_INCLUDE_DIR)

cmake/link_vt.cmake

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,9 +216,14 @@ function(link_target_with_vt)
216216
if (${ARG_DEBUG_LINK})
217217
message(STATUS "link_target_with_vt: papi=${ARG_LINK_PAPI}")
218218
endif()
219+
message(STATUS "target_link_libraries: ${ARG_TARGET} PUBLIC ${ARG_BUILD_TYPE} ${PAPI_LIBRARY}")
220+
message(STATUS "target_include_directories: ${ARG_TARGET} PUBLIC ${ARG_BUILD_TYPE} ${PAPI_INCLUDE_DIR}")
219221
target_link_libraries(
220222
${ARG_TARGET} PUBLIC ${ARG_BUILD_TYPE} ${PAPI_LIBRARY}
221223
)
224+
target_include_directories(
225+
${ARG_TARGET} PUBLIC ${ARG_BUILD_TYPE} ${PAPI_INCLUDE_DIR}
226+
)
222227
endif()
223228

224229
if (${vt_mimalloc_enabled})

src/vt/context/runnable_context/lb_data.cc

Lines changed: 25 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -53,17 +53,15 @@ void LBData::start(TimeType time) {
5353
}
5454

5555
/* -- PAPI START -- */
56-
5756
/* Start counting events in the Event Set */
58-
// papi_retval_ = PAPI_start(EventSet_);
59-
// if (papi_retval_ != PAPI_OK)
60-
// handle_papi_error(papi_retval_, "LBData start: Starting counting events in the Event Set: ");
61-
62-
/* Gets the starting time in clock cycles */
63-
start_cycles_ = PAPI_get_real_cyc();
57+
papi_retval_ = PAPI_start(EventSet_);
58+
if (papi_retval_ != PAPI_OK)
59+
handle_papi_error(papi_retval_, "LBData start: Starting counting events in the Event Set: ");
6460

65-
/* Gets the starting time in microseconds */
66-
start_usec_ = PAPI_get_real_usec();
61+
start_real_cycles_ = PAPI_get_real_cyc();
62+
start_real_usec_ = PAPI_get_real_usec();
63+
start_virt_cycles_ = PAPI_get_virt_cyc();
64+
start_virt_usec_ = PAPI_get_virt_usec();
6765

6866
/* ---------------- */
6967
}
@@ -74,30 +72,18 @@ void LBData::finish(TimeType time) {
7472
lb_data_->stop(time);
7573
}
7674

77-
/* -- PAPI READ AND STOP -- */
78-
79-
/* Read the counting events in the Event Set */
80-
// papi_retval_ = PAPI_read(EventSet_, papi_values_);
81-
// if (papi_retval_ != PAPI_OK)
82-
// handle_papi_error(papi_retval_, "LBData finish: Reading the counting events in the Event Set: ");
83-
84-
// printf("Counters after LBData::finish: %lld\n",papi_values_[0]);
85-
86-
// /* Stop the counting of events in the Event Set */
87-
// papi_retval_ = PAPI_stop(EventSet_, papi_values_);
88-
// if (papi_retval_ != PAPI_OK)
89-
// handle_papi_error(papi_retval_, "LBData finish: Stoping the counting of events in the Event Set: ");
75+
/* -- PAPI STOP -- */
76+
/* Stop the counting of events in the Event Set */
77+
papi_retval_ = PAPI_stop(EventSet_, papi_values_);
78+
if (papi_retval_ != PAPI_OK)
79+
handle_papi_error(papi_retval_, "LBData finish: Stoping the counting of events in the Event Set: ");
9080

91-
/* Gets the ending time in clock cycles */
92-
end_cycles_ = PAPI_get_real_cyc();
81+
end_real_cycles_ = PAPI_get_real_cyc();
82+
end_real_usec_ = PAPI_get_real_usec();
83+
end_virt_cycles_ = PAPI_get_virt_cyc();
84+
end_virt_usec_ = PAPI_get_virt_usec();
9385

94-
/* Gets the ending time in microseconds */
95-
end_usec_ = PAPI_get_real_usec();
96-
97-
printf("Wall clock cycles: %lld\n", end_cycles_ - start_cycles_);
98-
printf("Wall clock time in microseconds: %lld\n", end_usec_ - start_usec_);
99-
100-
/* ------------------------ */
86+
/* -------------- */
10187
}
10288

10389
void LBData::send(elm::ElementIDStruct dest, MsgSizeType bytes) {
@@ -118,4 +104,12 @@ typename LBData::ElementIDStruct const& LBData::getCurrentElementID() const {
118104
return cur_elm_id_;
119105
}
120106

107+
std::unordered_map<std::string, double> LBData::getPAPIMetrics() const {
108+
std::unordered_map<std::string, double> papi_metrics = {};
109+
for (size_t i = 0; i < native_events_.size(); i++) {
110+
papi_metrics[native_events_[i]] = papi_values_[i];
111+
}
112+
return papi_metrics;
113+
}
114+
121115
}} /* end namespace vt::ctx */

src/vt/context/runnable_context/lb_data.h

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,24 @@ struct LBData {
9090
{
9191
/* Create the PAPI Event Set */
9292
papi_retval_ = PAPI_create_eventset(&EventSet_);
93-
if (papi_retval_ != PAPI_OK)
94-
handle_papi_error(papi_retval_, "LBData Constructor 2: Creating the PAPI Event Set: ");
95-
96-
// /* Add Total Instructions Executed to the PAPI Event Set */
97-
// papi_retval_ = PAPI_add_event(EventSet_, PAPI_DP_OPS);
98-
// if (papi_retval_ != PAPI_OK)
99-
// handle_papi_error(papi_retval_, "LBData Constructor 2: Adding Total Instructions Executed to the PAPI Event Set: ");
93+
if (papi_retval_ != PAPI_OK) {
94+
printf("LBData Constructor 2: Creating the PAPI Event Set: PAPI error %d: %s\n", papi_retval_, PAPI_strerror(papi_retval_));
95+
exit(1);
96+
}
97+
98+
for (const auto& event_name : native_events_) {
99+
int native = 0x0;
100+
papi_retval_ = PAPI_event_name_to_code(event_name.c_str(), &native);
101+
if (papi_retval_ != PAPI_OK) {
102+
printf("LBData Constructor 2: Couldn't event_name_to_code for %s: PAPI error %d: %s\n",event_name.c_str(), papi_retval_, PAPI_strerror(papi_retval_));
103+
exit(1);
104+
}
105+
papi_retval_ = PAPI_add_event(EventSet_, native);
106+
if (papi_retval_ != PAPI_OK) {
107+
printf("LBData Constructor 2: Couldn't add %s to the PAPI Event Set: PAPI error %d: %s\n",event_name.c_str(), papi_retval_, PAPI_strerror(papi_retval_));
108+
exit(1);
109+
}
110+
}
100111
}
101112

102113
/**
@@ -133,14 +144,23 @@ struct LBData {
133144
*/
134145
ElementIDStruct const& getCurrentElementID() const;
135146

147+
/**
148+
* \brief Get the current PAPI metrics map for the running context
149+
*
150+
* \return the PAPI metrics map
151+
*/
152+
std::unordered_map<std::string, double> getPAPIMetrics() const;
153+
136154
private:
137155
ElementLBData* lb_data_ = nullptr; /**< Element LB data */
138156
ElementIDStruct cur_elm_id_ = {}; /**< Current element ID */
139157
bool should_instrument_ = false; /**< Whether we are instrumenting */
140-
long_long papi_values_[1];
141158
int EventSet_ = PAPI_NULL;
142159
int papi_retval_;
143-
long long start_cycles_, end_cycles_, start_usec_, end_usec_;
160+
long long start_real_cycles_, end_real_cycles_, start_real_usec_, end_real_usec_;
161+
long long start_virt_cycles_, end_virt_cycles_, start_virt_usec_, end_virt_usec_;
162+
std::vector<std::string> native_events_ = {"instructions", "cache-misses", "fp_arith_inst_retired.scalar_double"};
163+
long_long papi_values_[3];
144164
};
145165

146166
}} /* end namespace vt::ctx */

src/vt/context/runnable_context/lb_data.impl.h

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -63,19 +63,26 @@ LBData::LBData(ElmT* in_elm, MsgT* msg)
6363
// record the communication LB data right away!
6464
theCollection()->recordLBData(in_elm, msg);
6565

66-
// /* Create the PAPI Event Set */
67-
// papi_retval_ = PAPI_create_eventset(&EventSet_);
68-
// if (papi_retval_ != PAPI_OK) {
69-
// printf("LBData Constructor 1: Creating the PAPI Event Set: PAPI error %d: %s\n", papi_retval_, PAPI_strerror(papi_retval_));
70-
// exit(1);
71-
// }
66+
/* Create the PAPI Event Set */
67+
papi_retval_ = PAPI_create_eventset(&EventSet_);
68+
if (papi_retval_ != PAPI_OK) {
69+
printf("LBData Constructor 1: Creating the PAPI Event Set: PAPI error %d: %s\n", papi_retval_, PAPI_strerror(papi_retval_));
70+
exit(1);
71+
}
7272

73-
// /* Add Total Instructions Executed to the PAPI Event Set */
74-
// papi_retval_ = PAPI_add_event(EventSet_, PAPI_TOT_INS);
75-
// if (papi_retval_ != PAPI_OK) {
76-
// printf("LBData Constructor 1: Adding Total Instructions Executed to the PAPI Event Set: PAPI error %d: %s\n", papi_retval_, PAPI_strerror(papi_retval_));
77-
// exit(1);
78-
// }
73+
for (const auto& event_name : native_events_) {
74+
int native = 0x0;
75+
papi_retval_ = PAPI_event_name_to_code(event_name.c_str(), &native);
76+
if (papi_retval_ != PAPI_OK) {
77+
printf("LBData Constructor 1: Couldn't event_name_to_code for %s: PAPI error %d: %s\n",event_name.c_str(), papi_retval_, PAPI_strerror(papi_retval_));
78+
exit(1);
79+
}
80+
papi_retval_ = PAPI_add_event(EventSet_, native);
81+
if (papi_retval_ != PAPI_OK) {
82+
printf("LBData Constructor 1: Couldn't add %s to the PAPI Event Set: PAPI error %d: %s\n",event_name.c_str(), papi_retval_, PAPI_strerror(papi_retval_));
83+
exit(1);
84+
}
85+
}
7986
}
8087

8188
}} /* end namespace vt::ctx */

src/vt/runnable/runnable.cc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,15 @@ void RunnableNew::run() {
199199
#endif
200200
}
201201

202+
std::unordered_map<std::string, double> RunnableNew::getPAPIMetrics() const {
203+
std::unordered_map<std::string, double> result = {};
204+
if (contexts_.has_lb)
205+
{
206+
result = contexts_.lb.getPAPIMetrics();
207+
}
208+
return result;
209+
}
210+
202211
void RunnableNew::start(TimeType time) {
203212
contexts_.setcontext.start();
204213
if (contexts_.has_td) contexts_.td.start();

src/vt/runnable/runnable.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,13 @@ struct RunnableNew {
321321
*/
322322
BaseMsgType* getMsg() const { return msg_.get(); }
323323

324+
/**
325+
* \brief Get the dictionnary of PAPI metrics associated with the runnable
326+
*
327+
* \return the dictionnary
328+
*/
329+
std::unordered_map<std::string, double> getPAPIMetrics() const;
330+
324331
#if vt_check_enabled(fcontext)
325332
/**
326333
* \brief Check if this runnable is complete or not

0 commit comments

Comments
 (0)