OpenVINO™ is an open source toolkit for optimizing and deploying AI inference
C++ aicomputer-visiondeep-learningdeploy-aidiffusion-modelsgenerative-aigood-first-issueinferencellm-inferencenatural-language-processingnlpopenvinooptimize-aiperformance-boostrecommendation-systemspeech-recognitionstable-diffusiontransformersyolo
[GPU] release of dynamic layout from memory pool (#29148)
Michal Miotk5cc808c32796
diff --git a/src/plugins/intel_gpu/docs/memory_allocation_gpu_plugin.md b/src/plugins/intel_gpu/docs/memory_allocation_gpu_plugin.mdindex 1ad9039435f..183df1a496b 100644--- a/src/plugins/intel_gpu/docs/memory_allocation_gpu_plugin.md+++ b/src/plugins/intel_gpu/docs/memory_allocation_gpu_plugin.md@@ -20,7 +20,7 @@ calls the corresponding memory object wrapper for each allocation type: [gpu_buf## Dump memory allocation history-The memory allocation history is being managed by the `engine`, which can be dumped by setting the environment variable `OV_GPU_Verbose=2` if OpenVINO is built with the cmake configuration `ENABLE_DEBUG_CAPS=ON`.+The memory allocation history is being managed by the `engine`, which can be dumped by setting the environment variable `OV_VERBOSE=2` if OpenVINO is built with the cmake configuration `ENABLE_DEBUG_CAPS=ON`.```cpp...GPU_Debug: Allocate 58982400 bytes of usm_host allocation type (current=117969612; max=117969612)diff --git a/src/plugins/intel_gpu/src/graph/include/pass_manager.h b/src/plugins/intel_gpu/src/graph/include/pass_manager.hindex fb7f05927b2..79b7de789df 100644--- a/src/plugins/intel_gpu/src/graph/include/pass_manager.h+++ b/src/plugins/intel_gpu/src/graph/include/pass_manager.h@@ -320,7 +320,8 @@ public:return;}- if ((node->can_be_optimized() && !node->is_runtime_skippable()) || !dep->can_be_optimized()) {+ if ((!dep->can_be_optimized() || !dep->is_runtime_skippable()) && ((node->can_be_optimized() && !node->is_runtime_skippable())+ || !dep->can_be_optimized())) {node->add_memory_dependency(static_cast<int32_t>(dep->get_unique_id()));} else {if (node->is_runtime_skippable() || dep->is_runtime_skippable() || dep->can_be_optimized()) {diff --git a/src/plugins/intel_gpu/src/graph/primitive_inst.cpp b/src/plugins/intel_gpu/src/graph/primitive_inst.cppindex 37c70e03b4b..944924f1051 100644--- a/src/plugins/intel_gpu/src/graph/primitive_inst.cpp+++ b/src/plugins/intel_gpu/src/graph/primitive_inst.cpp@@ -1660,17 +1660,20 @@ void primitive_inst::do_runtime_skip_scatter_update() {return;GPU_DEBUG_TRACE_DETAIL << "[do_runtime_skip_scatter_update] " << id() << " : check optimizability" << std::endl;+ const auto& input_layout = _impl_params->get_input_layout(0);+ const auto& output_layout = _impl_params->get_output_layout(0);const auto& idx_layout = _impl_params->get_input_layout(1);const auto& update_layout = _impl_params->get_input_layout(2);- if (idx_layout.count() > 0 && update_layout.count() > 0) {+ if ((idx_layout.count() > 0 && update_layout.count() > 0) || (get_node().is_type<scatter_elements_update>() && input_layout != output_layout)) {// set shape_change to realloc memory for same input shapesif (can_be_optimized()) {set_flag(ExecutionFlags::SHAPE_CHANGED);}set_can_be_optimized(false);GPU_DEBUG_TRACE_DETAIL << "--- Cannot optimize because idx_layout (" << idx_layout.to_short_string()- << ") and update_layout(" << update_layout.to_short_string() << ") are not zero" << std::endl;+ << ") and update_layout(" << update_layout.to_short_string() << ") are not zero"+ "or input layout is different than output layout" << std::endl;return;}diff --git a/src/plugins/intel_gpu/src/kernel_selector/kernels/scatter_update/scatter_elements_update_kernel_ref.cpp b/src/plugins/intel_gpu/src/kernel_selector/kernels/scatter_update/scatter_elements_update_kernel_ref.cppindex aec278b6f45..41f04063cbe 100644--- a/src/plugins/intel_gpu/src/kernel_selector/kernels/scatter_update/scatter_elements_update_kernel_ref.cpp+++ b/src/plugins/intel_gpu/src/kernel_selector/kernels/scatter_update/scatter_elements_update_kernel_ref.cpp@@ -163,6 +163,15 @@ bool ScatterElementsUpdateKernelRef::Validate(const Params& p) const {return true;}+bool ScatterElementsUpdateKernelRef::SkipKernelExecution(const scatter_elements_update_params& params, size_t kernel_id) const {+ if (kernel_id == 0) {+ if (params.outputs[0].LogicalSize() != 0 && params.outputs[0] != params.inputs[0]) {+ return false;+ }+ }+ return KernelData::SkipKernelExecution(params);+}+void ScatterElementsUpdateKernelRef::GetUpdateDispatchDataFunc(KernelData& kd) const {kd.update_dispatch_data_func = [this](const Params& params, KernelData& kd) {const auto& prim_params = static_cast<const scatter_elements_update_params&>(params);@@ -172,7 +181,7 @@ void ScatterElementsUpdateKernelRef::GetUpdateDispatchDataFunc(KernelData& kd) cauto dispatchData = SetDefault(prim_params, i == 1);kd.kernels[i].params.workGroups.global = dispatchData.gws;kd.kernels[i].params.workGroups.local = dispatchData.lws;- kd.kernels[i].skip_execution = KernelData::SkipKernelExecution(prim_params);+ kd.kernels[i].skip_execution = SkipKernelExecution(prim_params, i);}};}diff --git a/src/plugins/intel_gpu/src/kernel_selector/kernels/scatter_update/scatter_elements_update_kernel_ref.h b/src/plugins/intel_gpu/src/kernel_selector/kernels/scatter_update/scatter_elements_update_kernel_ref.hindex f6bc4c9da96..eba82d8cc5a 100644--- a/src/plugins/intel_gpu/src/kernel_selector/kernels/scatter_update/scatter_elements_update_kernel_ref.h+++ b/src/plugins/intel_gpu/src/kernel_selector/kernels/scatter_update/scatter_elements_update_kernel_ref.h@@ -34,6 +34,7 @@ public:protected:bool Validate(const Params& p) const override;+ bool SkipKernelExecution(const scatter_elements_update_params& params, size_t kernel_id) const;void GetUpdateDispatchDataFunc(KernelData& kd) const override;};} // namespace kernel_selectordiff --git a/src/plugins/intel_gpu/src/runtime/memory_pool.cpp b/src/plugins/intel_gpu/src/runtime/memory_pool.cppindex a899f78eb56..809471d4c55 100644--- a/src/plugins/intel_gpu/src/runtime/memory_pool.cpp+++ b/src/plugins/intel_gpu/src/runtime/memory_pool.cpp@@ -49,6 +49,10 @@ bool memory_pool::has_conflict(const memory_set& mem_cand,void memory_pool::release_memory(memory* mem, const size_t& unique_id, primitive_id prim_id, uint32_t network_id) {// check non padded pool firstauto _layout = mem->get_layout();+ if (_layout.is_dynamic()) {+ const auto max_shape = _layout.get_partial_shape().get_max_shape();+ _layout = _layout.clone_with_other_shape(max_shape);+ }auto type = mem->get_allocation_type();const auto _layout_bytes_count = _layout.bytes_count();