Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 13 additions & 10 deletions src/plugins/intel_cpu/src/graph_optimizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@
#include <utility>
#include <vector>

#include "cpu/x64/cpu_isa_traits.hpp"
#if defined(OPENVINO_ARCH_X86) || defined(OPENVINO_ARCH_X86_64)
# include "cpu/x64/cpu_isa_traits.hpp"
# include "onednn/dnnl.h"
#endif

#include "cpu_types.h"
#include "dnnl_extension_utils.h"
#include "edge.h"
Expand All @@ -48,7 +52,6 @@
#include "nodes/rnn.h"
#include "nodes/scaled_attn.h"
#include "nodes/transpose.h"
#include "onednn/dnnl.h"
#include "onednn/iml_type_mapper.h"
#include "openvino/core/except.hpp"
#include "openvino/core/type/element_type.hpp"
Expand Down Expand Up @@ -1185,6 +1188,13 @@ void GraphOptimizer::FuseMatMulAndSimpleOperation(Graph& graph) {
}

void GraphOptimizer::FuseConvolutionAndDWConvolution(Graph& graph) {
#if defined(OPENVINO_ARCH_X86) || defined(OPENVINO_ARCH_X86_64)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems we better to refactor graph optimizer a bit to avoid ifdefs in such cases. There is also an ARM pr which changes the order of some optimizations based on arch. We could 'register' optimizations like it is done in core transformation pipeline.
Not asking to implement it in scope of this pr of course

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another order does not exclude this code from binaries for ARM and RISCV

// There is no optimized implementation for avx512, so two avx512 convolutions
// are expected to be faster than single fused avx2 convolution
if (!impl::cpu::x64::mayiuse(impl::cpu::x64::avx2) || impl::cpu::x64::mayiuse(impl::cpu::x64::avx512_core)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use utility implication(avx2, !avx512)?

return;
}

const auto& graphNodes = graph.GetNodes();

auto isConvolutionNode = [](const NodePtr& node) {
Expand Down Expand Up @@ -1313,14 +1323,6 @@ void GraphOptimizer::FuseConvolutionAndDWConvolution(Graph& graph) {

auto parentConvolutionNode = std::dynamic_pointer_cast<Convolution>(parentNode);
OPENVINO_ASSERT(parentConvolutionNode, "Cannot get convolution node ", parentNode->getName());
if (!impl::cpu::x64::mayiuse(impl::cpu::x64::avx2)) {
return false;
}
// there is no optimized implementation for avx512, so two avx512 convolutions
// are expected to be faster than single fused avx2 convolution
if (impl::cpu::x64::mayiuse(impl::cpu::x64::avx512_core)) {
return false;
}

return (dw_conv_input_size + dw_conv_output_size > L3_cache_size / 2);
};
Expand Down Expand Up @@ -1357,6 +1359,7 @@ void GraphOptimizer::FuseConvolutionAndDWConvolution(Graph& graph) {

graph.DropDWConvNode(childConvNode);
}
#endif
}

// TODO [NM]: unite with FuseConvolutionAndSimpleOperation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class AUGRUCellCPUTest : public testing::WithParamInterface<AUGRUCellCpuSpecific
auto augruCellOp =
ov::test::utils::make_augru(paramsOuts, WRB, hiddenSize /*, activations, {}, {}, clip, linearBeforeReset*/);

function = makeNgraphFunction(netPrecision, params, augruCellOp, "AUGRUCell");
function = create_ov_model(netPrecision, params, augruCellOp, "AUGRUCell");
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ class AUGRUSequenceCPUTest : public testing::WithParamInterface<AUGRUSequenceCpu
{batchSize}};
auto augruSequenceOp = ov::test::utils::make_augru(paramsOuts, WRB, hiddenSize, true, direction, seqMode);

function = makeNgraphFunction(netPrecision, params, augruSequenceOp, "augruSequenceOp");
function = create_ov_model(netPrecision, params, augruSequenceOp, "augruSequenceOp");

if (seqMode != ov::test::utils::SequenceTestsMode::PURE_SEQ) {
// TODO: ConvertAUGRUSequenceToTensorIterator
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ class BroadcastLayerCPUTest : public testing::WithParamInterface<BroadcastLayerC
}
}

function = makeNgraphFunction(netPrecision, functionParams, broadcastOp, "Broadcast");
function = create_ov_model(netPrecision, functionParams, broadcastOp, "Broadcast");
}

void generate_inputs(const std::vector<ov::Shape>& targetInputStaticShapes) override {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ void BitwiseShiftLayerCPUTest::SetUp() {
}

auto eltwise = utils::make_eltwise(parameters[0], secondaryInput, eltwiseType);
function = makeNgraphFunction(netType, parameters, eltwise, "Eltwise");
function = create_ov_model(netType, parameters, eltwise, "Eltwise");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't change, but It would be better to make re-factor as separate PR/

}

TEST_P(BitwiseShiftLayerCPUTest, CompareWithRefs) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ void Col2ImLayerCPUTest::SetUp() {
pads_begin,
pads_end);
ov::ParameterVector params{dataParameter};
function = makeNgraphFunction(inputPrecision, params, Col2Im, "Col2Im");
function = create_ov_model(inputPrecision, params, Col2Im, "Col2Im");
if (inputPrecision == ov::element::bf16) {
rel_threshold = 0.02;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ void ComparisonLayerCPUTest::SetUp() {
}
const auto comparison_node = ov::test::utils::make_comparison(params[0], secondInput, comparisonType);

function = makeNgraphFunction(currModelPrc, params, comparison_node, "Comparison");
function = create_ov_model(currModelPrc, params, comparison_node, "Comparison");
}

std::string ComparisonLayerCPUTest::getPrimitiveType(const utils::ComparisonTypes& type, ov::element::Type modelType) const {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ void ConvertCPULayerTest::SetUp() {
}
auto conversion = std::make_shared<ov::op::v0::Convert>(params.front(), outPrc);

function = makeNgraphFunction(inPrc, params, conversion, "ConversionCPU");
function = create_ov_model(inPrc, params, conversion, "ConversionCPU");

// issue 161636
if (special_value == ov::test::SpecialValue::none && outPrc == ov::element::f8e4m3) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ void ConvolutionLayerCPUTest::SetUp() {
auto convolution = ov::test::utils::make_convolution(inputParams[0], netType, kernel, stride, padBegin,
padEnd, dilation, padType, convOutChannels,
inputGenData.count(1) ? std::make_optional(inputGenData.at(1)) : std::nullopt);
function = makeNgraphFunction(netType, inputParams, convolution, "Convolution", qinfo);
function = create_ov_model(netType, inputParams, convolution, "Convolution", qinfo);
}

TEST_P(ConvolutionLayerCPUTest, CompareWithRefs) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ std::shared_ptr<ov::Model> DeconvolutionLayerCPUTest::createGraph(const std::vec
outPadding);
}

return makeNgraphFunction(prec, params, deconv, "DeconvCPU");
return create_ov_model(prec, params, deconv, "DeconvCPU");
}

void DeconvolutionLayerCPUTest::SetUp() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ void EltwiseLayerCPUTest::SetUp() {
}
}
auto eltwise = utils::make_eltwise(parameters[0], secondaryInput, eltwiseType);
function = makeNgraphFunction(netType, parameters, eltwise, "Eltwise");
function = create_ov_model(netType, parameters, eltwise, "Eltwise");
}

std::string EltwiseLayerCPUTest::getPrimitiveType(const utils::EltwiseTypes& eltwise_type,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ void GridSampleLayerTestCPU::SetUp() {
params[1]->set_friendly_name("grid");
ov::op::v9::GridSample::Attributes attributes = {alignCorners, interpolateMode, paddingMode};
auto gridSample = std::make_shared<ov::op::v9::GridSample>(params[0], params[1], attributes);
function = makeNgraphFunction(dataPrecision, params, gridSample, "GridSampleCPU");
function = create_ov_model(dataPrecision, params, gridSample, "GridSampleCPU");
}

TEST_P(GridSampleLayerTestCPU, CompareWithRefs) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ void InterpolateLayerCPUTest::SetUp() {
interp = std::make_shared<ov::op::v11::Interpolate>(params[0], sizesInput, axesInput, interpAttr);
}

function = makeNgraphFunction(ngPrc, params, interp, "InterpolateCPU");
function = create_ov_model(ngPrc, params, interp, "InterpolateCPU");

ov::pass::Manager m;
m.register_pass<ov::pass::ConvertInterpolate11ToInterpolate4>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ void LogicalLayerCPUTest::SetUp() {
logical_node = std::make_shared<ov::op::v1::LogicalNot>(params[0]);
}

function = makeNgraphFunction(prc, params, logical_node, "Logical");
function = create_ov_model(prc, params, logical_node, "Logical");
}

std::string LogicalLayerCPUTest::getPrimitiveType(const utils::LogicalTypes& type) const {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ void MatMulLayerCPUTest::SetUp() {
}

auto matMul = std::make_shared<ov::op::v0::MatMul>(paramOuts[0], matrixB, transpA, transpB);
function = makeNgraphFunction(netType, params, matMul, cpuNodeType);
function = create_ov_model(netType, params, matMul, cpuNodeType);
checkFusingPosition = false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ void MvnLayerCPUTest::SetUp() {
configuration.insert(additionalConfig.begin(), additionalConfig.end());
updateSelectedType(getPrimitiveType(), netPrecision, configuration);

function = makeNgraphFunction(netPrecision, params, mvn, "mvn");
function = create_ov_model(netPrecision, params, mvn, "mvn");
}

TEST_P(MvnLayerCPUTest, CompareWithRefs) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ void PoolingLayerCPUTest::SetUp() {
pooling = std::make_shared<ov::op::v1::AvgPool>(poolInput, stride, padBegin, padEnd, kernel, excludePad, roundingType, padType);
}

function = makeNgraphFunction(inPrc, params, pooling, "PoolingCPU");
function = create_ov_model(inPrc, params, pooling, "PoolingCPU");
}

std::string AvgPoolingV14LayerCPUTest::getTestCaseName(const testing::TestParamInfo<poolLayerCpuTestParamsSet>& obj) {
Expand Down Expand Up @@ -157,7 +157,7 @@ void AvgPoolingV14LayerCPUTest::SetUp() {

auto pooling = std::make_shared<ov::op::v14::AvgPool>(poolInput, stride, padBegin, padEnd, kernel, excludePad, roundingType, padType);

function = makeNgraphFunction(inPrc, params, pooling, "PoolingCPU");
function = create_ov_model(inPrc, params, pooling, "PoolingCPU");
}

std::string MaxPoolingV8LayerCPUTest::getTestCaseName(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ void ReduceCPULayerTest::SetUp() {
}
}

function = makeNgraphFunction(netPrecision, params, reduce, "Reduce");
function = create_ov_model(netPrecision, params, reduce, "Reduce");

if (netPrecision == ov::element::f32 && configuration.count(ov::hint::inference_precision.name()) &&
configuration.at(ov::hint::inference_precision.name()) == ov::element::f16) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ void RMSNormLayerCPUTest::SetUp() {
inputParams.push_back(scale);
auto rms = std::make_shared<ov::op::internal::RMS>(data, scale, 0.1f);
rms->set_friendly_name("rms");
function = makeNgraphFunction(inType, inputParams, rms, "rms");
function = create_ov_model(inType, inputParams, rms, "rms");
}

TEST_P(RMSNormLayerCPUTest, CompareWithRefs) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ void ScaledAttnLayerCPUTest::SetUp() {
}
auto sdp = std::make_shared<ov::opset13::ScaledDotProductAttention>(inputs, is_causal);
sdp->set_friendly_name("mha");
function = makeNgraphFunction(inType, inputParams, sdp, "SDP");
function = create_ov_model(inType, inputParams, sdp, "SDP");
}

void ScaledAttnLayerCPUTest::generate_inputs(const std::vector<ov::Shape>& targetInputStaticShapes) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ void SegmentMaxLayerCPUTest::SetUp() {
segmentMax = std::make_shared<ov::op::v16::SegmentMax>(dataParameter, segmentIdsParameter, fillMode);
}
}
function = makeNgraphFunction(inputPrecision, params, segmentMax, "SegmentMax");
function = create_ov_model(inputPrecision, params, segmentMax, "SegmentMax");
}

TEST_P(SegmentMaxLayerCPUTest, CompareWithRefs) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ void SoftMaxLayerCPUTest::SetUp() {

const auto softMax = std::make_shared<ov::op::v1::Softmax>(params.at(0), config.axis);

function = makeNgraphFunction(inType, params, softMax, "SoftMax");
function = create_ov_model(inType, params, softMax, "SoftMax");
}

TEST_P(SoftMaxLayerCPUTest, CompareWithRefs) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ void SparseFillEmptyRowsLayerCPUTest::SetUp() {
sparseFillEmptyRows = std::make_shared<ov::op::v16::SparseFillEmptyRows>(
valuesParameter, denseShapeParameter, indicesParameter, defaultValueParameter);
}
function = makeNgraphFunction(valuesPrecision, params, sparseFillEmptyRows, "SparseFillEmptyRows");
function = create_ov_model(valuesPrecision, params, sparseFillEmptyRows, "SparseFillEmptyRows");
}

TEST_P(SparseFillEmptyRowsLayerCPUTest, CompareWithRefs) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ void StringTensorPackLayerCPUTest::SetUp() {
auto StringTensorPack =
std::make_shared<ov::op::v15::StringTensorPack>(beginsParameter, endsParameter, symbolsParameter);
ov::ParameterVector params{beginsParameter, endsParameter, symbolsParameter};
function = makeNgraphFunction(ov::element::string, params, StringTensorPack, "StringTensorPack");
function = create_ov_model(ov::element::string, params, StringTensorPack, "StringTensorPack");
}

TEST_P(StringTensorPackLayerCPUTest, CompareWithRefs) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ void StringTensorUnpackLayerCPUTest::SetUp() {
auto dataParameter = std::make_shared<ov::op::v0::Parameter>(ov::element::string, inputDynamicShapes[0]);
auto StringTensorUnpack = std::make_shared<ov::op::v15::StringTensorUnpack>(dataParameter);
ov::ParameterVector params{dataParameter};
function = makeNgraphFunction(ov::element::string, params, StringTensorUnpack, "StringTensorUnpack");
function = create_ov_model(ov::element::string, params, StringTensorUnpack, "StringTensorUnpack");
}

TEST_P(StringTensorUnpackLayerCPUTest, CompareWithRefs) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class ConcatLayerCPUTest : public testing::WithParamInterface<concatCPUTestParam
}
auto concat = std::make_shared<ov::op::v0::Concat>(paramsOuts, axis);

function = makeNgraphFunction(netPrecision, params, concat, "ConcatCPU");
function = create_ov_model(netPrecision, params, concat, "ConcatCPU");
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ class DefConvLayerCPUTest : public testing::WithParamInterface<DefConvLayerCPUTe
withBilinearInterpolationPad);
}

function = makeNgraphFunction(netPrecision, parameters, deformable_conv, "deformable_convolution");
function = create_ov_model(netPrecision, parameters, deformable_conv, "deformable_convolution");

if (netPrecision == ov::element::f32) {
abs_threshold = 5e-6;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class DepthToSpaceLayerCPUTest : public testing::WithParamInterface<DepthToSpace
params.push_back(std::make_shared<ov::op::v0::Parameter>(inType, shape));
}
auto d2s = std::make_shared<ov::op::v0::DepthToSpace>(params[0], mode, blockSize);
function = makeNgraphFunction(inType, params, d2s, "DepthToSpace");
function = create_ov_model(inType, params, d2s, "DepthToSpace");
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class ExtractImagePatchesLayerCPUTest : public testing::WithParamInterface<extra
}
auto extImgPatches =
std::make_shared<ov::op::v3::ExtractImagePatches>(params[0], kernelSize, strides, rates, padType);
function = makeNgraphFunction(inputPrecision, params, extImgPatches, "ExtractImagePatches");
function = create_ov_model(inputPrecision, params, extImgPatches, "ExtractImagePatches");
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,11 @@ class EyeLayerCPUTest : public testing::WithParamInterface<EyeLayerCPUTestParams
auto eyelikeBatchShape =
std::make_shared<ov::op::v9::Eye>(rowsPar, colsPar, diagPar, batchShapePar, ov::element::i32);
eyelikeBatchShape->get_rt_info() = getCPUInfo();
return makeNgraphFunction(ov::element::i32, inputParams, eyelikeBatchShape, "Eye");
return create_ov_model(ov::element::i32, inputParams, eyelikeBatchShape, "Eye");
} else {
auto eyelikePure = std::make_shared<ov::op::v9::Eye>(rowsPar, colsPar, diagPar, ov::element::i32);
eyelikePure->get_rt_info() = getCPUInfo();
return makeNgraphFunction(ov::element::i32, inputParams, eyelikePure, "Eye");
return create_ov_model(ov::element::i32, inputParams, eyelikePure, "Eye");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class FakeQuantizeLayerCPUTest : public testing::WithParamInterface<fqLayerTestP
selectedType = getPrimitiveType() + "_" + inPrec.get_type_name();
}

function = makeNgraphFunction(inPrec, params, fq, "FakeQuantizeCPU");
function = create_ov_model(inPrec, params, fq, "FakeQuantizeCPU");

if (inPrec == ov::element::f32) {
abs_threshold = 1e-4;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class GatherLayerTestCPU : public testing::WithParamInterface<GatherLayerTestCPU
gatherNode = std::make_shared<ov::op::v8::Gather>(params[0], params[1], params[2], batchDims);
}

function = makeNgraphFunction(netPrecision, params, gatherNode, "GatherCPU");
function = create_ov_model(netPrecision, params, gatherNode, "GatherCPU");
}

void generate_inputs(const std::vector<ov::Shape>& targetInputStaticShapes) override {
Expand Down Expand Up @@ -192,7 +192,7 @@ class GatherInPlaceLayerTestCPU : public testing::WithParamInterface<GatherInPla
ov::op::v0::Constant::create(intInputsPrecision, ov::Shape({1}), {axis}),
batchDims);

function = makeNgraphFunction(netPrecision, params, gatherNode, "GatherCPU");
function = create_ov_model(netPrecision, params, gatherNode, "GatherCPU");
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class GatherElementsCPUTest : public testing::WithParamInterface<GatherElementsC
};

auto gather = std::make_shared<ov::op::v6::GatherElements>(params[0], params[1], axis);
function = makeNgraphFunction(dPrecision, params, gather, "GatherElements");
function = create_ov_model(dPrecision, params, gather, "GatherElements");
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ class GroupConvolutionLayerCPUTest : public testing::WithParamInterface<groupCon
padType,
convOutChannels,
numGroups);
function = makeNgraphFunction(netType, params, groupConv, "groupConvolution");
function = create_ov_model(netType, params, groupConv, "groupConvolution");
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ class GroupDeconvolutionLayerCPUTest : public testing::WithParamInterface<GroupD
outPadding);
}

return makeNgraphFunction(prec, params, deconv, "GroupDeconvCPU");
return create_ov_model(prec, params, deconv, "GroupDeconvCPU");
}

protected:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class GRUCellCPUTest : public testing::WithParamInterface<GRUCellCpuSpecificPara
auto gruCellOp =
ov::test::utils::make_gru(paramsOuts, WRB, hiddenSize, activations, {}, {}, clip, linearBeforeReset);

function = makeNgraphFunction(netPrecision, params, gruCellOp, "GRUCell");
function = create_ov_model(netPrecision, params, gruCellOp, "GRUCell");
}
};

Expand Down
Loading
Loading