diff --git a/projects/clr/hipamd/src/hip_graph.cpp b/projects/clr/hipamd/src/hip_graph.cpp index 481ab3f474..d79b5e860b 100644 --- a/projects/clr/hipamd/src/hip_graph.cpp +++ b/projects/clr/hipamd/src/hip_graph.cpp @@ -1813,44 +1813,62 @@ hipError_t hipGraphChildGraphNodeGetGraph(hipGraphNode_t node, hipGraph_t* pGrap HIP_RETURN(hipSuccess); } +hipError_t validateChildGraphNodeSetParams(hip::GraphNode* n, + hip::Graph* cg, bool exec = true) { + if (cg == nullptr || n == nullptr || !hip::GraphNode::isNodeValid(n) || + !hip::Graph::isGraphValid(cg) || n->GetType() != hipGraphNodeTypeGraph) { + return hipErrorInvalidValue; + } + // compare with parent graph fron cloned and original node + if (cg == n->GetParentGraph()->getOriginalGraph() + || cg == n->GetParentGraph()) { + return hipErrorUnknown; + } + + if (exec) { // validation only required for ExecnNodeSetParams + // Validate whether the topology of node and childGraph matches + std::vector childGraphNodes1; + n->TopologicalOrder(childGraphNodes1); + + std::vector childGraphNodes2; + cg->TopologicalOrder(childGraphNodes2); + + if (childGraphNodes1.size() != childGraphNodes2.size()) { + return hipErrorUnknown; + } + // Validate if the node insertion order matches + else { + for (std::vector::size_type i = 0; i != childGraphNodes1.size(); i++) { + if (childGraphNodes1[i]->GetType() != childGraphNodes2[i]->GetType()) { + return hipErrorUnknown; + } + } + } + } + return hipSuccess; +} + hipError_t hipGraphExecChildGraphNodeSetParams(hipGraphExec_t hGraphExec, hipGraphNode_t node, hipGraph_t childGraph) { HIP_INIT_API(hipGraphExecChildGraphNodeSetParams, hGraphExec, node, childGraph); - hip::GraphNode* n = reinterpret_cast(node); - hip::Graph* cg = reinterpret_cast(childGraph); - if (hGraphExec == nullptr || !hip::GraphNode::isNodeValid(n) || childGraph == nullptr || - !hip::Graph::isGraphValid(cg) || n->GetType() != hipGraphNodeTypeGraph) { + + if (hGraphExec == nullptr || childGraph == nullptr) { HIP_RETURN(hipErrorInvalidValue); } - if (cg == n->GetParentGraph()) { - HIP_RETURN(hipErrorUnknown); - } + hip::GraphNode* n = reinterpret_cast(node); + hip::Graph* cg = reinterpret_cast(childGraph); - // Validate whether the topology of node and childGraph matches - std::vector childGraphNodes1; - n->TopologicalOrder(childGraphNodes1); - - std::vector childGraphNodes2; - cg->TopologicalOrder(childGraphNodes2); - - if (childGraphNodes1.size() != childGraphNodes2.size()) { - HIP_RETURN(hipErrorUnknown); - } - // Validate if the node insertion order matches - else { - for (std::vector::size_type i = 0; i != childGraphNodes1.size(); i++) { - if (childGraphNodes1[i]->GetType() != childGraphNodes2[i]->GetType()) { - HIP_RETURN(hipErrorUnknown); - } - } + hipError_t status = validateChildGraphNodeSetParams(n, cg); + if (status != hipSuccess) { + return status; } hip::GraphNode* clonedNode = reinterpret_cast(hGraphExec)->GetClonedNode(n); if (clonedNode == nullptr) { HIP_RETURN(hipErrorInvalidValue); } - hipError_t status = reinterpret_cast(clonedNode)->SetParams(cg); + status = reinterpret_cast(clonedNode)->SetParams(cg); if (status != hipSuccess) { return status; } @@ -2451,14 +2469,14 @@ hipError_t hipGraphExecEventWaitNodeSetEvent(hipGraphExec_t hGraphExec, hipGraph hip::GraphNode* n = reinterpret_cast(hNode); if (hGraphExec == nullptr || hNode == nullptr || event == nullptr || - (n->GetType() != hipGraphNodeTypeWaitEvent) || n->GetType() != hipGraphNodeTypeWaitEvent) { + (n->GetType() != hipGraphNodeTypeWaitEvent)) { HIP_RETURN(hipErrorInvalidValue); } hip::GraphNode* clonedNode = reinterpret_cast(hGraphExec)->GetClonedNode(n); if (clonedNode == nullptr) { HIP_RETURN(hipErrorInvalidValue); } - HIP_RETURN(reinterpret_cast(clonedNode)->SetParams(event)); + HIP_RETURN(reinterpret_cast(clonedNode)->SetParams(event)); } hipError_t hipGraphAddHostNode(hipGraphNode_t* pGraphNode, hipGraph_t graph, @@ -3319,14 +3337,26 @@ hipError_t hipGraphExecGetFlags(hipGraphExec_t graphExec, unsigned long long* fl HIP_RETURN(hipSuccess); } -hipError_t ihipGraphNodeSetParams(hip::GraphNode* n, hipGraphNodeParams *nodeParams) { +hipError_t ihipGraphNodeSetParams(hip::GraphNode* n, hipGraphNodeParams *nodeParams, + bool exec = false) { hipGraphNodeType nodeType = nodeParams->type; + std::vector childGraphNodes1; + std::vector childGraphNodes2; + hip::Graph* cg; hipError_t status = hipSuccess; switch(nodeType) { case hipGraphNodeTypeKernel: status = reinterpret_cast(n)->SetParams(&nodeParams->kernel); break; case hipGraphNodeTypeMemcpy: + if (exec) { // this validation is only required for ExecNodeSetParams + hipMemcpyKind oldkind = reinterpret_cast(n)->GetMemcpyKind(); + hipMemcpyKind newkind = nodeParams->memcpy.copyParams.kind; + if (oldkind != newkind) { + status = hipErrorInvalidValue; + break; + } + } status = reinterpret_cast(n)->SetParams( &nodeParams->memcpy.copyParams); break; @@ -3335,18 +3365,35 @@ hipError_t ihipGraphNodeSetParams(hip::GraphNode* n, hipGraphNodeParams *nodePar reinterpret_cast(n)->SetParams(&nodeParams->memset); break; case hipGraphNodeTypeHost: + if (nodeParams->host.fn == nullptr || nodeParams->host.userData == nullptr) { + status = hipErrorInvalidValue; + break; + } status = reinterpret_cast(n)->SetParams(&nodeParams->host); break; case hipGraphNodeTypeGraph: + cg = reinterpret_cast(nodeParams->graph.graph); + status = validateChildGraphNodeSetParams(n, cg, exec); + if (status != hipSuccess) { + break; + } status = reinterpret_cast(n)->SetParams( reinterpret_cast(nodeParams->graph.graph)); break; case hipGraphNodeTypeWaitEvent: + if (nodeParams->eventWait.event == nullptr) { + status = hipErrorInvalidValue; + break; + } status = reinterpret_cast(n)->SetParams( nodeParams->eventWait.event); break; case hipGraphNodeTypeEventRecord: + if (nodeParams->eventRecord.event == nullptr) { + status = hipErrorInvalidValue; + break; + } status = reinterpret_cast(n)->SetParams( nodeParams->eventRecord.event); break; @@ -3377,7 +3424,7 @@ hipError_t hipGraphNodeSetParams(hipGraphNode_t node, hipGraphNodeParams *nodePa if (node == nullptr || nodeParams == nullptr || !hip::GraphNode::isNodeValid(n)) { HIP_RETURN(hipErrorInvalidValue); } - HIP_RETURN(ihipGraphNodeSetParams(n, nodeParams)); + HIP_RETURN(ihipGraphNodeSetParams(n, nodeParams, false)); } hipError_t hipGraphExecNodeSetParams(hipGraphExec_t graphExec, hipGraphNode_t node, @@ -3394,7 +3441,7 @@ hipError_t hipGraphExecNodeSetParams(hipGraphExec_t graphExec, hipGraphNode_t no HIP_RETURN(hipErrorInvalidValue); } - hipError_t status = ihipGraphNodeSetParams(clonedNode, nodeParams); + hipError_t status = ihipGraphNodeSetParams(clonedNode, nodeParams, true); if (status != hipSuccess) { return status; } diff --git a/projects/clr/hipamd/src/hip_graph_internal.hpp b/projects/clr/hipamd/src/hip_graph_internal.hpp index 3ac75adc16..0e1cbe415b 100644 --- a/projects/clr/hipamd/src/hip_graph_internal.hpp +++ b/projects/clr/hipamd/src/hip_graph_internal.hpp @@ -1079,7 +1079,6 @@ class GraphKernelNode : public GraphNode { GraphKernelNode(const hipKernelNodeParams* pNodeParams, const ihipExtKernelEvents* pEvents, int coopKernel = 0) : GraphNode(hipGraphNodeTypeKernel, "bold", "octagon", "KERNEL") { - kernelParams_ = *pNodeParams; kernelEvents_ = { 0 }; if (pEvents != nullptr) { kernelEvents_ = *pEvents;