Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GPU] Remove redundant usage of memory pool #23804

Merged
merged 1 commit into from
May 6, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,17 @@ class memory_pool {
const std::set<size_t>& restrictions,
allocation_type type,
bool reusable = true,
bool reset = true); // get from pool or create memory allocation
bool reset = true,
bool is_dynamic = false); // get from pool or create memory allocation
memory_ptr get_memory(const layout& layout, allocation_type type, bool reset = true);
memory_ptr get_from_non_padded_pool(const layout& layout,
const primitive_id& prim_id,
size_t unique_id,
uint32_t network_id,
const std::set<size_t>&,
allocation_type type,
bool reset = true);
bool reset = true,
bool is_dynamic = false);
memory_ptr get_from_padded_pool(const layout& layout,
const primitive_id& prim_id,
size_t unique_id,
Expand Down
10 changes: 9 additions & 1 deletion src/plugins/intel_gpu/src/graph/primitive_inst.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,15 @@ static memory::ptr get_memory_from_pool(engine& _engine,
if (_node.get_program().get_config().get_property(ov::intel_gpu::enable_memory_pool)) {
if (curr_memory != nullptr)
pool.release_memory(curr_memory, _node.get_unique_id(), _node.id(), net_id);
return pool.get_memory(layout, _node.id(), _node.get_unique_id(), net_id, memory_dependencies, type, reusable_across_network, reset);
return pool.get_memory(layout,
_node.id(),
_node.get_unique_id(),
net_id,
memory_dependencies,
type,
reusable_across_network,
reset,
_node.is_dynamic());
}
return pool.get_memory(layout, type, reset);
}
Expand Down
13 changes: 8 additions & 5 deletions src/plugins/intel_gpu/src/runtime/memory_pool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,16 +121,18 @@ memory::ptr memory_pool::get_from_non_padded_pool(const layout& layout,
uint32_t network_id,
const std::set<size_t>& restrictions,
allocation_type type,
bool reset) {
bool reset,
bool is_dynamic) {
auto it = _non_padded_pool.lower_bound(layout.bytes_count());
while (it != _non_padded_pool.end()) {
if (it->second._network_id == network_id &&
if ((!is_dynamic || (layout.bytes_count() > it->second._memory->get_layout().bytes_count() * 0.5)) &&
(it->second._network_id == network_id &&
it->second._type == type &&
it->second._memory->get_layout().format != format::fs_b_yx_fsv32 &&
layout.format != format::fs_b_yx_fsv32 &&
((layout.format != format::b_fs_yx_fsv32 && layout.format != format::b_fs_zyx_fsv32) ||
(layout.feature() % 32 == 0)) &&
!has_conflict(it->second._users, restrictions, network_id)) {
!has_conflict(it->second._users, restrictions, network_id))) {
it->second._users.insert(memory_user(unique_id, network_id, prim_id));
auto ret_mem = _engine->reinterpret_buffer(*it->second._memory, layout);
GPU_DEBUG_CODE(ret_mem->from_memory_pool = true);
Expand Down Expand Up @@ -228,7 +230,8 @@ memory::ptr memory_pool::get_memory(const layout& layout,
const std::set<size_t>& restrictions,
allocation_type type,
bool reusable_across_network,
bool reset) {
bool reset,
bool is_dynamic) {
bool do_reuse = reusable_across_network;
GPU_DEBUG_GET_INSTANCE(debug_config);
GPU_DEBUG_IF(debug_config->disable_memory_reuse) {
Expand All @@ -238,7 +241,7 @@ memory::ptr memory_pool::get_memory(const layout& layout,
// reusable within the same network
if (!layout.format.is_image() && layout.data_padding == padding{{0, 0, 0, 0}, 0}) {
// non-padded buffers
return get_from_non_padded_pool(layout, prim_id, unique_id, network_id, restrictions, type, reset);
return get_from_non_padded_pool(layout, prim_id, unique_id, network_id, restrictions, type, reset, is_dynamic);
} else if (!layout.format.is_image()) {
// padded buffers
return get_from_padded_pool(layout, prim_id, unique_id, network_id, restrictions, type);
Expand Down
Loading