Skip to content

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

[GPU] fix OV_GPU_FORCE_IMPLEMENTATIONS option (#35629)

Mikolaj Roszczyk4fe23231579b
diff --git a/src/plugins/intel_gpu/docs/gpu_debug_utils.md b/src/plugins/intel_gpu/docs/gpu_debug_utils.md
index 742f91a6580..f48b14d7c7f 100644
--- a/src/plugins/intel_gpu/docs/gpu_debug_utils.md
+++ b/src/plugins/intel_gpu/docs/gpu_debug_utils.md
@@ -52,7 +52,6 @@ Value of the global options is read from env on the first access to the option,
Full options list is defined in `src/plugins/intel_gpu/include/intel_gpu/runtime/options.inl` file. This can also be printed to console by setting `OV_HELP=1` option
-
### How to check debug-config works
All options that are found in environment or config file are printed to stdout:
```
@@ -193,6 +192,19 @@ When the source is dumped, it contains a huge amount of macros(`#define`). For r
`$ cpp dumped_source.cl > clean_source.cl`
+## Forcing implementations
+
+You can force a specific implementation for chosen primitives by setting ```OV_GPU_FORCE_IMPLEMENTATIONS``` option. Variable expects strings with the following format:
+
+`OV_GPU_FORCE_IMPLEMENTATIONS={Name:Impl:Kernel:Layout}`, where
+ - ```Name``` is the name of the primitive, for which you'd like to force a specific implementation. Name used in this context has the following form: ```'layer_name:primitive_id'```. Use quotation marks, otherwise the colon in the name will be treated as a separator.
+ - ```Impl``` is the forced implementation name, available: ```any```, ```ocl```, ```cm```, ```sycl```, ```onednn```, ```common```, ```cpu```
+ - ```Kernel``` is the name of the kernel you'd like to be executed. Please note that currently forcing the specific kernel works only for ```ocl``` implementation
+ - ```Layout``` is the output layout. The full list of available layouts is available [here](../include/intel_gpu/runtime/format.hpp)
+
+ You can force implementation for more than 1 primitive:
+
+ `OV_GPU_FORCE_IMPLEMENTATIONS={Name:Impl:Kernel:Layout},{Name:Impl:Kernel:Layout},...`
## Layer in/out buffer dumps
diff --git a/src/plugins/intel_gpu/include/intel_gpu/primitives/implementation_desc.hpp b/src/plugins/intel_gpu/include/intel_gpu/primitives/implementation_desc.hpp
index 16032ab3097..b3c3f54315e 100644
--- a/src/plugins/intel_gpu/include/intel_gpu/primitives/implementation_desc.hpp
+++ b/src/plugins/intel_gpu/include/intel_gpu/primitives/implementation_desc.hpp
@@ -4,8 +4,10 @@
#pragma once
+#include <istream>
#include <map>
#include <ostream>
+#include <sstream>
#include "openvino/core/except.hpp"
#include "intel_gpu/primitives/primitive.hpp"
@@ -45,6 +47,7 @@ inline std::ostream& operator<<(std::ostream& out, const impl_types& impl_type)
case impl_types::ocl: out << "ocl"; break;
case impl_types::onednn: out << "onednn"; break;
case impl_types::cm: out << "cm"; break;
+ case impl_types::sycl: out << "sycl"; break;
case impl_types::any: out << "any"; break;
default: out << "unknown"; break;
}
@@ -65,6 +68,8 @@ inline std::istream& operator>>(std::istream& is, impl_types& impl_type) {
impl_type = impl_types::onednn;
} else if (str == "cm") {
impl_type = impl_types::cm;
+ } else if (str == "sycl") {
+ impl_type = impl_types::sycl;
} else if (str == "any") {
impl_type = impl_types::any;
} else {
@@ -133,6 +138,43 @@ inline std::ostream& operator<<(std::ostream& out, const ImplementationDesc& des
return out;
}
+inline std::istream& operator>>(std::istream& is, ImplementationDesc& desc) {
+ std::string str;
+ is >> str;
+
+ const auto first_sep = str.find(':');
+ const auto second_sep = str.find(':', first_sep == std::string::npos ? first_sep : first_sep + 1);
+ if (first_sep == std::string::npos || second_sep == std::string::npos) {
+ OPENVINO_THROW("Invalid ImplementationDesc value: ", str,
+ ". Expected format: impl_type:kernel_name:output_format");
+ }
+
+ const auto impl_type_str = str.substr(0, first_sep);
+ const auto kernel_name_str = str.substr(first_sep + 1, second_sep - first_sep - 1);
+ const auto output_format_str = str.substr(second_sep + 1);
+
+ {
+ std::istringstream impl_type_ss(impl_type_str);
+ impl_type_ss >> desc.impl_type;
+ }
+ desc.kernel_name = kernel_name_str;
+
+ if (output_format_str == "any") {
+ desc.output_format = cldnn::format::any;
+ return is;
+ }
+
+ for (int i = 0; i < static_cast<int>(cldnn::format::type::format_num); i++) {
+ const auto format_type = static_cast<cldnn::format::type>(i);
+ if (cldnn::format(format_type).to_string() == output_format_str) {
+ desc.output_format = format_type;
+ return is;
+ }
+ }
+
+ OPENVINO_THROW("Unsupported output format: ", output_format_str);
+}
+
using ImplForcingMap = std::map<cldnn::primitive_id, ImplementationDesc>;
} // namespace ov::intel_gpu
diff --git a/src/plugins/intel_gpu/include/intel_gpu/runtime/execution_config.hpp b/src/plugins/intel_gpu/include/intel_gpu/runtime/execution_config.hpp
index 1e3fb395161..0cc0f14776e 100644
--- a/src/plugins/intel_gpu/include/intel_gpu/runtime/execution_config.hpp
+++ b/src/plugins/intel_gpu/include/intel_gpu/runtime/execution_config.hpp
@@ -9,6 +9,8 @@
#include "intel_gpu/runtime/device_info.hpp"
#include "intel_gpu/runtime/internal_properties.hpp"
#include "openvino/runtime/internal_properties.hpp"
+#include "intel_gpu/runtime/impl_forcing_map_read.hpp"
+
#include <thread>
namespace ov::intel_gpu {
diff --git a/src/plugins/intel_gpu/include/intel_gpu/runtime/impl_forcing_map_read.hpp b/src/plugins/intel_gpu/include/intel_gpu/runtime/impl_forcing_map_read.hpp
new file mode 100644
index 00000000000..18ceffd883b
--- /dev/null
+++ b/src/plugins/intel_gpu/include/intel_gpu/runtime/impl_forcing_map_read.hpp
@@ -0,0 +1,63 @@
+// Copyright (C) 2018-2026 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#pragma once
+
+#include "intel_gpu/primitives/implementation_desc.hpp"
+#include "openvino/core/any.hpp"
+
+namespace ov::util {
+
+// specific parser for ImplForcingMap supporting quotation marks interpretation.
+// it allows the keys to contain colons (:) which should not be treated as separators
+// to be removed when the support for quotation marks is implemented in generic ov::Any
+template <>
+struct Read<ov::intel_gpu::ImplForcingMap> {
+ void operator()(std::istream& is, ov::intel_gpu::ImplForcingMap& map) const {
+ char c;
+
+ is >> c;
+ OPENVINO_ASSERT(c == '{',
+ "Failed to parse ov::intel_gpu::ImplForcingMap. Starting symbol is not '{', it's ", c);
+
+ while (c != '}') {
+ std::string key, value;
+ if (is.peek() == '\'' || is.peek() == '"') {
+ is >> c;
+ const char separator = c;
+ std::getline(is, key, separator);
+ OPENVINO_ASSERT(is.get() == ':',
+ "Parsing error: Separator (:) needed after key name. format: {" +
+ std::string(1, separator) + "key" + std::string(1, separator) + ":value}");
+ } else {
+ std::getline(is, key, ':');
+ }
+
+ size_t enclosed_container_level = 0;
+
+ while (is.good()) {
+ is >> c;
+ if (c == ',') {
+ if (enclosed_container_level == 0)
+ break;
+ }
+ if (c == '{' || c == '[')
+ ++enclosed_container_level;
+ if (c == '}' || c == ']') {
+ if (enclosed_container_level == 0)
+ break;
+ --enclosed_container_level;
+ }
+
+ value += c;
+ }
+ map.emplace(from_string<cldnn::primitive_id>(key), from_string<ov::intel_gpu::ImplementationDesc>(value));
+ }
+
+ OPENVINO_ASSERT(c == '}',
+ "Failed to parse ov::intel_gpu::ImplForcingMap. Ending symbol is not '}', it's ", c);
+ }
+};
+
+} // namespace ov::util
\ No newline at end of file
diff --git a/src/plugins/intel_gpu/src/graph/graph_optimizer/compile_graph.cpp b/src/plugins/intel_gpu/src/graph/graph_optimizer/compile_graph.cpp
index 092018804e2..e00756a55e5 100644
--- a/src/plugins/intel_gpu/src/graph/graph_optimizer/compile_graph.cpp
+++ b/src/plugins/intel_gpu/src/graph/graph_optimizer/compile_graph.cpp
@@ -16,6 +16,8 @@ using namespace cldnn;
void compile_graph::run(program& p) {
OV_ITT_SCOPED_TASK(ov::intel_gpu::itt::domains::intel_gpu_plugin, "pass::CompileGraph");
+ const auto& forcing_map = p.get_config().get_force_implementations();
+
for (auto& node : p.get_processing_order()) {
node->set_unique_id();
if (!node->is_type<data>()) {
@@ -34,10 +36,11 @@ void compile_graph::run(program& p) {
bool can_select_impl = !node->is_type<data>() && !(node->is_type<mutable_data>() && node->get_dependencies().empty());
if (can_select_impl) {
- tasks.emplace_back([node, &exception] {
+ tasks.emplace_back([node, &forcing_map, &exception] {
try {
const auto& params = node->get_kernel_impl_params();
auto shape_type = ImplementationManager::get_shape_type(*params);
+ const bool has_forced_impl = forcing_map.find(node->id()) != forcing_map.end();
auto selected_impl_manager = node->type()->choose_impl(*node, shape_type);
std::string fail_reason;
try {
@@ -57,6 +60,19 @@ void compile_graph::run(program& p) {
"\noriginal_type: ",
node->get_primitive()->origin_op_type_name,
" ", fail_reason);
+
+ OPENVINO_ASSERT(!has_forced_impl || node->selected_impl != nullptr ||
+ shape_type == shape_types::dynamic_shape,
+ "[GPU] force_implementations requested for primitive but no implementation was selected"
+ "\nname: ",
+ node->id(),
+ "\nforced impl_type: ",
+ forcing_map.at(node->id()).impl_type,
+ "\nforced kernel_name: ",
+ forcing_map.at(node->id()).kernel_name,
+ "\nforced output_format: ",
+ forcing_map.at(node->id()).output_format,
+ "\n", fail_reason);
} catch (std::exception&) {
exception = std::current_exception();
}
diff --git a/src/plugins/intel_gpu/src/graph/graph_optimizer/graph_initializations.cpp b/src/plugins/intel_gpu/src/graph/graph_optimizer/graph_initializations.cpp
index f64c4780b12..186732fc620 100644
--- a/src/plugins/intel_gpu/src/graph/graph_optimizer/graph_initializations.cpp
+++ b/src/plugins/intel_gpu/src/graph/graph_optimizer/graph_initializations.cpp
@@ -38,12 +38,27 @@ void graph_initializations::run(program& p) {
set_outputs(p);
auto forcing_map = p.get_config().get_force_implementations();
+ std::vector<primitive_id> missing_forced_nodes;
for (auto& kv : forcing_map) {
if (p.has_node(kv.first)) {
p.get_node(kv.first).set_forced_impl_type(kv.second.impl_type);
+ } else {
+ missing_forced_nodes.push_back(kv.first);
}
}
+ if (!missing_forced_nodes.empty() && !p.is_internal_program()) {
+ std::string missing_ids;
+ for (size_t i = 0; i < missing_forced_nodes.size(); ++i) {
+ missing_ids += missing_forced_nodes[i];
+ if (i + 1 < missing_forced_nodes.size()) {
+ missing_ids += ", ";
+ }
+ }
+
+ OPENVINO_THROW("[GPU] force_implementations contains primitive ids that are not present in graph: ", missing_ids);
+ }
+
p.get_processing_order().calc_processing_order(p);
}
} // namespace cldnn
diff --git a/src/plugins/intel_gpu/tests/unit/module_tests/force_implementations_test.cpp b/src/plugins/intel_gpu/tests/unit/module_tests/force_implementations_test.cpp
new file mode 100644
index 00000000000..5db0e102d2e
--- /dev/null
+++ b/src/plugins/intel_gpu/tests/unit/module_tests/force_implementations_test.cpp
@@ -0,0 +1,168 @@
+// Copyright (C) 2018-2026 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#include "test_utils.h"
+
+#include "intel_gpu/runtime/execution_config.hpp"
+#include "intel_gpu/runtime/impl_forcing_map_read.hpp"
+#include "gemm_inst.h"
+
+using namespace cldnn;
+using namespace ::tests;
+
+using ImplForcingMap = ov::intel_gpu::ImplForcingMap;
+
+TEST(force_implementations, parse_ImplForcingMap_simple) {
+ const std::string force_impl_string = "{conv1:ocl:kernelname:any}";
+ ov::Any any(force_impl_string);
+
+ ImplForcingMap map;
+ OV_ASSERT_NO_THROW(map = any.as<ImplForcingMap>());
+ ASSERT_EQ(map.size(), 1);
+
+ ASSERT_NE(map.find("conv1"), map.end());
+ const auto& conv1_desc = map.at("conv1");
+ ASSERT_EQ(conv1_desc.impl_type, impl_types::ocl);
+ ASSERT_EQ(conv1_desc.kernel_name, "kernelname");
+ ASSERT_EQ(conv1_desc.output_format, format::any);
+}
+
+TEST(force_implementations, parse_ImplForcingMap_multiple_entries) {
+ const std::string force_impl_string = "{conv1:cpu::any,conv2:ocl:kernel:any,pool1:onednn::bfyx}";
+ ov::Any any(force_impl_string);
+
+ ImplForcingMap map;
+ OV_ASSERT_NO_THROW(map = any.as<ImplForcingMap>());
+ ASSERT_EQ(map.size(), 3);
+
+ ASSERT_NE(map.find("conv1"), map.end());
+ const auto& conv1_desc = map.at("conv1");
+ ASSERT_EQ(conv1_desc.impl_type, impl_types::cpu);
+ ASSERT_EQ(conv1_desc.kernel_name, "");
+ ASSERT_EQ(conv1_desc.output_format, format::any);
+
+ ASSERT_NE(map.find("conv2"), map.end());
+ const auto& conv2_desc = map.at("conv2");
+ ASSERT_EQ(conv2_desc.impl_type, impl_types::ocl);
+ ASSERT_EQ(conv2_desc.kernel_name, "kernel");
+ ASSERT_EQ(conv2_desc.output_format, format::any);
+
+ ASSERT_NE(map.find("pool1"), map.end());
+ const auto& pool1_desc = map.at("pool1");
+ ASSERT_EQ(pool1_desc.impl_type, impl_types::onednn);
+ ASSERT_EQ(pool1_desc.kernel_name, "");
+ ASSERT_EQ(pool1_desc.output_format, format::bfyx);
+}
+
+TEST(force_implementations, parse_ImplForcingMap_colon_in_name) {
+ const std::string force_impl_string = "{\"layer:name\":ocl::any}";
+ ov::Any any(force_impl_string);
+
+ ImplForcingMap map;
+ OV_ASSERT_NO_THROW(map = any.as<ImplForcingMap>());
+ ASSERT_EQ(map.size(), 1);
+
+ ASSERT_NE(map.find("layer:name"), map.end());
+ const auto& layer_desc = map.at("layer:name");
+ ASSERT_EQ(layer_desc.impl_type, impl_types::ocl);
+ ASSERT_EQ(layer_desc.kernel_name, "");
+ ASSERT_EQ(layer_desc.output_format, format::any);
+}
+
+
+TEST(force_implementations, force_ocl_for_gemm) {
+ auto& engine = get_test_engine();
+
+ auto input1_layout = layout{ov::PartialShape{1, 1, 3, 4}, data_types::f32, format::bfyx};
+ auto input2_layout = layout{ov::PartialShape{1, 1, 4, 2}, data_types::f32, format::bfyx};
+
+ auto input1 = engine.allocate_memory(input1_layout);
+ auto input2 = engine.allocate_memory(input2_layout);
+
+ set_values(input1, std::vector<float>{
+ 1.f, 2.f, 3.f, 4.f,
+ 5.f, 6.f, 7.f, 8.f,
+ 9.f, 1.f, 2.f, 3.f
+ });
+ set_values(input2, std::vector<float>{
+ 1.f, 2.f,
+ 3.f, 4.f,
+ 5.f, 6.f,
+ 7.f, 8.f
+ });
+
+ topology topology(
+ input_layout("input1", input1_layout),
+ input_layout("input2", input2_layout),
+ gemm("gemm", { input_info("input1"), input_info("input2") }, data_types::f32, false, false, 1.f, 0.f, 4, 4)
+ );
+
+ auto config = get_test_default_config(engine);
+ config.set_property(ov::intel_gpu::force_implementations(
+ ov::intel_gpu::ImplForcingMap{{"gemm", {format::any, "", impl_types::ocl}}}
+ ));
+
+ network network(engine, topology, config);
+ network.set_input_data("input1", input1);
+ network.set_input_data("input2", input2);
+
+ auto gemm_prim = network.get_primitive("gemm");
+ ASSERT_TRUE(gemm_prim != nullptr);
+ auto impl = gemm_prim->get_impl();
+ ASSERT_TRUE(impl != nullptr);
+ ASSERT_TRUE(impl->m_manager != nullptr);
+ EXPECT_EQ(impl->m_manager->get_impl_type(), impl_types::ocl);
+
+ ASSERT_NO_THROW(network.execute());
+}
+
+#ifdef ENABLE_ONEDNN_FOR_GPU
+TEST(force_implementations, force_onednn_for_gemm) {
+ auto& engine = get_test_engine();
+ if (!engine.get_device_info().supports_immad)
+ return;
+
+ auto input1_layout = layout{ov::PartialShape{1, 1, 3, 4}, data_types::f16, format::bfyx};
+ auto input2_layout = layout{ov::PartialShape{1, 1, 4, 2}, data_types::f16, format::bfyx};
+
+ auto input1 = engine.allocate_memory(input1_layout);
+ auto input2 = engine.allocate_memory(input2_layout);
+
+ set_values(input1, std::vector<ov::float16>{
+ ov::float16(1.f), ov::float16(2.f), ov::float16(3.f), ov::float16(4.f),
+ ov::float16(5.f), ov::float16(6.f), ov::float16(7.f), ov::float16(8.f),
+ ov::float16(9.f), ov::float16(1.f), ov::float16(2.f), ov::float16(3.f)
+ });
+ set_values(input2, std::vector<ov::float16>{
+ ov::float16(1.f), ov::float16(2.f),
+ ov::float16(3.f), ov::float16(4.f),
+ ov::float16(5.f), ov::float16(6.f),
+ ov::float16(7.f), ov::float16(8.f)
+ });
+
+ topology topology(
+ input_layout("input1", input1_layout),
+ input_layout("input2", input2_layout),
+ gemm("gemm", { input_info("input1"), input_info("input2") }, data_types::f16, false, false, 1.f, 0.f, 4, 4)
+ );
+
+ auto config = get_test_default_config(engine);
+ config.set_property(ov::intel_gpu::force_implementations(
+ ov::intel_gpu::ImplForcingMap{{"gemm", {format::any, "", impl_types::onednn}}}
+ ));
+
+ network network(engine, topology, config);
+ network.set_input_data("input1", input1);
+ network.set_input_data("input2", input2);
+
+ auto gemm_prim = network.get_primitive("gemm");
+ ASSERT_TRUE(gemm_prim != nullptr);
+ auto impl = gemm_prim->get_impl();
+ ASSERT_TRUE(impl != nullptr);
+ ASSERT_TRUE(impl->m_manager != nullptr);
+ EXPECT_EQ(impl->m_manager->get_impl_type(), impl_types::onednn);
+
+ ASSERT_NO_THROW(network.execute());
+}
+#endif
diff --git a/src/plugins/intel_gpu/tests/unit/test_cases/gemm_gpu_test.cpp b/src/plugins/intel_gpu/tests/unit/test_cases/gemm_gpu_test.cpp
index 3a295c931c5..ecce3d8f8a8 100644
--- a/src/plugins/intel_gpu/tests/unit/test_cases/gemm_gpu_test.cpp
+++ b/src/plugins/intel_gpu/tests/unit/test_cases/gemm_gpu_test.cpp
@@ -3285,7 +3285,7 @@ public:
ov::intel_gpu::ImplementationDesc gemm_impl = { format::bfyx, std::string(""), impl_types::onednn };
ExecutionConfig cfg{ ov::intel_gpu::queue_type(QueueTypes::in_order),
- ov::intel_gpu::force_implementations(ov::intel_gpu::ImplForcingMap{ {"gemm", gemm_impl} }),
+ ov::intel_gpu::force_implementations(ov::intel_gpu::ImplForcingMap{ {"gemm_ref", gemm_impl} }),
ov::intel_gpu::optimize_data(true),
ov::intel_gpu::allow_new_shape_infer(true) };