Skip to content

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

[GPU] Improvement of event-related primitives code (#27337)

Vladimir Paramuzovf72d95857bb0
diff --git a/src/plugins/intel_gpu/include/intel_gpu/graph/kernel_impl_params.hpp b/src/plugins/intel_gpu/include/intel_gpu/graph/kernel_impl_params.hpp
index 24b13e740be..2d6a3fc8213 100644
--- a/src/plugins/intel_gpu/include/intel_gpu/graph/kernel_impl_params.hpp
+++ b/src/plugins/intel_gpu/include/intel_gpu/graph/kernel_impl_params.hpp
@@ -25,6 +25,13 @@ struct program;
struct network;
+struct ExecutionFlags : public std::bitset<4> {
+ static const size_t SHAPE_CHANGED = 0;
+ static const size_t IMPL_CHANGED = 1;
+ static const size_t MEMORY_CHANGED = 2;
+ static const size_t SKIP = 3;
+};
+
struct kernel_impl_params final {
struct Hasher {
size_t operator()(const kernel_impl_params &k) const {
@@ -48,6 +55,11 @@ struct kernel_impl_params final {
std::shared_ptr<dnnl::primitive_attr> attrs_onednn;
#endif // ENABLE_ONEDNN_FOR_GPU
+ std::vector<event::ptr> dep_events = {};
+ event::ptr out_event = nullptr;
+
+ ExecutionFlags flags;
+
optional_layout weights_layout = optional_layout();
optional_layout bias_layout = optional_layout();
diff --git a/src/plugins/intel_gpu/include/intel_gpu/graph/network.hpp b/src/plugins/intel_gpu/include/intel_gpu/graph/network.hpp
index f4e09a51513..f6207e25a5c 100644
--- a/src/plugins/intel_gpu/include/intel_gpu/graph/network.hpp
+++ b/src/plugins/intel_gpu/include/intel_gpu/graph/network.hpp
@@ -36,7 +36,7 @@ struct network_output {
// TODO: in_order queue doesn't create proper output event in some cases which leads to syncronization issues with user app
// So call finish for associated stream to enusre that the output data is ready.
if (do_sync) {
- if (_stream->get_queue_type() == QueueTypes::in_order) {
+ if (_stream->get_queue_type() == QueueTypes::in_order || !_event) {
_stream->finish();
} else {
_event->wait();
@@ -167,12 +167,10 @@ public:
std::shared_ptr<const primitive_inst> get_primitive(const primitive_id& id) const;
std::string get_primitive_info(const primitive_id& id) const;
std::string get_implementation_info(const primitive_id& id) const;
- const event::ptr& get_primitive_event(const primitive_id& id) const { return _events.at(id); }
- bool has_event(const primitive_id& id) const { return _events.count(id); }
+ const event::ptr& get_primitive_event(const primitive_id& id) const;
+ bool has_event(const primitive_id& id) const;
std::vector<primitive_inst*> get_primitives(const std::vector<primitive_id>& ids);
std::vector<std::pair<primitive_inst*, int>> get_primitives(const std::vector<std::pair<program_node*, int>>& nodes);
- void execute_primitive(const std::shared_ptr<primitive_inst>& primitive,
- const std::vector<event::ptr>& events);
void allocate_primitives();
void configure_primitives_second_output();
void build_insts_deps();
@@ -231,9 +229,6 @@ private:
program::primitives_info _prims_info;
size_t _weights_cache_capacity = 1;
- std::unordered_map<primitive_id, event::ptr> _events;
- // This map is used to temporarily hold events that will be deallocated later
- std::unordered_map<primitive_id, event::ptr> _old_events;
output_chains_map _output_chains;
std::shared_ptr<ShapePredictor> _shape_predictor;
diff --git a/src/plugins/intel_gpu/include/intel_gpu/runtime/stream.hpp b/src/plugins/intel_gpu/include/intel_gpu/runtime/stream.hpp
index d990f356333..b7c2d214668 100644
--- a/src/plugins/intel_gpu/include/intel_gpu/runtime/stream.hpp
+++ b/src/plugins/intel_gpu/include/intel_gpu/runtime/stream.hpp
@@ -69,6 +69,7 @@ public:
virtual event::ptr aggregate_events(const std::vector<event::ptr>& events, bool group = false, bool is_output = false);
QueueTypes get_queue_type() const { return m_queue_type; }
+ SyncMethods get_sync_method() const { return m_sync_method; }
static QueueTypes detect_queue_type(engine_types engine_type, void* queue_handle);
static SyncMethods get_expected_sync_method(const ExecutionConfig& config);
diff --git a/src/plugins/intel_gpu/src/graph/impls/common/condition.cpp b/src/plugins/intel_gpu/src/graph/impls/common/condition.cpp
index c29ecce61d7..9b226378527 100644
--- a/src/plugins/intel_gpu/src/graph/impls/common/condition.cpp
+++ b/src/plugins/intel_gpu/src/graph/impls/common/condition.cpp
@@ -40,7 +40,6 @@ struct condition_impl : typed_primitive_impl<condition> {
events[0]->wait();
auto& stream = instance.get_network().get_stream();
- auto ev = stream.create_user_event(false);
set_node_params(instance.get_node());
auto pred = condition_inst::get_pred_from_memory(instance.pred_memory_ptr(), stream);
diff --git a/src/plugins/intel_gpu/src/graph/impls/common/loop.cpp b/src/plugins/intel_gpu/src/graph/impls/common/loop.cpp
index 3523b420d22..5039338a085 100644
--- a/src/plugins/intel_gpu/src/graph/impls/common/loop.cpp
+++ b/src/plugins/intel_gpu/src/graph/impls/common/loop.cpp
@@ -1,6 +1,7 @@
// Copyright (C) 2018-2024 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
+#include "intel_gpu/graph/kernel_impl_params.hpp"
#include "loop_inst.h"
#include "impls/registry/implementation_map.hpp"
#include "register.hpp"
@@ -122,7 +123,7 @@ struct loop_impl : typed_primitive_impl<loop> {
if (is_dynamic) {
instance.update_shape();
- if (instance.shape_changed()) {
+ if (instance.get_flag(ExecutionFlags::SHAPE_CHANGED)) {
instance.preproc_memories_done = false;
instance.reset_memory();
}
@@ -198,9 +199,7 @@ struct loop_impl : typed_primitive_impl<loop> {
// If there are concatenated_input_mem_mappings or backedge_memory_mappings we need to wait for
// previous tasks before accessing memory in get_sliced_mem() and setup_iteration() functions
if (!concatenated_input_mem_mappings.empty() || !backedge_memory_mappings.empty()) {
- for (auto& e : events) {
- e->wait();
- }
+ stream.wait_for_events(events);
}
// Set sliced input data
diff --git a/src/plugins/intel_gpu/src/graph/impls/common/wait_for_events.cpp b/src/plugins/intel_gpu/src/graph/impls/common/wait_for_events.cpp
index 17a6beaeee0..bb735a19c06 100644
--- a/src/plugins/intel_gpu/src/graph/impls/common/wait_for_events.cpp
+++ b/src/plugins/intel_gpu/src/graph/impls/common/wait_for_events.cpp
@@ -37,8 +37,7 @@ public:
event::ptr execute(const std::vector<event::ptr>& events, primitive_inst& instance) override {
auto& stream = instance.get_network().get_stream();
- return events.empty() ? stream.create_user_event(true)
- : stream.enqueue_marker(events);
+ return stream.aggregate_events(events);
}
static std::unique_ptr<primitive_impl> create_data(const data_node& data, const kernel_impl_params&) {
diff --git a/src/plugins/intel_gpu/src/graph/impls/cpu/activation.cpp b/src/plugins/intel_gpu/src/graph/impls/cpu/activation.cpp
index 1ec8c9458cf..a6ef4036c2d 100644
--- a/src/plugins/intel_gpu/src/graph/impls/cpu/activation.cpp
+++ b/src/plugins/intel_gpu/src/graph/impls/cpu/activation.cpp
@@ -2,6 +2,7 @@
// SPDX-License-Identifier: Apache-2.0
//
+#include "impls/cpu/cpu_impl_helpers.hpp"
#include "openvino/core/type/element_type_traits.hpp"
#include "register.hpp"
#include "activation_inst.h"
@@ -143,9 +144,7 @@ struct activation_impl : public typed_primitive_impl<activation> {
const bool pass_through_events = (stream.get_queue_type() == QueueTypes::out_of_order) && instance.all_dependencies_cpu_impl();
if (!pass_through_events) {
- for (auto e : events) {
- e->wait();
- }
+ stream.wait_for_events(events);
}
if (!op) {
@@ -276,14 +275,10 @@ struct activation_impl : public typed_primitive_impl<activation> {
}
if (pass_through_events) {
- if (events.size() > 1) {
- return stream.group_events(events);
- } else if (events.size() == 1) {
- return events[0];
- }
+ return stream.group_events(events);
}
- return stream.create_user_event(true);
+ return make_output_event(stream, instance.is_output());
}
void init_kernels(const kernels_cache& , const kernel_impl_params&) override {}
diff --git a/src/plugins/intel_gpu/src/graph/impls/cpu/assign.cpp b/src/plugins/intel_gpu/src/graph/impls/cpu/assign.cpp
index d03c49fb28e..9e1aca1203e 100644
--- a/src/plugins/intel_gpu/src/graph/impls/cpu/assign.cpp
+++ b/src/plugins/intel_gpu/src/graph/impls/cpu/assign.cpp
@@ -52,9 +52,7 @@ struct assign_impl : public typed_primitive_impl<assign> {
auto& stream = instance.get_network().get_stream();
- for (auto e : events) {
- e->wait();
- }
+ stream.wait_for_events(events);
const auto ev_set_memory = variable.get_memory()->copy_from(stream, instance.input_memory());
variable.set();
diff --git a/src/plugins/intel_gpu/src/graph/impls/cpu/broadcast.cpp b/src/plugins/intel_gpu/src/graph/impls/cpu/broadcast.cpp
index 7abd3a141c1..bb159019053 100644
--- a/src/plugins/intel_gpu/src/graph/impls/cpu/broadcast.cpp
+++ b/src/plugins/intel_gpu/src/graph/impls/cpu/broadcast.cpp
@@ -2,6 +2,7 @@
// SPDX-License-Identifier: Apache-2.0
//
+#include "impls/cpu/cpu_impl_helpers.hpp"
#include "register.hpp"
#include "broadcast_inst.h"
#include "impls/registry/implementation_map.hpp"
@@ -63,9 +64,7 @@ struct broadcast_impl : public typed_primitive_impl<broadcast> {
const bool pass_through_events = (stream.get_queue_type() == QueueTypes::out_of_order) && instance.all_dependencies_cpu_impl();
if (!pass_through_events) {
- for (auto e : events) {
- e->wait();
- }
+ stream.wait_for_events(events);
}
auto params = instance.get_impl_params();
@@ -110,14 +109,10 @@ struct broadcast_impl : public typed_primitive_impl<broadcast> {
input_mem_ptrs[i]->unlock(stream);
if (pass_through_events) {
- if (events.size() > 1) {
- return stream.group_events(events);
- } else if (events.size() == 1) {
- return events[0];
- }
+ return stream.group_events(events);
}
- return stream.create_user_event(true);
+ return make_output_event(stream, instance.is_output());
}
void init_kernels(const kernels_cache& , const kernel_impl_params&) override {}
diff --git a/src/plugins/intel_gpu/src/graph/impls/cpu/concat.cpp b/src/plugins/intel_gpu/src/graph/impls/cpu/concat.cpp
index a7d3beb5b94..c542ab21a20 100644
--- a/src/plugins/intel_gpu/src/graph/impls/cpu/concat.cpp
+++ b/src/plugins/intel_gpu/src/graph/impls/cpu/concat.cpp
@@ -2,6 +2,7 @@
// SPDX-License-Identifier: Apache-2.0
//
+#include "impls/cpu/cpu_impl_helpers.hpp"
#include "register.hpp"
#include "concatenation_inst.h"
#include "impls/registry/implementation_map.hpp"
@@ -54,9 +55,7 @@ struct concatenation_impl : public typed_primitive_impl<concatenation> {
const bool pass_through_events = (stream.get_queue_type() == QueueTypes::out_of_order) && instance.all_dependencies_cpu_impl();
if (!pass_through_events) {
- for (auto e : events) {
- e->wait();
- }
+ stream.wait_for_events(events);
}
auto params = instance.get_impl_params();
@@ -97,14 +96,10 @@ struct concatenation_impl : public typed_primitive_impl<concatenation> {
input_mem_ptrs[i]->unlock(stream);
if (pass_through_events) {
- if (events.size() > 1) {
- return stream.group_events(events);
- } else if (events.size() == 1) {
- return events[0];
- }
+ return stream.group_events(events);
}
- return stream.create_user_event(true);
+ return make_output_event(stream, instance.is_output());
}
void init_kernels(const kernels_cache& , const kernel_impl_params&) override {}
diff --git a/src/plugins/intel_gpu/src/graph/impls/cpu/cpu_impl_helpers.hpp b/src/plugins/intel_gpu/src/graph/impls/cpu/cpu_impl_helpers.hpp
index bdbd9bcb989..891a536b063 100644
--- a/src/plugins/intel_gpu/src/graph/impls/cpu/cpu_impl_helpers.hpp
+++ b/src/plugins/intel_gpu/src/graph/impls/cpu/cpu_impl_helpers.hpp
@@ -7,6 +7,9 @@
#include <algorithm>
#include <vector>
+#include "intel_gpu/runtime/event.hpp"
+#include "intel_gpu/runtime/stream.hpp"
+
namespace cldnn {
namespace cpu {
@@ -74,5 +77,11 @@ using vector3D = vector2D<vector1D<T>>;
template <typename T>
using vector4D = vector2D<vector2D<T>>;
+inline event::ptr make_output_event(cldnn::stream& stream, bool is_output) {
+ if (is_output)
+ return stream.create_user_event(true);
+ return nullptr;
+}
+
} // namespace cpu
} // namespace cldnn
diff --git a/src/plugins/intel_gpu/src/graph/impls/cpu/crop.cpp b/src/plugins/intel_gpu/src/graph/impls/cpu/crop.cpp
index c8041f44a78..816f4e1cb1e 100644
--- a/src/plugins/intel_gpu/src/graph/impls/cpu/crop.cpp
+++ b/src/plugins/intel_gpu/src/graph/impls/cpu/crop.cpp
@@ -2,6 +2,7 @@
// SPDX-License-Identifier: Apache-2.0
//
+#include "impls/cpu/cpu_impl_helpers.hpp"
#include "register.hpp"
#include "crop_inst.h"
#include "impls/registry/implementation_map.hpp"
@@ -40,9 +41,7 @@ struct crop_impl : public typed_primitive_impl<crop> {
const bool pass_through_events = (stream.get_queue_type() == QueueTypes::out_of_order) && instance.all_dependencies_cpu_impl();
if (!pass_through_events) {
- for (auto e : events) {
- e->wait();
- }
+ stream.wait_for_events(events);
}
auto params = instance.get_impl_params();
@@ -97,14 +96,10 @@ struct crop_impl : public typed_primitive_impl<crop> {
"[GPU] Couldn't execute crop primitive with id ", instance.id());
if (pass_through_events) {
- if (events.size() > 1) {
- return stream.group_events(events);
- } else if (events.size() == 1) {
- return events[0];
- }
+ return stream.group_events(events);
}
- return stream.create_user_event(true);
+ return make_output_event(stream, instance.is_output());
}
void init_kernels(const kernels_cache& , const kernel_impl_params&) override {}
diff --git a/src/plugins/intel_gpu/src/graph/impls/cpu/detection_output.cpp b/src/plugins/intel_gpu/src/graph/impls/cpu/detection_output.cpp
index 25676ea3e9a..637578fb014 100644
--- a/src/plugins/intel_gpu/src/graph/impls/cpu/detection_output.cpp
+++ b/src/plugins/intel_gpu/src/graph/impls/cpu/detection_output.cpp
@@ -830,9 +830,7 @@ public:
const bool pass_through_events = (stream.get_queue_type() == QueueTypes::out_of_order) && instance.all_dependencies_cpu_impl();
if (!pass_through_events) {
- for (auto e : events) {
- e->wait();
- }
+ stream.wait_for_events(events);
}
const int num_of_images = instance.location_memory()->get_layout().batch(); // batch size
@@ -851,14 +849,10 @@ public:
}
if (pass_through_events) {
- if (events.size() > 1) {
- return stream.group_events(events);
- } else if (events.size() == 1) {
- return events[0];
- }
+ return stream.group_events(events);
}
- return stream.create_user_event(true);
+ return make_output_event(stream, instance.is_output());
}
void init_kernels(const kernels_cache& , const kernel_impl_params&) override {}
diff --git a/src/plugins/intel_gpu/src/graph/impls/cpu/eltwise.cpp b/src/plugins/intel_gpu/src/graph/impls/cpu/eltwise.cpp
index 057686f9c2d..314749bf4a9 100644
--- a/src/plugins/intel_gpu/src/graph/impls/cpu/eltwise.cpp
+++ b/src/plugins/intel_gpu/src/graph/impls/cpu/eltwise.cpp
@@ -3,6 +3,7 @@
//
#include "eltwise_inst.h"
+#include "impls/cpu/cpu_impl_helpers.hpp"
#include "impls/registry/implementation_map.hpp"
#include "openvino/op/add.hpp"
#include "openvino/op/bitwise_and.hpp"
@@ -84,9 +85,7 @@ struct eltwise_impl : public typed_primitive_impl<eltwise> {
const bool pass_through_events = (stream.get_queue_type() == QueueTypes::out_of_order) && instance.all_dependencies_cpu_impl();
if (!pass_through_events) {
- for (auto e : events) {
- e->wait();
- }
+ stream.wait_for_events(events);
}
auto params = instance.get_impl_params();
@@ -210,14 +209,10 @@ struct eltwise_impl : public typed_primitive_impl<eltwise> {
input_mem_ptrs[i]->unlock(stream);
if (pass_through_events) {
- if (events.size() > 1) {
- return stream.group_events(events);
- } else if (events.size() == 1) {
- return events[0];
- }
+ return stream.group_events(events);
}
- return stream.create_user_event(true);
+ return make_output_event(stream, instance.is_output());
}
void init_kernels(const kernels_cache& , const kernel_impl_params&) override {}
diff --git a/src/plugins/intel_gpu/src/graph/impls/cpu/gather.cpp b/src/plugins/intel_gpu/src/graph/impls/cpu/gather.cpp
index 733e143b2c2..130ee6f8181 100644
--- a/src/plugins/intel_gpu/src/graph/impls/cpu/gather.cpp
+++ b/src/plugins/intel_gpu/src/graph/impls/cpu/gather.cpp
@@ -2,6 +2,7 @@
// SPDX-License-Identifier: Apache-2.0
//
+#include "impls/cpu/cpu_impl_helpers.hpp"
#include "register.hpp"
#include "gather_inst.h"
#include "impls/registry/implementation_map.hpp"
@@ -62,9 +63,7 @@ struct gather_impl : public typed_primitive_impl<gather> {
const bool pass_through_events = (stream.get_queue_type() == QueueTypes::out_of_order) && instance.all_dependencies_cpu_impl();
if (!pass_through_events) {
- for (auto e : events) {
- e->wait();
- }
+ stream.wait_for_events(events);
}
auto params = instance.get_impl_params();
@@ -100,14 +99,10 @@ struct gather_impl : public typed_primitive_impl<gather> {
input_mem_ptrs[i]->unlock(stream);
if (pass_through_events) {
- if (events.size() > 1) {
- return stream.group_events(events);
- } else if (events.size() == 1) {
- return events[0];
- }
+ return stream.group_events(events);
}
- return stream.create_user_event(true);
+ return make_output_event(stream, instance.is_output());
}
void init_kernels(const kernels_cache& , const kernel_impl_params&) override {}
diff --git a/src/plugins/intel_gpu/src/graph/impls/cpu/non_max_suppression.cpp b/src/plugins/intel_gpu/src/graph/impls/cpu/non_max_suppression.cpp
index 446a277866f..a9dc38b476a 100644
--- a/src/plugins/intel_gpu/src/graph/impls/cpu/non_max_suppression.cpp
+++ b/src/plugins/intel_gpu/src/graph/impls/cpu/non_max_suppression.cpp
@@ -406,22 +406,17 @@ struct non_max_suppression_impl : typed_primitive_impl<non_max_suppression> {
const bool pass_through_events = (stream.get_queue_type() == QueueTypes::out_of_order) && instance.all_dependencies_cpu_impl();
if (!pass_through_events) {
- for (auto e : events) {
- e->wait();
- }
+ stream.wait_for_events(events);
}
run(instance);
+
if (pass_through_events) {
- if (events.size() > 1) {
- return stream.group_events(events);
- } else if (events.size() == 1) {
- return events[0];
- }
+ return stream.group_events(events);
}
- return stream.create_user_event(true);
+ return make_output_event(stream, instance.is_output());
}
static std::unique_ptr<primitive_impl> create(const non_max_suppression_node&, const kernel_impl_params&) {
@@ -458,20 +453,14 @@ struct non_max_suppression_gather_impl : typed_primitive_impl<non_max_suppressio
const bool pass_through_events = (stream.get_queue_type() == QueueTypes::out_of_order) && instance.all_dependencies_cpu_impl();
if (!pass_through_events) {
- for (auto e : events) {
- e->wait();
- }
+ stream.wait_for_events(events);
}
if (pass_through_events) {
- if (events.size() > 1) {
- return stream.group_events(events);
- } else if (events.size() == 1) {
- return events[0];
- }
+ return stream.group_events(events);
}
- return stream.create_user_event(true);
+ return make_output_event(stream, instance.is_output());
}
static std::unique_ptr<primitive_impl> create(const non_max_suppression_gather_node&, const kernel_impl_params&) {
diff --git a/src/plugins/intel_gpu/src/graph/impls/cpu/proposal.cpp b/src/plugins/intel_gpu/src/graph/impls/cpu/proposal.cpp
index b295ee5f84c..ea4a3c30d30 100644
--- a/src/plugins/intel_gpu/src/graph/impls/cpu/proposal.cpp
+++ b/src/plugins/intel_gpu/src/graph/impls/cpu/proposal.cpp
@@ -2,6 +2,7 @@
// SPDX-License-Identifier: Apache-2.0
//
+#include "impls/cpu/cpu_impl_helpers.hpp"
#include "proposal_inst.h"
#include "intel_gpu/runtime/engine.hpp"
#include "impls/registry/implementation_map.hpp"
@@ -391,9 +392,7 @@ struct proposal_impl : typed_primitive_impl<proposal> {
const bool pass_through_events = (stream.get_queue_type() == QueueTypes::out_of_order) && instance.all_dependencies_cpu_impl();
if (!pass_through_events) {
- for (auto e : events) {
- e->wait();
- }
+ stream.wait_for_events(events);
}
im_info_t im_info;
@@ -432,16 +431,11 @@ struct proposal_impl : typed_primitive_impl<proposal> {
execute<ov::element_type_traits<data_types::f32>::value_type>(stream, instance, im_info);
}
}
-
if (pass_through_events) {
- if (events.size() > 1) {
- return stream.group_events(events);
- } else if (events.size() == 1) {
- return events[0];
- }
+ return stream.group_events(events);
}
- return stream.create_user_event(true);
+ return make_output_event(stream, instance.is_output());
}
void init_kernels(const kernels_cache&, const kernel_impl_params&) override {}
diff --git a/src/plugins/intel_gpu/src/graph/impls/cpu/range.cpp b/src/plugins/intel_gpu/src/graph/impls/cpu/range.cpp
index 439bbf5aa4e..9d4aafb812c 100644
--- a/src/plugins/intel_gpu/src/graph/impls/cpu/range.cpp
+++ b/src/plugins/intel_gpu/src/graph/impls/cpu/range.cpp
@@ -2,6 +2,7 @@
// SPDX-License-Identifier: Apache-2.0
//
+#include "impls/cpu/cpu_impl_helpers.hpp"
#include "register.hpp"
#include "range_inst.h"
#include "impls/registry/implementation_map.hpp"
@@ -40,9 +41,7 @@ struct range_impl : public typed_primitive_impl<range> {
const bool pass_through_events = (stream.get_queue_type() == QueueTypes::out_of_order) && instance.all_dependencies_cpu_impl();
if (!pass_through_events) {
- for (auto e : events) {
- e->wait();
- }
+ stream.wait_for_events(events);
}
auto params = instance.get_impl_params();
@@ -77,14 +76,10 @@ struct range_impl : public typed_primitive_impl<range> {
input_mem_ptrs[i]->unlock(stream);
if (pass_through_events) {
- if (events.size() > 1) {
- return stream.group_events(events);
- } else if (events.size() == 1) {
- return events[0];
- }
+ return stream.group_events(events);
}
- return stream.create_user_event(true);
+ return make_output_event(stream, instance.is_output());
}
void init_kernels(const kernels_cache& , const kernel_impl_params&) override {}
diff --git a/src/plugins/intel_gpu/src/graph/impls/cpu/read_value.cpp b/src/plugins/intel_gpu/src/graph/impls/cpu/read_value.cpp
index da7e95c4ab7..09734a68aca 100644
--- a/src/plugins/intel_gpu/src/graph/impls/cpu/read_value.cpp
+++ b/src/plugins/intel_gpu/src/graph/impls/cpu/read_value.cpp
@@ -2,6 +2,7 @@
// SPDX-License-Identifier: Apache-2.0
//
+#include "impls/cpu/cpu_impl_helpers.hpp"
#include "read_value_inst.h"
#include "impls/registry/implementation_map.hpp"
#include "register.hpp"
@@ -46,12 +47,9 @@ struct read_value_impl : public typed_primitive_impl<read_value> {
}
event::ptr execute_impl(const std::vector<event::ptr>& events, read_value_inst& instance) override {
- for (auto e : events) {
- e->wait();
- }
-
auto& variable = instance.get_network().get_variable(variable_id);
auto &stream = instance.get_network().get_stream();
+ stream.wait_for_events(events);
OPENVINO_ASSERT(variable.get_layout() == instance.get_output_layout(),
"[GPU] Layout mismatch: variable layout: ", variable.get_layout().to_short_string(),
@@ -83,7 +81,7 @@ struct read_value_impl : public typed_primitive_impl<read_value> {
return stream.aggregate_events(res_events, res_events.size() > 1);
}
- return instance.get_network().get_stream().create_user_event(true);
+ return make_output_event(stream, instance.is_output());
}
void init_kernels(const kernels_cache& , const kernel_impl_params&) override {}
diff --git a/src/plugins/intel_gpu/src/graph/impls/cpu/reduce.cpp b/src/plugins/intel_gpu/src/graph/impls/cpu/reduce.cpp
index dd6284a3dd7..af1a6d0d950 100644
--- a/src/plugins/intel_gpu/src/graph/impls/cpu/reduce.cpp
+++ b/src/plugins/intel_gpu/src/graph/impls/cpu/reduce.cpp
@@ -2,6 +2,7 @@
// SPDX-License-Identifier: Apache-2.0
//
+#include "impls/cpu/cpu_impl_helpers.hpp"
#include "register.hpp"
#include "reduce_inst.h"
#include "impls/registry/implementation_map.hpp"
@@ -80,9 +81,7 @@ struct reduce_impl : public typed_primitive_impl<reduce> {
const bool pass_through_events = (stream.get_queue_type() == QueueTypes::out_of_order) && instance.all_dependencies_cpu_impl();
if (!pass_through_events) {
- for (auto e : events) {
- e->wait();
- }
+ stream.wait_for_events(events);
}
auto params = instance.get_impl_params();
@@ -137,14 +136,10 @@ struct reduce_impl : public typed_primitive_impl<reduce> {
"[GPU] Couldn't execute reduce primitive with id ", instance.id());
if (pass_through_events) {
- if (events.size() > 1) {
- return stream.group_events(events);
- } else if (events.size() == 1) {
- return events[0];
- }
+ return stream.group_events(events);
}
- return stream.create_user_event(true);
+ return make_output_event(stream, instance.is_output());
}
void init_kernels(const kernels_cache& , const kernel_impl_params&) override {}
diff --git a/src/plugins/intel_gpu/src/graph/impls/cpu/reorder.cpp b/src/plugins/intel_gpu/src/graph/impls/cpu/reorder.cpp
index 6e4202f815d..fc7eb5329c3 100644
--- a/src/plugins/intel_gpu/src/graph/impls/cpu/reorder.cpp
+++ b/src/plugins/intel_gpu/src/graph/impls/cpu/reorder.cpp
@@ -2,6 +2,7 @@
// SPDX-License-Identifier: Apache-2.0
//
+#include "impls/cpu/cpu_impl_helpers.hpp"
#include "register.hpp"
#include "reorder_inst.h"
#include "impls/registry/implementation_map.hpp"
@@ -40,9 +41,7 @@ struct reorder_impl : public typed_primitive_impl<reorder> {
const bool pass_through_events = (stream.get_queue_type() == QueueTypes::out_of_order) && instance.all_dependencies_cpu_impl();
if (!pass_through_events) {
- for (auto e : events) {
- e->wait();
- }
+ stream.wait_for_events(events);
}
auto params = instance.get_impl_params();
@@ -70,14 +69,10 @@ struct reorder_impl : public typed_primitive_impl<reorder> {
"[GPU] Couldn't execute reorder primitive with id ", instance.id());
if (pass_through_events) {
- if (events.size() > 1) {
- return stream.group_events(events);
- } else if (events.size() == 1) {
- return events[0];
- }
+ return stream.group_events(events);
}
- return stream.create_user_event(true);
+ return make_output_event(stream, instance.is_output());
}
void init_kernels(const kernels_cache& , const kernel_impl_params&) override {}
diff --git a/src/plugins/intel_gpu/src/graph/impls/cpu/scatter_update.cpp b/src/plugins/intel_gpu/src/graph/impls/cpu/scatter_update.cpp
index 94a12dadddb..7e2b2beadf7 100644
--- a/src/plugins/intel_gpu/src/graph/impls/cpu/scatter_update.cpp
+++ b/src/plugins/intel_gpu/src/graph/impls/cpu/scatter_update.cpp
@@ -2,6 +2,7 @@
// SPDX-License-Identifier: Apache-2.0
//
+#include "impls/cpu/cpu_impl_helpers.hpp"
#include "register.hpp"
#include "scatter_update_inst.h"
#include "impls/registry/implementation_map.hpp"
@@ -54,9 +55,7 @@ struct scatter_update_impl : public typed_primitive_impl<scatter_update> {
const bool pass_through_events = (stream.get_queue_type() == QueueTypes::out_of_order) && instance.all_dependencies_cpu_impl();
if (!pass_through_events) {
- for (auto e : events) {
- e->wait();
- }
+ stream.wait_for_events(events);
}
auto params = instance.get_impl_params();
@@ -92,14 +91,10 @@ struct scatter_update_impl : public typed_primitive_impl<scatter_update> {
input_mem_ptrs[i]->unlock(stream);
if (pass_through_events) {
- if (events.size() > 1) {
- return stream.group_events(events);
- } else if (events.size() == 1) {
- return events[0];
- }
+ return stream.group_events(events);
}
- return stream.create_user_event(true);
+ return make_output_event(stream, instance.is_output());
}
void init_kernels(const kernels_cache& , const kernel_impl_params&) override {}
diff --git a/src/plugins/intel_gpu/src/graph/impls/cpu/select.cpp b/src/plugins/intel_gpu/src/graph/impls/cpu/select.cpp
index 78df55d5c7c..7c9c501bedf 100644
--- a/src/plugins/intel_gpu/src/graph/impls/cpu/select.cpp
+++ b/src/plugins/intel_gpu/src/graph/impls/cpu/select.cpp
@@ -2,6 +2,7 @@
// SPDX-License-Identifier: Apache-2.0
//
+#include "impls/cpu/cpu_impl_helpers.hpp"
#include "register.hpp"
#include "select_inst.h"
#include "impls/registry/implementation_map.hpp"
@@ -53,9 +54,7 @@ struct select_impl : public typed_primitive_impl<select> {
const bool pass_through_events = (stream.get_queue_type() == QueueTypes::out_of_order) && instance.all_dependencies_cpu_impl();
if (!pass_through_events) {
- for (auto e : events) {
- e->wait();
- }
+ stream.wait_for_events(events);
}
auto params = instance.get_impl_params();
@@ -87,14 +86,10 @@ struct select_impl : public typed_primitive_impl<select> {
input_mem_ptrs[i]->unlock(stream);
if (pass_through_events) {
- if (events.size() > 1) {
- return stream.group_events(events);
- } else if (events.size() == 1) {
- return events[0];
- }
+ return stream.group_events(events);
}
- return stream.create_user_event(true);
+ return make_output_event(stream, instance.is_output());
}
void init_kernels(const kernels_cache& , const kernel_impl_params&) override {}
diff --git a/src/plugins/intel_gpu/src/graph/impls/cpu/shape_of.cpp b/src/plugins/intel_gpu/src/graph/impls/cpu/shape_of.cpp
index 983987f9fed..458abdd3934 100644
--- a/src/plugins/intel_gpu/src/graph/impls/cpu/shape_of.cpp
+++ b/src/plugins/intel_gpu/src/graph/impls/cpu/shape_of.cpp
@@ -2,6 +2,7 @@
// SPDX-License-Identifier: Apache-2.0
//
+#include "impls/cpu/cpu_impl_helpers.hpp"
#include "register.hpp"
#include "shape_of_inst.h"
#include "impls/registry/implementation_map.hpp"
@@ -59,14 +60,10 @@ struct shape_of_impl : public typed_primitive_impl<shape_of> {
}
if (pass_through_events) {
- if (events.size() > 1) {
- return stream.group_events(events);
- } else if (events.size() == 1) {
- return events[0];
- }
+ return stream.group_events(events);
}
- return stream.create_user_event(true);
+ return make_output_event(stream, instance.is_output());
}
void init_kernels(const kernels_cache& , const kernel_impl_params&) override {}
diff --git a/src/plugins/intel_gpu/src/graph/impls/cpu/strided_slice.cpp b/src/plugins/intel_gpu/src/graph/impls/cpu/strided_slice.cpp
index ac9032fe466..3013e591956 100644
--- a/src/plugins/intel_gpu/src/graph/impls/cpu/strided_slice.cpp
+++ b/src/plugins/intel_gpu/src/graph/impls/cpu/strided_slice.cpp
@@ -2,6 +2,7 @@
// SPDX-License-Identifier: Apache-2.0
//
+#include "impls/cpu/cpu_impl_helpers.hpp"
#include "register.hpp"
#include "strided_slice_inst.h"
#include "impls/registry/implementation_map.hpp"
@@ -90,9 +91,7 @@ struct strided_slice_impl : public typed_primitive_impl<strided_slice> {
const bool pass_through_events = (stream.get_queue_type() == QueueTypes::out_of_order) && instance.all_dependencies_cpu_impl();
if (!pass_through_events) {
- for (auto e : events) {
- e->wait();
- }
+ stream.wait_for_events(events);
}
auto params = instance.get_impl_params();
@@ -166,14 +165,10 @@ struct strided_slice_impl : public typed_primitive_impl<strided_slice> {
output_mem_ptr->unlock(stream);
if (pass_through_events) {
- if (events.size() > 1) {
- return stream.group_events(events);
- } else if (events.size() == 1) {
- return events[0];
- }
+ return stream.group_events(events);
}
- return stream.create_user_event(true);
+ return make_output_event(stream, instance.is_output());
}
void init_kernels(const kernels_cache& , const kernel_impl_params&) override {}
diff --git a/src/plugins/intel_gpu/src/graph/impls/cpu/tile.cpp b/src/plugins/intel_gpu/src/graph/impls/cpu/tile.cpp
index 1f53781aedc..a1877c7b408 100644
--- a/src/plugins/intel_gpu/src/graph/impls/cpu/tile.cpp
+++ b/src/plugins/intel_gpu/src/graph/impls/cpu/tile.cpp
@@ -2,6 +2,7 @@
// SPDX-License-Identifier: Apache-2.0
//
+#include "impls/cpu/cpu_impl_helpers.hpp"
#include "register.hpp"
#include "tile_inst.h"
#include "impls/registry/implementation_map.hpp"
@@ -53,9 +54,7 @@ struct tile_impl : public typed_primitive_impl<tile> {
const bool pass_through_events = (stream.get_queue_type() == QueueTypes::out_of_order) && instance.all_dependencies_cpu_impl();
if (!pass_through_events) {
- for (auto e : events) {
- e->wait();
- }
+ stream.wait_for_events(events);
}
auto params = instance.get_impl_params();
@@ -94,14 +93,10 @@ struct tile_impl : public typed_primitive_impl<tile> {
input_mem_ptrs[i]->unlock(stream);
if (pass_through_events) {
- if (events.size() > 1) {
- return stream.group_events(events);
- } else if (events.size() == 1) {
- return events[0];
- }
+ return stream.group_events(events);
}
- return stream.create_user_event(true);
+ return make_output_event(stream, instance.is_output());
}
void init_kernels(const kernels_cache& , const kernel_impl_params&) override {}
diff --git a/src/plugins/intel_gpu/src/graph/impls/onednn/primitive_onednn_base.h b/src/plugins/intel_gpu/src/graph/impls/onednn/primitive_onednn_base.h
index 6a8f2cb57d2..275748da311 100644
--- a/src/plugins/intel_gpu/src/graph/impls/onednn/primitive_onednn_base.h
+++ b/src/plugins/intel_gpu/src/graph/impls/onednn/primitive_onednn_base.h
@@ -534,7 +534,7 @@ protected:
if (_enable_profiling) {
if (instance.can_be_optimized()) {
- event = stream.create_user_event(true);
+ event = nullptr;
} else {
dnnl::reset_profiling(stream.get_onednn_stream());
}
diff --git a/src/plugins/intel_gpu/src/graph/impls/sycl/primitive_sycl_base.h b/src/plugins/intel_gpu/src/graph/impls/sycl/primitive_sycl_base.h
index e937808bc00..e52bf365bd7 100644
--- a/src/plugins/intel_gpu/src/graph/impls/sycl/primitive_sycl_base.h
+++ b/src/plugins/intel_gpu/src/graph/impls/sycl/primitive_sycl_base.h
@@ -45,9 +45,9 @@ protected:
for (auto& e : native_events) {
events.push_back(std::make_shared<ocl::ocl_event>(cl::Event(e, true)));
}
- return events.empty() ? stream.create_user_event(true) : stream.group_events(events);
+ return stream.aggregate_events(events);
} else {
- return stream.create_user_event(true);
+ return nullptr;
}
}
diff --git a/src/plugins/intel_gpu/src/graph/include/primitive_inst.h b/src/plugins/intel_gpu/src/graph/include/primitive_inst.h
index 430d2652bb9..fffcd100d96 100644
--- a/src/plugins/intel_gpu/src/graph/include/primitive_inst.h
+++ b/src/plugins/intel_gpu/src/graph/include/primitive_inst.h
@@ -3,6 +3,7 @@
//
#pragma once
+#include "intel_gpu/graph/kernel_impl_params.hpp"
#include "intel_gpu/primitives/primitive.hpp"
#include "intel_gpu/primitives/concatenation.hpp"
#include "intel_gpu/runtime/event.hpp"
@@ -232,7 +233,19 @@ public:
memory::ptr shape_info_memory_ptr() const { return _shape_info_memory; }
- event::ptr execute(const std::vector<event::ptr>& events);
+ void add_dep_events(const std::vector<event::ptr>& events);
+ void add_dep_event(event::ptr ev);
+ void set_out_event(event::ptr&& ev);
+
+ void set_flag(size_t flag, bool value = true);
+ void unset_flag(size_t flag);
+ bool get_flag(size_t flag) const;
+ void reset_flags();
+
+ void reset_events();
+
+ void prepare_primitive();
+ void execute();
void init_kernels(const kernels_cache& kernels_cache) {
_impl->init_kernels(kernels_cache, *_impl_params);
}
@@ -242,13 +255,6 @@ public:
void validate() const {
OPENVINO_ASSERT(_impl != nullptr || is_dynamic(), "[GPU] Invalid impl object for ", id(), " primitive");
}
- bool output_changed() const { return _output_changed; }
- void reset_output_change() { _output_changed = false; }
-
- bool shape_changed() const { return _shape_changed; }
- bool mem_changed() const { return _mem_changed; }
- void reset_shape_change() { _shape_changed = false; }
- void set_shape_change() { _shape_changed = true; }
void build_deps();
@@ -337,6 +343,7 @@ protected:
bool update_shape_done_by_other = false;
bool allocation_done_by_other = false;
+ bool _use_shared_kernels = false;
std::unique_ptr<kernel_impl_params> _impl_params;
std::shared_ptr<primitive_impl> _impl;
std::shared_ptr<ImplementationsFactory> _impls_factory = nullptr;
@@ -378,9 +385,6 @@ protected:
// Buffer to store actual shapes of dynamic tensor which is automatically asigned as 1st argument to shape agnostic kernels
memory::ptr _shape_info_memory = nullptr;
- bool _output_changed; // todo: implement output reuse if neither of inputs has changed
- bool _shape_changed = false;
- bool _mem_changed = false;
bool _has_valid_input =
true; // by default all primitives has valid inputs, exception is input_layout (see input_layout_inst)
bool _has_mutable_input = false;
@@ -417,13 +421,13 @@ protected:
virtual void on_execute() {}
virtual void update_shape();
- virtual event::ptr update_weights();
+ virtual void update_weights();
void fill_shape_info_data(const layout& runtime_layout, const layout& node_layout, int32_t* shape_info_ptr, size_t& offset);
bool use_async_compilation();
// if primitive_inst doesn't replace impl to new impl(static impl with opt kerenl or dynamic impl), return false
- bool update_impl(bool use_async_compilation);
- event::ptr realloc_if_needed();
+ void update_impl(bool use_async_compilation);
+ void realloc_if_needed();
cldnn::network::ptr get_unfused_subgraph();
diff --git a/src/plugins/intel_gpu/src/graph/input_layout.cpp b/src/plugins/intel_gpu/src/graph/input_layout.cpp
index 042744517a7..9c60cd18740 100644
--- a/src/plugins/intel_gpu/src/graph/input_layout.cpp
+++ b/src/plugins/intel_gpu/src/graph/input_layout.cpp
@@ -2,6 +2,7 @@
// SPDX-License-Identifier: Apache-2.0
//
#include "input_layout_inst.h"
+#include "intel_gpu/graph/kernel_impl_params.hpp"
#include "primitive_type_base.h"
#include "intel_gpu/runtime/memory.hpp"
#include "json_object.h"
@@ -50,7 +51,6 @@ event::ptr input_layout_inst::set_data(memory::ptr mem) {
if (mem->is_allocated_by(engine) || mem->get_layout().count() == 0) {
OPENVINO_ASSERT(!_outputs.empty(), "[GPU] Can't set data for empty input memory");
_outputs[0] = mem;
- ev = stream.create_user_event(true);
} else {
if (_outputs.empty() || !_outputs[0]) {
_outputs.resize(1);
@@ -64,7 +64,6 @@ event::ptr input_layout_inst::set_data(memory::ptr mem) {
ev = _outputs[0]->copy_from(stream, src.data(), false);
}
_has_valid_input = true;
- _output_changed = true;
return ev;
}
@@ -72,7 +71,7 @@ void input_layout_inst::update_shape() {
OPENVINO_ASSERT(!_outputs.empty() && _outputs[0] != nullptr, "[GPU] input memory is not set");
auto mem_layout = _outputs[0]->get_layout();
if (_impl_params->get_output_layout() != mem_layout) {
- set_shape_change();
+ set_flag(ExecutionFlags::SHAPE_CHANGED);
}
_impl_params->output_layouts[0] = mem_layout;
}
diff --git a/src/plugins/intel_gpu/src/graph/loop.cpp b/src/plugins/intel_gpu/src/graph/loop.cpp
index 57f52a412df..15dc768b824 100644
--- a/src/plugins/intel_gpu/src/graph/loop.cpp
+++ b/src/plugins/intel_gpu/src/graph/loop.cpp
@@ -375,7 +375,7 @@ loop_inst::concatenated_memory_mapping::ptr loop_inst::create_concat_memory_map(
if (extern_mem_ptr != nullptr) {
layout sliced_layout = intern_prim->get_output_layout(internal_id.idx);
auto inter_mem_ptr = intern_prim->output_memory_ptr(internal_id.idx);
- if (inter_mem_ptr == nullptr || shape_changed()) {
+ if (inter_mem_ptr == nullptr || get_flag(ExecutionFlags::SHAPE_CHANGED)) {
// if inner body intern_prim has no output memory because it has dynamic shape,
// calculate inner body intern_prim layout using concat_mem's layout.
auto updated_sliced_layout = sliced_layout.get_partial_shape();
@@ -720,7 +720,7 @@ void loop_inst::postprocess_output_memory(bool is_dynamic, int64_t current_itera
}
}
} else {
- if (!output_allocated || shape_changed()) {
+ if (!output_allocated || get_flag(ExecutionFlags::SHAPE_CHANGED)) {
auto concat_layout = _impl_params->get_output_layout(external_id.idx);
auto concat_mem = ov::intel_gpu::allocate_memory_evenif_zero_bytes(_network.get_engine(), concat_layout, false);
external_outputs[external_id.idx] = concat_mem;
diff --git a/src/plugins/intel_gpu/src/graph/network.cpp b/src/plugins/intel_gpu/src/graph/network.cpp
index 24a103379a0..37bceb53396 100644
--- a/src/plugins/intel_gpu/src/graph/network.cpp
+++ b/src/plugins/intel_gpu/src/graph/network.cpp
@@ -2,6 +2,7 @@
// SPDX-License-Identifier: Apache-2.0
//
+#include "intel_gpu/graph/kernel_impl_params.hpp"
#include "intel_gpu/plugin/variable_state.hpp"
#include "intel_gpu/primitives/read_value.hpp"
@@ -307,26 +308,8 @@ void network::set_arguments() {
void network::reset_execution(bool wait) {
if (wait) {
- auto queue_type = get_config().get_property(ov::intel_gpu::queue_type);
- if (queue_type == QueueTypes::in_order) {
- get_stream().finish();
- } else if (queue_type == QueueTypes::out_of_order && _events.size() > 0) {
- std::vector<event::ptr> events;
- for (auto& pair : _events) {
- auto& ev = pair.second;
- if (ev->is_set())
- continue;
-
- events.push_back(ev);
- }
-
- get_stream().wait_for_events(events);
- }
+ get_stream().finish();
}
-
- // Move events to temporarily map to deallocate them at the end of network::execute() call for better overlapping with
- // kernels execution, since it may take significant time for high amount of events
- _old_events = std::move(_events);
}
event::ptr network::set_input_data(const primitive_id& id, memory::ptr data) {
@@ -730,20 +713,31 @@ std::map<primitive_id, network_output> network::execute(const std::vector<event:
event::ptr ev = nullptr;
const auto& id = inst->id();
if (get_stream().get_queue_type() == QueueTypes::out_of_order || _enable_profiling)
- ev = _events.at(id);
+ ev = inst->get_impl_params()->out_event;
result.emplace(id, network_output(ev, inst->output_memory_ptr(0), get_stream_ptr(), inst->get_output_layout(0)));
}
return result;
}
+const event::ptr& network::get_primitive_event(const primitive_id& id) const {
+ return get_primitive(id)->get_impl_params()->out_event;
+}
+
+bool network::has_event(const primitive_id& id) const {
+ auto it = _primitives.find(id);
+ if (it == _primitives.end())
+ return false;
+
+ return it->second->get_impl_params()->out_event != nullptr;
+}
+
void network::execute_impl(const std::vector<event::ptr>& events) {
set_arguments();
// This extra flush command is needed for dynamic models in both cases of out_of_order / in_order operating mode
// since it reduces `bubbles` number in pipeline and GPU's idle time by timely flushing new kernels to device.
// The freqency of flushing (16) is selected empirically, see details in tickets 116365, 116287, 139931.
- const bool is_out_of_order_queue = get_stream().get_queue_type() == QueueTypes::out_of_order;
const bool needs_flushing = _is_dynamic;
const size_t flush_frequency = needs_flushing ? 16 : 0;
size_t executed_prims = 0;
@@ -751,50 +745,18 @@ void network::execute_impl(const std::vector<event::ptr>& events) {
for (auto& inst : _exec_order) {
NODE_DEBUG(*inst);
- execute_primitive(inst, events);
- executed_prims++;
- if (needs_flushing && executed_prims % flush_frequency == 0)
- get_stream().flush();
- }
+ inst->reset_events();
- // Store events only in case of OOO queue or enabled Profiling
- auto store_events = is_out_of_order_queue || _enable_profiling;
- if (store_events) {
- if (_program != nullptr) {
- for (auto& inst : _program->get_processing_order()) {
- // Special handling for mutable data. The event should be the same as the user or dependency with highest
- // processing_num as the mutable_data can be updated when is both user or dependency.
- if (inst->is_type<mutable_data>()) {
- decltype(_program->get_processing_order().get_processing_number(inst)) proc_num = 0;
- for (auto& user : inst->get_users()) {
- auto user_proc_num = _program->get_processing_order().get_processing_number(user);
- if (user_proc_num > proc_num) {
- _events[inst->id()] = _events[user->id()];
- proc_num = user_proc_num;
- }
- }
-
- if (!inst->get_dependencies().empty()) {
- for (auto& dep : inst->get_dependencies()) {
- auto dep_proc_num = _program->get_processing_order().get_processing_number(dep.first);
- if (dep_proc_num > proc_num) {
- _events[inst->id()] = _events[dep.first->id()];
- proc_num = dep_proc_num;
- }
- }
- }
- }
- }
+ if (inst->is_input()) {
+ inst->add_dep_events(events);
}
- for (auto& dout : _data_outputs) { // data primitives are not executed so if they are marked as output we need to add
- // them valid events manually
- _events[dout->id()] = get_stream().create_user_event(true);
- }
- }
+ inst->prepare_primitive();
+ inst->execute();
- for (auto& prim : _primitives) {
- prim.second->reset_output_change();
+ executed_prims++;
+ if (needs_flushing && executed_prims % flush_frequency == 0)
+ get_stream().flush();
}
// Using output of previous network as input to another one may cause hazard (in OOOQ mode) if user would not
@@ -802,8 +764,10 @@ void network::execute_impl(const std::vector<event::ptr>& events) {
// In scenarios with a big number of very small networks it can provide performance drop.
get_stream().flush();
- // Deallocate events from the previos iteration
- _old_events.clear();
+ // Reset all flags for the next execution
+ for (auto& inst : _exec_order) {
+ inst->reset_flags();
+ }
}
std::vector<primitive_id> network::get_input_ids() const {
@@ -905,20 +869,6 @@ std::vector<std::pair<primitive_inst*, int>> network::get_primitives(const std::
return result;
}
-void network::execute_primitive(const std::shared_ptr<primitive_inst>& primitive,
- const std::vector<event::ptr>& events) {
- event::ptr ev = primitive->execute(events);
-
- // Collect events under any of the following conditions:
- // 1) OOO queue execution
- // 2) Profiling mode is enabled
- // 3) Primitive has CPU user or primitive is output
- if (get_stream().get_queue_type() == QueueTypes::out_of_order || _enable_profiling || primitive->needs_completion_event()) {
- auto id = primitive->id();
- _events.insert({id, ev});
- }
-}
-
void network::allocate_primitive_instance(program_node const& node) {
if (_primitives.count(node.id()))
return;
diff --git a/src/plugins/intel_gpu/src/graph/primitive_inst.cpp b/src/plugins/intel_gpu/src/graph/primitive_inst.cpp
index e5276ed678b..dac2c9a3403 100644
--- a/src/plugins/intel_gpu/src/graph/primitive_inst.cpp
+++ b/src/plugins/intel_gpu/src/graph/primitive_inst.cpp
@@ -2,6 +2,7 @@
// SPDX-License-Identifier: Apache-2.0
//
+#include "intel_gpu/graph/kernel_impl_params.hpp"
#include "intel_gpu/primitives/implementation_desc.hpp"
#include "intel_gpu/runtime/stream.hpp"
#include "program_helpers.h"
@@ -256,7 +257,7 @@ event::ptr primitive_inst::set_output_memory(memory::ptr mem_new, bool check, si
// skip all the buzz if no action actually required
event::ptr ev = nullptr;
if (_outputs[idx] && eng.is_the_same_buffer(*mem_new, *_outputs[idx])) {
- return get_network().get_stream().create_user_event(true);
+ return nullptr;
}
const auto& ol = _impl_params->get_output_layout(idx);
@@ -267,7 +268,6 @@ event::ptr primitive_inst::set_output_memory(memory::ptr mem_new, bool check, si
if (is_constant()) {
ev = mem_new->copy_from(_network.get_stream(), *_outputs[idx], false);
} else {
- ev = get_network().get_stream().create_user_event(true);
_outputs[idx] = mem_new;
}
return ev;
@@ -349,21 +349,16 @@ void primitive_inst::update_shape() {
}
}
- if (input_shape_changed)
- set_shape_change();
- else
- reset_shape_change();
+ set_flag(ExecutionFlags::SHAPE_CHANGED, input_shape_changed);
// We assume that tensor ranks are static, thus shape_of doesn't need to update anything even if input shape is dynamic
if (_node->is_type<shape_of>() && !input_shape_changed) {
- reset_shape_change();
return;
}
// if input shape is not changed, loop doesn't need to update anything.
// because actual output layout will be calculated after the end of body network execution.
if (_node->is_type<loop>() && !input_shape_changed) {
- reset_shape_change();
return;
}
@@ -371,14 +366,14 @@ void primitive_inst::update_shape() {
if (_node->is_in_shape_of_subgraph()) {
bool subgraph_input_changed = false;
for (size_t i = 0; i < dependant_shape_of_insts.size(); i++) {
- if (dependant_shape_of_insts[i]->shape_changed()) {
+ if (dependant_shape_of_insts[i]->get_flag(ExecutionFlags::SHAPE_CHANGED)) {
subgraph_input_changed = true;
break;
}
}
if (!subgraph_input_changed) {
GPU_DEBUG_TRACE_DETAIL << id() << ": skip shape_update, because it is in shape_of_subgraph and input shape is not changed\n";
- reset_shape_change();
+ unset_flag(ExecutionFlags::SHAPE_CHANGED);
return;
}
}
@@ -398,7 +393,7 @@ void primitive_inst::update_shape() {
bool can_skip = true;
const auto& insts = _deps[i].first->dependant_shape_of_insts;
for (auto& inst : insts) {
- can_skip &= !inst->shape_changed();
+ can_skip &= !inst->get_flag(ExecutionFlags::SHAPE_CHANGED);
}
if (can_skip)
continue;
@@ -439,8 +434,9 @@ void primitive_inst::update_shape() {
has_runtime_deps = true;
// Events may be not created for in-order queue, so take them for OOO queue only
- if (queue_type == QueueTypes::out_of_order && _network.has_event(dep->id())) {
- dependencies_events.push_back(_network.get_primitive_event(dep->id()));
+ if (queue_type == QueueTypes::out_of_order && dep->get_impl_params()->out_event) {
+ dependencies_events.push_back(dep->get_impl_params()->out_event);
+
GPU_DEBUG_TRACE_DETAIL << id() << ": shape infer waits for " << i << " dependency\n";
}
}
@@ -470,7 +466,7 @@ void primitive_inst::update_shape() {
if (_impl_params->get_output_layout(idx) != new_layout) {
GPU_DEBUG_TRACE_DETAIL << id() << ": update shape: was: " << _impl_params->get_output_layout(idx).to_short_string()
<< " now: " << new_layout.to_short_string() << std::endl;
- set_shape_change();
+ set_flag(ExecutionFlags::SHAPE_CHANGED);
}
_impl_params->output_layouts[idx].data_padding = new_layout.data_padding;
@@ -508,7 +504,7 @@ void primitive_inst::update_shape() {
auto var_mem_size = get_network().get_variable(desc->variable_info.variable_id).get_actual_mem_size();
// Need to trigger realloc_if_needed
if (var_mem_size < _impl_params->get_output_layout(0).get_linear_size())
- set_shape_change();
+ set_flag(ExecutionFlags::SHAPE_CHANGED);
}
}
@@ -553,12 +549,11 @@ bool primitive_inst::all_dependencies_cpu_impl() const {
return check_all_deps_cpu(this);
}
-event::ptr primitive_inst::realloc_if_needed() {
+void primitive_inst::realloc_if_needed() {
OV_ITT_SCOPED_TASK(ov::intel_gpu::itt::domains::intel_gpu_plugin, openvino::itt::handle("realloc_if_needed: " + id()));
GPU_DEBUG_GET_INSTANCE(debug_config);
GPU_DEBUG_PROFILED_STAGE(instrumentation::pipeline_stage::memory_allocation);
- event::ptr ev = nullptr;
const auto& users = get_user_insts();
if (users.size() == 1 && users.front()->get_node().is_type<concatenation>() && users.front()->get_node().is_runtime_skippable()) {
auto concat_inst = users.front();
@@ -569,7 +564,7 @@ event::ptr primitive_inst::realloc_if_needed() {
}
this->_outputs[0] = concat_inst->_outputs[0];
GPU_DEBUG_TRACE_DETAIL << id() << ": use concat user's memory " << this->_outputs[0]->buffer_ptr() << std::endl;
- return ev;
+ return;
}
}
@@ -581,7 +576,7 @@ event::ptr primitive_inst::realloc_if_needed() {
// input_layout node is supposed to always use external memory in dynamic case
if (_node->is_type<input_layout>())
- return ev;
+ return;
auto& sp = *get_network().get_shape_predictor();
std::vector<size_t> dt_sizes_in_B;
@@ -615,7 +610,7 @@ event::ptr primitive_inst::realloc_if_needed() {
for (size_t j = 0; j < _impl_params->output_layouts.size(); ++j)
sp.predict_preallocation_shape(id(), _impl_params->output_layouts[j], true, j);
GPU_DEBUG_PROFILED_STAGE_MEMALLOC_INFO("can_be_optimized");
- return ev;
+ return;
} else if (_outputs[0] && variable.get_memory() && get_network().get_engine().is_the_same_buffer(*_outputs[0], *variable.get_memory())) {
GPU_DEBUG_TRACE_DETAIL << id() << " : realloc_if_needed: Reset output mem" << std::endl;
for (size_t j = 0; j < _impl_params->output_layouts.size(); ++j) {
@@ -652,7 +647,7 @@ event::ptr primitive_inst::realloc_if_needed() {
}
}
GPU_DEBUG_PROFILED_STAGE_MEMALLOC_INFO("can_be_optimized");
- return ev;
+ return;
}
}
@@ -712,11 +707,11 @@ event::ptr primitive_inst::realloc_if_needed() {
// since update_Shape is already called in realloc_if_needed of current node's dep node
// but current node's output layout is not updated to the this user node yet.
user->update_shape_done_by_other = false;
- bool prev_shape_changed = user->shape_changed();
+ bool prev_shape_changed = user->get_flag(ExecutionFlags::SHAPE_CHANGED);
user->update_shape();
// Set again shape_change status if shape is changed in the prev udpate_shape() for this user node.
if (prev_shape_changed)
- user->set_shape_change();
+ user->set_flag(ExecutionFlags::SHAPE_CHANGED);
user->update_shape_done_by_other = true;
auto fc_impl_params = *user->_impl_params;
auto fc_input_layout = user->get_node().type()->get_fake_aligned_params(fc_impl_params).input_layouts[0];
@@ -775,7 +770,7 @@ event::ptr primitive_inst::realloc_if_needed() {
reset_user_output_memory(user_inst, dep_memory_ptr(0));
}
}
- return ev;
+ return;
} else if (_outputs[0] && dep_memory_ptr(0) &&
_network.get_engine().is_the_same_buffer(dep_memory(0), output_memory(0))) {
if (mem_allocated()) {
@@ -857,7 +852,7 @@ event::ptr primitive_inst::realloc_if_needed() {
if (_node->is_type<concatenation>() && can_be_optimized() && allocation_done_by_other) {
allocation_done_by_other = false;
GPU_DEBUG_PROFILED_STAGE_MEMALLOC_INFO("concat_alloc_by_other");
- return ev;
+ return;
}
for (size_t i = 0; i < actual_layouts.size(); ++i) {
@@ -899,14 +894,14 @@ event::ptr primitive_inst::realloc_if_needed() {
i == 0 ? "present_layout" : "present_scales_layout");
kv_cache_inst::update_pad(present_layout, max_pad, sequence_axis);
GPU_DEBUG_TRACE_DETAIL << i << ". " << _impl_params->output_layouts[i].to_string() << std::endl;
- set_shape_change();
+ set_flag(ExecutionFlags::SHAPE_CHANGED);
} else {
_outputs[i] = _network.get_engine().reinterpret_buffer(*_outputs[i], actual_layouts[i]);
}
// TODO: check need_reset_output_memory per output
if (need_reset_output_memory() && !can_be_optimized()) {
GPU_DEBUG_TRACE_DETAIL << id() << " : Need reset output memory considering user" << std::endl;
- ev = _outputs[i]->fill(_network.get_stream());
+ add_dep_event(_outputs[i]->fill(_network.get_stream()));
}
GPU_DEBUG_PROFILED_STAGE_MEMALLOC_INFO("reuse_buffer");
} else {
@@ -928,6 +923,7 @@ event::ptr primitive_inst::realloc_if_needed() {
output_memory_ptr(i).get(),
true);
_max_output_layout_count[i] = updated_params.output_layouts[i].get_linear_size();
+ set_flag(ExecutionFlags::MEMORY_CHANGED);
GPU_DEBUG_CODE(std::string memalloc_info = "");
GPU_DEBUG_CODE(memalloc_info += (((_outputs.size() > 1) ? ("o" + to_string(i) + ":") : "") +
(_outputs[i]->from_memory_pool ? "from_pool" : "new_alloc"));)
@@ -982,7 +978,7 @@ event::ptr primitive_inst::realloc_if_needed() {
kv_cache_inst::update_pad(present_layout, max_pad, sequence_axis);
if (!axis_is_outer_most) {
GPU_DEBUG_TRACE_DETAIL << id() << ": Update impl with new output padding" << std::endl;
- set_shape_change();
+ set_flag(ExecutionFlags::SHAPE_CHANGED);
_impl_params->output_layouts[0] = present_layout;
update_impl(use_async_compilation());
}
@@ -1032,10 +1028,10 @@ event::ptr primitive_inst::realloc_if_needed() {
// intermediate memory allocation is required for primitives consisting of multiple kernels in dynamic case
{
if (_impl == nullptr)
- return ev;
+ return;
const auto& ibuf_layouts = _impl->get_internal_buffer_layouts();
if (ibuf_layouts.empty())
- return ev;
+ return;
GPU_DEBUG_CODE(std::string memalloc_info = "");
for (size_t i = 0; i < ibuf_layouts.size(); ++i) {
if (i < _intermediates_memory.size() && ibuf_layouts[i].bytes_count() <= max_intermediates_memory_sizes[i]) {
@@ -1061,7 +1057,6 @@ event::ptr primitive_inst::realloc_if_needed() {
}
GPU_DEBUG_PROFILED_STAGE_MEMALLOC_INFO(memalloc_info);
}
- return ev;
}
bool primitive_inst::use_async_compilation() {
@@ -1157,7 +1152,7 @@ void primitive_inst::update_shape_info_tensor(const kernel_impl_params& params)
}
}
-bool primitive_inst::update_impl(bool use_async_compilation) {
+void primitive_inst::update_impl(bool use_async_compilation) {
OV_ITT_SCOPED_TASK(ov::intel_gpu::itt::domains::intel_gpu_plugin, openvino::itt::handle("update_impl: " + id()));
GPU_DEBUG_PROFILED_STAGE(instrumentation::pipeline_stage::update_implementation);
auto prev_impl_str = _impl != nullptr ? _impl->get_kernel_name() : "nullptr";
@@ -1165,13 +1160,15 @@ bool primitive_inst::update_impl(bool use_async_compilation) {
// no need to update impl for optimized out primitive
if (_impl != nullptr && can_be_optimized()) {
GPU_DEBUG_TRACE_DETAIL << id() << " Skip impl update: primitive is optimized out" << std::endl;
- return shape_changed();
+ set_flag(ExecutionFlags::IMPL_CHANGED, get_flag(ExecutionFlags::SHAPE_CHANGED));
+ return;
}
// Assume that we have already picked optimal impl
- if (!shape_changed() && _impl && _impl->is_dynamic() && !use_async_compilation) {
+ if (!get_flag(ExecutionFlags::SHAPE_CHANGED) && _impl && _impl->is_dynamic() && !use_async_compilation) {
GPU_DEBUG_TRACE_DETAIL << id() << " Skip impl update: shape not changed, optimal static impl is used" << std::endl;
- return false;
+ unset_flag(ExecutionFlags::IMPL_CHANGED);
+ return;
}
if (!_node->is_type<data>() && !(_node->is_type<mutable_data>() && _node->get_dependencies().empty())) {
@@ -1195,8 +1192,8 @@ bool primitive_inst::update_impl(bool use_async_compilation) {
_impl = _impls_factory->get_primitive_impl_for_params(*this, *_impl_params, use_async_compilation);
GPU_DEBUG_TRACE_DETAIL << id() << " impl update: was: " << prev_impl_str << " now: " << _impl->get_kernel_name() << std::endl;
}
- // impl is replaced
- return true;
+
+ set_flag(ExecutionFlags::IMPL_CHANGED);
}
void primitive_inst::update_paddings() {
@@ -1435,7 +1432,7 @@ void primitive_inst::do_runtime_skip_gather() {
if (input_shape[axis] != 1) {
auto queue_type = get_network().get_stream().get_queue_type();
if (queue_type == QueueTypes::out_of_order)
- get_network().get_stream().wait_for_events({_network.get_primitive_event(idx_id)});
+ get_network().get_stream().wait_for_events({_deps[1].first->get_impl_params()->out_event});
else
_network.get_stream().finish();
mem_lock<int32_t, mem_lock_type::read> idx_data(dep_memory_ptr(1), _network.get_stream());
@@ -1604,7 +1601,7 @@ void primitive_inst::do_runtime_in_place_concat() {
preds_layouts.push_back(pred.first->_impl_params->get_output_layout());
}
- if (!concat_inst->shape_changed())
+ if (!concat_inst->get_flag(ExecutionFlags::SHAPE_CHANGED))
return;
if (!concat_in_place_optimization::match(concat_inst->get_node(), *concat_inst->_impl_params, pred_params, true)) {
@@ -1618,7 +1615,7 @@ void primitive_inst::do_runtime_in_place_concat() {
size_t i = 0;
for (auto& dep : concat_inst->_deps) {
if (_impl_params->output_layouts[0] != preds_layouts[i]) {
- dep.first->set_shape_change();
+ dep.first->set_flag(ExecutionFlags::SHAPE_CHANGED);
dep.first->_impl_params->output_layouts[0] = preds_layouts[i];
}
GPU_DEBUG_TRACE_DETAIL << "[In place concat] Update padding of pred " << i << " : "
@@ -1641,15 +1638,13 @@ void primitive_inst::do_runtime_skip_scatter_update() {
return;
GPU_DEBUG_TRACE_DETAIL << "[do_runtime_skip_scatter_update] " << id() << " : check optimizability" << std::endl;
- auto input_layout = _impl_params->get_input_layout(0);
- auto output_layout = _impl_params->get_output_layout();
- auto idx_layout = _impl_params->get_input_layout(1);
- auto update_layout = _impl_params->get_input_layout(2);
+ 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) {
// set shape_change to realloc memory for same input shapes
if (can_be_optimized()) {
- set_shape_change();
+ set_flag(ExecutionFlags::SHAPE_CHANGED);
}
set_can_be_optimized(false);
GPU_DEBUG_TRACE_DETAIL << "--- Cannot optimize because idx_layout (" << idx_layout.to_short_string()
@@ -1664,7 +1659,7 @@ void primitive_inst::do_runtime_skip_scatter_update() {
GPU_DEBUG_TRACE_DETAIL << " - Output layout : " << _impl_params->get_output_layout().to_short_string() << std::endl;
// set shape_change to realloc memory for same input shapes
if (!can_be_optimized()) {
- set_shape_change();
+ set_flag(ExecutionFlags::SHAPE_CHANGED);
}
set_can_be_optimized(true);
}
@@ -1721,7 +1716,7 @@ void primitive_inst::do_runtime_in_place_crop() {
if (user_info.first) {
auto reshape_inst = crop_users.front();
reshape_inst->_impl_params->output_layouts[0] = user_info.second;
- reshape_inst->set_shape_change();
+ reshape_inst->set_flag(ExecutionFlags::SHAPE_CHANGED);
}
} else {
u->set_can_be_optimized(false);
@@ -1740,30 +1735,60 @@ bool primitive_inst::has_inner_networks() const {
return (_impl_params->inner_nets.size() > 0);
}
-event::ptr primitive_inst::execute(const std::vector<event::ptr>& events) {
+void primitive_inst::add_dep_events(const std::vector<event::ptr>& events) {
+ for (auto ev : events)
+ add_dep_event(std::move(ev));
+}
+
+void primitive_inst::add_dep_event(event::ptr ev) {
+ if (ev)
+ _impl_params->dep_events.push_back(ev);
+}
+
+void primitive_inst::set_out_event(event::ptr&& ev) {
+ _impl_params->out_event = ev;
+}
+
+void primitive_inst::reset_events() {
+ _impl_params->dep_events.clear();
+ _impl_params->out_event = nullptr;
+}
+
+void primitive_inst::set_flag(size_t flag, bool value) {
+ _impl_params->flags.set(flag, value);
+}
+void primitive_inst::unset_flag(size_t flag) {
+ _impl_params->flags.set(flag, false);
+}
+
+bool primitive_inst::get_flag(size_t flag) const {
+ return _impl_params->flags.test(flag);
+}
+
+void primitive_inst::reset_flags() {
+ _impl_params->flags.reset();
+}
+
+void primitive_inst::prepare_primitive() {
OV_ITT_SCOPED_TASK(ov::intel_gpu::itt::domains::intel_gpu_plugin, openvino::itt::handle("primitive_inst::execute: " + id()));
const auto& primitive_id = id();
OPENVINO_ASSERT(_has_valid_input, primitive_id, " has invalid/unset input");
- GPU_DEBUG_GET_INSTANCE(debug_config);
GPU_DEBUG_TRACE_DETAIL << "-----------------------------------------------------------------" << std::endl;
GPU_DEBUG_TRACE_DETAIL << "Execute " << id() << " (type: " << _impl_params->desc->type_string() << ") " << std::endl;
for (size_t i = 0; i < _deps.size(); ++i) {
GPU_DEBUG_TRACE_DETAIL << "- inputs[" << i << "] : " << _deps[i].first->id() << std::endl;
}
GPU_DEBUG_TRACE_DETAIL << "-----------------------------------------------------------------" << std::endl;
- bool need_args_update = false;
- _mem_changed = false;
+
const auto orig_outputs = _outputs;
- std::vector<event::ptr> dependencies;
if ((is_dynamic() || _node->is_in_shape_of_subgraph()) && !has_inner_networks()) {
do_runtime_in_place_concat();
OPENVINO_ASSERT(_node != nullptr, "[GPU] Invalid primitive_inst object for dynamic shapes case: program_node can't be null");
update_shape();
- bool can_skip_execution = false;
if (_impl_params->output_layouts[0].count() == 0) {
GPU_DEBUG_TRACE_DETAIL << id() << " : Skipping because output data is empty " << std::endl;
- can_skip_execution = true;
+ set_flag(ExecutionFlags::SKIP);
}
// subgraph_input_changed can be available only shape_of is dynamic.
@@ -1771,21 +1796,20 @@ event::ptr primitive_inst::execute(const std::vector<event::ptr>& events) {
if (_node->is_in_shape_of_subgraph() && dependant_shape_of_insts.front()->is_dynamic()) {
bool subgraph_input_changed = false;
for (size_t i = 0; i < dependant_shape_of_insts.size(); i++) {
- if (dependant_shape_of_insts[i]->shape_changed()) {
+ if (dependant_shape_of_insts[i]->get_flag(ExecutionFlags::SHAPE_CHANGED)) {
subgraph_input_changed = true;
break;
}
}
if (!subgraph_input_changed) {
GPU_DEBUG_TRACE_DETAIL << id() << " : Skipping execution because dependent shapeof node is not changed " << std::endl;
- can_skip_execution = true;
+ set_flag(ExecutionFlags::SKIP);
}
}
- if (can_skip_execution) {
- auto ev = get_network().get_stream().aggregate_events(events);
+ if (get_flag(ExecutionFlags::SKIP)) {
update_shape_done_by_other = false; // reset
- return ev;
+ return;
}
// Check successor reorder if layouts are same
@@ -1802,66 +1826,29 @@ event::ptr primitive_inst::execute(const std::vector<event::ptr>& events) {
do_runtime_in_place_crop();
if (!is_valid_fusion()) {
- OV_ITT_SCOPED_TASK(ov::intel_gpu::itt::domains::intel_gpu_plugin, openvino::itt::handle("unfused_subgraph_exec: " + id()));
- auto subgraph = get_unfused_subgraph();
-
- for (auto& d : _deps) {
- if (!d.first->get_node().is_type<data>()) {
- auto allocated_mem = d.first->output_memory_ptr();
- auto actual_input_layout = d.first->get_output_layout();
- auto& engine = _network.get_engine();
- cldnn::memory_ptr actual_mem = nullptr;
- // Need to use actual layout, not the fake aligned memory layout
- if (actual_input_layout.count() != 0) {
- actual_mem = engine.reinterpret_buffer(*allocated_mem, actual_input_layout);
- } else {
- actual_mem = engine.allocate_memory(actual_input_layout);
- }
- subgraph->set_input_data(d.first->id(), std::move(actual_mem));
- }
- }
- GPU_DEBUG_TRACE_DETAIL << "[Start] Executing unfused subgraph of " << id() << std::endl;
- auto outputs = subgraph->execute(events);
- GPU_DEBUG_TRACE_DETAIL << "[End] Finished executing unfused subgraph of " << id() << std::endl;
-
- auto last_fd = _impl_params->fused_desc.back();
- auto last_prim_id = last_fd.desc->id;
-
- OPENVINO_ASSERT(outputs.find(last_prim_id) != outputs.end(), "[GPU] Can't find output primitive ", last_prim_id, " for unfused subgraph");
-
- _outputs[0] = outputs.at(last_prim_id).get_memory();
-
- _impl_params->output_layouts[0] = subgraph->get_output_layout(last_prim_id);
- return outputs.at(last_prim_id).get_event();
+ OV_ITT_SCOPED_TASK(ov::intel_gpu::itt::domains::intel_gpu_plugin, openvino::itt::handle("unfused_subgraph_build: " + id()));
+ get_unfused_subgraph();
+ return;
}
// Try update impl if current impl is dynamic because opt kernel may be added to impl cache through async compilation.
// Only try update weight and realloc when impl is updated.
const bool can_use_async_compilation = use_async_compilation();
- bool is_updated = false;
- if (shape_changed() || !_impl || (!shape_changed() && _impl->is_dynamic() && can_use_async_compilation)) {
- if (update_impl(can_use_async_compilation)) {
- need_args_update = true;
- auto ev = update_weights();
- if (ev)
- dependencies.push_back(ev);
- auto ev_reset = realloc_if_needed();
- if (ev_reset)
- dependencies.push_back(ev_reset);
-
- is_updated = true;
+ const bool shape_changed = get_flag(ExecutionFlags::SHAPE_CHANGED);
+ if (shape_changed || !_impl || (!shape_changed && _impl->is_dynamic() && can_use_async_compilation)) {
+ update_impl(can_use_async_compilation);
+ if (get_flag(ExecutionFlags::IMPL_CHANGED)) {
+ update_weights();
+ realloc_if_needed();
}
}
// Paged Attention may require dispatch data update and internal buffers reallocation
// even if the input shapes haven't been changed
- if (_node->is_type<paged_attention>() && !is_updated && _impl->requires_update(*this, *_impl_params)) {
+ if (_node->is_type<paged_attention>() && !get_flag(ExecutionFlags::IMPL_CHANGED) && _impl->requires_update(*this, *_impl_params)) {
_impl->update(*this, *_impl_params);
- need_args_update = true;
- auto ev_reset = realloc_if_needed();
- if (ev_reset)
- dependencies.push_back(ev_reset);
+ realloc_if_needed();
}
OPENVINO_ASSERT(_impl_params->get_output_layout().is_static(),
@@ -1874,7 +1861,7 @@ event::ptr primitive_inst::execute(const std::vector<event::ptr>& events) {
[&has_dynamic_dependencies_insts](const cldnn::primitive_inst* prim_inst) {
for (auto& dep : prim_inst->_deps) {
const cldnn::primitive_inst* dep_inst = dep.first;
- if (dep_inst->mem_changed()) {
+ if (dep_inst->get_flag(ExecutionFlags::MEMORY_CHANGED)) {
return true;
} else if (dep_inst->can_be_optimized()) {
if (has_dynamic_dependencies_insts(dep_inst)) {
@@ -1885,10 +1872,10 @@ event::ptr primitive_inst::execute(const std::vector<event::ptr>& events) {
return false;
};
- bool use_shared_kernels = _node->get_program().get_config().get_property(ov::intel_gpu::hint::enable_kernels_reuse);
+ bool need_args_update = get_flag(ExecutionFlags::IMPL_CHANGED) || get_flag(ExecutionFlags::MEMORY_CHANGED);
// Output buffer may be changed under the following conditions, so we need to set args to kernel on each iteration
- if ((is_dynamic() && need_args_update) || has_mutable_input() || is_output() || has_dynamic_dependencies_insts(this) || use_shared_kernels) {
+ if ((is_dynamic() && need_args_update) || has_mutable_input() || is_output() || has_dynamic_dependencies_insts(this) || _use_shared_kernels) {
set_arguments();
}
on_execute();
@@ -1896,11 +1883,11 @@ event::ptr primitive_inst::execute(const std::vector<event::ptr>& events) {
if (!_node->is_type<condition>() && !_node->is_type<loop>()) {
for (size_t i = 0; i < _outputs.size(); ++i) {
if ((!orig_outputs[i] && _outputs[i]) || (orig_outputs[i] && !_outputs[i])) {
- _mem_changed = true;
+ set_flag(ExecutionFlags::MEMORY_CHANGED);
break;
}
if (!_network.get_engine().is_the_same_buffer(*orig_outputs[i], *_outputs[i])) {
- _mem_changed = true;
+ set_flag(ExecutionFlags::MEMORY_CHANGED);
break;
}
}
@@ -1910,52 +1897,78 @@ event::ptr primitive_inst::execute(const std::vector<event::ptr>& events) {
<< "can_be_optimized=" << can_be_optimized() << ")" << std::endl;
const bool out_of_order_queue = get_network().get_stream().get_queue_type() == QueueTypes::out_of_order;
- if (_exec_deps.empty() && dependencies.empty()) {
- dependencies = events;
- } else {
+ if (!_exec_deps.empty()) {
// Prepare dependencies events in case of OOO queue, CPU implementation,
// or optimized_out impl which has CPU users (needs_completion_event() && !is_output() condition)
if (out_of_order_queue || (_impl->is_cpu() && !can_be_optimized()) || (can_be_optimized() && needs_completion_event() && !is_output())) {
- dependencies.reserve(dependencies.size() + _exec_deps.size());
for (auto& input : _exec_deps) {
- auto& id = input->id();
- try {
- // if the requested event does not exists it means that it has not been executed, so the processing_order is
- // wrong or synchronization failed.
- auto ev = get_network().get_primitive_event(id);
- dependencies.emplace_back(ev);
- } catch (const std::out_of_range& oor) {
- OPENVINO_THROW("[GPU] execution order corrupted: ", oor.what());
- }
+ add_dep_event(input->get_impl_params()->out_event);
}
}
}
// Replace multiple events with single grouped event in case of barriers synchronization to prevent `_last_barrier_ev` usage as a dependency
// event of optimized_out instance's users, which may lead to unwanted extra synchronization of CPU impls with GPU kernels
- if (_node->is_in_shape_of_subgraph() && can_be_optimized() && dependencies.size() > 1 && out_of_order_queue) {
- auto grouped_ev = get_network().get_stream().group_events(dependencies);
- dependencies = {grouped_ev};
+ if (_node->is_in_shape_of_subgraph() && can_be_optimized() && _impl_params->dep_events.size() > 1 && out_of_order_queue) {
+ auto grouped_ev = get_network().get_stream().group_events(_impl_params->dep_events);
+ _impl_params->dep_events = {grouped_ev};
}
+}
- {
- GPU_DEBUG_PROFILED_STAGE(instrumentation::pipeline_stage::inference);
- auto ev = _impl->execute(dependencies, *this);
-
- GPU_DEBUG_IF(!debug_config->dump_profiling_data.empty()) {
- get_network().get_stream().wait_for_events({ev});
+void primitive_inst::execute() {
+ GPU_DEBUG_PROFILED_STAGE(instrumentation::pipeline_stage::inference);
+ if (get_flag(ExecutionFlags::SKIP)) {
+ set_out_event(get_network().get_stream().aggregate_events(_impl_params->dep_events));
+ return;
+ }
- if (ev != nullptr) {
- auto profiling_info = ev->get_profiling_info();
- for (const auto &interval : profiling_info) {
- if (interval.stage == cldnn::instrumentation::profiling_stage::executing) {
- GPU_DEBUG_CODE(stage_prof.set_custom_stage_duration(interval.value->value()));
- }
+ if (_unfused_subgraph != nullptr) {
+ for (auto& d : _deps) {
+ if (!d.first->get_node().is_type<data>()) {
+ auto allocated_mem = d.first->output_memory_ptr();
+ auto actual_input_layout = d.first->get_output_layout();
+ auto& engine = _network.get_engine();
+ cldnn::memory_ptr actual_mem = nullptr;
+ // Need to use actual layout, not the fake aligned memory layout
+ if (actual_input_layout.count() != 0) {
+ actual_mem = engine.reinterpret_buffer(*allocated_mem, actual_input_layout);
+ } else {
+ actual_mem = engine.allocate_memory(actual_input_layout);
}
+ _unfused_subgraph->set_input_data(d.first->id(), std::move(actual_mem));
}
}
+ GPU_DEBUG_TRACE_DETAIL << "[Start] Executing unfused subgraph of " << id() << std::endl;
+ auto outputs = _unfused_subgraph->execute(_impl_params->dep_events);
+ GPU_DEBUG_TRACE_DETAIL << "[End] Finished executing unfused subgraph of " << id() << std::endl;
- return ev;
+ auto last_fd = _impl_params->fused_desc.back();
+ auto last_prim_id = last_fd.desc->id;
+
+ OPENVINO_ASSERT(outputs.find(last_prim_id) != outputs.end(), "[GPU] Can't find output primitive ", last_prim_id, " for unfused subgraph");
+
+ _outputs[0] = outputs.at(last_prim_id).get_memory();
+
+ _impl_params->output_layouts[0] = _unfused_subgraph->get_output_layout(last_prim_id);
+ set_out_event(outputs.at(last_prim_id).get_event());
+ return;
+ }
+
+ set_out_event(_impl->execute(_impl_params->dep_events, *this));
+
+ GPU_DEBUG_GET_INSTANCE(debug_config);
+ GPU_DEBUG_IF(!debug_config->dump_profiling_data.empty()) {
+ auto ev = _impl_params->out_event;
+ get_network().get_stream().wait_for_events({ev});
+
+ if (ev != nullptr) {
+ auto profiling_info = ev->get_profiling_info();
+ for (const auto &interval : profiling_info) {
+ if (interval.stage == cldnn::instrumentation::profiling_stage::executing) {
+ GPU_DEBUG_CODE(stage_prof.set_custom_stage_duration(interval.value->value()));
+ }
+ }
+ }
}
}
@@ -1993,7 +2006,6 @@ primitive_inst::primitive_inst(network& network)
, _impl(nullptr)
, _outputs({})
, _reordered_weights_cache(network.get_weights_cache_capacity())
- , _output_changed(false)
, _mem_allocated(false)
, _type(nullptr) {}
@@ -2001,12 +2013,12 @@ primitive_inst::primitive_inst(network & network, program_node const& node, bool
: _network(network)
, _node(&node)
, _node_output_layout(node.get_output_layout())
+ , _use_shared_kernels(node.get_program().get_config().get_property(ov::intel_gpu::hint::enable_kernels_reuse))
, _impl_params(node.get_kernel_impl_params())
, _impl(node.get_selected_impl() ? node.get_selected_impl()->clone() : nullptr)
, _runtime_memory_dependencies(node.get_memory_dependencies())
, _outputs({})
, _reordered_weights_cache(network.get_weights_cache_capacity())
- , _output_changed(false)
, _is_dynamic(node.is_dynamic())
, _type(node.type())
, _id(node.id())
@@ -2177,15 +2189,15 @@ void primitive_inst::allocate_internal_buffers(bool reset) {
_intermediates_memory = intermediates_memory;
}
-event::ptr primitive_inst::update_weights() {
+void primitive_inst::update_weights() {
OV_ITT_SCOPED_TASK(ov::intel_gpu::itt::domains::intel_gpu_plugin, openvino::itt::handle("update_weights: " + id()));
GPU_DEBUG_PROFILED_STAGE(instrumentation::pipeline_stage::update_weights);
if (!_impl)
- return nullptr;
+ return;
bool weightable_node = _node->is_type<fully_connected>() || _node->is_type<convolution>() || _node->is_type<deconvolution>();
if (!weightable_node)
- return nullptr;
+ return;
auto& engine = _network.get_engine();
auto reorder_kernel_params = _impl->get_weights_reorder_kernel_params();
@@ -2213,13 +2225,13 @@ event::ptr primitive_inst::update_weights() {
if (_reordered_weights_cache.has(expected_layout)) {
GPU_DEBUG_PROFILED_STAGE_CACHE_HIT(true);
GPU_DEBUG_TRACE_DETAIL << id() << ": reuse weights for " << expected_layout.to_short_string() << std::endl;
- return nullptr;
+ return;
} else if (original_layout.compatible(expected_layout)) {
GPU_DEBUG_PROFILED_STAGE_CACHE_HIT(true);
GPU_DEBUG_TRACE_DETAIL << id() << ": reinterpret original weights memory from " << original_layout.to_short_string()
<< " to " << expected_layout.to_short_string() << std::endl;
_reordered_weights_cache.add(expected_layout, engine.reinterpret_buffer(*original_weights_memory, expected_layout));
- return nullptr;
+ return;
} else {
GPU_DEBUG_PROFILED_STAGE_CACHE_HIT(false);
auto& cache = get_network().get_program()->get_implementations_cache();
@@ -2241,7 +2253,7 @@ event::ptr primitive_inst::update_weights() {
auto kernels = kernels_cache.compile(*reorder_kernel_params, reorder_impl->get_kernels_source());
OPENVINO_ASSERT(kernels.size() == 1, "[GPU] Expected number of compiled kernels is 1, but got ", kernels.size());
reorder_impl->set_kernels(kernels);
- reorder_impl->can_share_kernels = _node->get_program().get_config().get_property(ov::intel_gpu::hint::enable_kernels_reuse);
+ reorder_impl->can_share_kernels = _use_shared_kernels;
}
reorder_inst->set_impl(reorder_impl->clone());
@@ -2277,20 +2289,20 @@ event::ptr primitive_inst::update_weights() {
auto reorder_impl = reorder_inst->get_impl();
reorder_impl->set_arguments(*reorder_inst, args);
- auto ev = reorder_impl->execute({}, *reorder_inst);
+ add_dep_event(reorder_impl->execute({}, *reorder_inst));
GPU_DEBUG_GET_INSTANCE(debug_config);
GPU_DEBUG_IF(!debug_config->dump_profiling_data.empty()) {
- stream.wait_for_events({ev});
+ stream.wait_for_events(_impl_params->dep_events);
}
- return ev;
+ return;
}
}
GPU_DEBUG_PROFILED_STAGE_CACHE_HIT(true);
- return nullptr;
+ return;
}
static bool user_requesting_mem_reuse_false(const program_node& node) {
@@ -2762,7 +2774,7 @@ std::shared_ptr<primitive_impl> ImplementationsFactory::get_primitive_impl_for_p
}
// 1. If we have static impl in the cache - use it
- if (use_async_compilation && ((inst.get_impl() && inst.get_impl()->is_dynamic()) || inst.shape_changed())) {
+ if (use_async_compilation && ((inst.get_impl() && inst.get_impl()->is_dynamic()) || inst.get_flag(ExecutionFlags::SHAPE_CHANGED))) {
auto cached_impl = m_static_impls_cache.get(updated_params);
if (cached_impl) {
return cached_impl->clone();
diff --git a/src/plugins/intel_gpu/src/plugin/graph.cpp b/src/plugins/intel_gpu/src/plugin/graph.cpp
index 22f616e3d39..08e59caeab7 100644
--- a/src/plugins/intel_gpu/src/plugin/graph.cpp
+++ b/src/plugins/intel_gpu/src/plugin/graph.cpp
@@ -578,9 +578,11 @@ void Graph::update_profiling_info() {
auto event = execIter->second;
executedPrimitives.erase(execIter);
- cldnn::instrumentation::profiling_info cldnnInfo{profiledID, event->get_profiling_info()};
+ if (event) {
+ cldnn::instrumentation::profiling_info cldnnInfo{profiledID, event->get_profiling_info()};
+ collectTimings(cldnnInfo, perfCount);
+ }
- collectTimings(cldnnInfo, perfCount);
perfCount.num++;
}
diff --git a/src/plugins/intel_gpu/src/runtime/ocl/ocl_memory.cpp b/src/plugins/intel_gpu/src/runtime/ocl/ocl_memory.cpp
index f7e5ada9e24..ee7e9a85d73 100644
--- a/src/plugins/intel_gpu/src/runtime/ocl/ocl_memory.cpp
+++ b/src/plugins/intel_gpu/src/runtime/ocl/ocl_memory.cpp
@@ -30,10 +30,10 @@ namespace ocl {
static inline cldnn::event::ptr create_event(stream& stream, size_t bytes_count, bool need_user_event) {
if (bytes_count == 0) {
GPU_DEBUG_TRACE_DETAIL << "Skip memory operation for 0 size tensor" << std::endl;
- return stream.create_user_event(true);
+ return nullptr;
}
- return need_user_event ? stream.create_user_event(true) : stream.create_base_event();
+ return need_user_event ? nullptr : stream.create_base_event();
}
static int get_cl_map_type(mem_lock_type type) {
@@ -92,17 +92,13 @@ void gpu_buffer::unlock(const stream& stream) {
}
event::ptr gpu_buffer::fill(stream& stream, bool blocking) {
- if (_bytes_count == 0) {
- GPU_DEBUG_TRACE_DETAIL << "Skip EnqueueMemcpy for 0 size tensor" << std::endl;
- return stream.create_user_event(true);
- }
return fill(stream, 0, blocking);
}
event::ptr gpu_buffer::fill(stream& stream, unsigned char pattern, bool blocking) {
if (_bytes_count == 0) {
GPU_DEBUG_TRACE_DETAIL << "Skip EnqueueMemcpy for 0 size tensor" << std::endl;
- return stream.create_user_event(true);
+ return nullptr;
}
auto& cl_stream = downcast<ocl_stream>(stream);
auto ev = stream.create_base_event();
@@ -276,17 +272,13 @@ gpu_image2d::gpu_image2d(ocl_engine* engine,
}
event::ptr gpu_image2d::fill(stream& stream, bool blocking) {
- if (_bytes_count == 0) {
- GPU_DEBUG_TRACE_DETAIL << "Skip EnqueueMemcpy for 0 size tensor" << std::endl;
- return stream.create_user_event(true);
- }
return fill(stream, 0, blocking);
}
event::ptr gpu_image2d::fill(stream& stream, unsigned char pattern, bool blocking) {
if (_bytes_count == 0) {
GPU_DEBUG_TRACE_DETAIL << "Skip EnqueueMemcpy for 0 size tensor" << std::endl;
- return stream.create_user_event(true);
+ return nullptr;
}
auto& cl_stream = downcast<ocl_stream>(stream);
auto ev = stream.create_base_event();
@@ -518,7 +510,7 @@ void gpu_usm::unlock(const stream& /* stream */) {
event::ptr gpu_usm::fill(stream& stream, unsigned char pattern, bool blocking) {
if (_bytes_count == 0) {
GPU_DEBUG_TRACE_DETAIL << "Skip gpu_usm::fill for 0 size tensor" << std::endl;
- return stream.create_user_event(true);
+ return nullptr;
}
auto& cl_stream = downcast<ocl_stream>(stream);
auto ev = stream.create_base_event();
@@ -537,16 +529,6 @@ event::ptr gpu_usm::fill(stream& stream, unsigned char pattern, bool blocking) {
}
event::ptr gpu_usm::fill(stream& stream, bool blocking) {
- // event::ptr ev{ new base_event(_context), false };
- // cl::Event ev_ocl = downcast<ocl_event>(ev.get())->get();
- // cl::usm::enqueue_set_mem(cl_stream.get_cl_queue(), _buffer.get(), 0, _bytes_count, nullptr, &ev_ocl);
- // ev->wait();
-
- // [WA]
- if (_bytes_count == 0) {
- GPU_DEBUG_TRACE_DETAIL << "Skip EnqueueMemcpy for 0 size tensor" << std::endl;
- return stream.create_user_event(true);
- }
return fill(stream, 0, blocking);
}
diff --git a/src/plugins/intel_gpu/src/runtime/ocl/ocl_stream.cpp b/src/plugins/intel_gpu/src/runtime/ocl/ocl_stream.cpp
index dba2bf4132a..7f55711b28c 100644
--- a/src/plugins/intel_gpu/src/runtime/ocl/ocl_stream.cpp
+++ b/src/plugins/intel_gpu/src/runtime/ocl/ocl_stream.cpp
@@ -3,6 +3,7 @@
//
#include "ocl_stream.hpp"
+#include "CL/cl.h"
#include "intel_gpu/runtime/stream.hpp"
#include "ocl_event.hpp"
#include "ocl_user_event.hpp"
@@ -343,6 +344,8 @@ event::ptr ocl_stream::enqueue_marker(std::vector<event::ptr> const& deps, bool
}
event::ptr ocl_stream::group_events(std::vector<event::ptr> const& deps) {
+ if (deps.size() == 1)
+ return deps[0];
return std::make_shared<ocl_events>(deps);
}
@@ -387,31 +390,35 @@ void ocl_stream::wait_for_events(const std::vector<event::ptr>& events) {
return;
bool needs_barrier = false;
- std::vector<cl::Event> clevents;
+ std::vector<cl_event> clevents;
for (auto& ev : events) {
+ if (!ev)
+ continue;
+
if (auto ocl_base_ev = downcast<ocl_base_event>(ev.get())) {
if (ocl_base_ev->get().get() != nullptr) {
- clevents.push_back(ocl_base_ev->get());
+ clevents.push_back(ocl_base_ev->get().get());
} else {
needs_barrier = true;
}
}
}
+ cl::Event barrier_ev;
if (needs_barrier) {
try {
- cl::Event barrier_ev;
_command_queue.enqueueBarrierWithWaitList(nullptr, &barrier_ev);
- clevents.push_back(barrier_ev);
+ clevents.push_back(barrier_ev.get());
} catch (cl::Error const& err) {
OPENVINO_THROW(OCL_ERR_MSG_FMT(err));
}
}
- try {
- cl::WaitForEvents(clevents);
- } catch (cl::Error const& err) {
- OPENVINO_THROW(OCL_ERR_MSG_FMT(err));
+ if (!clevents.empty()) {
+ auto err = clWaitForEvents(static_cast<cl_uint>(clevents.size()), &clevents[0]);
+ if (err != CL_SUCCESS) {
+ OPENVINO_THROW("[GPU] clWaitForEvents failed with ", err, " code");
+ }
}
}
diff --git a/src/plugins/intel_gpu/src/runtime/stream.cpp b/src/plugins/intel_gpu/src/runtime/stream.cpp
index 5f898596f46..d79a144c08e 100644
--- a/src/plugins/intel_gpu/src/runtime/stream.cpp
+++ b/src/plugins/intel_gpu/src/runtime/stream.cpp
@@ -33,8 +33,7 @@ event::ptr stream::aggregate_events(const std::vector<event::ptr>& events, bool
if (group && !is_output)
return group_events(events);
- return events.empty() ? create_user_event(true)
- : enqueue_marker(events, is_output);
+ return events.empty() ? (is_output ? create_user_event(true) : nullptr) : enqueue_marker(events, is_output);
}
} // namespace cldnn
diff --git a/src/plugins/intel_gpu/tests/unit/module_tests/network_test.cpp b/src/plugins/intel_gpu/tests/unit/module_tests/network_test.cpp
index f4353711126..23a393b9d02 100644
--- a/src/plugins/intel_gpu/tests/unit/module_tests/network_test.cpp
+++ b/src/plugins/intel_gpu/tests/unit/module_tests/network_test.cpp
@@ -95,7 +95,7 @@ TEST(network_test, has_proper_event_for_in_order_queue) {
net.set_input_data("input1", input_mem);
net.execute();
- ASSERT_FALSE(net.has_event("activation1"));
+ ASSERT_TRUE(net.has_event("activation1"));
ASSERT_TRUE(net.has_event("concat"));
ASSERT_TRUE(net.has_event("reorder"));
ASSERT_TRUE(net.has_event("activation2"));
diff --git a/src/plugins/intel_gpu/tests/unit/module_tests/usm_memory_test.cpp b/src/plugins/intel_gpu/tests/unit/module_tests/usm_memory_test.cpp
index 3f3cbfba692..a73650ed22c 100644
--- a/src/plugins/intel_gpu/tests/unit/module_tests/usm_memory_test.cpp
+++ b/src/plugins/intel_gpu/tests/unit/module_tests/usm_memory_test.cpp
@@ -299,13 +299,11 @@ TEST_P(copy_between_gpu_buffer_and_gpu_usm, basic) {
case allocation_type::usm_shared:
case allocation_type::usm_device:
{
- auto ev = mem_dst->copy_from(stream, *usm_host_src, true);
- ev->wait();
+ mem_dst->copy_from(stream, *usm_host_src, true);
break;
}
case allocation_type::cl_mem: {
- auto ev = mem_dst->copy_from(stream, *usm_host_src, true);
- ev->wait();
+ mem_dst->copy_from(stream, *usm_host_src, true);
break;
}
default: