Skip to content

Commit

Permalink
Add new NVTX tests for skipping regions
Browse files Browse the repository at this point in the history
These two new tests, `drhook_nvtx_skip_spam_regions` & `drhook_nvtx_no_skip_spam_regions`, demonstrate the following behaviours:

- drhook_nvtx_skip_spam_regions
    - Regions are successfully skipped when called frequently & with low total runtime
- drhook_nvtx_no_skip_spam_regions
    - Regions are successfully not skipped when called frequently, but with sufficient total runtime
  • Loading branch information
Andrew-Beggs-ECMWF committed Sep 12, 2024
1 parent eea2989 commit c721ed1
Show file tree
Hide file tree
Showing 3 changed files with 123 additions and 1 deletion.
43 changes: 42 additions & 1 deletion tests/drhook/drhook_nvtx/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,46 @@ ecbuild_add_test( TARGET fiat_test_drhook_nvtx_mismatched_regions
COMMAND "nsys"
ARGS "profile" "--force-overwrite=true" "--trace=nvtx" "--kill=none" "--output=nsys.drhook_nvtx_mismatched_regions.qdrep" "./drhook_nvtx_mismatched_regions"
ENVIRONMENT DR_HOOK=1 DR_HOOK_NVTX=1
PROPERTIES WILL_FAIL TRUE
CONDITION HAVE_DR_HOOK_NVTX )

set_tests_properties(fiat_test_drhook_nvtx_mismatched_regions
PROPERTIES WILL_FAIL TRUE )

# Test skip on spammy regions

ecbuild_add_executable( TARGET drhook_nvtx_skip_spam_regions
SOURCES drhook_nvtx_skip_spam_regions.F90
LIBS fiat
LINKER_LANGUAGE Fortran
CONDITION HAVE_DR_HOOK_NVTX
NOINSTALL )

ecbuild_add_test( TARGET fiat_test_drhook_nvtx_skip_spam_regions
TYPE SCRIPT
COMMAND "nsys"
ARGS "profile" "--force-overwrite=true" "--trace=nvtx" "--kill=none" "--output=nsys.drhook_nvtx_skip_spam_regions.qdrep" "./drhook_nvtx_skip_spam_regions"
ENVIRONMENT DR_HOOK=1 DR_HOOK_NVTX=1 DR_HOOK_SILENT=0
CONDITION HAVE_DR_HOOK_NVTX )

set_tests_properties(fiat_test_drhook_nvtx_skip_spam_regions
PROPERTIES PASS_REGULAR_EXPRESSION "DRHOOK:NVTX: Skipping closing of region foo" PASS_REGULAR_EXPRESSION "DRHOOK:NVTX: Skipping opening of region foo" )

# Test not to skip on spammy regions with long runtimes

ecbuild_add_executable( TARGET drhook_nvtx_no_skip_spam_regions
SOURCES drhook_nvtx_no_skip_spam_regions.F90
LIBS fiat
LINKER_LANGUAGE Fortran
CONDITION HAVE_DR_HOOK_NVTX
NOINSTALL )

ecbuild_add_test( TARGET fiat_test_drhook_nvtx_no_skip_spam_regions
TYPE SCRIPT
COMMAND "nsys"
ARGS "profile" "--force-overwrite=true" "--trace=nvtx" "--kill=none" "--output=nsys.drhook_nvtx_no_skip_spam_regions.qdrep" "./drhook_nvtx_no_skip_spam_regions"
ENVIRONMENT DR_HOOK=1 DR_HOOK_NVTX=1 DR_HOOK_SILENT=0

CONDITION HAVE_DR_HOOK_NVTX )

set_tests_properties(fiat_test_drhook_nvtx_no_skip_spam_regions
PROPERTIES FAIL_REGULAR_EXPRESSION "DRHOOK:NVTX: Skipping closing of region foo" FAIL_REGULAR_EXPRESSION "DRHOOK:NVTX: Skipping opening of region foo" )
44 changes: 44 additions & 0 deletions tests/drhook/drhook_nvtx/drhook_nvtx_no_skip_spam_regions.F90
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
! (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_nvtx_no_skip_spam_regions

use yomhook, only : jphook, dr_hook

implicit none

real(jphook) :: zhook_handle
call dr_hook('drhook_nvtx_no_skip_spam_regions', 0, zhook_handle)
call foo(-1)
call foo(0)
call dr_hook('drhook_nvtx_no_skip_spam_regions', 1, zhook_handle)

contains

recursive subroutine foo (depth)
integer, intent(in) :: depth
real(jphook) :: zhook_handle

call dr_hook('foo', 0, zhook_handle)

if (depth == -1) then
call sleep(1)
call dr_hook('foo', 1, zhook_handle)
return
end if

if (depth < 10) then
call foo(depth + 1)
end if

call dr_hook('foo', 1, zhook_handle)
end subroutine

end program drhook_nvtx_no_skip_spam_regions

37 changes: 37 additions & 0 deletions tests/drhook/drhook_nvtx/drhook_nvtx_skip_spam_regions.F90
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
! (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_nvtx_skip_spam_regions

use yomhook, only : jphook, dr_hook

implicit none

real(jphook) :: zhook_handle
call dr_hook('drhook_nvtx_skip_spam_regions', 0, zhook_handle)
call foo(0)
call dr_hook('drhook_nvtx_skip_spam_regions', 1, zhook_handle)

contains

recursive subroutine foo (depth)
integer, intent(in) :: depth
real(jphook) :: zhook_handle

call dr_hook('foo', 0, zhook_handle)

if (depth < 10) then
call foo(depth + 1)
end if

call dr_hook('foo', 1, zhook_handle)
end subroutine

end program drhook_nvtx_skip_spam_regions

0 comments on commit c721ed1

Please sign in to comment.