Skip to content

Commit

Permalink
[GPU] Remove redundant usage of memory pool (openvinotoolkit#23804)
Browse files Browse the repository at this point in the history
### Details:
- Not to assign a memory slot for a memory request < 50% of the
available memory

### Tickets:
 - 137490
  • Loading branch information
yeonbok authored May 6, 2024
1 parent 0c27ee5 commit bc3b32b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -119,15 +119,17 @@ class memory_pool {
const std::unordered_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::unordered_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 @@ -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);
}
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 @@ -112,16 +112,18 @@ memory::ptr memory_pool::get_from_non_padded_pool(const layout& layout,
uint32_t network_id,
const std::unordered_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 @@ -219,7 +221,8 @@ memory::ptr memory_pool::get_memory(const layout& layout,
const std::unordered_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 @@ -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);
Expand Down

0 comments on commit bc3b32b

Please sign in to comment.