Skip to content

OpenVINO™ is an open source toolkit for optimizing and deploying AI inference

[GPU] added memory checks to fix add_output_chain function (#31997)

Michal Miotk8a9a8fb2e9e4
diff --git a/src/plugins/intel_gpu/src/graph/network.cpp b/src/plugins/intel_gpu/src/graph/network.cpp
index e5198595492..72310ad7ba1 100644
--- a/src/plugins/intel_gpu/src/graph/network.cpp
+++ b/src/plugins/intel_gpu/src/graph/network.cpp
@@ -396,12 +396,12 @@ network::output_chains_map::iterator network::add_output_chain(std::shared_ptr<p
// its attached memory with both its inputs and outputs
for (auto& dep : p_inst->dependencies()) {
// check dependencies
- if (eng.is_the_same_buffer(mem_orig, dep.first->output_memory())) {
+ if (dep.first->outputs_allocated() && eng.is_the_same_buffer(mem_orig, dep.first->output_memory())) {
chain.push_back(const_cast<primitive_inst*>(dep.first));
}
// then second order dependencies
for (auto& second_dep : dep.first->dependencies()) {
- if (eng.is_the_same_buffer(mem_orig, second_dep.first->output_memory())) {
+ if (second_dep.first->outputs_allocated() && eng.is_the_same_buffer(mem_orig, second_dep.first->output_memory())) {
chain.push_back(const_cast<primitive_inst*>(second_dep.first));
}
}
@@ -411,7 +411,7 @@ network::output_chains_map::iterator network::add_output_chain(std::shared_ptr<p
const auto& user_ids = mdata_ptr->get_user_ids();
for (const auto& id : user_ids) {
auto usr_prim = get_primitive(id).get();
- if (eng.is_the_same_buffer(mem_orig, usr_prim->output_memory())) {
+ if (usr_prim->outputs_allocated() && eng.is_the_same_buffer(mem_orig, usr_prim->output_memory())) {
chain.push_back(usr_prim);
}
}
@@ -428,10 +428,9 @@ network::output_chains_map::iterator network::add_output_chain(std::shared_ptr<p
while (!candidates.empty()) {
auto cand = candidates.top();
candidates.pop();
- const auto& mem_cand = cand->output_memory();
// Add cand inst to the chain when cand's output is not allocated yet.
if (!p_inst->outputs_allocated()
- || eng.is_the_same_buffer(mem_orig, mem_cand)) {
+ || (cand->outputs_allocated() && eng.is_the_same_buffer(mem_orig, cand->output_memory()))) {
auto nc_cand = const_cast<primitive_inst*>(cand);
chain.push_back(nc_cand);
add_mdata_chain(nc_cand);