From 7f7340fb295d9aed6af37bf949ac92a90bedc8ce Mon Sep 17 00:00:00 2001 From: Ben Sander Date: Tue, 27 Sep 2016 14:53:13 -0500 Subject: [PATCH] Add debug option to print ThreadID with each message. Also print messages with single fprintf to prevents threads from interleaving. Change-Id: Ib3999fe6b1e67b4a16cd7dcde82f3dfc99dd48ff [ROCm/hip commit: 6de9136002e960cdd61479ed89520fd0f9e99684] --- projects/hip/include/hcc_detail/hip_hcc.h | 28 +++++++++++++++++++---- projects/hip/src/hip_hcc.cpp | 2 ++ 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/projects/hip/include/hcc_detail/hip_hcc.h b/projects/hip/include/hcc_detail/hip_hcc.h index 9d4b70c73f..34c743d07e 100644 --- a/projects/hip/include/hcc_detail/hip_hcc.h +++ b/projects/hip/include/hcc_detail/hip_hcc.h @@ -109,6 +109,19 @@ extern const char *API_COLOR_END; #endif +#define DB_SHOW_TID 1 + +#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 // through ptr-to-args (ie the pointers allocated by hipMalloc). @@ -127,7 +140,8 @@ 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) {\ - fprintf (stderr, "%s<_mutex.lock(); }; ~LockedAccessor() { if (_autoUnlock) { + tprintf(DB_SYNC, "auto-unlock critical data %s.%p\n",typeid(T).name(), _criticalData); _criticalData->_mutex.unlock(); } } void unlock() { + tprintf(DB_SYNC, "unlock critical data %s.%p\n", typeid(T).name(), _criticalData); _criticalData->_mutex.unlock(); } diff --git a/projects/hip/src/hip_hcc.cpp b/projects/hip/src/hip_hcc.cpp index fcbc553f83..1055e0ce46 100644 --- a/projects/hip/src/hip_hcc.cpp +++ b/projects/hip/src/hip_hcc.cpp @@ -1359,6 +1359,7 @@ bool ihipStream_t::canSeePeerMemory(const ihipCtx_t *thisCtx, ihipCtx_t *dstCtx, // Use blocks to control scope of critical sections. { LockedAccessor_CtxCrit_t ctxCrit(dstCtx->criticalData()); + tprintf(DB_SYNC, "dstCrit lock succeeded\n"); if (!ctxCrit->isPeer(thisCtx)) { return false; }; @@ -1366,6 +1367,7 @@ bool ihipStream_t::canSeePeerMemory(const ihipCtx_t *thisCtx, ihipCtx_t *dstCtx, { LockedAccessor_CtxCrit_t ctxCrit(srcCtx->criticalData()); + tprintf(DB_SYNC, "srcCrit lock succeeded\n"); if (!ctxCrit->isPeer(thisCtx)) { return false; };