[GPU] Fixed node.is_dynamic() check to check regardless output size is valid or not (#14173)
* Fixed node.is_dynamic() check to check regardless output size is valid or not * Additional fixes & added unittest
This commit is contained in:
@@ -67,7 +67,7 @@ struct concat_in_place_optimization : pattern_match_optimization_typed<concat_in
|
||||
bool concat_noop_optimization::match(concatenation_node& node) {
|
||||
if (node.is_output() && !get_program().is_debug_build())
|
||||
return false;
|
||||
if (node.is_valid_output_layout() && node.get_output_layout().is_dynamic())
|
||||
if (node.is_dynamic())
|
||||
return false;
|
||||
return node.get_dependencies().size() == 1 &&
|
||||
!node.has_fused_primitives() &&
|
||||
@@ -88,7 +88,7 @@ bool concat_in_place_optimization::match(concatenation_node& node) {
|
||||
return false;
|
||||
if (node.has_fused_primitives() || !node.get_fused_activations_funcs().empty())
|
||||
return false;
|
||||
if (node.is_valid_output_layout() && node.get_output_layout().is_dynamic())
|
||||
if (node.is_dynamic())
|
||||
return false;
|
||||
|
||||
bool is_onednn_impl = false;
|
||||
@@ -315,7 +315,7 @@ void prepare_buffer_fusing::run(program& p) {
|
||||
If crop is before concat there can be padding mismtach, since concat changes padding.
|
||||
*/
|
||||
auto can_optimize = [](const program_node* node) {
|
||||
if ((node->is_valid_output_layout() && node->get_output_layout().is_dynamic()) || node->is_output() || (!node->get_fused_activations_funcs().empty())) {
|
||||
if ((node->is_dynamic()) || node->is_output() || (!node->get_fused_activations_funcs().empty())) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
||||
@@ -140,7 +140,7 @@ void prepare_padding::run(program& p) {
|
||||
continue;
|
||||
|
||||
auto conv = node.get_primitive();
|
||||
if (node.is_valid_output_layout() && node.is_dynamic()) continue;
|
||||
if (node.is_dynamic()) continue;
|
||||
auto& conv_input_node = node.get_dependency(0);
|
||||
auto conv_layout = node.get_output_layout();
|
||||
|
||||
@@ -230,7 +230,7 @@ void prepare_padding::run(program& p) {
|
||||
if (node.get_dependencies().empty())
|
||||
continue;
|
||||
|
||||
if (node.is_valid_output_layout() && node.is_dynamic()) continue;
|
||||
if (node.is_dynamic()) continue;
|
||||
auto conv = node.get_primitive();
|
||||
auto& conv_input_node = node.get_dependency(0);
|
||||
auto conv_layout = node.get_output_layout();
|
||||
|
||||
@@ -222,6 +222,9 @@ public:
|
||||
bool is_dynamic() const;
|
||||
bool is_dynamic();
|
||||
|
||||
bool is_dynamic_output_layout(size_t idx = 0) const;
|
||||
bool is_dynamic_output_layout(size_t idx = 0);
|
||||
|
||||
bool is_padded() { return static_cast<bool>(get_output_layout().data_padding); }
|
||||
bool is_padded() const { return static_cast<bool>(get_output_layout().data_padding); }
|
||||
|
||||
|
||||
@@ -371,11 +371,15 @@ bool program_node::is_dynamic() const {
|
||||
}
|
||||
}
|
||||
for (const auto* input : get_dependencies()) {
|
||||
if (input->get_output_layout().is_dynamic())
|
||||
if (input->is_dynamic_output_layout())
|
||||
return true;
|
||||
}
|
||||
|
||||
return get_output_layout().is_dynamic();
|
||||
for (size_t i = 0; i < output_layouts.size(); ++i) {
|
||||
if (output_layouts[i].is_dynamic())
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool program_node::is_dynamic() {
|
||||
@@ -391,11 +395,23 @@ bool program_node::is_dynamic() {
|
||||
}
|
||||
|
||||
for (auto& input : get_dependencies()) {
|
||||
if (input->get_output_layout(true).is_dynamic())
|
||||
if (input->is_dynamic_output_layout())
|
||||
return true;
|
||||
}
|
||||
|
||||
return get_output_layout(true).is_dynamic();
|
||||
for (size_t i = 0; i < output_layouts.size(); ++i) {
|
||||
if (output_layouts[i].is_dynamic())
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool program_node::is_dynamic_output_layout(size_t idx) const {
|
||||
return (output_layouts[idx].is_dynamic()) || (output_layouts[idx].get_partial_shape().size() == 0);
|
||||
}
|
||||
|
||||
bool program_node::is_dynamic_output_layout(size_t idx) {
|
||||
return (output_layouts[idx].is_dynamic()) || (output_layouts[idx].get_partial_shape().size() == 0);
|
||||
}
|
||||
|
||||
bool program_node::has_padded_dependency() {
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
// Copyright (C) 2018-2022 Intel Corporation
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
#include "test_utils.h"
|
||||
|
||||
#include "intel_gpu/runtime/engine.hpp"
|
||||
|
||||
#include "intel_gpu/graph/program.hpp"
|
||||
#include "data_inst.h"
|
||||
#include "reshape_inst.h"
|
||||
#include "permute_inst.h"
|
||||
#include "intel_gpu/graph/network.hpp"
|
||||
#include "pass_manager.h"
|
||||
#include "to_string_utils.h"
|
||||
|
||||
#include "program_wrapper.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
using namespace cldnn;
|
||||
using namespace ::tests;
|
||||
|
||||
TEST(prepare_buffer_fusing, optimize_reshape) {
|
||||
auto& engine = get_test_engine();
|
||||
auto in_layout = layout{ ov::PartialShape::dynamic(4), data_types::f32, format::bfyx };
|
||||
auto pattern_layout = layout{ov::PartialShape::dynamic(4), data_types::i64, format::bfyx};
|
||||
topology topology;
|
||||
topology.add(input_layout("input", in_layout));
|
||||
topology.add(input_layout("pattern", pattern_layout));
|
||||
topology.add(permute("permute1", "input", {0, 2, 3, 1}));
|
||||
topology.add(reshape("reshape", "permute1", "pattern", false, ov::PartialShape::dynamic(4)));
|
||||
topology.add(permute("permute2", "reshape", {0, 3, 2, 1}));
|
||||
topology.add(reorder("reorder", "permute2", format::bfyx, data_types::f32));
|
||||
|
||||
build_options build_opts;
|
||||
build_opts.set_option(build_option::allow_new_shape_infer(true));
|
||||
auto prog = program::build_program(engine, topology, build_opts, false, true);
|
||||
|
||||
program_wrapper::apply_opt_pass<prepare_buffer_fusing>(*prog);
|
||||
|
||||
ASSERT_NE(prog, nullptr);
|
||||
ASSERT_TRUE(has_node_with_type<reshape>(*prog));
|
||||
|
||||
cldnn::network net(prog, 0);
|
||||
|
||||
auto input_memory = engine.allocate_memory(layout{ ov::PartialShape{1, 2, 2, 4}, data_types::f16, format::bfyx });
|
||||
auto pattern_memory = engine.allocate_memory(layout{ ov::PartialShape{4}, data_types::i64, format::bfyx });
|
||||
set_values<float>(input_memory, {0.1, 1.1, 2.2, 3.0, 4.0, -5.0, 0.1, 0.7, 4.8, 19.2, -10.1, 8.1, 10.2, 1.3, 1.44, 1.5});
|
||||
set_values<int64_t>(pattern_memory, {1, 4, 1, -1});
|
||||
|
||||
net.set_input_data("input", input_memory);
|
||||
net.set_input_data("pattern", pattern_memory);
|
||||
std::map<cldnn::primitive_id, cldnn::network_output> output;
|
||||
EXPECT_NO_THROW(output = net.execute());
|
||||
auto out_l = net.get_output_layout("reorder");
|
||||
auto out_mem = output.at("reorder").get_memory();
|
||||
|
||||
ASSERT_NE(out_mem, nullptr);
|
||||
ASSERT_EQ(out_mem->count(), 16);
|
||||
}
|
||||
Reference in New Issue
Block a user