Skip to content

Commit 19d83d5

Browse files
[NFC][SYCL][Graph] Use node_impl &/nodes_range in memory_pool (#19352)
Continuation of #19295 #19332 #19334
1 parent 4b1bcd2 commit 19d83d5

File tree

3 files changed

+17
-20
lines changed

3 files changed

+17
-20
lines changed

sycl/source/detail/graph/graph_impl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,7 @@ graph_impl::add(node_type NodeType,
520520
static_cast<CGAsyncFree *>(NodeImpl->MCommandGroup.get());
521521
// If this is an async free node mark that it is now available for reuse,
522522
// and pass the async free node for tracking.
523-
MGraphMemPool.markAllocationAsAvailable(AsyncFreeCG->getPtr(), NodeImpl);
523+
MGraphMemPool.markAllocationAsAvailable(AsyncFreeCG->getPtr(), *NodeImpl);
524524
}
525525

526526
return NodeImpl;

sycl/source/detail/graph/memory_pool.cpp

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,8 @@ namespace oneapi {
1919
namespace experimental {
2020
namespace detail {
2121

22-
void *
23-
graph_mem_pool::malloc(size_t Size, usm::alloc AllocType,
24-
const std::vector<std::shared_ptr<node_impl>> &DepNodes,
25-
memory_pool_impl *MemPool) {
22+
void *graph_mem_pool::malloc(size_t Size, usm::alloc AllocType,
23+
nodes_range DepNodes, memory_pool_impl *MemPool) {
2624
// We are potentially modifying contents of this memory pool and the owning
2725
// graph, so take a lock here.
2826
graph_impl::WriteLock Lock(MGraph.MMutex);
@@ -81,9 +79,9 @@ graph_mem_pool::malloc(size_t Size, usm::alloc AllocType,
8179
}
8280

8381
std::optional<graph_mem_pool::alloc_info>
84-
graph_mem_pool::tryReuseExistingAllocation(
85-
size_t Size, usm::alloc AllocType, bool ReadOnly,
86-
const std::vector<std::shared_ptr<node_impl>> &DepNodes) {
82+
graph_mem_pool::tryReuseExistingAllocation(size_t Size, usm::alloc AllocType,
83+
bool ReadOnly,
84+
nodes_range DepNodes) {
8785
// If we have no dependencies this is a no-op because allocations must connect
8886
// to a free node for reuse to be possible.
8987
if (DepNodes.empty()) {
@@ -119,8 +117,8 @@ graph_mem_pool::tryReuseExistingAllocation(
119117
std::queue<node_impl *> NodesToCheck;
120118

121119
// Add all the dependent nodes to the queue, they will be popped first
122-
for (auto &Dep : DepNodes) {
123-
NodesToCheck.push(&*Dep);
120+
for (node_impl &Dep : DepNodes) {
121+
NodesToCheck.push(&Dep);
124122
}
125123

126124
// Called when traversing over nodes to check if the current node is a free
@@ -175,10 +173,9 @@ graph_mem_pool::tryReuseExistingAllocation(
175173
return std::nullopt;
176174
}
177175

178-
void graph_mem_pool::markAllocationAsAvailable(
179-
void *Ptr, const std::shared_ptr<node_impl> &FreeNode) {
176+
void graph_mem_pool::markAllocationAsAvailable(void *Ptr, node_impl &FreeNode) {
180177
MFreeAllocations.push_back(Ptr);
181-
MAllocations.at(Ptr).LastFreeNode = FreeNode.get();
178+
MAllocations.at(Ptr).LastFreeNode = &FreeNode;
182179
}
183180

184181
} // namespace detail

sycl/source/detail/graph/memory_pool.hpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ namespace detail {
2323

2424
// Forward declarations
2525
class node_impl;
26+
class nodes_range;
2627

2728
/// Class handling graph-owned memory allocations. Device allocations are
2829
/// managed using virtual memory.
@@ -82,8 +83,7 @@ class graph_mem_pool {
8283
/// @param MemPool Optional memory pool from which allocations will not be
8384
/// made directly but properties may be respected.
8485
/// @return A pointer to the start of the allocation
85-
void *malloc(size_t Size, usm::alloc AllocType,
86-
const std::vector<std::shared_ptr<node_impl>> &DepNodes,
86+
void *malloc(size_t Size, usm::alloc AllocType, nodes_range DepNodes,
8787
memory_pool_impl *MemPool = nullptr);
8888

8989
/// Return the total amount of memory being used by this pool
@@ -160,8 +160,7 @@ class graph_mem_pool {
160160
/// @param Ptr The pointer to the allocation.
161161
/// @param FreeNode The graph node of node_type::async_free which is freeing
162162
/// the allocation.
163-
void markAllocationAsAvailable(void *Ptr,
164-
const std::shared_ptr<node_impl> &FreeNode);
163+
void markAllocationAsAvailable(void *Ptr, node_impl &FreeNode);
165164

166165
private:
167166
/// Tries to reuse an existing allocation which has been marked free in the
@@ -173,9 +172,10 @@ class graph_mem_pool {
173172
/// reusable allocations.
174173
/// @returns An optional allocation info value, where a null value indicates
175174
/// that no allocation could be reused.
176-
std::optional<alloc_info> tryReuseExistingAllocation(
177-
size_t Size, usm::alloc AllocType, bool ReadOnly,
178-
const std::vector<std::shared_ptr<node_impl>> &DepNodes);
175+
std::optional<alloc_info> tryReuseExistingAllocation(size_t Size,
176+
usm::alloc AllocType,
177+
bool ReadOnly,
178+
nodes_range DepNodes);
179179

180180
/// Returns an aligned byte size given a required granularity
181181
/// @param UnalignedByteSize The original requested allocation size

0 commit comments

Comments
 (0)