From 00c2e6621018086061fbbec51f0e97fbc1e2b217 Mon Sep 17 00:00:00 2001 From: wilson-seok Date: Fri, 5 Apr 2024 22:16:50 +0000 Subject: [PATCH] return false when dynamic shape in check_allocatable() to aviod assertion by big upper bound --- .../intel_gpu/src/runtime/ocl/ocl_engine.cpp | 17 ++++++++++++++--- .../single_layer_tests/dynamic/softmax.cpp | 6 +++++- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/plugins/intel_gpu/src/runtime/ocl/ocl_engine.cpp b/src/plugins/intel_gpu/src/runtime/ocl/ocl_engine.cpp index 0e701ebee5661c..fc94812438c66f 100644 --- a/src/plugins/intel_gpu/src/runtime/ocl/ocl_engine.cpp +++ b/src/plugins/intel_gpu/src/runtime/ocl/ocl_engine.cpp @@ -128,21 +128,32 @@ allocation_type ocl_engine::detect_usm_allocation_type(const void* memory) const bool ocl_engine::check_allocatable(const layout& layout, allocation_type type) { OPENVINO_ASSERT(supports_allocation(type) || type == allocation_type::cl_mem, "[GPU] Unsupported allocation type: ", type); - OPENVINO_ASSERT(layout.bytes_count() <= get_device_info().max_alloc_mem_size, + bool above_max_device_mem_size = (layout.bytes_count() > get_device_info().max_alloc_mem_size); + + // When dynamic shape upper bound makes bigger buffer, then return false. + if (above_max_device_mem_size && layout.is_dynamic()) + return false; + + OPENVINO_ASSERT(!above_max_device_mem_size, "[GPU] Exceeded max size of memory object allocation: ", "requested ", layout.bytes_count(), " bytes, " "but max alloc size supported by device is ", get_device_info().max_alloc_mem_size, " bytes.", "Please try to reduce batch size or use lower precision."); auto used_mem = get_used_device_memory(allocation_type::usm_device) + get_used_device_memory(allocation_type::usm_host); + auto above_max_usable_mem_size = (layout.bytes_count() + used_mem > get_max_memory_size()); + + // When dynamic shape upper bound makes bigger buffer, then return false. + if (above_max_usable_mem_size && layout.is_dynamic()) + return false; #ifdef __unix__ // Prevent from being killed by Ooo Killer of Linux - OPENVINO_ASSERT(layout.bytes_count() + used_mem <= get_max_memory_size(), + OPENVINO_ASSERT(!above_max_usable_mem_size, "[GPU] Exceeded max size of memory allocation: ", "Required ", layout.bytes_count(), " bytes, already occupied : ", used_mem, " bytes, ", "but available memory size is ", get_max_memory_size(), " bytes"); #else - if (layout.bytes_count() + used_mem > get_max_memory_size()) { + if (above_max_usable_mem_size) { GPU_DEBUG_COUT << "[Warning] [GPU] Exceeded max size of memory allocation: " << "Required " << layout.bytes_count() << " bytes, already occupied : " << used_mem << " bytes, but available memory size is " << get_max_memory_size() << " bytes" << std::endl; GPU_DEBUG_COUT << "Please note that performance might drop due to memory swap." << std::endl; diff --git a/src/plugins/intel_gpu/tests/functional/single_layer_tests/dynamic/softmax.cpp b/src/plugins/intel_gpu/tests/functional/single_layer_tests/dynamic/softmax.cpp index abdd317138a966..01b6aad0afe81e 100644 --- a/src/plugins/intel_gpu/tests/functional/single_layer_tests/dynamic/softmax.cpp +++ b/src/plugins/intel_gpu/tests/functional/single_layer_tests/dynamic/softmax.cpp @@ -100,7 +100,11 @@ const std::vector inputShapes4D = { { {{20, 100}, 12, {1, 400}, {1, 300}}, {{30, 12, 10, 20}, {20, 12, 5, 40}} - } + }, + { // Excessive upper bound case + {3, 8, {128, 16384}, {128, 16384}}, + {{3, 8, 128, 128}} + }, }; const std::vector axis5D = {0, 1, 2, 4};