Improve HIP TID printing in debug mode.

Map long thread-id to a short one that is printed with each message.
Remove clunky stirng creation code for tid_tr.
Print TID on every message.

Change-Id: I780a91d8ce789cb4957789036b478bf5cde8c4e4


[ROCm/clr commit: 7d69e858a5]
This commit is contained in:
Ben Sander
2016-10-24 17:38:22 -05:00
parent 3b4fc56e30
commit 4029bc31e6
2 ha cambiato i file con 40 aggiunte e 19 eliminazioni
+23 -2
Vedi File
@@ -84,6 +84,11 @@ std::vector<int> g_hip_visible_devices;
hsa_agent_t g_cpu_agent;
unsigned g_numLogicalThreads;
std::atomic<int> g_lastShortTid(1);
thread_local ShortTid tls_shortTid;
/*
Implementation of malloc and free device functions.
@@ -230,6 +235,22 @@ hipError_t ihipSynchronize(void)
return (hipSuccess);
}
//=================================================================================================
// ihipStream_t:
//=================================================================================================
ShortTid::ShortTid()
{
_shortTid = g_lastShortTid.fetch_add(1);
if (HIP_DB & (1<<DB_API)) {
std::stringstream tid_ss;
std::stringstream tid_ss_num;
tid_ss_num << std::this_thread::get_id();
tid_ss << std::hex << std::stoull(tid_ss_num.str());
tprintf(DB_API, "HIP initialized short_tid#%d (maps to full_tid: 0x%s)\n", _shortTid, tid_ss.str().c_str());
};
}
//=================================================================================================
// ihipStream_t:
@@ -1138,11 +1159,11 @@ void ihipInit()
}
if (HIP_TRACE_API && !COMPILE_HIP_TRACE_API) {
fprintf (stderr, "warning: env var HIP_TRACE_API=0x%x but COMPILE_HIP_TRACE_API=0. (perhaps enable COMPILE_HIP_DB in src code before compiling?)", HIP_DB);
fprintf (stderr, "warning: env var HIP_TRACE_API=0x%x but COMPILE_HIP_TRACE_API=0. (perhaps enable COMPILE_HIP_TRACE_API in src code before compiling?)", HIP_DB);
}
if (HIP_ATP_MARKER && !COMPILE_HIP_ATP_MARKER) {
fprintf (stderr, "warning: env var HIP_ATP_MARKER=0x%x but COMPILE_HIP_ATP_MARKER=0. (perhaps enable COMPILE_HIP_DB in src code before compiling?)", HIP_ATP_MARKER);
fprintf (stderr, "warning: env var HIP_ATP_MARKER=0x%x but COMPILE_HIP_ATP_MARKER=0. (perhaps enable COMPILE_HIP_ATP_MARKER in src code before compiling?)", HIP_ATP_MARKER);
}
if (HIP_DB) {
+17 -17
Vedi File
@@ -59,9 +59,23 @@ extern int HIP_VISIBLE_DEVICES; /* Contains a comma-separated sequence of GPU id
// Chicken bits for disabling functionality to work around potential issues:
extern int HIP_DISABLE_HW_KERNEL_DEP;
// Class to assign a short TID to each new thread, for HIP debugging purposes.
class ShortTid {
public:
ShortTid() ;
int tid() { return _shortTid; };
private:
int _shortTid;
};
//---
//Extern tls
extern thread_local hipError_t tls_lastHipError;
extern thread_local ShortTid tls_shortTid;
//---
@@ -112,18 +126,6 @@ extern const char *API_COLOR_END;
#endif
#define DB_SHOW_TID 0
#if DB_SHOW_TID
#define COMPUTE_TID_STR \
std::stringstream tid_ss;\
std::stringstream tid_ss_num;\
tid_ss_num << std::this_thread::get_id();\
tid_ss << " tid:" << std::hex << std::stoull(tid_ss_num.str());
#else
#define COMPUTE_TID_STR std::stringstream tid_ss;
#endif
// Compile support for trace markers that are displayed on CodeXL GUI at start/stop of each function boundary.
// TODO - currently we print the trace message at the beginning. if we waited, we could also include return codes, and any values returned
@@ -143,8 +145,7 @@ extern const char *API_COLOR_END;
if (HIP_ATP_MARKER || (COMPILE_HIP_DB && HIP_TRACE_API)) {\
std::string s = std::string(__func__) + " (" + ToString(__VA_ARGS__) + ')';\
if (COMPILE_HIP_DB && HIP_TRACE_API) {\
COMPUTE_TID_STR\
fprintf (stderr, "%s<<hip-api:%s %s\n%s" , API_COLOR, tid_ss.str().c_str(), s.c_str(), API_COLOR_END);\
fprintf (stderr, "%s<<hip-api:tid:%d %s\n%s" , API_COLOR, tls_shortTid.tid(), s.c_str(), API_COLOR_END);\
}\
SCOPED_MARKER(s.c_str(), "HIP", NULL);\
}\
@@ -174,7 +175,7 @@ extern const char *API_COLOR_END;
tls_lastHipError = localHipStatus;\
\
if ((COMPILE_HIP_TRACE_API & 0x2) && HIP_TRACE_API) {\
fprintf(stderr, " %ship-api: %-30s ret=%2d (%s)>>%s\n", (localHipStatus == 0) ? API_COLOR:KRED, __func__, localHipStatus, ihipErrorString(localHipStatus), API_COLOR_END);\
fprintf(stderr, " %ship-api:tid:%d %-30s ret=%2d (%s)>>%s\n", (localHipStatus == 0) ? API_COLOR:KRED, tls_shortTid.tid(), __func__, localHipStatus, ihipErrorString(localHipStatus), API_COLOR_END);\
}\
localHipStatus;\
})
@@ -216,8 +217,7 @@ static const DbName dbName [] =
if (HIP_DB & (1<<(trace_level))) {\
char msgStr[1000];\
snprintf(msgStr, 2000, __VA_ARGS__);\
COMPUTE_TID_STR\
fprintf (stderr, " %ship-%s%s:%s%s", dbName[trace_level]._color, dbName[trace_level]._shortName, tid_ss.str().c_str(), msgStr, KNRM); \
fprintf (stderr, " %ship-%s tid:%d:%s%s", dbName[trace_level]._color, dbName[trace_level]._shortName, tls_shortTid.tid(), msgStr, KNRM); \
}\
}
#else