Skip to content

Commit

Permalink
[GPU] Do not preallocate memory if desired size reaches the maximum s…
Browse files Browse the repository at this point in the history
…upported buffer size
  • Loading branch information
sshlyapn committed Sep 2, 2024
1 parent fb27863 commit 4fc6495
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/plugins/intel_gpu/src/runtime/shape_predictor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ bool ShapePredictor::can_preallocate(size_t desired_buffer_size) {
const auto memory_threshold = 0.90f;
auto device_mem_usage = _engine->get_used_device_memory(cldnn::allocation_type::usm_device);

if (desired_buffer_size > _engine->get_device_info().max_alloc_mem_size)
return false;

return device_mem_usage + desired_buffer_size < _engine->get_device_info().max_global_mem_size * memory_threshold;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,23 @@ INSTANTIATE_TEST_SUITE_P(smoke, shape_predictor_tests_b_fs_yx_fsv16,
{{{1,1}, {1,128}, {1,256}}, {}, 1.1f, true},
{{{1,3,128}, {1,3,112}, {1,3,418}, {1,3,512}}, {}, 1.1f, true},
}));

TEST(shape_predictor_tests, check_max_buffer_size) {
auto& engine = get_test_engine();

const auto& buffers_preallocation_ratio = 1.1;
ShapePredictor sp(&engine, buffers_preallocation_ratio);

const auto max_alloc_mem_size = engine.get_device_info().max_alloc_mem_size;
auto layout = cldnn::layout({static_cast<int64_t>(max_alloc_mem_size)}, ov::element::u8, format::bfyx);

std::pair<bool, ov::Shape> result;

// Perform 3 iteration to trigger shape preallocation
result = sp.predict_preallocation_shape("dummy_name", layout, false);
result = sp.predict_preallocation_shape("dummy_name", layout, false);
result = sp.predict_preallocation_shape("dummy_name", layout, false);

const auto bytes_count = ov::shape_size(result.second);
ASSERT_FALSE(sp.can_preallocate(bytes_count));
}

0 comments on commit 4fc6495

Please sign in to comment.