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