diff --git a/hipamd/include/hip/nvidia_detail/nvidia_hip_runtime_api.h b/hipamd/include/hip/nvidia_detail/nvidia_hip_runtime_api.h index b88548630a..20d73aec6c 100644 --- a/hipamd/include/hip/nvidia_detail/nvidia_hip_runtime_api.h +++ b/hipamd/include/hip/nvidia_detail/nvidia_hip_runtime_api.h @@ -1131,6 +1131,10 @@ typedef enum cudaStreamCaptureStatus hipStreamCaptureStatus; #define hipStreamCaptureStatusActive cudaStreamCaptureStatusActive #define hipStreamCaptureStatusInvalidated cudaStreamCaptureStatusInvalidated +typedef union cudaKernelNodeAttrValue hipKernelNodeAttrValue; +typedef enum cudaKernelNodeAttrID hipKernelNodeAttrID; + + #if CUDA_VERSION >= CUDA_11030 typedef enum cudaStreamUpdateCaptureDependenciesFlags hipStreamUpdateCaptureDependenciesFlags; #define hipStreamAddCaptureDependencies cudaStreamAddCaptureDependencies @@ -2677,6 +2681,16 @@ inline static hipError_t hipGraphKernelNodeSetParams(hipGraphNode_t node, return hipCUDAErrorTohipError(cudaGraphKernelNodeSetParams(node, pNodeParams)); } +inline static hipError_t hipGraphKernelNodeSetAttribute(hipGraphNode_t hNode, hipKernelNodeAttrID attr, + const hipKernelNodeAttrValue* value) { + return hipCUDAErrorTohipError(cudaGraphKernelNodeSetAttribute(hNode, attr, value)); +} + +inline static hipError_t hipGraphKernelNodeGetAttribute(hipGraphNode_t hNode, hipKernelNodeAttrID attr, + hipKernelNodeAttrValue* value) { + return hipCUDAErrorTohipError(cudaGraphKernelNodeGetAttribute(hNode, attr, value)); +} + inline static hipError_t hipGraphMemcpyNodeGetParams(hipGraphNode_t node, hipMemcpy3DParms* pNodeParams) { return hipCUDAErrorTohipError(cudaGraphMemcpyNodeGetParams(node, pNodeParams)); diff --git a/hipamd/src/amdhip.def b/hipamd/src/amdhip.def index c44f60d1c1..9a39401953 100644 --- a/hipamd/src/amdhip.def +++ b/hipamd/src/amdhip.def @@ -314,6 +314,8 @@ hipGraphGetNodes hipGraphGetRootNodes hipGraphKernelNodeGetParams hipGraphKernelNodeSetParams +hipGraphKernelNodeSetAttribute +hipGraphKernelNodeGetAttribute hipGraphMemcpyNodeGetParams hipGraphMemcpyNodeSetParams hipGraphMemsetNodeGetParams diff --git a/hipamd/src/hip_graph.cpp b/hipamd/src/hip_graph.cpp index 9dd7b93d6e..4a0537cd94 100644 --- a/hipamd/src/hip_graph.cpp +++ b/hipamd/src/hip_graph.cpp @@ -1113,6 +1113,30 @@ hipError_t hipGraphMemcpyNodeGetParams(hipGraphNode_t node, hipMemcpy3DParms* pN HIP_RETURN(hipSuccess); } +hipError_t hipGraphKernelNodeSetAttribute(hipGraphNode_t hNode, hipKernelNodeAttrID attr, + const hipKernelNodeAttrValue* value) { + HIP_INIT_API(hipGraphKernelNodeSetAttribute, hNode, attr, value); + if (hNode == nullptr || value == nullptr) { + HIP_RETURN(hipErrorInvalidValue); + } + if (attr != hipKernelNodeAttributeAccessPolicyWindow && attr != hipKernelNodeAttributeCooperative ) { + HIP_RETURN(hipErrorInvalidValue); + } + HIP_RETURN(reinterpret_cast(hNode)->SetAttrParams(attr, value)); +} + +hipError_t hipGraphKernelNodeGetAttribute(hipGraphNode_t hNode, hipKernelNodeAttrID attr, + hipKernelNodeAttrValue* value) { + HIP_INIT_API(hipGraphKernelNodeGetAttribute, hNode, attr, value); + if (hNode == nullptr || value == nullptr) { + HIP_RETURN(hipErrorInvalidValue); + } + if (attr != hipKernelNodeAttributeAccessPolicyWindow && attr != hipKernelNodeAttributeCooperative ) { + HIP_RETURN(hipErrorInvalidValue); + } + HIP_RETURN(reinterpret_cast(hNode)->GetAttrParams(attr, value)); +} + hipError_t hipGraphMemcpyNodeSetParams(hipGraphNode_t node, const hipMemcpy3DParms* pNodeParams) { HIP_INIT_API(hipGraphMemcpyNodeSetParams, node, pNodeParams); if (node == nullptr || pNodeParams == nullptr) { diff --git a/hipamd/src/hip_graph_internal.hpp b/hipamd/src/hip_graph_internal.hpp index 4e88178424..6477235799 100644 --- a/hipamd/src/hip_graph_internal.hpp +++ b/hipamd/src/hip_graph_internal.hpp @@ -60,6 +60,7 @@ struct hipGraphNode { struct ihipGraph* parentGraph_; static std::unordered_set nodeSet_; static amd::Monitor nodeSetLock_; + hipKernelNodeAttrValue kernelAttr_; public: hipGraphNode(hipGraphNodeType type) @@ -72,6 +73,7 @@ struct hipGraphNode { parentGraph_(nullptr) { amd::ScopedLock lock(nodeSetLock_); nodeSet_.insert(this); + memset(&kernelAttr_, 0, sizeof(kernelAttr_)); } /// Copy Constructor hipGraphNode(const hipGraphNode& node) { @@ -453,7 +455,6 @@ struct hipChildGraphNode : public hipGraphNode { class hipGraphKernelNode : public hipGraphNode { hipKernelNodeParams* pKernelParams_; hipFunction_t func_; - public: static hipError_t getFunc(hipFunction_t* func, const hipKernelNodeParams& params, unsigned int device) { hipError_t status = PlatformState::instance().getStatFunc(func, params.func, device); @@ -515,6 +516,40 @@ class hipGraphKernelNode : public hipGraphNode { std::memcpy(pKernelParams_, params, sizeof(hipKernelNodeParams)); return status; } + hipError_t SetAttrParams(hipKernelNodeAttrID attr, const hipKernelNodeAttrValue* params) { + // updates kernel attr params + if (attr == hipKernelNodeAttributeAccessPolicyWindow) { + if (params->accessPolicyWindow.base_ptr == NULL) { + return hipErrorInvalidResourceHandle; + } + kernelAttr_.accessPolicyWindow.base_ptr = params->accessPolicyWindow.base_ptr; + kernelAttr_.accessPolicyWindow.hitProp = params->accessPolicyWindow.hitProp; + kernelAttr_.accessPolicyWindow.hitRatio = params->accessPolicyWindow.hitRatio; + kernelAttr_.accessPolicyWindow.missProp = params->accessPolicyWindow.missProp; + kernelAttr_.accessPolicyWindow.num_bytes = params->accessPolicyWindow.num_bytes; + } else if (attr == hipKernelNodeAttributeCooperative) + { + kernelAttr_.cooperative = params->cooperative; + } + return hipSuccess; + } + hipError_t GetAttrParams(hipKernelNodeAttrID attr, hipKernelNodeAttrValue* params) { + // Get kernel attr params + if (attr == hipKernelNodeAttributeAccessPolicyWindow) { + if (kernelAttr_.accessPolicyWindow.base_ptr == NULL) { + return hipErrorInvalidResourceHandle; + } + params->accessPolicyWindow.base_ptr = kernelAttr_.accessPolicyWindow.base_ptr; + params->accessPolicyWindow.hitProp = kernelAttr_.accessPolicyWindow.hitProp; + params->accessPolicyWindow.hitRatio = kernelAttr_.accessPolicyWindow.hitRatio; + params->accessPolicyWindow.missProp = kernelAttr_.accessPolicyWindow.missProp; + params->accessPolicyWindow.num_bytes = kernelAttr_.accessPolicyWindow.num_bytes; + } else if (attr == hipKernelNodeAttributeCooperative) + { + params->cooperative = kernelAttr_.cooperative; + } + return hipSuccess; + } // ToDo: use this when commands are cloned and command params are to be updated hipError_t SetCommandParams(const hipKernelNodeParams* params) { if (params->func != pKernelParams_->func) { diff --git a/hipamd/src/hip_hcc.def.in b/hipamd/src/hip_hcc.def.in index fcb4504a9c..242b07ad6c 100644 --- a/hipamd/src/hip_hcc.def.in +++ b/hipamd/src/hip_hcc.def.in @@ -328,6 +328,8 @@ hipGraphGetRootNodes hipGraphKernelNodeGetParams hipGraphKernelNodeSetParams hipGraphMemcpyNodeGetParams +hipGraphKernelNodeSetAttribute +hipGraphKernelNodeGetAttribute hipGraphMemcpyNodeSetParams hipGraphMemsetNodeGetParams hipGraphMemsetNodeSetParams diff --git a/hipamd/src/hip_hcc.map.in b/hipamd/src/hip_hcc.map.in index 2adb0ddc26..d31ace338f 100644 --- a/hipamd/src/hip_hcc.map.in +++ b/hipamd/src/hip_hcc.map.in @@ -398,6 +398,8 @@ global: hipPointerGetAttribute; hipDrvPointerGetAttributes; hipThreadExchangeStreamCaptureMode; + hipGraphKernelNodeSetAttribute; + hipGraphKernelNodeGetAttribute; local: *; } hip_4.5;