Skip to content

Commit

Permalink
#2302: Refine access to PAPI events and use preset events
Browse files Browse the repository at this point in the history
  • Loading branch information
pierrepebay committed Aug 15, 2024
1 parent 5832319 commit 86b505a
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 27 deletions.
21 changes: 18 additions & 3 deletions src/vt/context/runnable_context/lb_data.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ void LBData::start(TimeType time) {
if (should_instrument_) {
lb_data_->start(time);
}
}

void LBData::startPAPIMetrics() {
/* -- PAPI START -- */
/* Start counting events in the Event Set */
papi_retval_ = PAPI_start(EventSet_);
Expand All @@ -71,7 +73,9 @@ void LBData::finish(TimeType time) {
if (should_instrument_) {
lb_data_->stop(time);
}
}

void LBData::stopPAPIMetrics() {
/* -- PAPI STOP -- */
/* Stop the counting of events in the Event Set */
papi_retval_ = PAPI_stop(EventSet_, papi_values_);
Expand Down Expand Up @@ -104,11 +108,22 @@ typename LBData::ElementIDStruct const& LBData::getCurrentElementID() const {
return cur_elm_id_;
}

std::unordered_map<std::string, double> LBData::getPAPIMetrics() const {
std::unordered_map<std::string, double> LBData::getPAPIMetrics() {
std::unordered_map<std::string, double> papi_metrics = {};
for (size_t i = 0; i < native_events_.size(); i++) {
papi_metrics[native_events_[i]] = papi_values_[i];
char event_code_str[PAPI_MAX_STR_LEN];
for (size_t i = 0; i < events_.size(); i++) {
papi_retval_ = PAPI_event_code_to_name(events_[i], event_code_str);
if (papi_retval_ != PAPI_OK)
handle_papi_error(papi_retval_, "LBData getPAPIMetrics: couldn't get name from event code: ");
papi_metrics[std::string(event_code_str)] = papi_values_[i];
}
papi_metrics[std::string("real_time")] = end_real_usec_ - start_real_usec_;
papi_metrics[std::string("real_cycles")] = end_real_cycles_ - start_real_cycles_;
papi_metrics[std::string("virt_time")] = end_virt_usec_ - start_virt_usec_;
papi_metrics[std::string("virt_cycles")] = end_virt_cycles_ - start_virt_cycles_;
// for (auto [name, value] : papi_metrics) {
// fmt::print("{}: {}\n", name, value);
// }
return papi_metrics;
}

Expand Down
35 changes: 22 additions & 13 deletions src/vt/context/runnable_context/lb_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ struct LBData {
using ElementIDStruct = elm::ElementIDStruct;
using ElementLBData = elm::ElementLBData;

void handle_papi_error (int retval, std::string info)
void handle_papi_error (int retval, std::string info) const
{
printf("%s: PAPI error %d: %s\n", info.c_str(), retval, PAPI_strerror(retval));
exit(1);
Expand Down Expand Up @@ -95,16 +95,12 @@ struct LBData {
exit(1);
}

for (const auto& event_name : native_events_) {
int native = 0x0;
papi_retval_ = PAPI_event_name_to_code(event_name.c_str(), &native);
for (const auto& event : events_) {
papi_retval_ = PAPI_add_event(EventSet_, event);
char event_code_str[PAPI_MAX_STR_LEN];
if (papi_retval_ != PAPI_OK) {
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_));
exit(1);
}
papi_retval_ = PAPI_add_event(EventSet_, native);
if (papi_retval_ != PAPI_OK) {
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_));
PAPI_event_code_to_name(event, event_code_str);
printf("LBData Constructor 2: Couldn't add %s: PAPI error %d: %s\n", event_code_str, papi_retval_, PAPI_strerror(papi_retval_));
exit(1);
}
}
Expand Down Expand Up @@ -144,12 +140,25 @@ struct LBData {
*/
ElementIDStruct const& getCurrentElementID() const;

/**
* \brief Start PAPI metrics map for the running context
*/
void startPAPIMetrics();

/**
* \brief Stop PAPI metrics map for the running context
*
* \note has to be called after startPAPIMetrics
*
*/
void stopPAPIMetrics();

/**
* \brief Get the current PAPI metrics map for the running context
*
* \return the PAPI metrics map
*/
std::unordered_map<std::string, double> getPAPIMetrics() const;
std::unordered_map<std::string, double> getPAPIMetrics();

private:
ElementLBData* lb_data_ = nullptr; /**< Element LB data */
Expand All @@ -159,8 +168,8 @@ struct LBData {
int papi_retval_;
long long start_real_cycles_, end_real_cycles_, start_real_usec_, end_real_usec_;
long long start_virt_cycles_, end_virt_cycles_, start_virt_usec_, end_virt_usec_;
std::vector<std::string> native_events_ = {"instructions", "cache-misses", "fp_arith_inst_retired.scalar_double"};
long_long papi_values_[3];
std::vector<int> events_ = {PAPI_L1_DCM, PAPI_TOT_INS};
long_long papi_values_[5];
};

}} /* end namespace vt::ctx */
Expand Down
14 changes: 5 additions & 9 deletions src/vt/context/runnable_context/lb_data.impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,12 @@ LBData::LBData(ElmT* in_elm, MsgT* msg)
exit(1);
}

for (const auto& event_name : native_events_) {
int native = 0x0;
papi_retval_ = PAPI_event_name_to_code(event_name.c_str(), &native);
for (const auto& event : events_) {
papi_retval_ = PAPI_add_event(EventSet_, event);
char event_code_str[PAPI_MAX_STR_LEN];
if (papi_retval_ != PAPI_OK) {
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_));
exit(1);
}
papi_retval_ = PAPI_add_event(EventSet_, native);
if (papi_retval_ != PAPI_OK) {
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_));
PAPI_event_code_to_name(event, event_code_str);
printf("LBData Constructor 1: Couldn't add %s: PAPI error %d: %s\n", event_code_str, papi_retval_, PAPI_strerror(papi_retval_));
exit(1);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/vt/runnable/runnable.cc
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ void RunnableNew::run() {
#endif
}

std::unordered_map<std::string, double> RunnableNew::getPAPIMetrics() const {
std::unordered_map<std::string, double> RunnableNew::getPAPIMetrics() {
std::unordered_map<std::string, double> result = {};
if (contexts_.has_lb)
{
Expand Down
15 changes: 14 additions & 1 deletion src/vt/runnable/runnable.h
Original file line number Diff line number Diff line change
Expand Up @@ -321,12 +321,25 @@ struct RunnableNew {
*/
BaseMsgType* getMsg() const { return msg_.get(); }

/**
* \brief Start PAPI metrics map for the running context
*/
void startPAPIMetrics() { contexts_.lb.startPAPIMetrics(); }

/**
* \brief Stop PAPI metrics map for the running context
*
* \note has to be called after startPAPIMetrics
*
*/
void stopPAPIMetrics() { contexts_.lb.stopPAPIMetrics(); }

/**
* \brief Get the dictionnary of PAPI metrics associated with the runnable
*
* \return the dictionnary
*/
std::unordered_map<std::string, double> getPAPIMetrics() const;
std::unordered_map<std::string, double> getPAPIMetrics();

#if vt_check_enabled(fcontext)
/**
Expand Down

0 comments on commit 86b505a

Please sign in to comment.