-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add PAPI functionality to Dr Hook #26
base: develop
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, Ioan asked me to have a look at this PR. I really like it overall, so I hope my harsh review doesn't make it seem like the contrary!
A lot of my comments are either for clarification or style : )
@@ -2882,6 +2931,11 @@ putkey(int tid, drhook_key_t *keyptr, const char *name, int name_len, | |||
else if (tid >= 1 && tid <= numthreads) { | |||
double delta_wall = 0; | |||
double delta_cpu = 0; | |||
long_long * delta_counters=NULL; | |||
#if defined(DR_HOOK_HAVE_PAPI) | |||
delta_counters=alloca(drhook_papi_num_counters() * sizeof(long_long) ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the reason for the use of alloca
? I'd not come across it before and I'm wondering why it's chosen over malloc_drhook
etc : )
Also, will it have an unintended affect on Dr Hook's memory tracking?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
alloca is allocating on the stack, not on the heap - so fast, thread friendly, and with automatic deletion when the stack frame goes away. So this doesn't collide with Dr. Hooks heap allocator at all...
@@ -2603,6 +2647,8 @@ process_options() | |||
else if (strequ(p,"CALLPATH")) { | |||
opt_callpath = 1; | |||
OPTPRINT(fp,"%s%s",comma,"CALLPATH"); comma = ","; | |||
} else { | |||
printf("DrHook: Note - no match for HOOK_OPT : %s\n",p); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice QoL improvement!
/* hardwired for now */ | ||
const char* hookCounters[NPAPICNTRS][2]= { | ||
{"PAPI_TOT_CYC","Cycles"}, | ||
{"PAPI_FP_OPS","FP Operations"}, | ||
{"PAPI_L1_DCA","L1 Access"}, | ||
{"PAPI_L2_DCM","L2 Miss"} | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I appreciate this is probably not the intended long term solution for specifying counters, but is it worth making this more flexible now? My concern is that a temporary solution will become permanent.
Perhaps a DR_HOOK_PAPI_COUNTERS
similar to how DR_HOOK_OPT
is done? If not specified it could default to these 4. I am happy to implement this if we want to do this now : )
/* function to use for thread id | ||
- it should be better than omp_get_thread_num! | ||
*/ | ||
unsigned long safe_thread_num(){ | ||
return oml_my_thread()-1; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be here? I'm of the opinion it's either:
- Part of PAPI and should be namespaced as such
- For general use and doesn't belong in this file
/* a = b - c (b or c == NULL means use current readings) */ | ||
void drhook_papi_subtract(long_long* a, long_long* b, long_long* c){ | ||
if (b==NULL || c==NULL){ | ||
long_long * tmp=alloca(drhook_papi_num_counters() * sizeof(long_long)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar comments about alloca
as above
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar answer :-)
events[thread]=PAPI_NULL; | ||
papiErr=PAPI_create_eventset(&events[thread]); | ||
if (papiErr != PAPI_OK){ | ||
snprintf(pmsg,STD_MSG_LEN,"DRHOOK:PAPI: create event set failed (%s) \n",PAPI_strerror(papiErr)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
snprintf(pmsg,STD_MSG_LEN,"DRHOOK:PAPI: create event set failed (%s) \n",PAPI_strerror(papiErr)); | |
snprintf(pmsg,STD_MSG_LEN,"DRHOOK:PAPI: Error, create event set failed (%s) \n",PAPI_strerror(papiErr)); |
|
||
papiErr=PAPI_event_name_to_code(hookCounters[counter][0],&eventCode); | ||
if (papiErr != PAPI_OK){ | ||
snprintf(pmsg,STD_MSG_LEN,"DRHOOK:PAPI: event name to code failed (%s)",PAPI_strerror(papiErr)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
snprintf(pmsg,STD_MSG_LEN,"DRHOOK:PAPI: event name to code failed (%s)",PAPI_strerror(papiErr)); | |
snprintf(pmsg,STD_MSG_LEN,"DRHOOK:PAPI: Error, event name to code failed (%s)",PAPI_strerror(papiErr)); |
|
||
papiErr=PAPI_add_event(events[thread],eventCode); | ||
if (papiErr!=PAPI_OK){ | ||
snprintf(pmsg,STD_MSG_LEN,"DRHOOK:PAPI: add_event failed: %d (%s)",papiErr,PAPI_strerror(papiErr)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
snprintf(pmsg,STD_MSG_LEN,"DRHOOK:PAPI: add_event failed: %d (%s)",papiErr,PAPI_strerror(papiErr)); | |
snprintf(pmsg,STD_MSG_LEN,"DRHOOK:PAPI: Error, add_event failed: %d (%s)",papiErr,PAPI_strerror(papiErr)); |
papiErr=PAPI_start(events[thread]); | ||
|
||
if (papiErr != PAPI_OK) { | ||
snprintf(pmsg,STD_MSG_LEN,"DRHOOK:PAPI: starting counters failed (%d=%s)",papiErr,PAPI_strerror(papiErr)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
snprintf(pmsg,STD_MSG_LEN,"DRHOOK:PAPI: starting counters failed (%d=%s)",papiErr,PAPI_strerror(papiErr)); | |
snprintf(pmsg,STD_MSG_LEN,"DRHOOK:PAPI: Error, starting counters failed (%d=%s)",papiErr,PAPI_strerror(papiErr)); |
use OML_MOD | ||
implicit none | ||
INTEGER(KIND=C_INT), INTENT(INOUT) :: Events(n) | ||
INTEGER(KIND=C_INT), VALUE :: n |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
INTEGER(KIND=C_INT), VALUE :: n | |
INTEGER(KIND=C_INT), VALUE, INTENT(IN) :: n |
Should this have an INTENT
attribute?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It could though VALUE is doing the heavy lifting already ...
This commit removes all tabs, in favour of two spaces, in files touched by ecmwf-ifs#26 and ecmwf-ifs#27.
This commit removes all tabs, in favour of two spaces, in files touched by ecmwf-ifs#26 and ecmwf-ifs#27.
This is cleaned up, updated and rebased PR superseding #18
To enable the DR_HOOK hardware counters, use following environment variables for DR_HOOK-ed programs:
DR_HOOK=1 DR_HOOK_OPT=COUNTERS
The CMake feature DR_HOOK_PAPI is enabled by default when PAPI is found. This can be toggled with
-DENABLE_DR_HOOK_PAPI=ON|OFF
. In the case the feature is enabled, then the testfiat_test_drhook_counters
is built. For unit-testing purpose, when run as part ofctest
, the problem size is very small and the test runs in under 1 second.This test can also be run standalone:
Then the problem size is by default what was chosen by @MartynF for sanity checks.
Upon finalisation the file drhook.prof.0.csv is created which contains all the counter information.