Skip to content

Instantly share code, notes, and snippets.

@PatricZhao
Forked from jefflarkin/nvtx.F90
Last active August 29, 2015 14:23
Show Gist options
  • Select an option

  • Save PatricZhao/9bf398f998c8b39e20e5 to your computer and use it in GitHub Desktop.

Select an option

Save PatricZhao/9bf398f998c8b39e20e5 to your computer and use it in GitHub Desktop.
! 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) :: 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
#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