MFC
Exascale flow solver
Loading...
Searching...
No Matches
m_nvtx.f90
Go to the documentation of this file.
1!>
2!! @file
3!! @brief Contains module m_nvtx
4
5!> @brief NVIDIA NVTX profiling API bindings for GPU performance instrumentation
6module m_nvtx
7
8 use iso_c_binding
9
10 implicit none
11
12 integer, private :: col(7) = [ &
13 int(z'0000ff00'), int(z'000000ff'), int(z'00ffff00'), &
14 int(z'00ff00ff'), int(z'0000ffff'), int(z'00ff0000'), &
15 int(z'00ffffff') &
16 ]
17
18 character(len=256), private :: tempname
19
20 type, bind(C) :: nvtxEventAttributes
21 integer(c_int16_t) :: version = 1
22 integer(c_int16_t) :: size = 48 !
23 integer(c_int) :: category = 0
24 integer(c_int) :: colortype = 1 ! NVTX_COLOR_ARGB = 1
25 integer(c_int) :: color
26 integer(c_int) :: payloadtype = 0 ! NVTX_PAYLOAD_UNKNOWN = 0
27 integer(c_int) :: reserved0
28 integer(c_int64_t) :: payload ! union uint,int,double
29 integer(c_int) :: messagetype = 1 ! NVTX_MESSAGE_TYPE_ASCII = 1
30 type(c_ptr) :: message ! ascii char
31 end type nvtxeventattributes
32
33#if defined(MFC_GPU) && defined(__PGI)
34
35 interface nvtxrangepush
36 ! push range with custom label and standard color
37 subroutine nvtxrangepusha(name) bind(C, name='nvtxRangePushA')
38 use iso_c_binding
39
40 character(kind=c_char, len=*), intent(IN) :: name
41 end subroutine nvtxrangepusha
42
43 ! push range with custom label and custom color
44 subroutine nvtxrangepushex(event) bind(C, name='nvtxRangePushEx')
45 use iso_c_binding
46
47 import :: nvtxeventattributes
48 type(nvtxeventattributes), intent(IN) :: event
49 end subroutine nvtxrangepushex
50 end interface nvtxrangepush
51
52 interface nvtxrangepop
53 subroutine nvtxrangepop() bind(C, name='nvtxRangePop')
54 end subroutine nvtxrangepop
55 end interface nvtxrangepop
56
57#endif
58
59contains
60
61 !> @brief Pushes a named NVTX range for GPU profiling, optionally with a color based on the given identifier.
62 subroutine nvtxstartrange(name, id)
63 character(kind=c_char, len=*), intent(IN) :: name
64 integer, intent(IN), optional :: id
65 type(nvtxeventattributes) :: event
66
67#if defined(MFC_GPU) && defined(__PGI)
68
69 tempname = trim(name)//c_null_char
70
71 if (.not. present(id)) then
73 else
74 event%color = col(mod(id, 7) + 1)
75 event%message = c_loc(tempname)
76 call nvtxrangepushex(event)
77 end if
78
79#endif
80 end subroutine nvtxstartrange
81
82 !> @brief Pops the current NVTX range to end the GPU profiling region.
83 subroutine nvtxendrange
84#if defined(MFC_GPU) && defined(__PGI)
85 call nvtxrangepop
86#endif
87 end subroutine nvtxendrange
88
89end module m_nvtx
NVIDIA NVTX profiling API bindings for GPU performance instrumentation.
Definition m_nvtx.f90:6
subroutine nvtxstartrange(name, id)
Pushes a named NVTX range for GPU profiling, optionally with a color based on the given identifier.
Definition m_nvtx.f90:63
character(len=256), private tempname
Definition m_nvtx.f90:18
subroutine nvtxendrange
Pops the current NVTX range to end the GPU profiling region.
Definition m_nvtx.f90:84
integer, dimension(7), private col
Definition m_nvtx.f90:12