-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ab4c080
commit dfad60a
Showing
10 changed files
with
269 additions
and
234 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
module dr_nvtx | ||
|
||
use iso_c_binding | ||
implicit none | ||
|
||
interface | ||
|
||
subroutine dr_nvtx_start (name) | ||
use iso_c_binding | ||
character(kind=c_char,len=*) :: name | ||
end subroutine | ||
|
||
subroutine dr_nvtx_end (name) | ||
use iso_c_binding | ||
character(kind=c_char,len=*) :: name | ||
end subroutine | ||
|
||
end interface | ||
|
||
public :: dr_nvtx_push_range | ||
public :: dr_nvtx_pop_range | ||
|
||
contains | ||
|
||
subroutine dr_nvtx_push_range (fstr) | ||
character(kind=c_char,len=*), intent(in) :: fstr | ||
character(kind=c_char,len=1024) :: cstr | ||
|
||
!$omp master | ||
|
||
cstr=trim(fstr)//c_null_char | ||
call dr_nvtx_start (cstr) | ||
|
||
!$omp end master | ||
|
||
end subroutine | ||
|
||
subroutine dr_nvtx_pop_range (fstr) | ||
character(kind=c_char,len=*), intent(in) :: fstr | ||
character(kind=c_char,len=1024) :: cstr | ||
|
||
!$omp master | ||
|
||
cstr=trim(fstr)//c_null_char | ||
call dr_nvtx_end (cstr) | ||
|
||
!$omp end master | ||
|
||
end subroutine | ||
|
||
end module dr_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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
#include <nvToolsExt.h> | ||
#include <string.h> | ||
#include <stdlib.h> | ||
|
||
#include "dr_nvtx_map.h" | ||
|
||
#define INDENT(n) \ | ||
do { \ | ||
int __i; \ | ||
for (int __i = 0; __i < (n); __i++) \ | ||
printf (" "); \ | ||
} while (1) | ||
|
||
static uint32_t myadler32 (const unsigned char *data) | ||
{ | ||
const uint32_t MOD_ADLER = 65521; | ||
uint32_t a = 1, b = 0; | ||
size_t index; | ||
|
||
for (index = 0; data[index] != 0; ++index) | ||
{ | ||
a = (a + data[index]*2) % MOD_ADLER; | ||
b = (b + a) % MOD_ADLER; | ||
} | ||
|
||
return (b << 16) | a; | ||
} | ||
|
||
#ifdef NVTX_VERYVERBOSE | ||
static const char namestack[256][256]; | ||
static int istack=0; | ||
#endif | ||
|
||
void dr_nvtx_start_ (const char * name) | ||
{ | ||
if (! dr_nvtx_map_start (name)) | ||
{ | ||
#ifdef NVTX_VERYVERBOSE | ||
INDENT (istack); | ||
printf ("Skipped open --- %s\n", name); | ||
#endif | ||
return; | ||
} | ||
|
||
int hash = 0; | ||
int color_id = myadler32 ((const unsigned char*)name); | ||
int r,g,b; | ||
|
||
r=color_id & 0x000000ff; | ||
g=(color_id & 0x000ff000) >> 12; | ||
b=(color_id & 0x0ff00000) >> 20; | ||
|
||
if (r<64 & g<64 & b<64) | ||
{ | ||
r=r*3; | ||
g=g*3+64; | ||
b=b*4; | ||
} | ||
|
||
color_id = 0xff000000 | (r << 16) | (g << 8) | (b); | ||
|
||
nvtxEventAttributes_t eventAttrib = {0}; | ||
eventAttrib.version = NVTX_VERSION; | ||
eventAttrib.size = NVTX_EVENT_ATTRIB_STRUCT_SIZE; | ||
eventAttrib.colorType = NVTX_COLOR_ARGB; | ||
eventAttrib.color = color_id; | ||
eventAttrib.messageType = NVTX_MESSAGE_TYPE_ASCII; | ||
eventAttrib.message.ascii = name; | ||
|
||
#ifdef NVTX_VERYVERBOSE | ||
INDENT (istack); | ||
printf ("Opening %s\n", name); | ||
#endif | ||
|
||
nvtxRangePushEx (&eventAttrib); | ||
|
||
#ifdef NVTX_VERYVERBOSE | ||
strncpy (namestack[istack], name, 128); | ||
istack++; | ||
#endif | ||
|
||
} | ||
|
||
void dr_nvtx_end_ (const char * name) | ||
{ | ||
|
||
if (! dr_nvtx_map_stop ()) | ||
{ | ||
#ifdef NVTX_VERYVERBOSE | ||
INDENT (istack); | ||
printf ("Skipped end --- %s\n",name); | ||
#endif | ||
return; | ||
} | ||
|
||
#ifdef NVTX_VERYVERBOSE | ||
istack--; | ||
if (istack < 0) | ||
{ | ||
printf ("NVTX error negative stack\n"); | ||
abort (); | ||
} | ||
|
||
INDENT (istack); | ||
|
||
printf ("Closing %s\n",name); | ||
|
||
if (strcmp (name,namestack[istack])) | ||
{ | ||
printf ("Error just closed the wrong marker: %s expected: %s\n",name, namestack[istack]); | ||
abort (); | ||
} | ||
#endif | ||
|
||
nvtxRangePop (); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
#include <unordered_map> | ||
#include <cstring> | ||
#include <iostream> | ||
|
||
#include "dr_nvtx_map.h" | ||
|
||
using namespace std; | ||
|
||
extern "C" double MPI_Wtime (); | ||
#pragma weak MPI_Wtime | ||
|
||
namespace | ||
{ | ||
struct counter | ||
{ | ||
int calls = 0; | ||
double elapsed = 0; | ||
double t0 = 0; | ||
}; | ||
|
||
template <class _Tp> | ||
struct equal_to : public binary_function<_Tp, _Tp, bool> | ||
{ | ||
bool operator()(const _Tp& __x, const _Tp& __y) const | ||
{ | ||
return strcmp( __x, __y ) == 0; | ||
} | ||
}; | ||
|
||
|
||
struct hash | ||
{ | ||
//BKDR hash algorithm | ||
int operator() (const char * str) const | ||
{ | ||
int seed = 131;//31 131 1313 13131131313 etc// | ||
int hash = 0; | ||
while(*str) | ||
{ | ||
hash = (hash * seed) + (*str); | ||
str ++; | ||
} | ||
|
||
return hash & (0x7FFFFFFF); | ||
} | ||
}; | ||
|
||
counter * stack[128]; | ||
|
||
std::unordered_map<char const*, counter, hash, equal_to<const char*>> map; | ||
|
||
int ilast = 0; | ||
}; | ||
|
||
extern "C" int dr_nvtx_map_start (const char * str) | ||
{ | ||
counter * elem = &(map[str]); | ||
ilast++; | ||
stack[ilast] = elem; | ||
elem->calls ++; | ||
if (elem->calls >= 11 && elem->elapsed < 0.0001) | ||
return 0; | ||
if (elem->calls > 1) | ||
elem->t0 = MPI_Wtime(); | ||
return 1; | ||
} | ||
|
||
extern "C" int dr_nvtx_map_stop () | ||
{ | ||
counter * last = stack[ilast]; | ||
ilast--; | ||
if (last->calls >= 11 && last->elapsed < 0.0001) | ||
return 0; | ||
if (last->calls > 1) | ||
last->elapsed += MPI_Wtime() - last->t0; | ||
return 1; | ||
} | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#ifndef _DR_NVTX_MAP_START | ||
#define _DR_NVTX_MAP_START | ||
|
||
#ifdef __cplusplus | ||
extern "C" | ||
{ | ||
#endif | ||
|
||
int dr_nvtx_map_start (const char * str); | ||
int dr_nvtx_map_stop (); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
|
||
#endif | ||
|
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
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.