diff --git a/src/plugins/intel_gpu/include/intel_gpu/runtime/memory_pool.hpp b/src/plugins/intel_gpu/include/intel_gpu/runtime/memory_pool.hpp index 28bd81ddc6eee5..2bf629c281df90 100644 --- a/src/plugins/intel_gpu/include/intel_gpu/runtime/memory_pool.hpp +++ b/src/plugins/intel_gpu/include/intel_gpu/runtime/memory_pool.hpp @@ -119,7 +119,8 @@ class memory_pool { const std::unordered_set& 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, @@ -127,7 +128,8 @@ class memory_pool { uint32_t network_id, const std::unordered_set&, 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, diff --git a/src/plugins/intel_gpu/src/graph/primitive_inst.cpp b/src/plugins/intel_gpu/src/graph/primitive_inst.cpp index b646f237aa9b13..818b4df792e548 100644 --- a/src/plugins/intel_gpu/src/graph/primitive_inst.cpp +++ b/src/plugins/intel_gpu/src/graph/primitive_inst.cpp @@ -160,7 +160,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); } diff --git a/src/plugins/intel_gpu/src/runtime/memory_pool.cpp b/src/plugins/intel_gpu/src/runtime/memory_pool.cpp index 6f2551591d5a6e..67495a53724801 100644 --- a/src/plugins/intel_gpu/src/runtime/memory_pool.cpp +++ b/src/plugins/intel_gpu/src/runtime/memory_pool.cpp @@ -112,16 +112,18 @@ memory::ptr memory_pool::get_from_non_padded_pool(const layout& layout, uint32_t network_id, const std::unordered_set& 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); @@ -219,7 +221,8 @@ memory::ptr memory_pool::get_memory(const layout& layout, const std::unordered_set& 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) { @@ -229,7 +232,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);