From 49e684361fb6d013df93c8de2b21f1dae0eabb06 Mon Sep 17 00:00:00 2001 From: Anusha GodavarthySurya Date: Fri, 8 Dec 2023 07:29:57 +0000 Subject: [PATCH] SWDEV-422207 - Added debug env to dump graph during Instantiation Change-Id: Ibde2ae5b8d240f3986bcd168facc513a319c0f17 [ROCm/clr commit: 0a055f874b6e45eeda5cdf7fdd82f873fb23c986] --- projects/clr/hipamd/src/hip_graph.cpp | 19 +++++++++++++++---- projects/clr/rocclr/utils/flags.hpp | 2 ++ 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/projects/clr/hipamd/src/hip_graph.cpp b/projects/clr/hipamd/src/hip_graph.cpp index 7cfb1babde..9e35fe0372 100644 --- a/projects/clr/hipamd/src/hip_graph.cpp +++ b/projects/clr/hipamd/src/hip_graph.cpp @@ -32,6 +32,7 @@ std::vector g_captureStreams; amd::Monitor g_captureStreamsLock{"StreamCaptureGlobalList"}; amd::Monitor g_streamSetLock{"StreamCaptureset"}; std::unordered_set g_allCapturingStreams; +hipError_t ihipGraphDebugDotPrint(hipGraph_t graph, const char* path, unsigned int flags); inline hipError_t ihipGraphAddNode(hip::GraphNode* graphNode, hip::Graph* graph, hip::GraphNode* const* pDependencies, size_t numDependencies, @@ -1223,6 +1224,16 @@ hipError_t ihipGraphInstantiate(hip::GraphExec** pGraphExec, hip::Graph* graph, flags); if (*pGraphExec != nullptr) { graph->SetGraphInstantiated(true); + if (DEBUG_HIP_GRAPH_DOT_PRINT) { + static int i = 1; + std::string filename = + "graph_" + std::to_string(amd::Os::getProcessId()) + "_dot_print_" + std::to_string(i++); + hipError_t status = + ihipGraphDebugDotPrint(reinterpret_cast(graph), filename.c_str(), 0); + if (status == hipSuccess) { + LogPrintfInfo("[hipGraph] graph dump:%s", filename.c_str()); + } + } return (*pGraphExec)->Init(); } else { return hipErrorOutOfMemory; @@ -2550,13 +2561,10 @@ hipError_t hipGraphKernelNodeCopyAttributes(hipGraphNode_t hSrc, hipGraphNode_t } hipError_t ihipGraphDebugDotPrint(hipGraph_t graph, const char* path, unsigned int flags) { - if (graph == nullptr || path == nullptr) { - return hipErrorInvalidValue; - } std::ofstream fout; fout.open(path, std::ios::out); if (fout.fail()) { - ClPrint(amd::LOG_INFO, amd::LOG_API, "[hipGraph] Error during opening of file : %s", path); + LogPrintfError("[hipGraph] Error during opening of file : %s", path); return hipErrorOperatingSystem; } fout << "digraph dot {" << std::endl; @@ -2568,6 +2576,9 @@ hipError_t ihipGraphDebugDotPrint(hipGraph_t graph, const char* path, unsigned i hipError_t hipGraphDebugDotPrint(hipGraph_t graph, const char* path, unsigned int flags) { HIP_INIT_API(hipGraphDebugDotPrint, graph, path, flags); + if (graph == nullptr || path == nullptr) { + return hipErrorInvalidValue; + } HIP_RETURN(ihipGraphDebugDotPrint(graph, path, flags)); } diff --git a/projects/clr/rocclr/utils/flags.hpp b/projects/clr/rocclr/utils/flags.hpp index 51ebdd0d39..cd1f40c42d 100644 --- a/projects/clr/rocclr/utils/flags.hpp +++ b/projects/clr/rocclr/utils/flags.hpp @@ -245,6 +245,8 @@ release(cstring, HIPRTC_LINK_OPTIONS_APPEND, "", \ "Set link options needed for hiprtc compilation") \ release(bool, HIP_VMEM_MANAGE_SUPPORT, true, \ "Virtual Memory Management Support") \ +release(bool, DEBUG_HIP_GRAPH_DOT_PRINT, false, \ + "Enable/Disable graph debug dot print dump") \ namespace amd {