SWDEV-377804 - Initial commit to support hipGraphInstantiateFlagAutoFreeOnLaunch

Change-Id: I7a35becb6c98a6ff70264e141317d98be7457a37
Этот коммит содержится в:
Jaydeep Patel
2023-01-27 13:07:01 +00:00
коммит произвёл Jaydeepkumar Patel
родитель 14477c24d0
Коммит f9e27bcdd4
5 изменённых файлов: 27 добавлений и 8 удалений
+5 -3
Просмотреть файл
@@ -1215,7 +1215,8 @@ hipError_t hipGraphAddChildGraphNode(hipGraphNode_t* pGraphNode, hipGraph_t grap
HIP_RETURN(status);
}
hipError_t ihipGraphInstantiate(hipGraphExec_t* pGraphExec, hipGraph_t graph) {
hipError_t ihipGraphInstantiate(hipGraphExec_t* pGraphExec, hipGraph_t graph,
uint64_t flags = 0) {
if (pGraphExec == nullptr || graph == nullptr) {
HIP_RETURN(hipErrorInvalidValue);
}
@@ -1232,7 +1233,8 @@ hipError_t ihipGraphInstantiate(hipGraphExec_t* pGraphExec, hipGraph_t graph) {
clonedGraph->LevelOrder(levelOrder);
clonedGraph->GetUserObjs(graphExeUserObj);
*pGraphExec =
new hipGraphExec(levelOrder, parallelLists, nodeWaitLists, clonedNodes, graphExeUserObj);
new hipGraphExec(levelOrder, parallelLists, nodeWaitLists, clonedNodes,
graphExeUserObj, flags);
if (*pGraphExec != nullptr) {
return (*pGraphExec)->Init();
} else {
@@ -1247,7 +1249,7 @@ hipError_t hipGraphInstantiate(hipGraphExec_t* pGraphExec, hipGraph_t graph,
}
hipError_t hipGraphInstantiateWithFlags(hipGraphExec_t* pGraphExec, hipGraph_t graph,
unsigned long long flags) {
unsigned long long flags = 0) {
HIP_INIT_API(hipGraphInstantiateWithFlags, pGraphExec, graph, flags);
if (pGraphExec == nullptr || graph == nullptr) {
HIP_RETURN(hipErrorInvalidValue);
+5
Просмотреть файл
@@ -796,6 +796,11 @@ hipError_t hipGraphExec::Run(hipStream_t stream) {
if (queue == nullptr) {
return hipErrorInvalidResourceHandle;
}
if (flags_ == hipGraphInstantiateFlagAutoFreeOnLaunch) {
if (!levelOrder_.empty()) {
levelOrder_[0]->GetParentGraph()->FreeAllMemory();
}
}
UpdateQueue(parallelLists_, queue, this);
std::vector<amd::Command*> rootCommands;
amd::Command* endCommand = nullptr;
+9 -3
Просмотреть файл
@@ -530,6 +530,10 @@ struct ihipGraph {
}
return false;
}
void FreeAllMemory() {
mem_pool_->FreeAllMemory();
}
};
struct hipGraphExec {
@@ -544,19 +548,21 @@ struct hipGraphExec {
static std::unordered_set<hipGraphExec*> graphExecSet_;
std::unordered_set<hipUserObject*> graphExeUserObj_;
static amd::Monitor graphExecSetLock_;
uint64_t flags_ = 0;
public:
hipGraphExec(std::vector<Node>& levelOrder, std::vector<std::vector<Node>>& lists,
std::unordered_map<Node, std::vector<Node>>& nodeWaitLists,
std::unordered_map<Node, Node>& clonedNodes,
std::unordered_set<hipUserObject*>& userObjs)
std::unordered_set<hipUserObject*>& userObjs,
uint64_t flags = 0)
: parallelLists_(lists),
levelOrder_(levelOrder),
nodeWaitLists_(nodeWaitLists),
clonedNodes_(clonedNodes),
lastEnqueuedCommand_(nullptr),
graphExeUserObj_(userObjs),
currentQueueIndex_(0) {
currentQueueIndex_(0),
flags_(flags) {
amd::ScopedLock lock(graphExecSetLock_);
graphExecSet_.insert(this);
}
+6
Просмотреть файл
@@ -397,4 +397,10 @@ void MemoryPool::GetAccess(hip::Device* device, hipMemAccessFlags* flags) {
}
}
void MemoryPool::FreeAllMemory(hip::Stream* stream) {
while (!busy_heap_.Allocations().empty()) {
FreeMemory(busy_heap_.Allocations().begin()->first, stream);
}
}
}
+2 -2
Просмотреть файл
@@ -136,7 +136,7 @@ public:
bool IsActiveMemory(amd::Memory* memory) const {
return (allocations_.find(memory) != allocations_.end());
}
const auto& Allocations() { return allocations_; }
private:
Heap() = delete;
Heap(const Heap&) = delete;
@@ -217,7 +217,7 @@ public:
bool EventDependencies() const { return (state_.event_dependencies_) ? true : false; }
bool Opportunistic() const { return (state_.opportunistic_) ? true : false; }
bool InternalDependencies() const { return (state_.internal_dependencies_) ? true : false; }
void FreeAllMemory(hip::Stream* stream = nullptr);
private:
MemoryPool() = delete;
MemoryPool(const MemoryPool&) = delete;