4 use,
intrinsic :: iso_c_binding
9 integer,
parameter ::
color(24) = [int(z
'00A6CEE3'), int(z
'001F78B4'), &
10 int(z
'00B2DF8A'), int(z
'0033A02C'), &
11 int(z
'00FB9A99'), int(z
'00E31A1C'), &
12 int(z
'00FDBF6F'), int(z
'00FF7F00'), &
13 int(z
'00CAB2D6'), int(z
'006A3D9A'), &
14 int(z
'00FFFF99'), int(z
'00B15928'), &
15 int(z
'008DD3C7'), int(z
'00FFFFB3'), &
16 int(z
'00BEBADA'), int(z
'00FB8072'), &
17 int(z
'0080B1D3'), int(z
'00FDB462'), &
18 int(z
'00B3DE69'), int(z
'00FCCDE5'), &
19 int(z
'00D9D9D9'), int(z
'00BC89BD'), &
20 int(z
'00CCEBC5'), int(z
'00FFED6F')]
24 type,
bind(c) :: nvtxeventattributes
25 integer(c_int16_t) :: version = 1
26 integer(c_int16_t) :: size = 48
27 integer(c_int32_t) :: category = 0
28 integer(c_int32_t) :: colortype = 1
29 integer(c_int32_t) ::
color
30 integer(c_int32_t) :: payloadtype = 0
31 integer(c_int32_t) :: reserved0
32 integer(c_int64_t) :: payload
33 integer(c_int) :: messagetype = 1
34 type(c_ptr) :: message
35 end type nvtxeventattributes
37 interface nvtxrangepusha
38 subroutine nvtxrangepusha(name) bind(C, name='nvtxRangePushA')
40 character(kind=c_char) :: name(256)
41 end subroutine nvtxrangepusha
42 end interface nvtxrangepusha
44 interface nvtxrangepushex
45 subroutine nvtxrangepushex(event) bind(C, name='nvtxRangePushEx')
47 import :: nvtxeventattributes
48 type(nvtxeventattributes) :: event
49 end subroutine nvtxrangepushex
50 end interface nvtxrangepushex
52 interface nvtxrangepop
53 subroutine nvtxrangepop() bind(C, name='nvtxRangePop')
54 end subroutine nvtxrangepop
55 end interface nvtxrangepop
57 public :: nvtxstartrange, nvtxrangepusha, nvtxrangepop
61 subroutine nvtxstartrange(name, region_id)
62 character(kind=c_char,len=*) :: name
63 integer,
optional :: region_id
64 type(nvtxeventattributes) :: event
68 str_len = len(trim(name))
69 do i = 1, len(trim(name))
72 c_name(str_len+1) = c_null_char
74 if (
present(region_id))
then
75 event%color =
color(mod(region_id, 24) + 1)
76 event%message = c_loc(c_name)
77 call nvtxrangepushex(event)
79 call nvtxrangepusha(c_name)
82 end subroutine nvtxstartrange
Interface to NVTX Based on https://github.com/maxcuda/NVTX_example.
integer, parameter nvtx_max_len
integer, dimension(24), parameter color