Add support of printing process ID for HIP Tracing

This commit is contained in:
Qianfeng Zhang
2018-11-22 18:58:06 +08:00
parent d4f1d15f8d
commit 81cf7cabfa
2 changed files with 29 additions and 26 deletions
+3 -2
View File
@@ -179,7 +179,7 @@ uint64_t recordApiTrace(std::string* fullStr, const std::string& apiStr) {
if (COMPILE_HIP_DB && HIP_TRACE_API) { if (COMPILE_HIP_DB && HIP_TRACE_API) {
fprintf(stderr, "%s<<hip-api tid:%s @%lu%s\n", API_COLOR, fullStr->c_str(), apiStartTick, fprintf(stderr, "%s<<hip-api pid:%d tid:%s @%lu%s\n", API_COLOR, tls_tidInfo.pid(), fullStr->c_str(), apiStartTick,
API_COLOR_END); API_COLOR_END);
} }
@@ -237,6 +237,7 @@ hipError_t ihipSynchronize(void) {
//================================================================================================= //=================================================================================================
TidInfo::TidInfo() : _apiSeqNum(0) { TidInfo::TidInfo() : _apiSeqNum(0) {
_shortTid = g_lastShortTid.fetch_add(1); _shortTid = g_lastShortTid.fetch_add(1);
_pid = getpid();
if (COMPILE_HIP_DB && HIP_TRACE_API) { if (COMPILE_HIP_DB && HIP_TRACE_API) {
std::stringstream tid_ss; std::stringstream tid_ss;
@@ -1535,7 +1536,7 @@ void ihipPrintKernelLaunch(const char* kernelName, const grid_launch_parm* lp,
if ((HIP_TRACE_API & (1 << TRACE_KCMD)) || HIP_PROFILE_API || if ((HIP_TRACE_API & (1 << TRACE_KCMD)) || HIP_PROFILE_API ||
(COMPILE_HIP_DB & HIP_TRACE_API)) { (COMPILE_HIP_DB & HIP_TRACE_API)) {
std::stringstream os; std::stringstream os;
os << tls_tidInfo.tid() << "." << tls_tidInfo.apiSeqNum() << " hipLaunchKernel '" os << tls_tidInfo.pid() << " " << tls_tidInfo.tid() << "." << tls_tidInfo.apiSeqNum() << " hipLaunchKernel '"
<< kernelName << "'" << kernelName << "'"
<< " gridDim:" << lp->grid_dim << " groupDim:" << lp->group_dim << " sharedMem:+" << " gridDim:" << lp->grid_dim << " groupDim:" << lp->group_dim << " sharedMem:+"
<< lp->dynamic_group_mem_bytes << " " << *stream; << lp->dynamic_group_mem_bytes << " " << *stream;
+26 -24
View File
@@ -94,11 +94,13 @@ class TidInfo {
TidInfo(); TidInfo();
int tid() const { return _shortTid; }; int tid() const { return _shortTid; };
pid_t pid() const { return _pid; };
uint64_t incApiSeqNum() { return ++_apiSeqNum; }; uint64_t incApiSeqNum() { return ++_apiSeqNum; };
uint64_t apiSeqNum() const { return _apiSeqNum; }; uint64_t apiSeqNum() const { return _apiSeqNum; };
private: private:
int _shortTid; int _shortTid;
pid_t _pid;
// monotonically increasing API sequence number for this threa. // monotonically increasing API sequence number for this threa.
uint64_t _apiSeqNum; uint64_t _apiSeqNum;
@@ -243,14 +245,14 @@ static const DbName dbName[] = {
#if COMPILE_HIP_DB #if COMPILE_HIP_DB
#define tprintf(trace_level, ...) \ #define tprintf(trace_level, ...) \
{ \ { \
if (HIP_DB & (1 << (trace_level))) { \ if (HIP_DB & (1 << (trace_level))) { \
char msgStr[1000]; \ char msgStr[1000]; \
snprintf(msgStr, sizeof(msgStr), __VA_ARGS__); \ snprintf(msgStr, sizeof(msgStr), __VA_ARGS__); \
fprintf(stderr, " %ship-%s tid:%d:%s%s", dbName[trace_level]._color, \ fprintf(stderr, " %ship-%s pid:%d tid:%d:%s%s", dbName[trace_level]._color, \
dbName[trace_level]._shortName, tls_tidInfo.tid(), msgStr, KNRM); \ dbName[trace_level]._shortName, tls_tidInfo.pid(), tls_tidInfo.tid(), msgStr, KNRM); \
} \ } \
} }
#else #else
/* Compile to empty code */ /* Compile to empty code */
@@ -313,22 +315,22 @@ extern uint64_t recordApiTrace(std::string* fullStr, const std::string& apiStr);
// This macro should be called at the end of every HIP API, and only at the end of top-level hip // This macro should be called at the end of every HIP API, and only at the end of top-level hip
// APIS (not internal hip) It has dual function: logs the last error returned for use by // APIS (not internal hip) It has dual function: logs the last error returned for use by
// hipGetLastError, and also prints the closing message when the debug trace is enabled. // hipGetLastError, and also prints the closing message when the debug trace is enabled.
#define ihipLogStatus(hipStatus) \ #define ihipLogStatus(hipStatus) \
({ \ ({ \
hipError_t localHipStatus = hipStatus; /*local copy so hipStatus only evaluated once*/ \ hipError_t localHipStatus = hipStatus; /*local copy so hipStatus only evaluated once*/ \
tls_lastHipError = localHipStatus; \ tls_lastHipError = localHipStatus; \
\ \
if ((COMPILE_HIP_TRACE_API & 0x2) && HIP_TRACE_API & (1 << TRACE_ALL)) { \ if ((COMPILE_HIP_TRACE_API & 0x2) && HIP_TRACE_API & (1 << TRACE_ALL)) { \
auto ticks = getTicks() - hipApiStartTick; \ auto ticks = getTicks() - hipApiStartTick; \
fprintf(stderr, " %ship-api tid:%d.%lu %-30s ret=%2d (%s)>> +%lu ns%s\n", \ fprintf(stderr, " %ship-api pid:%d tid:%d.%lu %-30s ret=%2d (%s)>> +%lu ns%s\n", \
(localHipStatus == 0) ? API_COLOR : KRED, tls_tidInfo.tid(), \ (localHipStatus == 0) ? API_COLOR : KRED, tls_tidInfo.pid(), tls_tidInfo.tid(), \
tls_tidInfo.apiSeqNum(), __func__, localHipStatus, \ tls_tidInfo.apiSeqNum(), __func__, localHipStatus, \
ihipErrorString(localHipStatus), ticks, API_COLOR_END); \ ihipErrorString(localHipStatus), ticks, API_COLOR_END); \
} \ } \
if (HIP_PROFILE_API) { \ if (HIP_PROFILE_API) { \
MARKER_END(); \ MARKER_END(); \
} \ } \
localHipStatus; \ localHipStatus; \
}) })