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 ability for users to specify PAPI events in Dr Hook #27

Open
wants to merge 33 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
586191a
Add DR_HOOK support for HW counters with PAPI
MartynF Nov 3, 2023
e3ff319
Make fiat-drhook-sanity a unit-test, refactor CMake and other cosmetic
wdeconinck Jul 24, 2024
bcd9d78
Fix invalid arguments error to PAPI_list_events
wdeconinck Jul 24, 2024
374e33a
Fix DR_HOOK_SILENT option
wdeconinck Jul 24, 2024
61d3927
Change error messages to be more explicit
Andrew-Beggs-ECMWF Aug 19, 2024
d652f0d
Fix missing intent
Andrew-Beggs-ECMWF Aug 19, 2024
8e0a9e2
Add new debug print
Andrew-Beggs-ECMWF Aug 19, 2024
8553e73
Add functionality for user specified PAPI events
Andrew-Beggs-ECMWF Aug 21, 2024
23810e1
Fix whitespacing
Andrew-Beggs-ECMWF Aug 28, 2024
77179d9
Fix malloc -> malloc_drhook
Andrew-Beggs-ECMWF Oct 22, 2024
b19fdd2
Fix safe_thread_num -> papi_safe_thread_num
Andrew-Beggs-ECMWF Oct 22, 2024
9ca74b7
Merge branch 'develop' into papi
Andrew-Beggs-ECMWF Oct 23, 2024
8049e04
Add if (opt_papi) guards
Andrew-Beggs-ECMWF Oct 23, 2024
6bc7379
Refactor PAPI extension
Andrew-Beggs-ECMWF Oct 23, 2024
0e5fffe
Fix NPAPICNTRS -> MAXNPAPICNTRS
Andrew-Beggs-ECMWF Oct 24, 2024
b10867b
Remove static from malloc_drhook()
Andrew-Beggs-ECMWF Oct 24, 2024
9596442
Move OML_MY_THREAD() into parallel region
Andrew-Beggs-ECMWF Oct 24, 2024
4cd9b52
Add PAPI tests
Andrew-Beggs-ECMWF Oct 28, 2024
8a558aa
Fix nproc being initialised to 1
Andrew-Beggs-ECMWF Oct 28, 2024
84d0362
Rename dr_hook -> drhook
Andrew-Beggs-ECMWF Oct 28, 2024
997bc63
Add copyright headers
Andrew-Beggs-ECMWF Oct 28, 2024
e609d23
Revert "Fix nproc being initialised to 1"
Andrew-Beggs-ECMWF Oct 30, 2024
0bee022
Fix output formatting
Andrew-Beggs-ECMWF Oct 29, 2024
f87140b
Change initialising process info
Andrew-Beggs-ECMWF Oct 30, 2024
aade15c
Fix drhook_papi_max_name_len() missing from header
Andrew-Beggs-ECMWF Oct 30, 2024
b93a1f3
Add drhook_papi_user_counters_more_than_max test
Andrew-Beggs-ECMWF Oct 30, 2024
652ca48
Fix set_tests_properties() not finding MPI tests
Andrew-Beggs-ECMWF Oct 30, 2024
19522b3
Use tid argument vs drhook_oml_get_thread_num()
Andrew-Beggs-ECMWF Oct 30, 2024
ac793d2
Add guards to set_tests_properties() in tests
Andrew-Beggs-ECMWF Nov 12, 2024
82a5b50
Add C_DR_HOOK_PROCINFO()
Andrew-Beggs-ECMWF Nov 12, 2024
aaad9fe
Fix compiler warnings
Andrew-Beggs-ECMWF Nov 12, 2024
7558ac5
Fix valid_csv tests
Andrew-Beggs-ECMWF Nov 13, 2024
b207369
Remove reliance on papi.h when building without PAPI
Andrew-Beggs-ECMWF Feb 10, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions src/fiat/drhook/drhook.c
Original file line number Diff line number Diff line change
Expand Up @@ -2028,11 +2028,11 @@ signal_drhook_init(int enforce)
char *env = getenv("DR_HOOK_SILENT");
int silent = env ? atoi(env) : 0;
int j;
dr_hook_procinfo_(&myproc, &nproc);
if (myproc < 1) myproc = 1; /* Just to enable output as if myproc was == 1 */
int mpi_init;
dr_hook_procinfo_(&myproc, &nproc, &mpi_init);
/* Signals may not yet been set, since MPI not initialized
Only enforce-parameter can enforce to set these => no output on myproc=1 */
if (!enforce && (myproc < 1 || nproc < 0)) return;
Enforce parameter for setting signals regardless of MPI state */
if (!enforce && !mpi_init) return;
if (signals_set) return; /* Extra safety */
/* To present sumpini.F90 (f.ex.) initializing DrHook-signals in case of
DR_HOOK was turned off (=0), then set also export DR_HOOK_INIT_SIGNALS=0 */
Expand Down Expand Up @@ -2759,6 +2759,10 @@ process_options()
p++;
}
p = strtok(s,delim);
if (p && fp) {
fprintf(fp,"%s %s [%s@%s:%d]",pfx,TIMESTR(tid),FFL);
newline = 1;
}
for (int i = 0; p && i < drhook_papi_max_num_counters(); p = strtok(NULL,delim), i++) {
drhook_papi_add_counter_name(strdup_drhook(p));
OPTPRINT(fp,"%s%s",comma,p); comma = ",";
Expand Down Expand Up @@ -2934,7 +2938,7 @@ getkey(int tid, const char *name, int name_len,
}
#if defined(DR_HOOK_HAVE_NVTX)
// Helps filter out wrapper calls that may be noise
if (opt_nvtx && drhook_oml_get_thread_num() == 1){
if (opt_nvtx && tid == 1){
if (keyptr->calls > opt_nvtx_SCC && keyptr->delta_wall_all < opt_nvtx_SWT) {
if (!opt_silent)
fprintf(stderr,"DRHOOK:NVTX: Skipping opening of region %s\n", keyptr->name);
Expand Down
1 change: 1 addition & 0 deletions src/fiat/drhook/extensions/papi/drhook_papi.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
int drhook_papi_init(int rank);
int drhook_papi_num_counters();
int drhook_papi_max_num_counters();
int drhook_papi_max_name_len();
void drhook_papi_counter_name(int c, char* event_name);
void drhook_papi_add_counter_name(const char* counter_name);
long_long drhook_papi_read(int counterId);
Expand Down
8 changes: 4 additions & 4 deletions src/fiat/drhook/internal/dr_hook_procinfo.F90
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
! nor does it submit to any jurisdiction.
!

SUBROUTINE DR_HOOK_PROCINFO(KMYPROC, KNPROC)
SUBROUTINE DR_HOOK_PROCINFO(KMYPROC, KNPROC, LMPI_INITIALIZED)
USE EC_PARKIND ,ONLY : JPIM
USE MPL_MPIF
IMPLICIT NONE
INTEGER(KIND=JPIM),INTENT(OUT) :: KMYPROC, KNPROC
LOGICAL :: LMPI_INITIALIZED
INTEGER(KIND=JPIM), INTENT(OUT) :: KMYPROC, KNPROC
LOGICAL, INTENT(OUT) :: LMPI_INITIALIZED
INTEGER(KIND=JPIM) :: IERROR

KMYPROC=-1
KMYPROC=1
KNPROC=1
CALL MPI_INITIALIZED(LMPI_INITIALIZED,IERROR)
IF( LMPI_INITIALIZED ) THEN
Expand Down
2 changes: 1 addition & 1 deletion src/fiat/include/fiat/drhook.h
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ dr_hook_prt_(const int *ftnunitno,
, int s_len);

extern void
dr_hook_procinfo_(int *myproc, int *nproc);
dr_hook_procinfo_(int *myproc, int *nproc, int *mpi_init);

#ifdef __cplusplus
} // extern "C"
Expand Down
8 changes: 4 additions & 4 deletions tests/drhook/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ if (HAVE_DR_HOOK_NVTX)
add_subdirectory(drhook_nvtx)
endif ()

# PAPI
if (HAVE_DR_HOOK_PAPI)
add_subdirectory(drhook_papi)
endif ()
# PAPI
if (HAVE_DR_HOOK_PAPI)
add_subdirectory(drhook_papi)
endif ()
30 changes: 26 additions & 4 deletions tests/drhook/drhook_papi/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,11 @@ ecbuild_add_test( TARGET fiat_test_drhook_papi_mpi_valid_csv
ENVIRONMENT DR_HOOK=1 DR_HOOK_OPT=COUNTERS
CONDITION HAVE_DR_HOOK_PAPI AND HAVE_MPI )

set_tests_properties(fiat_test_drhook_papi_mpi_valid_csv
PROPERTIES DEPENDS fiat_test_drhook_papi_mpi
PASS_REGULAR_EXPRESSION "5" )
if (HAVE_MPI)
set_tests_properties(fiat_test_drhook_papi_mpi_valid_csv
PROPERTIES DEPENDS fiat_test_drhook_papi_mpi
PASS_REGULAR_EXPRESSION "5" )
endif()

# Test user specified output file names

Expand Down Expand Up @@ -106,4 +108,24 @@ ecbuild_add_executable( TARGET drhook_papi_user_counters
ecbuild_add_test( TARGET fiat_test_drhook_papi_user_counters
COMMAND drhook_papi_user_counters
ENVIRONMENT DR_HOOK=1 DR_HOOK_OPT=COUNTERS DR_HOOK_PAPI_COUNTERS=PAPI_TOT_INS DR_HOOK_PROFILE=fiat_test_drhook_papi_user_counters
CONDITION HAVE_DR_HOOK_PAPI )
CONDITION HAVE_DR_HOOK_PAPI )

set_tests_properties(fiat_test_drhook_papi_user_counters
PROPERTIES PASS_REGULAR_EXPRESSION "PAPI_TOT_INS" )

# Test user specified counters going over max allowed

ecbuild_add_executable( TARGET drhook_papi_user_counters_more_than_max
SOURCES drhook_papi_user_counters_more_than_max.F90
LIBS fiat
LINKER_LANGUAGE Fortran
CONDITION HAVE_DR_HOOK_PAPI
NOINSTALL )

ecbuild_add_test( TARGET fiat_test_drhook_papi_user_counters_more_than_max
COMMAND drhook_papi_user_counters_more_than_max
ENVIRONMENT DR_HOOK=1 DR_HOOK_OPT=COUNTERS DR_HOOK_PAPI_COUNTERS=PAPI_TOT_CYC,PAPI_FP_OPS,PAPI_L1_DCA,PAPI_L2_DCM,PAPI_TOT_INS DR_HOOK_PROFILE=drhook_papi_user_counters_more_than_max
CONDITION HAVE_DR_HOOK_PAPI )

set_tests_properties(fiat_test_drhook_papi_user_counters_more_than_max
PROPERTIES FAIL_REGULAR_EXPRESSION "PAPI_TOT_INS" )
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
! (C) Copyright 2024- ECMWF.
!
! This software is licensed under the terms of the Apache Licence Version 2.0
! which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
!
! In applying this licence, ECMWF does not waive the privileges and immunities
! granted to it by virtue of its status as an intergovernmental organisation
! nor does it submit to any jurisdiction.

program drhook_papi_user_counters_more_than_max

use yomhook, only : jphook, dr_hook

implicit none

real(jphook) :: zhook_handle
integer :: a

call dr_hook('drhook_papi_user_counters_more_than_max', 0, zhook_handle)

a = 1
a = a + a

call dr_hook('drhook_papi_user_counters_more_than_max', 1, zhook_handle)

end program drhook_papi_user_counters_more_than_max