-
Notifications
You must be signed in to change notification settings - Fork 143
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(gpu): add nvtx tool for profiling
- Loading branch information
1 parent
baa3075
commit 8b1d8ca
Showing
4 changed files
with
54 additions
and
0 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
39 changes: 39 additions & 0 deletions
39
backends/tfhe-cuda-backend/cuda/src/utils/helper_profile.cu
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,39 @@ | ||
#include "helper_profile.cuh" | ||
|
||
uint32_t adler32(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; | ||
} | ||
|
||
void cuda_nvtx_label_with_color(const char *name) { | ||
int color_id = adler32((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; | ||
nvtxRangePushEx(&eventAttrib); | ||
} | ||
|
||
|
12 changes: 12 additions & 0 deletions
12
backends/tfhe-cuda-backend/cuda/src/utils/helper_profile.cuh
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,12 @@ | ||
#ifndef HELPER_PROFILE | ||
#define HELPER_PROFILE | ||
#include <nvToolsExt.h> | ||
|
||
|
||
void cuda_nvtx_label_with_color(const char *name); | ||
|
||
#define PUSH_RANGE(name) { cuda_nvtx_label_with_color(name);} | ||
#define POP_RANGE() nvtxRangePop(); | ||
|
||
|
||
#endif |