SWDEV-325711: Add userobject functions for graph

- add user obj APIs for creating release and retain of user onbjects

Signed-off-by: sdashmiz <shadi.dashmiz@amd.com>
Change-Id: I0bf2999c77e44269565b27c31c7c1461f8a160a2
This commit is contained in:
sdashmiz
2022-04-25 13:42:17 -04:00
committed by Shadi Dashmiz
parent a682934251
commit 2c010dec17
8 changed files with 323 additions and 7 deletions
+66 -2
View File
@@ -23,6 +23,7 @@
#include "hip_conversions.hpp"
#include "hip_platform.hpp"
#include "hip_event.hpp"
#include "top.hpp"
std::vector<hip::Stream*> g_captureStreams;
amd::Monitor g_captureStreamsLock{"StreamCaptureGlobalList"};
@@ -1017,10 +1018,12 @@ hipError_t ihipGraphInstantiate(hipGraphExec_t* pGraphExec, hipGraph_t graph) {
}
std::vector<std::vector<Node>> parallelLists;
std::unordered_map<Node, std::vector<Node>> nodeWaitLists;
std::unordered_set<hipUserObject*> graphExeUserObj;
clonedGraph->GetRunList(parallelLists, nodeWaitLists);
std::vector<Node> levelOrder;
clonedGraph->LevelOrder(levelOrder);
*pGraphExec = new hipGraphExec(levelOrder, parallelLists, nodeWaitLists, clonedNodes);
clonedGraph->GetUserObjs(graphExeUserObj);
*pGraphExec = new hipGraphExec(levelOrder, parallelLists, nodeWaitLists, clonedNodes, graphExeUserObj);
if (*pGraphExec != nullptr) {
return (*pGraphExec)->Init();
} else {
@@ -1965,4 +1968,65 @@ hipError_t hipDeviceGraphMemTrim(int device) {
}
// not implemented yet
return HIP_RETURN(hipSuccess);
}
}
hipError_t hipUserObjectCreate(hipUserObject_t* object_out, void* ptr, hipHostFn_t destroy, unsigned int initialRefcount, unsigned int flags) {
HIP_INIT_API(hipUserObjectCreate, object_out, ptr, destroy, initialRefcount, flags);
if (object_out == nullptr || flags != hipUserObjectNoDestructorSync) {
HIP_RETURN(hipErrorInvalidValue);
}
*object_out = new hipUserObject(destroy, ptr, flags);
//! Creating object adds one reference.
if (initialRefcount > 1) {
(*object_out)->increaseRefCount(static_cast<const unsigned int>(initialRefcount - 1));
}
HIP_RETURN(hipSuccess);
}
hipError_t hipUserObjectRelease(hipUserObject_t object, unsigned int count) {
HIP_INIT_API(hipUserObjectRelease, object, count);
if (object == nullptr || !hipUserObject::isUserObjvalid(object) || (object->referenceCount() < count)) {
HIP_RETURN(hipErrorInvalidValue);
}
object->decreaseRefCount(count);
HIP_RETURN(hipSuccess);
}
hipError_t hipUserObjectRetain(hipUserObject_t object, unsigned int count) {
HIP_INIT_API(hipUserObjectRetain, object, count);
if (object == nullptr || !hipUserObject::isUserObjvalid(object)) {
HIP_RETURN(hipErrorInvalidValue);
}
object->increaseRefCount(count);
HIP_RETURN(hipSuccess);
}
hipError_t hipGraphRetainUserObject(hipGraph_t graph, hipUserObject_t object, unsigned int count, unsigned int flags) {
HIP_INIT_API(hipGraphRetainUserObject, graph, object, count, flags);
hipError_t status = hipSuccess;
if (graph == nullptr || object == nullptr || !hipUserObject::isUserObjvalid(object)) {
HIP_RETURN(hipErrorInvalidValue);
}
if (flags != hipGraphUserObjectMove) {
status = hipUserObjectRetain(object, count);
if (status != hipSuccess) {
HIP_RETURN(status);
}
}
graph->addUserObjGraph(object);
HIP_RETURN(status);
}
hipError_t hipGraphReleaseUserObject(hipGraph_t graph, hipUserObject_t object, unsigned int count) {
HIP_INIT_API(hipGraphReleaseUserObject, graph, object, count);
if (graph == nullptr || object == nullptr || !ihipGraph::isUserObjGraphValid(object)) {
HIP_RETURN(hipErrorInvalidValue);
}
//! Obj is being destroyed
if (object->referenceCount() == count) {
graph->RemoveUserObjGraph(object);
}
hipError_t status = hipUserObjectRelease(object, count);
HIP_RETURN(status);
}