20 #ifndef GALOIS_RUNTIME_PROFILE_H
21 #define GALOIS_RUNTIME_PROFILE_H
25 #ifdef GALOIS_ENABLE_VTUNE
26 #include "ittnotify.h"
29 #ifdef GALOIS_ENABLE_PAPI
32 #include <papiStdEventDefs.h>
36 #include "galois/config.h"
41 namespace galois::runtime {
43 #ifdef GALOIS_ENABLE_VTUNE
48 region = region ? region :
"(NULL)";
52 "profileVtune can only be called from master thread (thread 0)");
66 region = region ? region :
"(NULL)";
74 #ifdef GALOIS_ENABLE_PAPI
78 unsigned long papiGetTID(
void);
80 template <
typename __T =
void>
84 int retval = PAPI_library_init(PAPI_VER_CURRENT);
86 if (retval != PAPI_VER_CURRENT && retval > 0) {
87 GALOIS_DIE(
"PAPI library version mismatch: ", retval,
88 " != ", PAPI_VER_CURRENT);
95 if ((retval = PAPI_thread_init(&papiGetTID)) != PAPI_OK) {
100 template <
typename V1,
typename V2>
101 void decodePapiEvents(
const V1& eventNames, V2& papiEvents) {
102 for (
size_t i = 0; i < eventNames.size(); ++i) {
104 std::strcpy(buf, eventNames[i].c_str());
105 if (PAPI_event_name_to_code(buf, &papiEvents[i]) != PAPI_OK) {
106 GALOIS_DIE(
"failed to recognize eventName = ", eventNames[i],
107 ", event code: ", papiEvents[i]);
112 template <
typename V1,
typename V2,
typename V3>
113 void papiStart(V1& eventSets, V2& papiResults, V3& papiEvents) {
115 if (PAPI_register_thread() != PAPI_OK) {
116 GALOIS_DIE(
"failed to register thread with PAPI");
119 int& eventSet = *eventSets.getLocal();
121 eventSet = PAPI_NULL;
122 papiResults.getLocal()->resize(papiEvents.size());
124 if (PAPI_create_eventset(&eventSet) != PAPI_OK) {
127 if (PAPI_add_events(eventSet, papiEvents.data(), papiEvents.size()) !=
132 if (PAPI_start(eventSet) != PAPI_OK) {
138 template <
typename V1,
typename V2,
typename V3>
139 void papiStop(V1& eventSets, V2& papiResults, V3& eventNames,
140 const char* region) {
142 int& eventSet = *eventSets.getLocal();
144 if (PAPI_stop(eventSet, papiResults.getLocal()->data()) != PAPI_OK) {
148 if (PAPI_cleanup_eventset(eventSet) != PAPI_OK) {
152 if (PAPI_destroy_eventset(&eventSet) != PAPI_OK) {
156 assert(eventNames.size() == papiResults.getLocal()->size() &&
157 "Both vectors should be of equal length");
158 for (
size_t i = 0; i < eventNames.size(); ++i) {
160 (*papiResults.getLocal())[i]);
163 if (PAPI_unregister_thread() != PAPI_OK) {
164 GALOIS_DIE(
"failed to un-register thread with PAPI");
169 template <
typename C>
170 void splitCSVstr(
const std::string& inputStr, C& output,
171 const char delim =
',') {
172 std::stringstream ss(inputStr);
174 for (std::string item; std::getline(ss, item, delim);) {
175 output.push_back(item);
181 template <
typename F>
182 void profilePapi(
const F& func,
const char* region) {
184 const char*
const PAPI_VAR_NAME =
"GALOIS_PAPI_EVENTS";
185 region = region ? region :
"(NULL)";
187 std::string eventNamesCSV;
190 eventNamesCSV.empty()) {
192 "No Events specified. Set environment variable GALOIS_PAPI_EVENTS");
197 internal::papiInit();
199 std::vector<std::string> eventNames;
201 internal::splitCSVstr(eventNamesCSV, eventNames);
203 std::vector<int> papiEvents(eventNames.size());
205 internal::decodePapiEvents(eventNames, papiEvents);
210 internal::papiStart(eventSets, papiResults, papiEvents);
214 internal::papiStop(eventSets, papiResults, eventNames, region);
219 template <
typename F>
222 region = region ? region :
"(NULL)";
void profileVtune(const F &func, const char *region)
Definition: Profile.h:64
#define GALOIS_DIE(...)
Definition: gIO.h:96
void reportStat_Tsum(const S1 ®ion, const S2 &category, const T &value)
Definition: Statistics.h:562
#define GALOIS_ASSERT(cond,...)
Like assert but unconditionally executed.
Definition: gIO.h:102
bool EnvCheck(const char *varName)
Return true if the Enviroment variable is set.
Definition: EnvCheck.cpp:24
void timeThis(const F &f, const char *const name)
Definition: Timer.h:108
static unsigned getTID()
Definition: ThreadPool.h:204
Definition: PerThreadStorage.h:88
void on_each(FunctionTy &&fn, const Args &...args)
Low-level parallel loop.
Definition: Loops.h:86
void profilePapi(const F &func, const char *region)
Definition: Profile.h:220
void gWarn(Args &&...args)
Prints a warning string from a sequence of things.
Definition: gIO.h:63