Skip to content

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

[GPU] Rotate runtime weights of transposed convolutions run by oneDNN (#39815)

David Nam05751a037dec
diff --git a/src/plugins/intel_gpu/src/graph/graph_optimizer/post_optimize_weights.cpp b/src/plugins/intel_gpu/src/graph/graph_optimizer/post_optimize_weights.cpp
index a0d6353d9e7..4a93b72b52f 100644
--- a/src/plugins/intel_gpu/src/graph/graph_optimizer/post_optimize_weights.cpp
+++ b/src/plugins/intel_gpu/src/graph/graph_optimizer/post_optimize_weights.cpp
@@ -14,6 +14,10 @@
#include "intel_gpu/runtime/format.hpp"
#include "permute_inst.h"
#include "crop_inst.h"
+#include "reorder_inst.h"
+#include "intel_gpu/runtime/debug_configuration.hpp"
+
+#include <tuple>
#ifdef ENABLE_ONEDNN_FOR_GPU
#include "graph/impls/onednn/utils.hpp"
#endif // ENABLE_ONEDNN_FOR_GPU
@@ -134,6 +138,7 @@ void post_optimize_weights::optimize_weights(T& node, program& p) {
weights_reorder_node.recalc_output_layout(false);
if (!weights_reorder.second) {
+ add_weights_rotation(p, weights_reorder_node);
set_implementation(weights_reorder_node);
}
} else {
@@ -162,6 +167,7 @@ void post_optimize_weights::optimize_weights(T& node, program& p) {
weights_reorder_node.get_output_layout(false);
if (!weights_reorder.second) {
+ add_weights_rotation(p, weights_reorder_node);
set_implementation(weights_reorder_node);
}
}
@@ -180,6 +186,40 @@ void post_optimize_weights::select_implementation(program& p, program_node& node
}
}
+// A transposed convolution (a stride-1 deconvolution replaced by pre_replace_deconv) needs its weights rotated by
+// 180 degrees. The oneDNN weights reorder only changes the layout, so propagate_constants rotates constant weights
+// with an extra OCL reorder in front of it. Runtime weights don't go through propagate_constants, so insert the same
+// rotation for them here.
+void post_optimize_weights::add_weights_rotation(program& p, program_node& weights_reorder_node) {
+#ifdef ENABLE_ONEDNN_FOR_GPU
+ if (weights_reorder_node.is_constant()) {
+ return;
+ }
+
+ const auto& weights_params = weights_reorder_node.as<reorder>().get_primitive()->weights_reorder_params;
+ auto onednn_weights_params = std::dynamic_pointer_cast<onednn::WeightsReorderParamsOneDNN>(weights_params);
+ if (onednn_weights_params == nullptr || !onednn_weights_params->should_be_transposed()) {
+ return;
+ }
+
+ const auto weights_dep = weights_reorder_node.get_dependency_with_port(0);
+ auto grouped = weights_params->get_grouped();
+ auto layout = weights_params->get_input_layout().convert_to_weights_layout(grouped);
+ auto rotate_params = std::make_shared<WeightsReorderParams>(layout, layout, true, grouped);
+ auto rotate_prim = std::make_shared<reorder>(weights_reorder_node.id() + "_rotate",
+ input_info(weights_dep.first->id(), weights_dep.second),
+ rotate_params);
+ auto& rotate_node = p.get_or_create(rotate_prim);
+ p.add_intermediate(rotate_node, weights_reorder_node, 0);
+ rotate_node.recalc_output_layout(false);
+ select_implementation(p, rotate_node);
+ GPU_DEBUG_LOG << "Added " << rotate_node.id() << " for rotating runtime weights before " << weights_reorder_node.id() << std::endl;
+#else
+ std::ignore = p;
+ std::ignore = weights_reorder_node;
+#endif // ENABLE_ONEDNN_FOR_GPU
+}
+
void post_optimize_weights::add_gru_weights_reorder(primitive_id input_id,
program& p,
cldnn::program_node& prev,
diff --git a/src/plugins/intel_gpu/src/graph/graph_optimizer/remove_redundant_reorders.cpp b/src/plugins/intel_gpu/src/graph/graph_optimizer/remove_redundant_reorders.cpp
index 7638b330dfe..3217e2d2266 100644
--- a/src/plugins/intel_gpu/src/graph/graph_optimizer/remove_redundant_reorders.cpp
+++ b/src/plugins/intel_gpu/src/graph/graph_optimizer/remove_redundant_reorders.cpp
@@ -41,6 +41,12 @@ bool does_any_user_have_impl_type(program_node& node, impl_types impl) {
});
}
+// Weights reorder for a convolution that replaces a stride-1 deconvolution, which rotates the weights by 180 degrees
+bool rotates_weights(const program_node& reorder_node) {
+ const auto& weights_params = reorder_node.as<reorder>().get_primitive()->weights_reorder_params;
+ return weights_params != nullptr && weights_params->should_be_transposed();
+}
+
} // namespace
remove_redundant_reorders::remove_redundant_reorders(bool enable_reorder_fusing, bool update_implementations, bool remove_output_reorders)
@@ -426,7 +432,8 @@ void remove_redundant_reorders::run(program& p) {
auto l1_port_idx = node->get_dependency_with_port(0).second;
auto l2_port_idx = user->get_dependency_with_port(0).second;
- if (l1.identical(l2) && (l1_port_idx == l2_port_idx)) {
+ // A reorder that rotates the weights gives other data than one that doesn't, even with the same output layout
+ if (l1.identical(l2) && (l1_port_idx == l2_port_idx) && rotates_weights(*node) == rotates_weights(*user)) {
r_nodes_to_remove.push_back(user);
}
}
diff --git a/src/plugins/intel_gpu/src/graph/include/layout_optimizer.h b/src/plugins/intel_gpu/src/graph/include/layout_optimizer.h
index aa43c6a3cc8..5797d2f22d8 100644
--- a/src/plugins/intel_gpu/src/graph/include/layout_optimizer.h
+++ b/src/plugins/intel_gpu/src/graph/include/layout_optimizer.h
@@ -27,9 +27,12 @@ class primitive_inst;
struct reorder_cache_key {
primitive_id data_source;
layout expected_layout;
+ // Weights reorder that rotates the weights by 180 degrees (WeightsReorderParams::should_be_transposed()). It must
+ // not be shared with a consumer of the same weights that needs them as they are.
+ bool transposed = false;
friend bool operator==(const reorder_cache_key& lhs, const reorder_cache_key& rhs) {
- bool ret = lhs.data_source == rhs.data_source && lhs.expected_layout == rhs.expected_layout;
+ bool ret = lhs.data_source == rhs.data_source && lhs.expected_layout == rhs.expected_layout && lhs.transposed == rhs.transposed;
if (ret && lhs.expected_layout.format == cldnn::format::custom) {
ret &= (lhs.expected_layout.format.traits().block_sizes == rhs.expected_layout.format.traits().block_sizes);
@@ -48,6 +51,9 @@ struct reorder_cache_key {
if (lhs.expected_layout != rhs.expected_layout) {
return (lhs.expected_layout < rhs.expected_layout);
}
+ if (lhs.transposed != rhs.transposed) {
+ return rhs.transposed;
+ }
return lhs.expected_layout.format.traits().block_sizes < rhs.expected_layout.format.traits().block_sizes;
}
};
diff --git a/src/plugins/intel_gpu/src/graph/include/pass_manager.h b/src/plugins/intel_gpu/src/graph/include/pass_manager.h
index 44931867adb..62880623ec9 100644
--- a/src/plugins/intel_gpu/src/graph/include/pass_manager.h
+++ b/src/plugins/intel_gpu/src/graph/include/pass_manager.h
@@ -225,6 +225,7 @@ private:
template <typename T>
void optimize_weights(T& node, program& p);
static void select_implementation(program& p, program_node& node);
+ static void add_weights_rotation(program& p, program_node& weights_reorder_node);
void add_lstm_weights_reorder(primitive_id input_id,
std::shared_ptr<WeightsReorderParams> reorder_params,
program& p,
diff --git a/src/plugins/intel_gpu/src/graph/layout_optimizer.cpp b/src/plugins/intel_gpu/src/graph/layout_optimizer.cpp
index b6c3667071c..047437a9781 100644
--- a/src/plugins/intel_gpu/src/graph/layout_optimizer.cpp
+++ b/src/plugins/intel_gpu/src/graph/layout_optimizer.cpp
@@ -155,7 +155,7 @@ std::pair<std::shared_ptr<primitive>, bool> reorder_factory::get_weights_reorder
std::shared_ptr<WeightsReorderParams> reorder_params) {
OPENVINO_ASSERT(reorder_params != nullptr, "[GPU] WeightsReorderParams is not initialized.");
- reorder_cache_key ckey{ input_id, reorder_params->get_output_layout()};
+ reorder_cache_key ckey{input_id, reorder_params->get_output_layout(), reorder_params->should_be_transposed()};
auto itr = _cached_reorders.find(ckey);
if (itr != _cached_reorders.end()) {
return std::make_pair(itr->second, true);
diff --git a/src/plugins/intel_gpu/tests/functional/sources.cmake b/src/plugins/intel_gpu/tests/functional/sources.cmake
index b9a15ee6c5f..3ef448d61e6 100644
--- a/src/plugins/intel_gpu/tests/functional/sources.cmake
+++ b/src/plugins/intel_gpu/tests/functional/sources.cmake
@@ -326,6 +326,7 @@ set(GPU_FUNCTIONAL_TEST_SOURCES
${CMAKE_CURRENT_LIST_DIR}/single_layer_tests/tensor_iterator.cpp
${CMAKE_CURRENT_LIST_DIR}/subgraph_tests/batch_replicated_branches.cpp
${CMAKE_CURRENT_LIST_DIR}/subgraph_tests/condition.cpp
+ ${CMAKE_CURRENT_LIST_DIR}/subgraph_tests/convolution_backprop_data_runtime_weights.cpp
${CMAKE_CURRENT_LIST_DIR}/subgraph_tests/convolution_in_place_crop.cpp
${CMAKE_CURRENT_LIST_DIR}/subgraph_tests/convolution_sum_fusion.cpp
${CMAKE_CURRENT_LIST_DIR}/subgraph_tests/dynamic/activations_scaling.cpp
diff --git a/src/plugins/intel_gpu/tests/functional/subgraph_tests/convolution_backprop_data_runtime_weights.cpp b/src/plugins/intel_gpu/tests/functional/subgraph_tests/convolution_backprop_data_runtime_weights.cpp
new file mode 100644
index 00000000000..4ba06689f99
--- /dev/null
+++ b/src/plugins/intel_gpu/tests/functional/subgraph_tests/convolution_backprop_data_runtime_weights.cpp
@@ -0,0 +1,84 @@
+// Copyright (C) 2018-2026 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#include "common_test_utils/ov_tensor_utils.hpp"
+#include "openvino/core/coordinate_diff.hpp"
+#include "openvino/core/strides.hpp"
+#include "openvino/op/convolution.hpp"
+#include "openvino/op/group_conv.hpp"
+#include "openvino/op/parameter.hpp"
+#include "openvino/op/result.hpp"
+#include "shared_test_classes/base/ov_subgraph.hpp"
+
+namespace {
+
+// Stride-1 (Group)ConvolutionBackpropData whose weights are a model input rather than a constant. The GPU plugin
+// executes it as a convolution over 180-degree rotated weights, so the rotation has to be applied at runtime.
+using ConvolutionBackpropDataRuntimeWeightsParams = std::tuple<size_t, // groups
+ ov::element::Type>; // inference precision
+
+class ConvolutionBackpropDataRuntimeWeights : public ov::test::SubgraphBaseStaticTest,
+ public ::testing::WithParamInterface<ConvolutionBackpropDataRuntimeWeightsParams> {
+public:
+ static std::string getTestCaseName(const ::testing::TestParamInfo<ConvolutionBackpropDataRuntimeWeightsParams>& obj) {
+ const auto& [groups, inference_precision] = obj.param;
+ return "groups=" + std::to_string(groups) + "_inference_precision=" + inference_precision.get_type_name();
+ }
+
+protected:
+ void SetUp() override {
+ targetDevice = ov::test::utils::DEVICE_GPU;
+
+ const auto& [groups, inference_precision] = GetParam();
+ configuration[ov::hint::inference_precision.name()] = inference_precision.get_type_name();
+ if (inference_precision == ov::element::f16) {
+ abs_threshold = 0.02;
+ rel_threshold = 0.02;
+ }
+
+ const size_t in_channels = 8;
+ const size_t out_channels = 16;
+ const size_t kernel = 3;
+ const ov::Strides strides{1, 1};
+ const ov::Strides dilations{1, 1};
+ const ov::CoordinateDiff pads{1, 1};
+
+ auto input = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::Shape{1, in_channels, 7, 7});
+ std::shared_ptr<ov::Node> deconv;
+ std::shared_ptr<ov::op::v0::Parameter> weights;
+ if (groups == 1) {
+ weights = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::Shape{in_channels, out_channels, kernel, kernel});
+ deconv = std::make_shared<ov::op::v1::ConvolutionBackpropData>(input, weights, strides, pads, pads, dilations);
+ } else {
+ weights = std::make_shared<ov::op::v0::Parameter>(ov::element::f32,
+ ov::Shape{groups, in_channels / groups, out_channels / groups, kernel, kernel});
+ deconv = std::make_shared<ov::op::v1::GroupConvolutionBackpropData>(input, weights, strides, pads, pads, dilations);
+ }
+
+ auto result = std::make_shared<ov::op::v0::Result>(deconv);
+ function = std::make_shared<ov::Model>(ov::ResultVector{result}, ov::ParameterVector{input, weights}, "ConvolutionBackpropDataRuntimeWeights");
+ }
+
+ void generate_inputs(const std::vector<ov::Shape>& target_input_static_shapes) override {
+ inputs.clear();
+ const auto& model_inputs = function->inputs();
+ for (size_t i = 0; i < model_inputs.size(); ++i) {
+ auto tensor = ov::test::utils::create_and_fill_tensor(model_inputs[i].get_element_type(),
+ target_input_static_shapes[i],
+ ov::test::utils::InputGenerateData(-1, 2, 1000, static_cast<int>(i + 1)));
+ inputs.insert({model_inputs[i].get_node_shared_ptr(), tensor});
+ }
+ }
+};
+
+TEST_P(ConvolutionBackpropDataRuntimeWeights, Inference) {
+ run();
+}
+
+INSTANTIATE_TEST_SUITE_P(smoke_ConvolutionBackpropDataRuntimeWeights,
+ ConvolutionBackpropDataRuntimeWeights,
+ ::testing::Combine(::testing::Values(size_t{1}, size_t{2}), ::testing::Values(ov::element::f16, ov::element::f32)),
+ ConvolutionBackpropDataRuntimeWeights::getTestCaseName);
+
+} // namespace
diff --git a/src/plugins/intel_gpu/tests/unit/test_cases/deconvolution_gpu_test.cpp b/src/plugins/intel_gpu/tests/unit/test_cases/deconvolution_gpu_test.cpp
index 4c9903efe18..fc6aedd58f1 100644
--- a/src/plugins/intel_gpu/tests/unit/test_cases/deconvolution_gpu_test.cpp
+++ b/src/plugins/intel_gpu/tests/unit/test_cases/deconvolution_gpu_test.cpp
@@ -2515,6 +2515,239 @@ TEST(export_import_deconvolution_f16_fw_gpu, basic_wsiz2x2_in1x2x2x2_fs_b_yx_fsv
test_deconvolution_f16_fw_gpu_basic_wsiz2x2_in1x2x2x2_fs_b_yx_fsv32_stride1_pad1_replace_to_conv<float>(true);
}
+// A stride-1 deconvolution is replaced by a convolution with transposed (180-degree rotated) weights. When the weights
+// are not constant, the rotation has to happen in the weights reorder executed at runtime.
+static void test_deconvolution_stride1_runtime_weights_replace_to_conv(impl_types impl_type, uint32_t groups) {
+ auto& engine = get_test_engine();
+ if (impl_type == impl_types::onednn && !engine.get_device_info().supports_immad) {
+ GTEST_SKIP();
+ }
+
+ const int64_t ifm = 8, ofm = 16, in_size = 5, k = 3, pad = 1;
+ const int64_t ifm_g = ifm / groups, ofm_g = ofm / groups;
+ const int64_t out_size = in_size - 1 - 2 * pad + k;
+
+ layout in_layout{ov::PartialShape{1, ifm, in_size, in_size}, data_types::f16, format::bfyx};
+ layout weights_layout = groups == 1 ? layout{ov::PartialShape{ofm, ifm, k, k}, data_types::f16, format::bfyx}
+ : layout{ov::PartialShape{groups, ofm_g, ifm_g, k, k}, data_types::f16, format::bfzyx};
+
+ tests::random_generator rg(GET_SUITE_NAME);
+ auto input_data = rg.generate_random_1d<ov::float16>(in_layout.count(), -1, 1);
+ auto weights_data = rg.generate_random_1d<ov::float16>(weights_layout.count(), -1, 1);
+ auto input = engine.allocate_memory(in_layout);
+ auto weights = engine.allocate_memory(weights_layout);
+ set_values(input, input_data);
+ set_values(weights, weights_data);
+
+ topology topology(input_layout("input", in_layout),
+ input_layout("weights", weights_layout),
+ deconvolution("deconv", input_info("input"), "weights", "", groups, {1, 1}, {pad, pad}, {1, 1},
+ tensor(1, ofm, out_size, out_size), groups > 1),
+ reorder("out", input_info("deconv"), format::bfyx, data_types::f32));
+
+ ExecutionConfig config = get_test_default_config(engine);
+ config.set_property(ov::intel_gpu::optimize_data(true));
+ ov::intel_gpu::ImplementationDesc deconv_impl = {format::bfyx, "", impl_type};
+ config.set_property(ov::intel_gpu::force_implementations(ov::intel_gpu::ImplForcingMap{{"deconv", deconv_impl}}));
+
+ network network(engine, topology, config);
+ auto deconv_inst = network.get_primitive("deconv");
+ ASSERT_TRUE(deconv_inst->get_node().is_type<convolution>());
+ ASSERT_EQ(deconv_inst->get_impl()->is_onednn(), impl_type == impl_types::onednn);
+
+ network.set_input_data("input", input);
+ network.set_input_data("weights", weights);
+ auto outputs = network.execute();
+ auto output = outputs.at("out").get_memory();
+ ASSERT_EQ(output->get_layout().get_shape(), ov::Shape({1, static_cast<size_t>(ofm), static_cast<size_t>(out_size), static_cast<size_t>(out_size)}));
+ cldnn::mem_lock<float, mem_lock_type::read> output_ptr(output, get_test_stream());
+
+ // out[g * ofm_g + o][y][x] += in[g * ifm_g + i][iy][ix] * w[g][o][i][ky][kx], where y = iy - pad + ky
+ std::vector<float> expected(output->count(), 0.f);
+ for (int64_t g = 0; g < groups; g++) {
+ for (int64_t o = 0; o < ofm_g; o++) {
+ for (int64_t i = 0; i < ifm_g; i++) {
+ for (int64_t iy = 0; iy < in_size; iy++) {
+ for (int64_t ix = 0; ix < in_size; ix++) {
+ for (int64_t ky = 0; ky < k; ky++) {
+ for (int64_t kx = 0; kx < k; kx++) {
+ const int64_t y = iy - pad + ky;
+ const int64_t x = ix - pad + kx;
+ if (y < 0 || y >= out_size || x < 0 || x >= out_size) {
+ continue;
+ }
+ const auto in_val = static_cast<float>(input_data[((g * ifm_g + i) * in_size + iy) * in_size + ix]);
+ const auto w_val = static_cast<float>(weights_data[(((g * ofm_g + o) * ifm_g + i) * k + ky) * k + kx]);
+ expected[((g * ofm_g + o) * out_size + y) * out_size + x] += in_val * w_val;
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+
+ for (size_t i = 0; i < expected.size(); i++) {
+ ASSERT_NEAR(expected[i], output_ptr[i], 2e-2f) << "i = " << i;
+ }
+}
+
+// A convolution and a stride-1 deconvolution sharing weights need separate weights reorders: only the convolution
+// that replaces the deconvolution needs the weights rotated. The layers are chained in both orders, so that each of
+// them is the first one to get its weights reorder.
+static void test_deconvolution_stride1_weights_shared_with_conv(impl_types impl_type, bool constant_weights, bool deconv_first) {
+ auto& engine = get_test_engine();
+ if (impl_type == impl_types::onednn && !engine.get_device_info().supports_immad) {
+ GTEST_SKIP();
+ }
+
+ // Both layers keep the shape, so the second one can read the output of the first one
+ const int64_t fm = 16, size = 5, k = 3, pad = 1;
+ layout in_layout{ov::PartialShape{1, fm, size, size}, data_types::f16, format::bfyx};
+ layout weights_layout{ov::PartialShape{fm, fm, k, k}, data_types::f16, format::bfyx};
+
+ tests::random_generator rg(GET_SUITE_NAME);
+ // Inputs from {-1, 0, 1} and weights from {-0.25, 0, 0.25} keep every partial sum of both layers a multiple of 1/16
+ // well below 128, which f16 represents exactly. The OCL kernels accumulate in f16, so with finer values the result
+ // of the second layer would depend on the kernel the device selects and on its accumulation order.
+ auto input_data = rg.generate_random_1d<ov::float16>(in_layout.count(), -1, 1, 1);
+ auto weights_data = rg.generate_random_1d<ov::float16>(weights_layout.count(), -0.25, 0.25, 4);
+ auto input = engine.allocate_memory(in_layout);
+ auto weights = engine.allocate_memory(weights_layout);
+ set_values(input, input_data);
+ set_values(weights, weights_data);
+
+ const primitive_id first = deconv_first ? "deconv" : "conv";
+ const primitive_id second = deconv_first ? "conv" : "deconv";
+ topology topology(input_layout("input", in_layout));
+ if (constant_weights) {
+ topology.add(data("weights", weights));
+ } else {
+ topology.add(input_layout("weights", weights_layout));
+ }
+ for (const auto& [id, in] : {std::make_pair(first, input_info("input")), std::make_pair(second, input_info(first))}) {
+ if (id == "deconv") {
+ topology.add(deconvolution(id, in, "weights", "", 1, {1, 1}, {pad, pad}, {1, 1}, tensor(1, fm, size, size), false));
+ } else {
+ topology.add(convolution(id, in, "weights", "", 1, {1, 1}, {1, 1}, {pad, pad}, {pad, pad}, false));
+ }
+ topology.add(reorder(id + "_out", input_info(id), format::bfyx, data_types::f32));
+ }
+
+ ExecutionConfig config = get_test_default_config(engine);
+ config.set_property(ov::intel_gpu::optimize_data(true));
+ ov::intel_gpu::ImplementationDesc impl = {format::bfyx, "", impl_type};
+ config.set_property(ov::intel_gpu::force_implementations(ov::intel_gpu::ImplForcingMap{{"conv", impl}, {"deconv", impl}}));
+
+ network network(engine, topology, config);
+ ASSERT_TRUE(network.get_primitive("deconv")->get_node().is_type<convolution>());
+ for (const auto& id : {first, second}) {
+ ASSERT_EQ(network.get_primitive(id)->get_impl()->is_onednn(), impl_type == impl_types::onednn) << id;
+ }
+
+ network.set_input_data("input", input);
+ if (!constant_weights) {
+ network.set_input_data("weights", weights);
+ }
+ auto outputs = network.execute();
+ auto read_output = [&](const primitive_id& id) {
+ auto output = outputs.at(id + "_out").get_memory();
+ cldnn::mem_lock<float, mem_lock_type::read> output_ptr(output, get_test_stream());
+ return std::vector<float>(output_ptr.data(), output_ptr.data() + output->count());
+ };
+
+ // The convolution computes out[o][y][x] += in[i][y - pad + ky][x - pad + kx] * w[o][i][ky][kx], and the
+ // deconvolution out[o][y - pad + ky][x - pad + kx] += in[i][y][x] * w[o][i][ky][kx].
+ auto reference = [&](const std::vector<float>& in, bool deconv) {
+ std::vector<float> out(in.size(), 0.f);
+ for (int64_t o = 0; o < fm; o++) {
+ for (int64_t i = 0; i < fm; i++) {
+ for (int64_t y = 0; y < size; y++) {
+ for (int64_t x = 0; x < size; x++) {
+ for (int64_t ky = 0; ky < k; ky++) {
+ for (int64_t kx = 0; kx < k; kx++) {
+ const int64_t sy = y - pad + ky;
+ const int64_t sx = x - pad + kx;
+ if (sy < 0 || sy >= size || sx < 0 || sx >= size) {
+ continue;
+ }
+ const auto w_val = static_cast<float>(weights_data[((o * fm + i) * k + ky) * k + kx]);
+ if (deconv) {
+ out[(o * size + sy) * size + sx] += in[(i * size + y) * size + x] * w_val;
+ } else {
+ out[(o * size + y) * size + x] += in[(i * size + sy) * size + sx] * w_val;
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ return out;
+ };
+
+ // The second layer is checked against the output of the first one, so the f16 error of the first one doesn't add up
+ const std::vector<float> input_f32(input_data.begin(), input_data.end());
+ const auto first_output = read_output(first);
+ const auto second_output = read_output(second);
+ const auto first_expected = reference(input_f32, deconv_first);
+ const auto second_expected = reference(first_output, !deconv_first);
+ for (size_t i = 0; i < first_expected.size(); i++) {
+ ASSERT_NEAR(first_expected[i], first_output[i], 2e-2f) << first << ": i = " << i;
+ ASSERT_NEAR(second_expected[i], second_output[i], 2e-2f) << second << ": i = " << i;
+ }
+}
+
+TEST(deconvolution_f16_fw_gpu, stride1_runtime_weights_replace_to_conv) {
+ test_deconvolution_stride1_runtime_weights_replace_to_conv(impl_types::ocl, 1);
+}
+
+TEST(deconvolution_f16_fw_gpu, stride1_runtime_grouped_weights_replace_to_conv) {
+ test_deconvolution_stride1_runtime_weights_replace_to_conv(impl_types::ocl, 2);
+}
+
+TEST(deconvolution_f16_fw_gpu, stride1_runtime_weights_shared_conv_first) {
+ test_deconvolution_stride1_weights_shared_with_conv(impl_types::ocl, false, false);
+}
+
+TEST(deconvolution_f16_fw_gpu, stride1_runtime_weights_shared_deconv_first) {
+ test_deconvolution_stride1_weights_shared_with_conv(impl_types::ocl, false, true);
+}
+
+TEST(deconvolution_f16_fw_gpu, stride1_const_weights_shared_conv_first) {
+ test_deconvolution_stride1_weights_shared_with_conv(impl_types::ocl, true, false);
+}
+
+TEST(deconvolution_f16_fw_gpu, stride1_const_weights_shared_deconv_first) {
+ test_deconvolution_stride1_weights_shared_with_conv(impl_types::ocl, true, true);
+}
+
+#ifdef ENABLE_ONEDNN_FOR_GPU
+TEST(deconvolution_gpu_onednn, stride1_runtime_weights_replace_to_conv) {
+ test_deconvolution_stride1_runtime_weights_replace_to_conv(impl_types::onednn, 1);
+}
+
+TEST(deconvolution_gpu_onednn, stride1_runtime_grouped_weights_replace_to_conv) {
+ test_deconvolution_stride1_runtime_weights_replace_to_conv(impl_types::onednn, 2);
+}
+
+TEST(deconvolution_gpu_onednn, stride1_runtime_weights_shared_conv_first) {
+ test_deconvolution_stride1_weights_shared_with_conv(impl_types::onednn, false, false);
+}
+
+TEST(deconvolution_gpu_onednn, stride1_runtime_weights_shared_deconv_first) {
+ test_deconvolution_stride1_weights_shared_with_conv(impl_types::onednn, false, true);
+}
+
+TEST(deconvolution_gpu_onednn, stride1_const_weights_shared_conv_first) {
+ test_deconvolution_stride1_weights_shared_with_conv(impl_types::onednn, true, false);
+}
+
+TEST(deconvolution_gpu_onednn, stride1_const_weights_shared_deconv_first) {
+ test_deconvolution_stride1_weights_shared_with_conv(impl_types::onednn, true, true);
+}
+#endif // ENABLE_ONEDNN_FOR_GPU
+
struct deconvolution_random_test_params {
data_types input_type;
format::type input_format;