Skip to content

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

[GPU] updated OneDNN convolution impl to handle a_zp properly for dynamic models (#26106)

Eddy Kim295917037bf9
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 fb9fbb4ab96..ed9f6b05817 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
@@ -77,6 +77,13 @@ void compile_graph::run(program& p) {
if (w_layout.spatial(0) != 1 || w_layout.spatial(1) != 1) {
change_initial_impl = false;
}
+
+ // OneDNN convolution requires activations zero points (a_zp) of int32 type, and the data is converted while executing choose_impl.
+ // If this task is done in the async compilation queue, it could result in wrong calculation of cldnn shape-agnostic kernels.
+ // [TODO] Is it possible to update memory of primitive_inst for a_zp in the choose_impl of onednn conv?
+ if (node->as<convolution>().activations_zero_points_term()) {
+ change_initial_impl = false;
+ }
}
}
diff --git a/src/plugins/intel_gpu/src/graph/impls/onednn/convolution_onednn.cpp b/src/plugins/intel_gpu/src/graph/impls/onednn/convolution_onednn.cpp
index a52314b3fd7..4892968cda9 100644
--- a/src/plugins/intel_gpu/src/graph/impls/onednn/convolution_onednn.cpp
+++ b/src/plugins/intel_gpu/src/graph/impls/onednn/convolution_onednn.cpp
@@ -51,6 +51,15 @@ protected:
if (instance.activations_zero_points_term()) {
auto a_zp = instance.activations_zero_points_memory();
+
+ // In the case of dynamic model, if choose_impl was executed in runtime,
+ // a_zp could be remained as u8 or i8.
+ if (a_zp->get_layout().data_type != data_types::i32) {
+ auto& conv_node = instance.get_node().as<convolution>();
+ auto& a_zp_node = conv_node.activations_zero_points().as<data>();
+ a_zp = a_zp_node.get_attached_memory_ptr();
+ }
+
dnnl::memory::desc desc = onednn::layout_to_memory_desc(a_zp->get_layout(), dnnl::memory::format_tag::a, true);
args.insert({DNNL_ARG_ATTR_ZERO_POINTS | DNNL_ARG_SRC, a_zp->get_onednn_memory(desc)});
diff --git a/src/plugins/intel_gpu/tests/unit/test_cases/convolution_gpu_test.cpp b/src/plugins/intel_gpu/tests/unit/test_cases/convolution_gpu_test.cpp
index 132b2378420..5e7aa5735ab 100644
--- a/src/plugins/intel_gpu/tests/unit/test_cases/convolution_gpu_test.cpp
+++ b/src/plugins/intel_gpu/tests/unit/test_cases/convolution_gpu_test.cpp
@@ -4600,6 +4600,111 @@ TEST(convolution_int8_fw_gpu, quantized_convolution_u8s8f32_asymmetric_activatio
}
}
+TEST(convolution_int8_fw_gpu, quantized_convolution_u8s8f32_asymmetric_activations_per_channel_dynamic) {
+ auto& engine = get_test_engine();
+
+ auto input = engine.allocate_memory({ data_types::u8, format::bfyx, {1, 2, 5, 4} });
+ auto weights = engine.allocate_memory({ data_types::i8, format::bfyx, { 3, 2, 3, 3 } });
+ auto biases = engine.allocate_memory({ data_types::f32, format::bfyx, { 1, 3, 1, 1 } });
+ auto a_zp = engine.allocate_memory({ data_types::u8, format::bfyx, { 1, 3, 1, 1 } });
+
+ set_values<uint8_t>(input, { 1, 2, 3, 4, 5,
+ 2, 2, 3, 4, 6,
+ 3, 3, 3, 5, 1,
+ 1, 1, 1, 1, 1,
+
+ 1, 2, 3, 4, 5,
+ 2, 2, 3, 4, 6,
+ 3, 3, 3, 5, 1,
+ 1, 1, 1, 1, 1 });
+
+ set_values<int8_t>(weights, { 1, 2, -1,
+ -2, 1, 2,
+ 9, 7, -1,
+
+ 9, 0, -4,
+ -1, 3, 2,
+ 0, 2, 5,
+
+ 1, 2, -1,
+ -2, 1, 2,
+ 9, 7, -1,
+
+ 9, 0, -4,
+ -1, 3, 2,
+ 0, 2, 5,
+
+ 1, 2, -1,
+ -2, 1, 2,
+ 9, 7, -1,
+
+ 9, 0, -4,
+ -1, 3, 2,
+ 0, 2, 5 });
+ set_values<uint8_t>(a_zp, { 2, 5, 5 });
+ set_values(biases, { 1.0f, -8.0f, -8.0f });
+
+ VVVF<float> output_vec = {
+ {
+ { -36.0f, 5.0f, -14.0f },
+ { -24.0f, -10.0f, -30.0f }
+ },
+ {
+ { -45.0f, -4.0f, -23.0f },
+ { -33.0f, -19.0f, -39.0f }
+ },
+ {
+ { -45.0f, -4.0f, -23.0f },
+ { -33.0f, -19.0f, -39.0f }
+ } };
+
+ auto in_dyn_layout = layout{ov::PartialShape::dynamic(input->get_layout().get_shape().size()), data_types::u8, format::bfyx};
+
+ topology topology(
+ input_layout("input", in_dyn_layout),
+ data("weights", weights),
+ data("biases", biases),
+ data("a_zp", a_zp),
+ reorder("input_fsv", input_info("input"), { data_types::u8, format::b_fs_yx_fsv16, input->get_layout().get_tensor() }),
+ convolution("conv", input_info("input_fsv"), "weights", "biases", "", { "a_zp" }, "", 1,
+ { 2, 2 }, { 1, 1 }, { 0, 0 }, { 1, 2 }, false, data_types::f32),
+ reorder("out", input_info("conv"), format::bfyx, data_types::f32));
+
+ ExecutionConfig config = get_test_default_config(engine);
+ config.set_property(ov::intel_gpu::allow_new_shape_infer(true));
+ ov::intel_gpu::ImplementationDesc conv_impl;
+ if (engine.get_device_info().supports_immad) {
+ conv_impl = { format::b_fs_yx_fsv16, "", impl_types::onednn };
+ config.set_property(ov::intel_gpu::force_implementations(ov::intel_gpu::ImplForcingMap{ { "conv", conv_impl } }));
+ }
+ network network(engine, topology, config);
+ network.set_input_data("input", input);
+
+ auto outputs = network.execute();
+ ASSERT_EQ(outputs.begin()->first, "out");
+
+ auto output_memory = outputs.at("out").get_memory();
+ cldnn::mem_lock<float> output_ptr(output_memory, get_test_stream());
+
+ auto output_layout = output_memory->get_layout();
+ int y_size = output_layout.spatial(1);
+ int x_size = output_layout.spatial(0);
+ int f_size = output_layout.feature();
+ int b_size = output_layout.batch();
+ ASSERT_EQ(output_layout.format, format::bfyx);
+ ASSERT_EQ(y_size, 2);
+ ASSERT_EQ(x_size, 3);
+ ASSERT_EQ(f_size, 3);
+ ASSERT_EQ(b_size, 1);
+ for (int f = 0; f < f_size; f++)
+ for (int y = 0; y < y_size; ++y) {
+ for (int x = 0; x < x_size; ++x) {
+ ASSERT_NEAR(output_vec[f][y][x], ((float)output_ptr[f * y_size * x_size + y * x_size + x]), 1e-5f) <<
+ " x="<< x << " y=" << y << " f=" << f;
+ }
+ }
+}
+
TEST(convolution_int8_fw_gpu, quantized_convolution_u8s8f32_asymmetric_activations_per_channel_3ic_with_sub) {
auto& engine = get_test_engine();