Last active
February 21, 2023 16:57
Simple Fortran bindings to a subset of the NVTX library.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
! Fortran bindings for a small subset of the NVIDIA Tools Extensions library | |
module nvtx | |
use iso_c_binding | |
public :: nvtxrangepusha, nvtxrangepop | |
public :: nvtxrangepushaargb | |
interface | |
! Annotate the timeline with a message | |
! Parameters: | |
! * string : the message in a string format | |
subroutine nvtxrangepusha(string) bind(C, name="nvtxRangePushA") | |
use iso_c_binding , only : c_char | |
character(kind=c_char) :: string(*) | |
end subroutine nvtxrangepusha | |
! Annotate the timeline with both a message and an ARGB color | |
! Parameters: | |
! * string : the message in a string format | |
! * argb : the color in argb format (example: Z'FF880000' | |
subroutine nvtxrangepushaargb(string,argb) bind(C, name="_nvtxRangePushAARGB") | |
use iso_c_binding , only : c_char, c_int | |
character(kind=c_char) :: string(*) | |
integer(kind=c_int), value :: argb | |
end subroutine nvtxrangepushaargb | |
! Pop the last range off the stack | |
subroutine nvtxrangepop() bind(C, name="nvtxRangePop") | |
end subroutine | |
! Place a mark on the timeline with a message | |
! Parameters: | |
! * string : the message in a string format | |
! NOT YET EXPOSED | |
subroutine nvtxMarkA(string) bind(C, name="nvtxMarkA") | |
use iso_c_binding , only : c_char | |
character(kind=c_char) :: string(*) | |
end subroutine | |
! Name an OS thread | |
! NOT YET EXPOSED | |
subroutine nvtxNameOsThread(tid, string) bind(C, name="nvtxNameOsThread") | |
use iso_c_binding , only : c_int, c_char | |
integer(kind=c_int) :: tid | |
character(kind=c_char) :: string(*) | |
end subroutine | |
end interface | |
end module nvtx |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <nvToolsExt.h> | |
/* | |
* Utility routine for marking a range with both | |
* a message and a color from a single function call. | |
*/ | |
extern "C" | |
void _nvtxRangePushAARGB(char *message, int argb) | |
{ | |
nvtxEventAttributes_t eventAttrib = {0}; | |
eventAttrib.version = NVTX_VERSION; | |
eventAttrib.size = NVTX_EVENT_ATTRIB_STRUCT_SIZE; | |
eventAttrib.colorType = NVTX_COLOR_ARGB; | |
eventAttrib.color = argb; | |
eventAttrib.messageType = NVTX_MESSAGE_TYPE_ASCII; | |
eventAttrib.message.ascii = message; | |
nvtxRangePushEx(&eventAttrib); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Recent update now requires both the nvtx.F90 bindings and the nvtx_wrapper.cpp file, which creates a simplified interface to specifying a color for a range. This was done to avoid replicating the nvtxEventAttributes_t struct in Fortran. If you do not need the colored ranges, remove the nvtxrangepushaargb subroutine from the Fortran module to avoid the need to build the wrapper too.