Skip to content

Commit f9afe07

Browse files
[GPU] Add reorder between FC matmal and reshape (#11706)
1 parent 7335984 commit f9afe07

File tree

3 files changed

+38
-4
lines changed

3 files changed

+38
-4
lines changed

src/plugins/intel_gpu/src/graph/layout_optimizer.cpp

+7-1
Original file line numberDiff line numberDiff line change
@@ -1664,7 +1664,13 @@ format layout_optimizer::get_preferred_format(program_node& node) {
16641664
};
16651665
if (only_gemm_users(node)) {
16661666
// TODO: Gemm is not supporting fsv layouts
1667-
expected = format::bfyx;
1667+
if (node.get_output_layout().format.dimension() == 6) {
1668+
expected = format::bfwzyx;
1669+
} else if (node.get_output_layout().format.dimension() == 5) {
1670+
expected = format::bfzyx;
1671+
} else if (node.get_output_layout().format.dimension() == 4) {
1672+
expected = format::bfyx;
1673+
}
16681674
} else if (use_onednn_impls && needs_all_usr_onednn_small_ic_to_blocked(node)) {
16691675
// All user nodes are convolutions which satisfy options for onednn first conv
16701676
if (layout.data_type == data_types::f16) {

src/plugins/intel_gpu/src/plugin/ops/matmul.cpp

+29-3
Original file line numberDiff line numberDiff line change
@@ -157,12 +157,38 @@ static void CreateMatMulOp(Program& p, const std::shared_ptr<ngraph::op::v0::Mat
157157

158158
auto lastLayerName = layerName;
159159
if (reshape_fc) {
160-
auto outputShape = tensor_from_dims(op->get_output_shape(0));
161160
auto outReshapeName = layerName + "_cldnn_out_reshape";
162-
auto outReshapePrim = cldnn::reshape(outReshapeName, layerName, outputShape, op->get_friendly_name());
161+
162+
// add reorder
163+
auto outDims = op->get_output_shape(0);
164+
auto outTensor = tensor_from_dims(outDims);
165+
166+
if (outDims.size() > 4) {
167+
cldnn::format outputFormat = cldnn::format::bfyx;
168+
switch (outDims.size()) {
169+
case 5: outputFormat = cldnn::format::bfzyx; break;
170+
case 6: outputFormat = cldnn::format::bfwzyx; break;
171+
default: break;
172+
}
173+
174+
cldnn::primitive_id reorderId = "reorder:" + outReshapeName + "_reorder";
175+
cldnn::layout outputLayout(DataTypeFromPrecision(op->get_output_element_type(0)), outputFormat, outTensor);
176+
p.AddPrimitive(cldnn::reorder(reorderId,
177+
layerName,
178+
outputLayout,
179+
std::vector<float>(),
180+
cldnn::reorder_mean_mode::subtract,
181+
op->get_friendly_name()));
182+
p.InitProfileInfo(reorderId, "Reorder", false, InferenceEngine::InferenceEngineProfileInfo::EXECUTED, layerName);
183+
p.AddInnerPrimitiveToProfiler(reorderId, layerName, op);
184+
lastLayerName = reorderId;
185+
}
186+
187+
// add reshape
188+
auto outReshapePrim = cldnn::reshape(outReshapeName, lastLayerName, outTensor, op->get_friendly_name());
163189

164190
p.AddPrimitive(outReshapePrim);
165-
p.AddInnerPrimitiveToProfiler(outReshapeName, layerName, op);
191+
p.AddInnerPrimitiveToProfiler(outReshapeName, lastLayerName, op);
166192

167193
lastLayerName = outReshapeName;
168194
}

src/tests/functional/plugin/gpu/shared_tests_instances/single_layer_tests/mat_mul.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ const std::vector<InferenceEngine::Precision> inputPrecisions = {
1616
};
1717

1818
const std::vector<ShapeRelatedParams> shapeRelatedParams = {
19+
{ { {2, 1, 1, 5, 6}, false }, { {1, 1, 6, 4}, false } },
20+
{ { {2, 1, 2, 3, 5, 6}, false }, { {1, 1, 6, 4}, false } },
1921
{ { {1, 4, 5, 6}, false }, { {1, 4, 6, 4}, false } },
2022
{ { {1, 16, 128}, false }, { {1, 64, 128}, true } },
2123
{ { {4, 5, 6}, false }, { {6, 3}, false } },

0 commit comments

Comments
 (0)