Skip to content
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

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open

Add PAPI functionality to Dr Hook #26

wants to merge 5 commits into from

Conversation

wdeconinck
Copy link
Collaborator

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 test fiat_test_drhook_counters is built. For unit-testing purpose, when run as part of ctest, the problem size is very small and the test runs in under 1 second.
This test can also be run standalone:

<build-dir>/tests/fiat_test_drhook_counters

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.

@wdeconinck wdeconinck changed the base branch from main to develop July 24, 2024 16:17
Copy link

@Andrew-Beggs-ECMWF Andrew-Beggs-ECMWF left a 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) );

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?

@@ -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);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice QoL improvement!

Comment on lines +22 to +28
/* 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"}
};

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 : )

Comment on lines +30 to +35
/* 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;
}

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:

  1. Part of PAPI and should be namespaced as such
  2. 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));

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

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));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
INTEGER(KIND=C_INT), VALUE :: n
INTEGER(KIND=C_INT), VALUE, INTENT(IN) :: n

Should this have an INTENT attribute?

Andrew-Beggs-ECMWF added a commit to Andrew-Beggs-ECMWF/fiat that referenced this pull request Aug 28, 2024
This commit removes all tabs, in favour of two spaces, in files touched by ecmwf-ifs#26 and ecmwf-ifs#27.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants