[GPU] Fix a bug that occurred when the optimized layer is executed. (#13568)

This commit is contained in:
Jade Cho
2022-11-01 13:43:09 +09:00
committed by GitHub
parent d31c9b0b3a
commit 54ea15fbf9
8 changed files with 44 additions and 0 deletions

View File

@@ -256,4 +256,15 @@ void crop_inst::on_execute() {
void crop_inst::reuse_input() {
_outputs[0] = _network.get_engine().reinterpret_buffer(input_memory(), node->get_output_layout());
}
void crop_inst::update_output_memory() {
if (!node->can_be_optimized())
return;
if (_outputs[0] && _network.get_engine().is_the_same_buffer(output_memory(), input_memory()))
return;
_outputs[0] = _network.get_engine().reinterpret_buffer(input_memory(), node->get_output_layout());
}
} // namespace cldnn

View File

@@ -54,6 +54,7 @@ public:
static layout calc_output_layout(crop_node const& node, kernel_impl_params const& impl_param);
static std::string to_string(crop_node const& node);
typed_primitive_inst(network& network, crop_node const& node);
void update_output_memory() override;
private:
void on_execute() override;

View File

@@ -197,6 +197,8 @@ public:
layout get_node_output_layout() const { return _node_output_layout; }
virtual void update_output_memory() {}
protected:
primitive_inst(network& network, program_node const& node, bool allocate_memory);

View File

@@ -67,6 +67,8 @@ public:
bool has_mean() const { return !argument->mean.empty(); }
void update_output_memory() override;
private:
void on_execute() override;
void reuse_input();

View File

@@ -51,6 +51,8 @@ public:
typed_primitive_inst(network& network, reshape_node const& node);
void update_output_memory() override;
private:
void on_execute() override;

View File

@@ -643,6 +643,15 @@ void network::allocate_primitives() {
}
}
}
// Update the output memory address of optimized-out layer if it is not valid.
for (auto const& node : po) {
if (node->can_be_optimized()) {
auto opt_inst = _primitives.at(node->id());
opt_inst->update_output_memory();
}
}
// allocate intermediate buffers
for (auto const& node : po) {
auto prim = _primitives[node->id()];

View File

@@ -243,6 +243,13 @@ void reorder_inst::on_execute() {
}
void reorder_inst::reuse_input() {
update_output_memory();
}
void reorder_inst::update_output_memory() {
if (!node->can_be_optimized())
return;
if (static_cast<bool>(_outputs[0]) && _network.get_engine().is_the_same_buffer(output_memory(), input_memory()))
return;

View File

@@ -189,6 +189,16 @@ void reshape_inst::on_execute() {
}
void reshape_inst::reuse_input() {
update_output_memory();
}
void reshape_inst::update_output_memory() {
if (!node->can_be_optimized())
return;
if (_outputs[0] && _network.get_engine().is_the_same_buffer(output_memory(), input_memory()))
return;
build_deps(); // reshape need deps
OPENVINO_ASSERT(input_memory_ptr() != nullptr, "[GPU] Failed to reuse input in ", id(), " primitive: input memory was not allocated");
_outputs = {_network.get_engine().reinterpret_buffer(input_memory(), _impl_params->output_layout)};