From 104992ffda97b2828d2f01e293aa45a445789edf Mon Sep 17 00:00:00 2001 From: Sourabh Betigeri Date: Mon, 7 Mar 2022 13:01:08 -0800 Subject: [PATCH] SWDEV-317016 - Fixes bad parameters such as uninitialized graph object, pass parent instead of child graph and changed topology Change-Id: I2e7a7fa30be57d420a3228b495222f4cf579cb05 --- hipamd/src/hip_graph.cpp | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/hipamd/src/hip_graph.cpp b/hipamd/src/hip_graph.cpp index 17890e3dda..a4b64f9e1b 100644 --- a/hipamd/src/hip_graph.cpp +++ b/hipamd/src/hip_graph.cpp @@ -1102,7 +1102,7 @@ hipError_t hipGraphExecMemcpyNodeSetParams(hipGraphExec_t hGraphExec, hipGraphNo // Check if pNodeParams passed is a empty struct if (((pNodeParams->srcArray == 0) && (pNodeParams->srcPtr.ptr == nullptr)) || ((pNodeParams->dstArray == 0) && (pNodeParams->dstPtr.ptr == nullptr))) { - return hipErrorInvalidValue; + HIP_RETURN(hipErrorInvalidValue); } hipGraphNode_t clonedNode = hGraphExec->GetClonedNode(node); if (clonedNode == nullptr) { @@ -1202,9 +1202,23 @@ hipError_t hipGraphChildGraphNodeGetGraph(hipGraphNode_t node, hipGraph_t* pGrap hipError_t hipGraphExecChildGraphNodeSetParams(hipGraphExec_t hGraphExec, hipGraphNode_t node, hipGraph_t childGraph) { HIP_INIT_API(hipGraphExecChildGraphNodeSetParams, hGraphExec, node, childGraph); - if (hGraphExec == nullptr || node == nullptr || childGraph == nullptr) { + if (hGraphExec == nullptr || node == nullptr || childGraph == nullptr || + !ihipGraph::isGraphValid(childGraph)) { HIP_RETURN(hipErrorInvalidValue); } + + if (childGraph == node->GetParentGraph()) { + HIP_RETURN(hipErrorUnknown); + } + + hipGraphNode_t hipErrorNode_out; + hipGraphExecUpdateResult updateResult_out; + // Check if this instantiated graph is updatable. All restrictions in hipGraphExecUpdate() apply. + if (hipGraphExecUpdate(hGraphExec, childGraph, &hipErrorNode_out, &updateResult_out) == + hipErrorGraphExecUpdateFailure) { + HIP_RETURN(hipErrorUnknown); + } + hipGraphNode_t clonedNode = hGraphExec->GetClonedNode(node); if (clonedNode == nullptr) { HIP_RETURN(hipErrorInvalidValue);