From 0ae70a4c8dec0ac97a1a184ebc5526cffebe5e67 Mon Sep 17 00:00:00 2001 From: Sourabh Betigeri Date: Mon, 7 Mar 2022 12:08:26 -0800 Subject: [PATCH] SWDEV-313503 - Returns appropriate error code when destroyed exec graphs are launched Change-Id: I3ca025494fd27f9ed0cd4534c740f7e19e1c66b3 --- hipamd/src/hip_graph.cpp | 2 +- hipamd/src/hip_graph_internal.cpp | 10 ++++++++++ hipamd/src/hip_graph_internal.hpp | 12 +++++++++++- 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/hipamd/src/hip_graph.cpp b/hipamd/src/hip_graph.cpp index fc07149498..17890e3dda 100644 --- a/hipamd/src/hip_graph.cpp +++ b/hipamd/src/hip_graph.cpp @@ -997,7 +997,7 @@ hipError_t ihipGraphLaunch(hipGraphExec_t graphExec, hipStream_t stream) { hipError_t hipGraphLaunch(hipGraphExec_t graphExec, hipStream_t stream) { HIP_INIT_API(hipGraphLaunch, graphExec, stream); - if (graphExec == nullptr || !hip::isValid(stream)) { + if (graphExec == nullptr || !hip::isValid(stream) || !hipGraphExec::isGraphExecValid(graphExec)) { HIP_RETURN(hipErrorInvalidValue); } HIP_RETURN_DURATION(ihipGraphLaunch(graphExec, stream)); diff --git a/hipamd/src/hip_graph_internal.cpp b/hipamd/src/hip_graph_internal.cpp index 28a824b101..7569f1a639 100644 --- a/hipamd/src/hip_graph_internal.cpp +++ b/hipamd/src/hip_graph_internal.cpp @@ -51,6 +51,8 @@ std::unordered_set hipGraphNode::nodeSet_; amd::Monitor hipGraphNode::nodeSetLock_{"Guards global node set"}; std::unordered_set ihipGraph::graphSet_; amd::Monitor ihipGraph::graphSetLock_{"Guards global graph set"}; +std::unordered_set hipGraphExec::graphExecSet_; +amd::Monitor hipGraphExec::graphExecSetLock_{"Guards global exec graph set"}; hipError_t hipGraphMemcpyNode1D::ValidateParams(void* dst, const void* src, size_t count, hipMemcpyKind kind) { @@ -673,6 +675,14 @@ ihipGraph* ihipGraph::clone() const{ return clone(clonedNodes); } +bool hipGraphExec::isGraphExecValid(hipGraphExec* pGraphExec) { + amd::ScopedLock lock(graphExecSetLock_); + if (graphExecSet_.find(pGraphExec) == graphExecSet_.end()) { + return false; + } + return true; +} + hipError_t hipGraphExec::CreateQueues(size_t numQueues) { parallelQueues_.reserve(numQueues); for (size_t i = 0; i < numQueues; i++) { diff --git a/hipamd/src/hip_graph_internal.hpp b/hipamd/src/hip_graph_internal.hpp index cfb3594699..11dda0bfaa 100644 --- a/hipamd/src/hip_graph_internal.hpp +++ b/hipamd/src/hip_graph_internal.hpp @@ -290,6 +290,8 @@ struct hipGraphExec { uint currentQueueIndex_; std::unordered_map clonedNodes_; amd::Command* lastEnqueuedCommand_; + static std::unordered_set graphExecSet_; + static amd::Monitor graphExecSetLock_ ; public: hipGraphExec(std::vector& levelOrder, std::vector>& lists, @@ -300,7 +302,10 @@ struct hipGraphExec { nodeWaitLists_(nodeWaitLists), clonedNodes_(clonedNodes), lastEnqueuedCommand_(nullptr), - currentQueueIndex_(0) {} + currentQueueIndex_(0) { + amd::ScopedLock lock(graphExecSetLock_); + graphExecSet_.insert(this); + } ~hipGraphExec() { // new commands are launched for every launch they are destroyed as and when command is @@ -309,6 +314,8 @@ struct hipGraphExec { queue->release(); } for (auto it = clonedNodes_.begin(); it != clonedNodes_.end(); it++) delete it->second; + amd::ScopedLock lock(graphExecSetLock_); + graphExecSet_.erase(this); } Node GetClonedNode(Node node) { @@ -321,6 +328,9 @@ struct hipGraphExec { return clonedNode; } + // check executable graphs validity + static bool isGraphExecValid(hipGraphExec* pGraphExec); + std::vector& GetNodes() { return levelOrder_; } amd::HostQueue* GetAvailableQueue() { return parallelQueues_[currentQueueIndex_++]; }