diff --git a/hipamd/src/hip_graph.cpp b/hipamd/src/hip_graph.cpp index 406c259a0a..151c5c78d7 100644 --- a/hipamd/src/hip_graph.cpp +++ b/hipamd/src/hip_graph.cpp @@ -1218,12 +1218,20 @@ hipError_t hipGraphAddChildGraphNode(hipGraphNode_t* pGraphNode, hipGraph_t grap hipError_t ihipGraphInstantiate(hipGraphExec_t* pGraphExec, hipGraph_t graph, uint64_t flags = 0) { if (pGraphExec == nullptr || graph == nullptr) { - HIP_RETURN(hipErrorInvalidValue); + return hipErrorInvalidValue; + } + if (graph->IsGraphInstantiated() == true) { + for (auto node : graph->GetNodes()) { + if ((node->GetType() == hipGraphNodeTypeMemAlloc) + || (node->GetType() == hipGraphNodeTypeMemFree)) { + return hipErrorNotSupported; + } + } } std::unordered_map clonedNodes; hipGraph_t clonedGraph = graph->clone(clonedNodes); if (clonedGraph == nullptr) { - HIP_RETURN(hipErrorInvalidValue); + return hipErrorInvalidValue; } std::vector> parallelLists; std::unordered_map> nodeWaitLists; @@ -1236,6 +1244,7 @@ hipError_t ihipGraphInstantiate(hipGraphExec_t* pGraphExec, hipGraph_t graph, new hipGraphExec(levelOrder, parallelLists, nodeWaitLists, clonedNodes, graphExeUserObj, flags); if (*pGraphExec != nullptr) { + graph->SetGraphInstantiated(true); return (*pGraphExec)->Init(); } else { return hipErrorOutOfMemory; diff --git a/hipamd/src/hip_graph_internal.hpp b/hipamd/src/hip_graph_internal.hpp index d3cac3a09f..af3a10857b 100644 --- a/hipamd/src/hip_graph_internal.hpp +++ b/hipamd/src/hip_graph_internal.hpp @@ -398,6 +398,7 @@ struct ihipGraph { hip::Device* device_; //!< HIP device object hip::MemoryPool* mem_pool_; //!< Memory pool, associated with this graph std::unordered_set capturedNodes_; + bool graphInstantiated_; public: ihipGraph(hip::Device* device, const ihipGraph* original = nullptr) @@ -408,6 +409,7 @@ struct ihipGraph { graphSet_.insert(this); mem_pool_ = device->GetGraphMemoryPool(); mem_pool_->retain(); + graphInstantiated_ = false; } ~ihipGraph() { @@ -529,6 +531,14 @@ struct ihipGraph { void FreeAllMemory() { mem_pool_->FreeAllMemory(); } + + bool IsGraphInstantiated() const { + return graphInstantiated_; + } + + void SetGraphInstantiated(bool graphInstantiate) { + graphInstantiated_ = graphInstantiate; + } }; struct hipGraphExec {