diff --git a/hipamd/include/hip/amd_detail/hip_api_trace.hpp b/hipamd/include/hip/amd_detail/hip_api_trace.hpp index 0749e4bb27..2152d519eb 100644 --- a/hipamd/include/hip/amd_detail/hip_api_trace.hpp +++ b/hipamd/include/hip/amd_detail/hip_api_trace.hpp @@ -870,6 +870,24 @@ typedef int (*t_hipGetStreamDeviceId)(hipStream_t stream); typedef hipError_t (*t_hipDrvGraphAddMemsetNode)(hipGraphNode_t* phGraphNode, hipGraph_t hGraph, const hipGraphNode_t* dependencies, size_t numDependencies, const HIP_MEMSET_NODE_PARAMS* memsetParams, hipCtx_t ctx); +typedef hipError_t (*t_hipGraphAddExternalSemaphoresWaitNode)(hipGraphNode_t* pGraphNode, hipGraph_t graph, + const hipGraphNode_t* pDependencies, size_t numDependencies, + const hipExternalSemaphoreWaitNodeParams* nodeParams); +typedef hipError_t (*t_hipGraphAddExternalSemaphoresSignalNode)(hipGraphNode_t* pGraphNode, hipGraph_t graph, + const hipGraphNode_t* pDependencies, size_t numDependencies, + const hipExternalSemaphoreSignalNodeParams* nodeParams); +typedef hipError_t (*t_hipGraphExternalSemaphoresSignalNodeSetParams)(hipGraphNode_t hNode, + const hipExternalSemaphoreSignalNodeParams* nodeParams); +typedef hipError_t (*t_hipGraphExternalSemaphoresWaitNodeSetParams)(hipGraphNode_t hNode, + const hipExternalSemaphoreWaitNodeParams* nodeParams); +typedef hipError_t (*t_hipGraphExternalSemaphoresSignalNodeGetParams)(hipGraphNode_t hNode, + hipExternalSemaphoreSignalNodeParams* params_out); +typedef hipError_t (*t_hipGraphExternalSemaphoresWaitNodeGetParams)(hipGraphNode_t hNode, + hipExternalSemaphoreWaitNodeParams* params_out); +typedef hipError_t (*t_hipGraphExecExternalSemaphoresSignalNodeSetParams)(hipGraphExec_t hGraphExec, hipGraphNode_t hNode, + const hipExternalSemaphoreSignalNodeParams* nodeParams); +typedef hipError_t (*t_hipGraphExecExternalSemaphoresWaitNodeSetParams)(hipGraphExec_t hGraphExec, hipGraphNode_t hNode, + const hipExternalSemaphoreWaitNodeParams* nodeParams); // HIP Compiler dispatch table struct HipCompilerDispatchTable { @@ -1321,4 +1339,12 @@ struct HipDispatchTable { t_hipLaunchHostFunc_spt hipLaunchHostFunc_spt_fn; t_hipGetStreamDeviceId hipGetStreamDeviceId_fn; t_hipDrvGraphAddMemsetNode hipDrvGraphAddMemsetNode_fn; + t_hipGraphAddExternalSemaphoresWaitNode hipGraphAddExternalSemaphoresWaitNode_fn; + t_hipGraphAddExternalSemaphoresSignalNode hipGraphAddExternalSemaphoresSignalNode_fn; + t_hipGraphExternalSemaphoresSignalNodeSetParams hipGraphExternalSemaphoresSignalNodeSetParams_fn; + t_hipGraphExternalSemaphoresWaitNodeSetParams hipGraphExternalSemaphoresWaitNodeSetParams_fn; + t_hipGraphExternalSemaphoresSignalNodeGetParams hipGraphExternalSemaphoresSignalNodeGetParams_fn; + t_hipGraphExternalSemaphoresWaitNodeGetParams hipGraphExternalSemaphoresWaitNodeGetParams_fn; + t_hipGraphExecExternalSemaphoresSignalNodeSetParams hipGraphExecExternalSemaphoresSignalNodeSetParams_fn; + t_hipGraphExecExternalSemaphoresWaitNodeSetParams hipGraphExecExternalSemaphoresWaitNodeSetParams_fn; }; diff --git a/hipamd/src/amdhip.def b/hipamd/src/amdhip.def index 0b0b668831..c8223fa7fb 100644 --- a/hipamd/src/amdhip.def +++ b/hipamd/src/amdhip.def @@ -451,3 +451,11 @@ hipGraphMemFreeNodeGetParams hipDrvGraphAddMemcpyNode hipDrvGraphAddMemsetNode hipExtGetLastError +hipGraphAddExternalSemaphoresSignalNode +hipGraphAddExternalSemaphoresWaitNode +hipGraphExternalSemaphoresSignalNodeSetParams +hipGraphExternalSemaphoresSignalNodeGetParams +hipGraphExternalSemaphoresWaitNodeSetParams +hipGraphExternalSemaphoresWaitNodeGetParams +hipGraphExecExternalSemaphoresSignalNodeSetParams +hipGraphExecExternalSemaphoresWaitNodeSetParams diff --git a/hipamd/src/hip_graph.cpp b/hipamd/src/hip_graph.cpp index bfeeceb410..173065f28e 100644 --- a/hipamd/src/hip_graph.cpp +++ b/hipamd/src/hip_graph.cpp @@ -2623,4 +2623,117 @@ hipError_t hipGraphUpload(hipGraphExec_t graphExec, hipStream_t stream) { // memory for memAlloc nodes if any when support is added with mempool feature HIP_RETURN(hipSuccess); } + +hipError_t hipGraphAddExternalSemaphoresSignalNode(hipGraphNode_t* pGraphNode, hipGraph_t graph, + const hipGraphNode_t* pDependencies, size_t numDependencies, + const hipExternalSemaphoreSignalNodeParams* nodeParams) { + HIP_INIT_API(hipGraphAddExternalSemaphoresSignalNode, pGraphNode, graph, pDependencies, + numDependencies, nodeParams); + if (pGraphNode == nullptr || graph == nullptr || + (numDependencies > 0 && pDependencies == nullptr) || nodeParams == nullptr) { + HIP_RETURN(hipErrorInvalidValue); + } + hip::GraphNode* node = new hip::hipGraphExternalSemSignalNode(nodeParams); + hipError_t status = ihipGraphAddNode(node, reinterpret_cast(graph), + reinterpret_cast(pDependencies), numDependencies); + *pGraphNode = reinterpret_cast(node); + HIP_RETURN(status); +} + +hipError_t hipGraphAddExternalSemaphoresWaitNode(hipGraphNode_t* pGraphNode, hipGraph_t graph, + const hipGraphNode_t* pDependencies, size_t numDependencies, + const hipExternalSemaphoreWaitNodeParams* nodeParams) { + HIP_INIT_API(hipGraphAddExternalSemaphoresWaitNode, pGraphNode, graph, pDependencies, + numDependencies, nodeParams); + if (pGraphNode == nullptr || graph == nullptr || + (numDependencies > 0 && pDependencies == nullptr) || nodeParams == nullptr) { + HIP_RETURN(hipErrorInvalidValue); + } + hip::GraphNode* node = new hip::hipGraphExternalSemWaitNode(nodeParams); + hipError_t status = ihipGraphAddNode(node, reinterpret_cast(graph), + reinterpret_cast(pDependencies), numDependencies); + *pGraphNode = reinterpret_cast(node); + HIP_RETURN(status); +} + +hipError_t hipGraphExternalSemaphoresSignalNodeSetParams(hipGraphNode_t hNode, + const hipExternalSemaphoreSignalNodeParams* nodeParams) { + HIP_INIT_API(hipGraphExternalSemaphoresSignalNodeSetParams, hNode, nodeParams); + hip::GraphNode* n = reinterpret_cast(hNode); + if (!hip::GraphNode::isNodeValid(n) || nodeParams == nullptr) { + HIP_RETURN(hipErrorInvalidValue); + } + HIP_RETURN(reinterpret_cast(n)->SetParams(nodeParams)); +} + +hipError_t hipGraphExternalSemaphoresWaitNodeSetParams(hipGraphNode_t hNode, + const hipExternalSemaphoreWaitNodeParams* nodeParams) { + HIP_INIT_API(hipGraphExternalSemaphoresWaitNodeSetParams, hNode, nodeParams); + hip::GraphNode* n = reinterpret_cast(hNode); + if (!hip::GraphNode::isNodeValid(n) || nodeParams == nullptr) { + HIP_RETURN(hipErrorInvalidValue); + } + HIP_RETURN(reinterpret_cast(n)->SetParams(nodeParams)); +} + +hipError_t hipGraphExternalSemaphoresSignalNodeGetParams(hipGraphNode_t hNode, + hipExternalSemaphoreSignalNodeParams* params_out) { + HIP_INIT_API(hipGraphExternalSemaphoresSignalNodeGetParams, hNode, params_out); + hip::GraphNode* n = reinterpret_cast(hNode); + if (!hip::GraphNode::isNodeValid(n) || params_out == nullptr) { + HIP_RETURN(hipErrorInvalidValue); + } + reinterpret_cast(n)->GetParams(params_out); + HIP_RETURN(hipSuccess); +} + +hipError_t hipGraphExternalSemaphoresWaitNodeGetParams(hipGraphNode_t hNode, + hipExternalSemaphoreWaitNodeParams* params_out) { + HIP_INIT_API(hipGraphExternalSemaphoresWaitNodeGetParams, hNode, params_out); + hip::GraphNode* n = reinterpret_cast(hNode); + if (!hip::GraphNode::isNodeValid(n) || params_out == nullptr) { + HIP_RETURN(hipErrorInvalidValue); + } + reinterpret_cast(n)->GetParams(params_out); + HIP_RETURN(hipSuccess); +} + +hipError_t hipGraphExecExternalSemaphoresSignalNodeSetParams(hipGraphExec_t hGraphExec, + hipGraphNode_t hNode, + const hipExternalSemaphoreSignalNodeParams* nodeParams) { + HIP_INIT_API(hipGraphExecExternalSemaphoresSignalNodeSetParams, hGraphExec, hNode, nodeParams); + hip::GraphNode* n = reinterpret_cast(hNode); + hip::GraphExec* graphExec = reinterpret_cast(hGraphExec); + if (hGraphExec == nullptr || hNode == nullptr || !hip::GraphExec::isGraphExecValid(graphExec) || + !hip::GraphNode::isNodeValid(n) || nodeParams == nullptr) { + HIP_RETURN(hipErrorInvalidValue); + } + hip::GraphNode* clonedNode = graphExec->GetClonedNode(n); + if (clonedNode == nullptr) { + HIP_RETURN(hipErrorInvalidValue); + } + HIP_RETURN(reinterpret_cast(clonedNode)->SetParams( + nodeParams)); +} + +hipError_t hipGraphExecExternalSemaphoresWaitNodeSetParams(hipGraphExec_t hGraphExec, + hipGraphNode_t hNode, + const hipExternalSemaphoreWaitNodeParams* nodeParams) { + HIP_INIT_API(hipGraphExecExternalSemaphoresWaitNodeSetParams, hGraphExec, hNode, nodeParams); + hip::GraphNode* n = reinterpret_cast(hNode); + hip::GraphExec* graphExec = reinterpret_cast(hGraphExec); + if (hGraphExec == nullptr || hNode == nullptr || !hip::GraphExec::isGraphExecValid(graphExec) || + !hip::GraphNode::isNodeValid(n) || nodeParams == nullptr) { + HIP_RETURN(hipErrorInvalidValue); + } + hip::GraphNode* clonedNode = graphExec->GetClonedNode(n); + if (clonedNode == nullptr) { + HIP_RETURN(hipErrorInvalidValue); + } + HIP_RETURN(reinterpret_cast(clonedNode)->SetParams( + nodeParams)); +} + } // namespace hip + + diff --git a/hipamd/src/hip_graph_internal.hpp b/hipamd/src/hip_graph_internal.hpp index fbd581c3ec..3fddf2a860 100644 --- a/hipamd/src/hip_graph_internal.hpp +++ b/hipamd/src/hip_graph_internal.hpp @@ -2329,5 +2329,124 @@ class GraphDrvMemcpyNode : public GraphNode { } return hipSuccess; } + }; + +class hipGraphExternalSemSignalNode : public GraphNode { + hipExternalSemaphoreSignalNodeParams externalSemaphorNodeParam_; + + public: + hipGraphExternalSemSignalNode(const hipExternalSemaphoreSignalNodeParams* pNodeParams) + : GraphNode(hipGraphNodeTypeExtSemaphoreSignal, "solid", "rectangle", + "EXTERNAL_SEMAPHORE_SIGNAL") { + externalSemaphorNodeParam_ = *pNodeParams; + } + + hipGraphExternalSemSignalNode(const hipGraphExternalSemSignalNode& rhs) + : GraphNode(rhs) { + externalSemaphorNodeParam_ = rhs.externalSemaphorNodeParam_; + } + + ~hipGraphExternalSemSignalNode() {} + + GraphNode* clone() const { + return new hipGraphExternalSemSignalNode( + static_cast(*this)); + } + + hipError_t CreateCommand(hip::Stream* stream) { + hipError_t status = GraphNode::CreateCommand(stream); + if (status != hipSuccess) { + return status; + } + unsigned int numExtSems = externalSemaphorNodeParam_.numExtSems; + commands_.reserve(numExtSems); + for (unsigned int i = 0; i < numExtSems; i++) { + if (externalSemaphorNodeParam_.extSemArray[i] != nullptr) { + amd::ExternalSemaphoreCmd* command = new amd::ExternalSemaphoreCmd(*stream, + externalSemaphorNodeParam_.extSemArray[i], + externalSemaphorNodeParam_.paramsArray[i].params.fence.value, + amd::ExternalSemaphoreCmd::COMMAND_SIGNAL_EXTSEMAPHORE); + if (command == nullptr) { + return hipErrorOutOfMemory; + } + commands_.emplace_back(command); + } else { + return hipErrorInvalidValue; + } + } + return hipSuccess; + } + + void GetParams(hipExternalSemaphoreSignalNodeParams* pNodeParams) const { + std::memcpy(pNodeParams, &externalSemaphorNodeParam_, + sizeof(hipExternalSemaphoreSignalNodeParams)); + } + + hipError_t SetParams(const hipExternalSemaphoreSignalNodeParams* pNodeParams) { + std::memcpy(&externalSemaphorNodeParam_, pNodeParams, + sizeof(hipExternalSemaphoreSignalNodeParams)); + return hipSuccess; + } +}; + +class hipGraphExternalSemWaitNode : public GraphNode { + hipExternalSemaphoreWaitNodeParams externalSemaphorNodeParam_; + + public: + hipGraphExternalSemWaitNode(const hipExternalSemaphoreWaitNodeParams* pNodeParams) + : GraphNode(hipGraphNodeTypeExtSemaphoreWait, "solid", + "rectangle", "EXTERNAL_SEMAPHORE_WAIT") { + externalSemaphorNodeParam_ = *pNodeParams; + } + + hipGraphExternalSemWaitNode(const hipGraphExternalSemWaitNode& rhs) : GraphNode(rhs) { + externalSemaphorNodeParam_ = rhs.externalSemaphorNodeParam_; + } + ~hipGraphExternalSemWaitNode() {} + + GraphNode* clone() const { + return new hipGraphExternalSemWaitNode(static_cast(*this)); + } + + hipError_t CreateCommand(hip::Stream* stream) { + hipError_t status = GraphNode::CreateCommand(stream); + if (status != hipSuccess) { + return status; + + } + unsigned int numExtSems = externalSemaphorNodeParam_.numExtSems; + commands_.reserve(numExtSems); + for (unsigned int i = 0; i < numExtSems; i++) { + if (externalSemaphorNodeParam_.extSemArray[i] != nullptr) { + amd::ExternalSemaphoreCmd* command = new amd::ExternalSemaphoreCmd(*stream, + externalSemaphorNodeParam_.extSemArray[i], + externalSemaphorNodeParam_.paramsArray[i].params.fence.value, + amd::ExternalSemaphoreCmd::COMMAND_WAIT_EXTSEMAPHORE); + if (command == nullptr) { + return hipErrorOutOfMemory; + } + commands_.emplace_back(command); + } else { + return hipErrorInvalidValue; + } + } + return hipSuccess; + } + + void GetParams(hipExternalSemaphoreWaitNodeParams* pNodeParams) const { + std::memcpy(pNodeParams, &externalSemaphorNodeParam_, + sizeof(hipExternalSemaphoreWaitNodeParams)); + } + + hipError_t SetParams(const hipExternalSemaphoreWaitNodeParams* pNodeParams) { + std::memcpy(&externalSemaphorNodeParam_, pNodeParams, + sizeof(hipExternalSemaphoreWaitNodeParams)); + return hipSuccess; + } +}; + } // namespace hip + + + diff --git a/hipamd/src/hip_hcc.map.in b/hipamd/src/hip_hcc.map.in index 9122f2956b..85b458a4ec 100644 --- a/hipamd/src/hip_hcc.map.in +++ b/hipamd/src/hip_hcc.map.in @@ -504,6 +504,14 @@ global: hipGraphNodeGetEnabled; hipGraphNodeSetEnabled; hipGraphUpload; + hipGraphAddExternalSemaphoresSignalNode; + hipGraphAddExternalSemaphoresWaitNode; + hipGraphExternalSemaphoresSignalNodeSetParams; + hipGraphExternalSemaphoresSignalNodeGetParams; + hipGraphExternalSemaphoresWaitNodeSetParams; + hipGraphExternalSemaphoresWaitNodeGetParams; + hipGraphExecExternalSemaphoresSignalNodeSetParams; + hipGraphExecExternalSemaphoresWaitNodeSetParams; local: *; } hip_5.2;