Skip to content

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

[CPU] Always select nspc layout for int8 Convolution (#30656)

Egor Duplenskii1842565bbf48
diff --git a/src/plugins/intel_cpu/src/nodes/executors/convolution_implementations.cpp b/src/plugins/intel_cpu/src/nodes/executors/convolution_implementations.cpp
index 09d4ba71624..1795ef559e6 100644
--- a/src/plugins/intel_cpu/src/nodes/executors/convolution_implementations.cpp
+++ b/src/plugins/intel_cpu/src/nodes/executors/convolution_implementations.cpp
@@ -63,6 +63,11 @@ template <typename PostOpType>
});
}
+[[maybe_unused]] static inline bool isQuantized(const ConvConfig& config) {
+ return one_of(config.descs.at(ARG_SRC)->getPrecision(), ov::element::u8, ov::element::i8) &&
+ config.descs.at(ARG_WEI)->getPrecision() == ov::element::i8;
+};
+
template <typename Attrs>
bool MatchesMemoryFormatFilter(const executor::Config<Attrs>& config,
const LayoutConfig& layoutConfig,
@@ -113,7 +118,7 @@ const std::vector<ExecutorImplementation<ConvAttrs>>& getImplementations() {
}
VERIFY(!hasPostOp<DepthwiseConvolutionPostOp>(config), UNSUPPORTED_POST_OPS);
- VERIFY(DnnlConvolutionPrimitive::isBrgConvAvailable(config), "brgemm convolution is not available");
+ VERIFY(isQuantized(config) || DnnlConvolutionPrimitive::isBrgConvAvailable(config), "is not quantized or brgemm convolution is not available");
return true;
},
@@ -131,6 +136,7 @@ const std::vector<ExecutorImplementation<ConvAttrs>>& getImplementations() {
}
// fork kernel with dw conv post ops supports only src: (ncsp | nCsp8c), dst: nCsp8c
+ VERIFY(!isQuantized(config), UNSUPPORTED_SRC_PRECISIONS);
VERIFY(!hasPostOp<DepthwiseConvolutionPostOp>(config), UNSUPPORTED_POST_OPS);
const auto [groupNum, groupIC, IC, groupOC] = DnnlConvolutionPrimitive::getChannelParams(config);
@@ -150,6 +156,7 @@ const std::vector<ExecutorImplementation<ConvAttrs>>& getImplementations() {
}
// fork kernel with dw conv post ops supports only src: (ncsp | nCsp8c), dst: nCsp8c
+ VERIFY(!isQuantized(config), UNSUPPORTED_SRC_PRECISIONS);
VERIFY(!hasPostOp<DepthwiseConvolutionPostOp>(config), UNSUPPORTED_POST_OPS);
const auto [groupNum, groupIC, IC, groupOC] = DnnlConvolutionPrimitive::getChannelParams(config);
@@ -169,6 +176,7 @@ const std::vector<ExecutorImplementation<ConvAttrs>>& getImplementations() {
return false;
}
+ VERIFY(!isQuantized(config), UNSUPPORTED_SRC_PRECISIONS);
const auto [groupNum, groupIC, IC, groupOC] = DnnlConvolutionPrimitive::getChannelParams(config);
return IC < 4 && groupOC != 1;
@@ -187,6 +195,7 @@ const std::vector<ExecutorImplementation<ConvAttrs>>& getImplementations() {
}
// fork kernel with dw conv post ops supports only src: (ncsp | nCsp8c), dst: nCsp8c
+ VERIFY(!isQuantized(config), UNSUPPORTED_SRC_PRECISIONS);
VERIFY(!hasPostOp<DepthwiseConvolutionPostOp>(config), UNSUPPORTED_POST_OPS);
const auto [groupNum, groupIC, IC, groupOC] = DnnlConvolutionPrimitive::getChannelParams(config);
@@ -206,6 +215,7 @@ const std::vector<ExecutorImplementation<ConvAttrs>>& getImplementations() {
return false;
}
+ VERIFY(!isQuantized(config), UNSUPPORTED_SRC_PRECISIONS);
const auto [groupNum, groupIC, IC, groupOC] = DnnlConvolutionPrimitive::getChannelParams(config);
return IC > 4;
@@ -223,6 +233,7 @@ const std::vector<ExecutorImplementation<ConvAttrs>>& getImplementations() {
return false;
}
+ VERIFY(!isQuantized(config), UNSUPPORTED_SRC_PRECISIONS);
// fork kernel with dw conv post ops supports only src: (ncsp | nCsp8c), dst: nCsp8c
VERIFY(!hasPostOp<DepthwiseConvolutionPostOp>(config), UNSUPPORTED_POST_OPS);
@@ -241,6 +252,8 @@ const std::vector<ExecutorImplementation<ConvAttrs>>& getImplementations() {
return false;
}
+ VERIFY(!isQuantized(config), UNSUPPORTED_SRC_PRECISIONS);
+
return !one_of(srcType(config), ov::element::bf16, ov::element::f16) && DnnlConvolutionPrimitive::isNspcAvailable(config);
},
RequiresFallbackDefault{{LayoutType::nspc, LayoutType::ncsp, LayoutType::nspc, LayoutType::nspc}},
diff --git a/src/plugins/intel_cpu/src/nodes/executors/debug_messages.hpp b/src/plugins/intel_cpu/src/nodes/executors/debug_messages.hpp
index cba22a25c75..5f9c16e79c4 100644
--- a/src/plugins/intel_cpu/src/nodes/executors/debug_messages.hpp
+++ b/src/plugins/intel_cpu/src/nodes/executors/debug_messages.hpp
@@ -20,6 +20,7 @@
#define HEURISTICS_MISMATCH " heuristics mismatch"
#define UNSUPPORTED_PER_CHANNEL_QUANTIZATION " unsupported per-channel quantization"
+// @todo implement VERIFY_OR version to support multiple conditions and error messages
#define VERIFY(condition, ...) \
do { \
if (!(condition)) { \
diff --git a/src/plugins/intel_cpu/tests/functional/custom/subgraph_tests/src/x64/conv_u8s8f32.cpp b/src/plugins/intel_cpu/tests/functional/custom/subgraph_tests/src/x64/conv_u8s8f32.cpp
new file mode 100644
index 00000000000..304977f2f60
--- /dev/null
+++ b/src/plugins/intel_cpu/tests/functional/custom/subgraph_tests/src/x64/conv_u8s8f32.cpp
@@ -0,0 +1,112 @@
+// Copyright (C) 2025 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#include <memory>
+
+#include "common_test_utils/node_builders/fake_quantize.hpp"
+#include "openvino/core/type/element_type.hpp"
+#include "openvino/op/constant.hpp"
+#include "openvino/op/convolution.hpp"
+#include "shared_test_classes/base/ov_subgraph.hpp"
+#include "utils/cpu_test_utils.hpp"
+#include "utils/filter_cpu_info.hpp"
+#include "utils/fusing_test_utils.hpp"
+
+using namespace CPUTestUtils;
+
+namespace ov {
+namespace test {
+
+/* Verify simple quantized convolution subgraph.
+ No reference implementations are expected to be used.
+
+ Param1
+ |
+ FQ_U8
+ |
+ Conv1
+ |
+ PreLU
+ |
+ Result
+
+*/
+
+typedef std::tuple<CPUSpecificParams, fusingSpecificParams> ConvU8I8FP32Params;
+
+class ConvU8I8FP32 : public testing::WithParamInterface<ConvU8I8FP32Params>,
+ virtual public SubgraphBaseStaticTest,
+ public CpuTestWithFusing {
+public:
+ static std::string getTestCaseName(const testing::TestParamInfo<ConvU8I8FP32Params>& obj) {
+ CPUSpecificParams cpuParams;
+ fusingSpecificParams fusingParams;
+ std::tie(cpuParams, fusingParams) = obj.param;
+
+ std::ostringstream result;
+ result << "CPU_";
+ result << CPUTestsBase::getTestCaseName(cpuParams);
+ result << CpuTestWithFusing::getTestCaseName(fusingParams);
+ return result.str();
+ }
+
+ void SetUp() override {
+ const auto& [cpuParams, fusingParams] = this->GetParam();
+
+ std::tie(inFmts, outFmts, priority, selectedType) = cpuParams;
+ std::tie(postOpMgrPtr, fusedOps) = fusingParams;
+
+ ov::element::Type netPrecision = ov::element::f32;
+
+ targetDevice = ov::test::utils::DEVICE_CPU;
+
+ auto make_i8_fake_quantize = [&](std::shared_ptr<ov::Node> input, ov::element::Type dataType) {
+ return ov::test::utils::make_fake_quantize(input, dataType, 256, {}, {-1.28f}, {1.27f}, {-1.28f}, {1.27f});
+ };
+
+ auto make_u8_fake_quantize = [&](std::shared_ptr<ov::Node> input, ov::element::Type dataType) {
+ return ov::test::utils::make_fake_quantize(input, dataType, 256, {}, {0.0f}, {2.55f}, {0.0f}, {2.55f});
+ };
+
+ auto make_quantized_weights = [&make_i8_fake_quantize](const Shape& shape, ov::element::Type dataType) {
+ auto weights = ov::op::v0::Constant::create(dataType, shape, std::vector<float>{-0.0512377955019474});
+ return make_i8_fake_quantize(weights, dataType);
+ };
+
+ ov::ParameterVector params{std::make_shared<ov::op::v0::Parameter>(netPrecision, ov::Shape{1, 3, 8, 8})};
+
+ auto fq_input = make_u8_fake_quantize(params[0], netPrecision);
+ auto fq_weights = make_quantized_weights({3, 3, 4, 4}, netPrecision);
+
+ auto conv = std::make_shared<ov::op::v1::Convolution>(fq_input,
+ fq_weights,
+ Strides{1, 1},
+ CoordinateDiff{0, 0},
+ CoordinateDiff{0, 0},
+ Strides{1, 1},
+ ov::op::PadType::SAME_UPPER);
+
+ auto result = std::make_shared<ov::op::v0::Result>(conv);
+
+ function = makeNgraphFunction(netPrecision, params, conv, "Convolution");
+ }
+};
+
+TEST_P(ConvU8I8FP32, smoke_CompareWithRefs) {
+ run();
+ CheckPluginRelatedResults(compiledModel, "Convolution");
+}
+
+INSTANTIATE_TEST_SUITE_P(
+ smoke_Conv,
+ ConvU8I8FP32,
+ ::testing::Combine(::testing::ValuesIn(filterCPUInfo(
+ {CPUSpecificParams{{}, {}, {"jit_sse42"}, {"jit_sse42_I8"}}, // verify i8 SSE42 just in case
+ CPUSpecificParams{{}, {}, {"jit_avx2"}, {"jit_avx2_I8"}},
+ CPUSpecificParams{{}, {}, {"brgconv_avx512"}, {"brgconv_avx512_I8"}}})),
+ ::testing::Values(fusingPReluPerTensor)),
+ ConvU8I8FP32::getTestCaseName);
+
+} // namespace test
+} // namespace ov