Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,8 @@ libdevice/nativecpu* @intel/dpcpp-nativecpu-reviewers
sycl/include/sycl/ext/oneapi/experimental/graph.hpp @intel/sycl-graphs-reviewers
sycl/source/detail/graph_impl.cpp @intel/sycl-graphs-reviewers
sycl/source/detail/graph_impl.hpp @intel/sycl-graphs-reviewers
sycl/source/detail/graph_memory_pool.hpp @intel/sycl-graphs-reviewers
sycl/source/detail/graph_memory_pool.cpp @intel/sycl-graphs-reviewers
sycl/unittests/Extensions/CommandGraph/ @intel/sycl-graphs-reviewers
sycl/test-e2e/Graph @intel/sycl-graphs-reviewers
sycl/doc/design/CommandGraph.md @intel/sycl-graphs-reviewers
Expand Down
46 changes: 21 additions & 25 deletions sycl/source/detail/graph_memory_pool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ graph_mem_pool::tryReuseExistingAllocation(
const std::vector<std::shared_ptr<node_impl>> &DepNodes) {
// If we have no dependencies this is a no-op because allocations must connect
// to a free node for reuse to be possible.
// if (DepNodes.empty()) {
// return std::nullopt;
// }
if (DepNodes.empty()) {
return std::nullopt;
}

std::vector<alloc_info> CompatibleAllocs;
// Compatible allocs can only be as big as MFreeAllocations
Expand Down Expand Up @@ -127,26 +127,22 @@ graph_mem_pool::tryReuseExistingAllocation(
NodesToCheck.push(Dep);
}

std::optional<alloc_info> AllocInfo = {};

// Called when traversing over nodes to check if the current node is a free
// node for one of the available allocations. If it is we populate AllocInfo
// with the allocation to be reused.
auto CheckNodeEqual =
[&CompatibleAllocs,
&AllocInfo](const std::shared_ptr<node_impl> &CurrentNode) -> bool {
[&CompatibleAllocs](const std::shared_ptr<node_impl> &CurrentNode)
-> std::optional<alloc_info> {
for (auto &Alloc : CompatibleAllocs) {
const auto &AllocFreeNode = Alloc.LastFreeNode;
// Compare control blocks without having to lock AllocFreeNode to check
// for node equality
if (!CurrentNode.owner_before(AllocFreeNode) &&
!AllocFreeNode.owner_before(CurrentNode)) {
Alloc.LastFreeNode.reset();
AllocInfo = Alloc;
return true;
return Alloc;
}
}
return false;
return std::nullopt;
};

while (!NodesToCheck.empty()) {
Expand All @@ -161,11 +157,19 @@ graph_mem_pool::tryReuseExistingAllocation(
// for any of the allocations which are free for reuse. We should not bother
// checking nodes that are not free nodes, so we continue and check their
// predecessors.
if (CurrentNode->MNodeType == node_type::async_free &&
CheckNodeEqual(CurrentNode)) {
// If we found an allocation AllocInfo has already been populated in
// CheckNodeEqual(), so we simply break out of the loop
break;
if (CurrentNode->MNodeType == node_type::async_free) {
std::optional<alloc_info> AllocFound = CheckNodeEqual(CurrentNode);
if (AllocFound) {
// Reset visited nodes tracking
MGraph.resetNodeVisitedEdges();
// Reset last free node for allocation
MAllocations.at(AllocFound.value().Ptr).LastFreeNode.reset();
// Remove found allocation from the free list
MFreeAllocations.erase(std::find(MFreeAllocations.begin(),
MFreeAllocations.end(),
AllocFound.value().Ptr));
return AllocFound;
}
}

// Add CurrentNode predecessors to queue
Expand All @@ -176,16 +180,8 @@ graph_mem_pool::tryReuseExistingAllocation(
// Mark node as visited
CurrentNode->MTotalVisitedEdges = 1;
}
// Reset visited nodes tracking
MGraph.resetNodeVisitedEdges();
// If we found an allocation, remove it from the free list.
if (AllocInfo) {
MFreeAllocations.erase(std::find(MFreeAllocations.begin(),
MFreeAllocations.end(),
AllocInfo.value().Ptr));
}

return AllocInfo;
return std::nullopt;
}

void graph_mem_pool::markAllocationAsAvailable(
Expand Down