diff --git a/src/plugins/intel_gpu/include/intel_gpu/plugin/common_utils.hpp b/src/plugins/intel_gpu/include/intel_gpu/plugin/common_utils.hpp index ccb2cb84f98..929a8fb91b3 100644 --- a/src/plugins/intel_gpu/include/intel_gpu/plugin/common_utils.hpp +++ b/src/plugins/intel_gpu/include/intel_gpu/plugin/common_utils.hpp @@ -170,25 +170,6 @@ inline cldnn::format ImageFormatFromLayout(InferenceEngine::Layout l) { } } -inline cldnn::format DefaultFormatForDims(size_t dimensions) { - switch (dimensions) { - case 0: - case 1: - case 2: - case 3: - case 4: - return cldnn::format::bfyx; - case 5: - return cldnn::format::bfzyx; - case 6: - return cldnn::format::bfwzyx; - default: - IE_THROW() << "Unsupported number of dimensions: " << dimensions; - } - - return cldnn::format::bfyx; // Should not get here -} - inline InferenceEngine::Layout InferenceEngineLayoutFromOVLayout(ov::Layout l) { if (l == ov::Layout("C")) return InferenceEngine::Layout::C; if (l == ov::Layout("CN")) return InferenceEngine::Layout::CN; diff --git a/src/plugins/intel_gpu/include/intel_gpu/runtime/format.hpp b/src/plugins/intel_gpu/include/intel_gpu/runtime/format.hpp index fa0db51f5cb..f30e1c3cc98 100644 --- a/src/plugins/intel_gpu/include/intel_gpu/runtime/format.hpp +++ b/src/plugins/intel_gpu/include/intel_gpu/runtime/format.hpp @@ -299,31 +299,9 @@ struct format { fmt == bfzyx || fmt == bfwzyx); } - static format get_default_format(size_t rank, bool is_weights = false, bool is_grouped = false) { - auto default_fmt = cldnn::format::bfyx; - if (is_weights) { - if (is_grouped) { - if (rank == 5) { - default_fmt = cldnn::format::goiyx; - } else if (rank == 6) { - default_fmt = cldnn::format::goizyx; - } - } else { - if (rank == 4) { - default_fmt = cldnn::format::oiyx; - } else if (rank == 5) { - default_fmt = cldnn::format::oizyx; - } - } - } else { - if (rank == 5) { - default_fmt = cldnn::format::bfzyx; - } else if (rank == 6) { - default_fmt = cldnn::format::bfwzyx; - } - } - return default_fmt; - } + static format get_default_format(size_t rank, bool is_weights = false, bool is_grouped = false); + + static format adjust_to_rank(format fmt, size_t new_rank); /// @brief Checks if @p format is of grouped type static bool is_grouped(type fmt) { return group_num(fmt) != 0; } diff --git a/src/plugins/intel_gpu/include/intel_gpu/runtime/memory.hpp b/src/plugins/intel_gpu/include/intel_gpu/runtime/memory.hpp index af106273fd2..25d0cf4e21a 100644 --- a/src/plugins/intel_gpu/include/intel_gpu/runtime/memory.hpp +++ b/src/plugins/intel_gpu/include/intel_gpu/runtime/memory.hpp @@ -166,7 +166,7 @@ struct surfaces_lock { }; template -inline std::vector read_vector(cldnn::memory::ptr mem, cldnn::stream& stream) { +inline std::vector read_vector(cldnn::memory::ptr mem, const cldnn::stream& stream) { std::vector out_vecs; if (mem->get_allocation_type() == allocation_type::usm_host || mem->get_allocation_type() == allocation_type::usm_shared) { switch (mem->get_layout().data_type) { @@ -184,19 +184,21 @@ inline std::vector read_vector(cldnn::memory::ptr mem, cldnn::stream& stream) } break; } - default: throw ov::Exception("[GPU] read_vector: unsupported data type"); + default: OPENVINO_ASSERT(false, "[GPU] read_vector: unsupported data type"); } } else { switch (mem->get_layout().data_type) { case data_types::i32: { mem_lock lock{mem, stream}; out_vecs = std::move(std::vector(lock.begin(), lock.end())); + break; } case data_types::i64: { mem_lock lock{mem, stream}; out_vecs = std::move(std::vector(lock.begin(), lock.end())); + break; } - default: throw ov::Exception("[GPU] read_vector: unsupported data type"); + default: OPENVINO_ASSERT(false, "[GPU] read_vector: unsupported data type"); } } return out_vecs; diff --git a/src/plugins/intel_gpu/src/plugin/ops/adaptive_pooling.cpp b/src/plugins/intel_gpu/src/plugin/ops/adaptive_pooling.cpp index 1741b52971e..5c1bf0671a8 100644 --- a/src/plugins/intel_gpu/src/plugin/ops/adaptive_pooling.cpp +++ b/src/plugins/intel_gpu/src/plugin/ops/adaptive_pooling.cpp @@ -42,7 +42,7 @@ static void CreateAdaptiveMaxPoolOp(Program& p, const std::shared_ptrget_output_element_type(1); const auto indices_shape = op->get_output_shape(1); const cldnn::layout indices_layout{DataTypeFromPrecision(indices_precision), - DefaultFormatForDims(indices_shape.size()), + cldnn::format::get_default_format(indices_shape.size()), tensor_from_dims(indices_shape)}; const auto indices_memory = p.GetEngine().allocate_memory(indices_layout); diff --git a/src/plugins/intel_gpu/src/plugin/ops/batch_to_space.cpp b/src/plugins/intel_gpu/src/plugin/ops/batch_to_space.cpp index 6cd678e7e78..a519ffa15f4 100644 --- a/src/plugins/intel_gpu/src/plugin/ops/batch_to_space.cpp +++ b/src/plugins/intel_gpu/src/plugin/ops/batch_to_space.cpp @@ -19,7 +19,7 @@ static void CreateBatchToSpaceOp(Program& p, const std::shared_ptrget_input_shape(0).size(); - auto format = DefaultFormatForDims(rank); + auto format = cldnn::format::get_default_format(rank); std::vector inputs; inputs.reserve(3); diff --git a/src/plugins/intel_gpu/src/plugin/ops/broadcast.cpp b/src/plugins/intel_gpu/src/plugin/ops/broadcast.cpp index 70fbdb22766..80fbaf19ffb 100644 --- a/src/plugins/intel_gpu/src/plugin/ops/broadcast.cpp +++ b/src/plugins/intel_gpu/src/plugin/ops/broadcast.cpp @@ -28,8 +28,8 @@ static void CreateCommonBroadcastOp(Program& p, const std::shared_ptrget_input_element_type(0)); auto reorderPrim = cldnn::reorder(reorderName, diff --git a/src/plugins/intel_gpu/src/plugin/ops/constant.cpp b/src/plugins/intel_gpu/src/plugin/ops/constant.cpp index dce1781a081..cd6c945a43f 100644 --- a/src/plugins/intel_gpu/src/plugin/ops/constant.cpp +++ b/src/plugins/intel_gpu/src/plugin/ops/constant.cpp @@ -143,7 +143,7 @@ static void CreateConstantOp(Program& p, const std::shared_ptr& op, const ConstProperties& props) { cldnn::tensor constTensor = getConstTensor(constDims); - auto constFormat = DefaultFormatForDims(constDims.size()); + auto constFormat = cldnn::format::get_default_format(constDims.size()); if (props.needsBatchInterpretation) { constTensor.batch[0] = constTensor.count(); diff --git a/src/plugins/intel_gpu/src/plugin/ops/ctc_greedy_decoder.cpp b/src/plugins/intel_gpu/src/plugin/ops/ctc_greedy_decoder.cpp index 98dc05eea8e..bb9d0f51125 100644 --- a/src/plugins/intel_gpu/src/plugin/ops/ctc_greedy_decoder.cpp +++ b/src/plugins/intel_gpu/src/plugin/ops/ctc_greedy_decoder.cpp @@ -31,7 +31,7 @@ static void CreateCommonCTCGreedyDecoderOp(Program& p, const std::shared_ptrget_friendly_name() + Program::m_preProcessTag; - auto targetFormat = DefaultFormatForDims(op->get_input_shape(portIndex).size()); + auto targetFormat = cldnn::format::get_default_format(op->get_input_shape(portIndex).size()); auto preprocessPrim = cldnn::reorder(reorderPrimName, inputPrimitives[portIndex], targetFormat, @@ -72,7 +72,7 @@ static void CreateCommonCTCGreedyDecoderOp(Program& p, const std::shared_ptrget_output_shape(1).size()), + cldnn::format::get_default_format(op->get_output_shape(1).size()), tensor_from_dims(op->get_output_shape(1))); GPU_DEBUG_GET_INSTANCE(debug_config); diff --git a/src/plugins/intel_gpu/src/plugin/ops/custom.cpp b/src/plugins/intel_gpu/src/plugin/ops/custom.cpp index d1e55415253..b3edead7287 100644 --- a/src/plugins/intel_gpu/src/plugin/ops/custom.cpp +++ b/src/plugins/intel_gpu/src/plugin/ops/custom.cpp @@ -243,7 +243,7 @@ void CreateCustomOp(Program& p, const std::shared_ptr& op, CustomL p.AddPrimitive( cldnn::reorder(reorderPrimName, genericLayerName, - DefaultFormatForDims(op->get_output_shape(0).size()), + cldnn::format::get_default_format(op->get_output_shape(0).size()), customPrim.output_layout.data_type, std::vector(), cldnn::reorder_mean_mode::subtract, diff --git a/src/plugins/intel_gpu/src/plugin/ops/eltwise.cpp b/src/plugins/intel_gpu/src/plugin/ops/eltwise.cpp index 49124738513..166f118911b 100644 --- a/src/plugins/intel_gpu/src/plugin/ops/eltwise.cpp +++ b/src/plugins/intel_gpu/src/plugin/ops/eltwise.cpp @@ -43,8 +43,8 @@ void CreateElementwiseOp(Program& p, const std::shared_ptr& op, cl auto inputRank = inputShape.size(); if (inputRank != outRank) { // Add reorder if changing number of dimensions requires changing format - auto targetFormat = DefaultFormatForDims(outRank); - if (targetFormat.value != DefaultFormatForDims(inputRank).value) { + auto targetFormat = cldnn::format::get_default_format(outRank); + if (targetFormat.value != cldnn::format::get_default_format(inputRank).value) { auto reorderName = layerName + "_cldnn_in" + std::to_string(i) + "_reorder"; auto targetDatatype = DataTypeFromPrecision(op->get_input_element_type(i)); auto reorderPrim = cldnn::reorder(reorderName, diff --git a/src/plugins/intel_gpu/src/plugin/ops/embedding_bag.cpp b/src/plugins/intel_gpu/src/plugin/ops/embedding_bag.cpp index 87b6faa2498..3d61bc6d2bb 100644 --- a/src/plugins/intel_gpu/src/plugin/ops/embedding_bag.cpp +++ b/src/plugins/intel_gpu/src/plugin/ops/embedding_bag.cpp @@ -46,7 +46,7 @@ static void CreateEmbeddingBagOffsetsSumOp(Program& p, const std::shared_ptrget_friendly_name() + Program::m_preProcessTag; - auto targetFormat = DefaultFormatForDims(op->get_input_shape(portIndex).size()); + auto targetFormat = cldnn::format::get_default_format(op->get_input_shape(portIndex).size()); auto preprocessPrim = cldnn::reorder(reorderPrimName, inputPrimitives[portIndex], targetFormat, @@ -87,7 +87,7 @@ static void CreateEmbeddingBagPackedSumOp(Program& p, const std::shared_ptrget_friendly_name() + Program::m_preProcessTag; - auto targetFormat = DefaultFormatForDims(op->get_input_shape(portIndex).size()); + auto targetFormat = cldnn::format::get_default_format(op->get_input_shape(portIndex).size()); auto preprocessPrim = cldnn::reorder(reorderPrimName, inputPrimitives[portIndex], targetFormat, @@ -146,7 +146,7 @@ static void CreateEmbeddingSegmentsSumOp(Program& p, const std::shared_ptrget_friendly_name() + Program::m_preProcessTag; - auto targetFormat = DefaultFormatForDims(op->get_input_shape(portIndex).size()); + auto targetFormat = cldnn::format::get_default_format(op->get_input_shape(portIndex).size()); auto preprocessPrim = cldnn::reorder(reorderPrimName, inputPrimitives[portIndex], targetFormat, diff --git a/src/plugins/intel_gpu/src/plugin/ops/experimental_detectron_detection_output.cpp b/src/plugins/intel_gpu/src/plugin/ops/experimental_detectron_detection_output.cpp index 0735169ae14..4274439f93a 100644 --- a/src/plugins/intel_gpu/src/plugin/ops/experimental_detectron_detection_output.cpp +++ b/src/plugins/intel_gpu/src/plugin/ops/experimental_detectron_detection_output.cpp @@ -33,7 +33,7 @@ static void CreateExperimentalDetectronDetectionOutputOp( const auto mutable_precision1 = op->get_output_element_type(1); const auto output_shape1 = op->get_output_shape(1); const cldnn::layout mutable_layout1{DataTypeFromPrecision(mutable_precision1), - DefaultFormatForDims(output_shape1.size()), + cldnn::format::get_default_format(output_shape1.size()), tensor_from_dims(output_shape1)}; cldnn::memory::ptr shared_memory1{p.GetEngine().allocate_memory(mutable_layout1)}; @@ -46,7 +46,7 @@ static void CreateExperimentalDetectronDetectionOutputOp( const auto mutable_precision2 = op->get_output_element_type(2); const auto output_shape2 = op->get_output_shape(2); const cldnn::layout mutable_layout2{DataTypeFromPrecision(mutable_precision2), - DefaultFormatForDims(output_shape2.size()), + cldnn::format::get_default_format(output_shape2.size()), tensor_from_dims(output_shape2)}; cldnn::memory::ptr shared_memory2{p.GetEngine().allocate_memory(mutable_layout2)}; diff --git a/src/plugins/intel_gpu/src/plugin/ops/experimental_detectron_generate_proposals_single_image.cpp b/src/plugins/intel_gpu/src/plugin/ops/experimental_detectron_generate_proposals_single_image.cpp index b1e7a9e369f..dc5f7d88e73 100644 --- a/src/plugins/intel_gpu/src/plugin/ops/experimental_detectron_generate_proposals_single_image.cpp +++ b/src/plugins/intel_gpu/src/plugin/ops/experimental_detectron_generate_proposals_single_image.cpp @@ -33,7 +33,7 @@ static void CreateExperimentalDetectronGenerateProposalsSingleImageOp( const auto mutable_precision = op->get_output_element_type(1); const auto output_shape = op->get_output_shape(1); const cldnn::layout mutable_layout{DataTypeFromPrecision(mutable_precision), - DefaultFormatForDims(output_shape.size()), + cldnn::format::get_default_format(output_shape.size()), tensor_from_dims(output_shape)}; cldnn::memory::ptr shared_memory{p.GetEngine().allocate_memory(mutable_layout)}; diff --git a/src/plugins/intel_gpu/src/plugin/ops/experimental_detectron_roi_feature_extractor.cpp b/src/plugins/intel_gpu/src/plugin/ops/experimental_detectron_roi_feature_extractor.cpp index cdd3c69a468..fdc47a071eb 100644 --- a/src/plugins/intel_gpu/src/plugin/ops/experimental_detectron_roi_feature_extractor.cpp +++ b/src/plugins/intel_gpu/src/plugin/ops/experimental_detectron_roi_feature_extractor.cpp @@ -19,7 +19,7 @@ static void CreateExperimentalDetectronROIFeatureExtractorOp(Program& p, const s cldnn::layout mutableLayout = cldnn::layout( DataTypeFromPrecision(op->get_output_element_type(1)), - DefaultFormatForDims(op->get_output_shape(1).size()), + cldnn::format::get_default_format(op->get_output_shape(1).size()), tensor_from_dims(op->get_output_shape(1))); cldnn::memory::ptr shared_memory {p.GetEngine().allocate_memory(mutableLayout)}; diff --git a/src/plugins/intel_gpu/src/plugin/ops/gather tree.cpp b/src/plugins/intel_gpu/src/plugin/ops/gather tree.cpp index 15fbe279081..6513479cbe4 100644 --- a/src/plugins/intel_gpu/src/plugin/ops/gather tree.cpp +++ b/src/plugins/intel_gpu/src/plugin/ops/gather tree.cpp @@ -27,7 +27,7 @@ static void CreateGatherTreeOp(Program& p, const std::shared_ptrget_friendly_name() + Program::m_preProcessTag; - auto targetFormat = DefaultFormatForDims(op->get_input_shape(portIndex).size()); + auto targetFormat = cldnn::format::get_default_format(op->get_input_shape(portIndex).size()); auto preprocessPrim = cldnn::reorder(reorderPrimName, inputPrimitives[portIndex], targetFormat, diff --git a/src/plugins/intel_gpu/src/plugin/ops/gather.cpp b/src/plugins/intel_gpu/src/plugin/ops/gather.cpp index 3872c35243d..f145d0ebce2 100644 --- a/src/plugins/intel_gpu/src/plugin/ops/gather.cpp +++ b/src/plugins/intel_gpu/src/plugin/ops/gather.cpp @@ -29,7 +29,7 @@ void CreateGatherOpBase(Program& p, const std::shared_ptr& op, const int64_t // GPU primitive does not support i64 inputs, // so we need additional reorders to convert them to i32 auto reorderPrimName = inputPrimitives[portIndex] + "_" + op->get_friendly_name() + Program::m_preProcessTag; - auto targetFormat = DefaultFormatForDims(op->get_input_shape(portIndex).size()); + auto targetFormat = cldnn::format::get_default_format(op->get_input_shape(portIndex).size()); auto preprocessPrim = cldnn::reorder(reorderPrimName, inputPrimitives[portIndex], targetFormat, diff --git a/src/plugins/intel_gpu/src/plugin/ops/gather_elements.cpp b/src/plugins/intel_gpu/src/plugin/ops/gather_elements.cpp index d8437ed7e2f..fa5c0c5e93f 100644 --- a/src/plugins/intel_gpu/src/plugin/ops/gather_elements.cpp +++ b/src/plugins/intel_gpu/src/plugin/ops/gather_elements.cpp @@ -49,7 +49,7 @@ static void CreateGatherElementsOp(Program& p, const std::shared_ptrget_input_shape(0).size(); int32_t axis = static_cast(op->get_axis()); - auto outLayout = DefaultFormatForDims(op->get_output_shape(0).size()); + auto outLayout = cldnn::format::get_default_format(op->get_output_shape(0).size()); auto primitive = cldnn::gather_elements(layerName, inputPrimitives[0], diff --git a/src/plugins/intel_gpu/src/plugin/ops/loop.cpp b/src/plugins/intel_gpu/src/plugin/ops/loop.cpp index dde1508dbf0..3845a11adcc 100644 --- a/src/plugins/intel_gpu/src/plugin/ops/loop.cpp +++ b/src/plugins/intel_gpu/src/plugin/ops/loop.cpp @@ -41,7 +41,7 @@ static cldnn::mutable_data CreateAdditionalOutputData(Program &p, const std::sha const cldnn::primitive_id& id, const cldnn::primitive_id& input, const int32_t output_idx) { const auto precision = DataTypeFromPrecision(op->get_output_element_type(output_idx)); - const auto format = DefaultFormatForDims(op->get_output_shape(output_idx).size()); + const auto format = cldnn::format::get_default_format(op->get_output_shape(output_idx).size()); const auto tensor = tensor_from_dims(op->get_output_shape(output_idx)); cldnn::layout output_layout = cldnn::layout(precision, format, tensor); auto mem = p.GetEngine().allocate_memory(output_layout); diff --git a/src/plugins/intel_gpu/src/plugin/ops/matmul.cpp b/src/plugins/intel_gpu/src/plugin/ops/matmul.cpp index 9471f288692..81126cf610a 100644 --- a/src/plugins/intel_gpu/src/plugin/ops/matmul.cpp +++ b/src/plugins/intel_gpu/src/plugin/ops/matmul.cpp @@ -214,9 +214,9 @@ static void CreateMatMulOp(Program& p, const std::shared_ptrget_output_element_type(0)); auto reorderPrim = cldnn::reorder(reorderName, diff --git a/src/plugins/intel_gpu/src/plugin/ops/non_max_suppression.cpp b/src/plugins/intel_gpu/src/plugin/ops/non_max_suppression.cpp index c37cedd0c7d..a9a2ca805bf 100644 --- a/src/plugins/intel_gpu/src/plugin/ops/non_max_suppression.cpp +++ b/src/plugins/intel_gpu/src/plugin/ops/non_max_suppression.cpp @@ -29,7 +29,7 @@ static void CreateNonMaxSuppressionIEInternalOp(Program& p, const std::shared_pt // GPU primitive supports only i32 data type for 'max_output_boxes_per_class' input // so we need additional reorder if it's provided as i64 auto reorderPrimName = inputPrimitives[portIndex] + "_" + op->get_friendly_name() + Program::m_preProcessTag; - auto targetFormat = DefaultFormatForDims(op->get_input_shape(portIndex).size()); + auto targetFormat = cldnn::format::get_default_format(op->get_input_shape(portIndex).size()); auto preprocessPrim = cldnn::reorder(reorderPrimName, inputPrimitives[portIndex], targetFormat, @@ -67,7 +67,7 @@ static void CreateNonMaxSuppressionIEInternalOp(Program& p, const std::shared_pt } cldnn::layout mutableLayoutSecond = cldnn::layout( DataTypeFromPrecision(mutable_precision_second), - DefaultFormatForDims(op->get_output_shape(2).size()), + cldnn::format::get_default_format(op->get_output_shape(2).size()), tensor_from_dims(op->get_output_shape(2))); GPU_DEBUG_IF(debug_config->verbose >= 2) { diff --git a/src/plugins/intel_gpu/src/plugin/ops/pooling.cpp b/src/plugins/intel_gpu/src/plugin/ops/pooling.cpp index 3bc152b483d..4e92db7b630 100644 --- a/src/plugins/intel_gpu/src/plugin/ops/pooling.cpp +++ b/src/plugins/intel_gpu/src/plugin/ops/pooling.cpp @@ -86,7 +86,7 @@ static void CreateMaxPoolOp(Program& p, const std::shared_ptrget_output_element_type(1); const auto output_shape = op->get_output_shape(1); cldnn::layout mutableLayout = cldnn::layout(DataTypeFromPrecision(mutable_precision), - DefaultFormatForDims(output_shape.size()), + cldnn::format::get_default_format(output_shape.size()), tensor_from_dims(output_shape)); const auto shared_memory = p.GetEngine().allocate_memory(mutableLayout); const cldnn::primitive_id maxpool_mutable_id_w = layer_type_name + "_md_write"; diff --git a/src/plugins/intel_gpu/src/plugin/ops/proposal.cpp b/src/plugins/intel_gpu/src/plugin/ops/proposal.cpp index 328dd64a334..de7897e1f6c 100644 --- a/src/plugins/intel_gpu/src/plugin/ops/proposal.cpp +++ b/src/plugins/intel_gpu/src/plugin/ops/proposal.cpp @@ -61,7 +61,7 @@ static void CreateProposalOp(Program& p, const std::shared_ptrget_output_shape(1).size()), + cldnn::format::get_default_format(op->get_output_shape(1).size()), tensor_from_dims(op->get_output_shape(1))); GPU_DEBUG_GET_INSTANCE(debug_config); diff --git a/src/plugins/intel_gpu/src/plugin/ops/random_uniform.cpp b/src/plugins/intel_gpu/src/plugin/ops/random_uniform.cpp index 51e1cfb228d..de4c6491029 100644 --- a/src/plugins/intel_gpu/src/plugin/ops/random_uniform.cpp +++ b/src/plugins/intel_gpu/src/plugin/ops/random_uniform.cpp @@ -16,7 +16,7 @@ namespace { void CreateRandomUniformOp(Program &p, const std::shared_ptr &op) { auto input_primitives = p.GetInputPrimitiveIDs(op); auto output_shape = op->get_output_shape(0); - cldnn::format outputFormat = DefaultFormatForDims(output_shape.size()); + cldnn::format outputFormat = cldnn::format::get_default_format(output_shape.size()); auto random_uniform_prim = cldnn::random_uniform(layer_type_name_ID(op), input_primitives, diff --git a/src/plugins/intel_gpu/src/plugin/ops/roll.cpp b/src/plugins/intel_gpu/src/plugin/ops/roll.cpp index 6a0c35c1e77..3d544bf6866 100644 --- a/src/plugins/intel_gpu/src/plugin/ops/roll.cpp +++ b/src/plugins/intel_gpu/src/plugin/ops/roll.cpp @@ -22,7 +22,7 @@ void CreateRollOp(Program& p, const std::shared_ptr& op) { const auto& op_friendly_name = op->get_friendly_name(); const auto& input_shape = op->get_input_shape(0); const uint8_t rank = input_shape.size(); - const auto format = DefaultFormatForDims(rank); + const auto format = cldnn::format::get_default_format(rank); const auto default_rank = format.dimension(); auto shift_constant = std::dynamic_pointer_cast(op->get_input_node_shared_ptr(1)); diff --git a/src/plugins/intel_gpu/src/plugin/ops/select.cpp b/src/plugins/intel_gpu/src/plugin/ops/select.cpp index 429e170be7e..85e0c000487 100644 --- a/src/plugins/intel_gpu/src/plugin/ops/select.cpp +++ b/src/plugins/intel_gpu/src/plugin/ops/select.cpp @@ -36,9 +36,9 @@ static void CreateSelectOp(Program& p, const std::shared_ptrget_input_element_type(i)); auto reorderPrim = cldnn::reorder(reorderName, diff --git a/src/plugins/intel_gpu/src/plugin/ops/space_to_batch.cpp b/src/plugins/intel_gpu/src/plugin/ops/space_to_batch.cpp index 12c40f348a4..0c4799c38a4 100644 --- a/src/plugins/intel_gpu/src/plugin/ops/space_to_batch.cpp +++ b/src/plugins/intel_gpu/src/plugin/ops/space_to_batch.cpp @@ -19,7 +19,7 @@ static void CreateSpaceToBatchOp(Program& p, const std::shared_ptrget_input_shape(0).size(); - auto format = DefaultFormatForDims(rank); + auto format = cldnn::format::get_default_format(rank); std::vector inputs; inputs.reserve(3); diff --git a/src/plugins/intel_gpu/src/plugin/ops/tensor_iterator.cpp b/src/plugins/intel_gpu/src/plugin/ops/tensor_iterator.cpp index 4f6e7484789..c7ae6326d1e 100644 --- a/src/plugins/intel_gpu/src/plugin/ops/tensor_iterator.cpp +++ b/src/plugins/intel_gpu/src/plugin/ops/tensor_iterator.cpp @@ -38,7 +38,7 @@ static cldnn::mutable_data CreateAdditionalOutputData(Program &p, const std::sha const cldnn::primitive_id& id, const cldnn::primitive_id& input, const int32_t output_idx) { const auto precision = DataTypeFromPrecision(op->get_output_element_type(output_idx)); - const auto format = DefaultFormatForDims(op->get_output_shape(output_idx).size()); + const auto format = cldnn::format::get_default_format(op->get_output_shape(output_idx).size()); const auto tensor = tensor_from_dims(op->get_output_shape(output_idx)); cldnn::layout output_layout = cldnn::layout(precision, format, tensor); auto mem = p.GetEngine().allocate_memory(output_layout); diff --git a/src/plugins/intel_gpu/src/plugin/ops/topk.cpp b/src/plugins/intel_gpu/src/plugin/ops/topk.cpp index 000bc0cae58..ae424e0619a 100644 --- a/src/plugins/intel_gpu/src/plugin/ops/topk.cpp +++ b/src/plugins/intel_gpu/src/plugin/ops/topk.cpp @@ -32,7 +32,7 @@ static void CreateTopKOp(Program& p, const std::shared_ptr } cldnn::layout mutableLayout = cldnn::layout(DataTypeFromPrecision(mutable_precision), - DefaultFormatForDims(op->get_output_shape(1).size()), + cldnn::format::get_default_format(op->get_output_shape(1).size()), tensor_from_dims(op->get_output_shape(1))); GPU_DEBUG_GET_INSTANCE(debug_config); diff --git a/src/plugins/intel_gpu/src/plugin/ops/variable.cpp b/src/plugins/intel_gpu/src/plugin/ops/variable.cpp index b0670003483..37ce70d7c15 100644 --- a/src/plugins/intel_gpu/src/plugin/ops/variable.cpp +++ b/src/plugins/intel_gpu/src/plugin/ops/variable.cpp @@ -21,7 +21,7 @@ void CreateVariableAccessPrimitive(Program &p, const std::shared_ptrget_output_element_type(0)); const auto op_output_shape = op->get_output_shape(0); - const auto output_format = DefaultFormatForDims(op_output_shape.size()); + const auto output_format = cldnn::format::get_default_format(op_output_shape.size()); const auto output_shape = tensor_from_dims(op_output_shape); const auto variable_layout = cldnn::layout{output_data_type, diff --git a/src/plugins/intel_gpu/src/runtime/format.cpp b/src/plugins/intel_gpu/src/runtime/format.cpp index 0fff64d616e..b0b10e4b866 100644 --- a/src/plugins/intel_gpu/src/runtime/format.cpp +++ b/src/plugins/intel_gpu/src/runtime/format.cpp @@ -3,184 +3,184 @@ // #include "intel_gpu/runtime/format.hpp" +#include "openvino/core/except.hpp" #include #include #include +#define FMT_TRAITS(fmt, ...) {format::fmt, {#fmt, __VA_ARGS__}} + namespace cldnn { +static const std::map format_traits_map { + // B - number of Batch dimensions + // F - number of Feature dimensions + // S - number of Spatial dimensions + // G - number of Group dimensions + // Order - dims changing order from rare to often + // Inner order - dims order for internal storage in _sizes array + // Block sizes - vector of pairs of dimension number (by inner order) and block size ordered from rare to often + // Format B F S G Dims order Order Inner order Block sizes + FMT_TRAITS(yxfb, 1, 1, 2, 0, {2, 3, 1, 0}, "yxfb", "bfxy?", {}), + FMT_TRAITS(byxf, 1, 1, 2, 0, {0, 2, 3, 1}, "byxf", "bfxy?", {}), + FMT_TRAITS(bfyx, 1, 1, 2, 0, {0, 1, 2, 3}, "bfyx", "bfxy?", {}), + FMT_TRAITS(fyxb, 1, 1, 2, 0, {1, 2, 3, 0}, "fyxb", "bfxy?", {}), + FMT_TRAITS(b_fs_yx_fsv2, 1, 1, 2, 0, {0, 1, 2, 3}, "bfyx", "bfxy?", {{1, 2}}), + FMT_TRAITS(b_fs_yx_fsv4, 1, 1, 2, 0, {0, 1, 2, 3}, "bfyx", "bfxy?", {{1, 4}}), + FMT_TRAITS(b_fs_yx_fsv16, 1, 1, 2, 0, {0, 1, 2, 3}, "bfyx", "bfxy", {{1, 16}}), + FMT_TRAITS(b_fs_yx_fsv32, 1, 1, 2, 0, {0, 1, 2, 3}, "bfyx", "bfxy", {{1, 32}}), + FMT_TRAITS(b_fs_zyx_fsv2, 1, 1, 3, 0, {0, 1, 2, 3, 4}, "bfzyx", "bfxyz", {{1, 2}}), + FMT_TRAITS(b_fs_zyx_fsv4, 1, 1, 3, 0, {0, 1, 2, 3, 4}, "bfzyx", "bfxyz", {{1, 4}}), + FMT_TRAITS(b_fs_zyx_fsv32, 1, 1, 3, 0, {0, 1, 2, 3, 4}, "bfzyx", "bfxyz", {{1, 32}}), + FMT_TRAITS(bs_xs_xsv8_bsv8, 1, 0, 1, 0, {0, 1}, "bx", "b?x??", {{2, 8}, {0, 8}}), + FMT_TRAITS(bs_xs_xsv8_bsv16, 1, 0, 1, 0, {0, 1}, "bx", "b?x??", {{2, 8}, {0, 16}}), + FMT_TRAITS(bs_x_bsv16, 1, 1, 1, 0, {0, 1}, "bx", "b?x??", {{0, 16}}), + FMT_TRAITS(winograd_2x3_s1_data, 1, 1, 2, 0, {0, 2, 3, 1}, "bxyf", "bfxy?", {}), + FMT_TRAITS(bfzyx, 1, 1, 3, 0, {0, 1, 2, 3, 4}, "bfzyx", "bfxyz", {}), + FMT_TRAITS(bfwzyx, 1, 1, 4, 0, {0, 1, 2, 3, 4, 5}, "bfwzyx", "bfxyzw", {}), + FMT_TRAITS(fs_b_yx_fsv32, 1, 1, 2, 0, {1, 0, 2, 3}, "fbyx", "bfxy?", {{1, 32}}), + FMT_TRAITS(b_fs_yx_32fp, 1, 1, 2, 0, {0, 1, 2, 3}, "bfyx", "bfxy?", {}), + FMT_TRAITS(b_fs_zyx_fsv16, 1, 1, 3, 0, {0, 1, 2, 3, 4}, "bfzyx", "bfxyz", {{1, 16}}), + FMT_TRAITS(bs_fs_zyx_bsv16_fsv32, 1, 1, 3, 0, {0, 1, 2, 3, 4}, "bfzyx", "bfxyz", {{0, 16 }, {1, 32}}), + FMT_TRAITS(bs_fs_zyx_bsv16_fsv16, 1, 1, 3, 0, {0, 1, 2, 3, 4}, "bfzyx", "bfxyz", {{0, 16 }, {1, 16}}), + FMT_TRAITS(bs_fs_yx_bsv16_fsv16, 1, 1, 2, 0, {0, 1, 2, 3}, "bfyx", "bfxy?", {{0, 16 }, {1, 16}}), + FMT_TRAITS(bs_fs_yx_bsv4_fsv4, 1, 1, 2, 0, {0, 1, 2, 3}, "bfyx", "bfxy?", {{0, 4 }, {1, 4}}), + FMT_TRAITS(bs_fs_yx_bsv8_fsv4, 1, 1, 2, 0, {0, 1, 2, 3}, "bfyx", "bfxy?", {{0, 8 }, {1, 4}}), + FMT_TRAITS(bs_fs_zyx_bsv8_fsv4, 1, 1, 3, 0, {0, 1, 2, 3, 4}, "bfzyx", "bfxyz", {{0, 8 }, {1, 4}}), + FMT_TRAITS(bs_fs_yx_bsv8_fsv2, 1, 1, 2, 0, {0, 1, 2, 3}, "bfyx", "bfxy?", {{0, 8 }, {1, 2}}), + FMT_TRAITS(bs_fs_zyx_bsv8_fsv2, 1, 1, 3, 0, {0, 1, 2, 3, 4}, "bfzyx", "bfxyz", {{0, 8 }, {1, 2}}), + FMT_TRAITS(bs_fs_yx_bsv4_fsv2, 1, 1, 2, 0, {0, 1, 2, 3}, "bfyx", "bfxy?", {{0, 4 }, {1, 2}}), + FMT_TRAITS(bs_fs_zyx_bsv4_fsv4, 1, 1, 3, 0, {0, 1, 2, 3, 4}, "bfzyx", "bfxyz", {{0, 4 }, {1, 4}}), + FMT_TRAITS(bs_fs_zyx_bsv4_fsv2, 1, 1, 3, 0, {0, 1, 2, 3, 4}, "bfzyx", "bfxyz", {{0, 4 }, {1, 2}}), + FMT_TRAITS(bs_fs_zyx_bsv32_fsv32, 1, 1, 3, 0, {0, 1, 2, 3, 4}, "bfzyx", "bfxyz", {{0, 32 }, {1, 32}}), + FMT_TRAITS(bs_fs_zyx_bsv32_fsv16, 1, 1, 3, 0, {0, 1, 2, 3, 4}, "bfzyx", "bfxyz", {{0, 32 }, {1, 16}}), + FMT_TRAITS(bs_fs_yx_bsv32_fsv32, 1, 1, 2, 0, {0, 1, 2, 3}, "bfyx", "bfxy?", {{0, 32 }, {1, 32}}), + FMT_TRAITS(bs_fs_yx_bsv32_fsv16, 1, 1, 2, 0, {0, 1, 2, 3}, "bfyx", "bfxy?", {{0, 32 }, {1, 16}}), + FMT_TRAITS(nv12, 1, 1, 2, 0, {0, 1, 2, 3}, "bfyx", "bfxy?", {}), + FMT_TRAITS(image_2d_rgba, 1, 1, 2, 0, {0, 1, 2, 3}, "bfyx", "bfxy?", {}), + + FMT_TRAITS(oiyx, 1, 1, 2, 0, {0, 1, 2, 3}, "oiyx", "oixy", {}), + FMT_TRAITS(ioyx, 1, 1, 2, 0, {1, 0, 2, 3}, "ioyx", "oixy", {}), + FMT_TRAITS(iyxo, 1, 1, 2, 0, {1, 2, 3, 0}, "iyxo", "oixy", {}), + FMT_TRAITS(oyxi, 1, 1, 2, 0, {0, 2, 3, 1}, "oyxi", "oixy", {}), + FMT_TRAITS(yxio, 1, 1, 2, 0, {2, 3, 1, 0}, "yxio", "oixy?", {}), + FMT_TRAITS(oizyx, 1, 1, 3, 0, {0, 1, 2, 3, 4}, "oizyx", "oixyz", {}), + FMT_TRAITS(iozyx, 1, 1, 3, 0, {1, 0, 2, 3, 4}, "iozyx", "oixyz", {}), + FMT_TRAITS(os_is_yx_isv16_osv16, 1, 1, 2, 0, {0, 1, 2, 3}, "oiyx", "oixy", {{1, 16}, {0, 16}}), + FMT_TRAITS(o_is_yx_isv16, 1, 1, 2, 0, {0, 1, 2, 3}, "oiyx", "oixy?", {{1, 16}}), + FMT_TRAITS(os_yxi_osv16, 1, 1, 2, 0, {0, 2, 3, 1}, "oyxi", "oixy?", {{0, 16}}), + FMT_TRAITS(os_iyx_osv16, 1, 1, 2, 0, {0, 1, 2, 3}, "oiyx", "oixy?", {{0, 16}}), + FMT_TRAITS(os_iyx_osv32, 1, 1, 2, 0, {0, 1, 2, 3}, "oiyx", "oixy?", {{0, 32}}), + FMT_TRAITS(os_iyx_osv64, 1, 1, 2, 0, {0, 1, 2, 3}, "oiyx", "oixy?", {{0, 64}}), + FMT_TRAITS(winograd_2x3_s1_weights, 1, 1, 2, 0, {0, 1, 2, 3}, "oiyx", "oixy?", {}), + FMT_TRAITS(winograd_2x3_s1_fused_weights, 1, 1, 2, 0, {3, 2, 1, 0}, "xyio", "oixy?", {}), + FMT_TRAITS(winograd_6x3_s1_fused_weights, 1, 1, 2, 0, {3, 2, 1, 0}, "xyio", "oixy?", {}), + FMT_TRAITS(image_2d_weights_winograd_6x3_s1_fbxyb, 1, 1, 2, 0, {3, 2, 1, 0}, "xyio", "oixy?", {}), + FMT_TRAITS(image_2d_weights_winograd_6x3_s1_xfbyb, 1, 1, 2, 0, {3, 2, 1, 0}, "xyio", "oixy?", {}), + FMT_TRAITS(image_2d_weights_c4_fyx_b, 1, 1, 2, 0, {0, 1, 2, 3}, "oiyx", "oixy?", {}), + FMT_TRAITS(image_2d_weights_c1_b_fyx, 1, 1, 2, 0, {0, 1, 2, 3}, "oiyx", "oixy?", {}), + FMT_TRAITS(lstm_weights_dio, 1, 1, 2, 0, {0, 1, 3, 2}, "oixy", "oixy?", {}), + FMT_TRAITS(os_is_yx_isa8_osv8_isv4, 1, 1, 2, 0, {0, 1, 2, 3}, "oiyx", "oixy?", {}), + FMT_TRAITS(os_is_yx_isa8_osv16_isv4, 1, 1, 2, 0, {0, 1, 2, 3}, "oiyx", "oixy?", {}), + FMT_TRAITS(os_is_yx_isa8_osv8_isv4_swizzled_by_4, 1, 1, 2, 0, {0, 1, 2, 3}, "oiyx", "oixy?", {}), + FMT_TRAITS(os_is_yx_osa4_isa8_osv8_isv2, 1, 1, 2, 0, {0, 1, 2, 3}, "oiyx", "oixy?", {{0, 32}, {1, 16}}), + FMT_TRAITS(os_is_yx_osa4_isa8_osv8_isv4, 1, 1, 2, 0, {0, 1, 2, 3}, "oiyx", "oixy", {{0, 32}, {1, 32}}), + FMT_TRAITS(os_is_zyx_osa4_isa8_osv8_isv2, 1, 1, 3, 0, {0, 1, 2, 3, 4}, "oizyx", "oixyz", {{0, 32}, {1, 16}}), + FMT_TRAITS(os_is_zyx_osa4_isa8_osv8_isv4, 1, 1, 3, 0, {0, 1, 2, 3, 4}, "oizyx", "oixyz", {{0, 32}, {1, 32}}), + FMT_TRAITS(os_is_yx_osa2_isa8_osv16_isv2, 1, 1, 2, 0, {0, 1, 2, 3}, "oiyx", "oixy", {{0, 32}, {1, 16}}), + FMT_TRAITS(os_is_yx_osa2_isa8_osv16_isv4, 1, 1, 2, 0, {0, 1, 2, 3}, "oiyx", "oixy", {{0, 32}, {1, 32}}), + FMT_TRAITS(os_is_yx_osa2_isa8_osv8_isv2, 1, 1, 2, 0, {0, 1, 2, 3}, "oiyx", "oixy", {{0, 16}, {1, 16}}), + FMT_TRAITS(os_is_zyx_osa2_isa8_osv8_isv2, 1, 1, 3, 0, {0, 1, 2, 3, 4}, "oizyx", "oixyz", {{0, 16}, {1, 16}}), + FMT_TRAITS(os_is_zyx_isa8_osv8_isv4, 1, 1, 3, 0, {0, 1, 2, 3, 4}, "oizyx", "oixyz", {{1, 8}, {0, 8}, {1, 4}}), + FMT_TRAITS(os_is_zyx_isa8_osv16_isv4, 1, 1, 3, 0, {0, 1, 2, 3, 4}, "oizyx", "oixyz", {{1, 8}, {0, 16}, {1, 4}}), + FMT_TRAITS(os_is_yx_osa4_isa8_osv8_isv4_swizzled_by_4, 1, 1, 2, 0, {0, 1, 2, 3}, "oiyx", "oixy?", {{0, 32}, {1, 32}}), + FMT_TRAITS(os_is_zyx_osa4_isa8_osv8_isv4_swizzled_by_4, 1, 1, 3, 0, {0, 1, 2, 3, 4}, "oizyx", "oixyz", {{0, 32}, {1, 32}}), + FMT_TRAITS(is_os_yx_osa4_isa8_osv8_isv4, 1, 1, 2, 0, {1, 0, 2, 3}, "ioyx", "ioxy", {{0, 32}, {1, 32}}), + FMT_TRAITS(is_os_yx_isa2_osa8_isv8_osv2, 1, 1, 2, 0, {1, 0, 2, 3}, "ioyx", "ioxy?", {{1, 16}, {0, 16}}), + FMT_TRAITS(is_os_yx_isa4_osa8_isv8_osv4, 1, 1, 2, 0, {1, 0, 2, 3}, "ioyx", "ioxy?", {{1, 32}, {0, 32}}), + FMT_TRAITS(is_o_yx_isv32, 1, 1, 2, 0, {1, 0, 2, 3}, "oyxi", "oixy?", {{1, 32}}), + FMT_TRAITS(is_o32_yx_isv32_swizzled_by_4, 1, 1, 2, 0, {0, 1, 2, 3}, "oyxi", "oixy?", {}), + FMT_TRAITS(os_is_y_x8_osv8_isv4, 1, 1, 2, 0, {0, 1, 2, 3}, "oyxi", "oixy?", {}), + FMT_TRAITS(os_is_y_x8_osv8_isv4_swizzled_by_4, 1, 1, 2, 0, {0, 1, 2, 3}, "oyxi", "oixy?", {}), + FMT_TRAITS(os_is_yx_osv16_isv4, 1, 1, 2, 0, {0, 1, 2, 3}, "oixy", "oixy?", {{0, 16}, {1, 4}}), + FMT_TRAITS(os_is_yx_osv8_isv4, 1, 1, 2, 0, {0, 1, 2, 3}, "oiyx", "oixy", {{1, 4}, {0, 8}}), + FMT_TRAITS(os_is_zyx_osv8_isv4, 1, 1, 3, 0, {0, 1, 2, 3, 4}, "oizyx", "oixyz", {{1, 4}, {0, 8}}), + FMT_TRAITS(os_is_yx_osv8_isv2, 1, 1, 2, 0, {0, 1, 2, 3}, "oiyx", "oixy", {{1, 2}, {0, 8}}), + FMT_TRAITS(os_is_zyx_osv8_isv2, 1, 1, 3, 0, {0, 1, 2, 3, 4}, "oizyx", "oixyz", {{1, 2}, {0, 8}}), + FMT_TRAITS(os_is_zyx_osv16_isv16, 1, 1, 3, 0, {0, 1, 2, 3, 4}, "oizyx", "oixyz", {{0, 16}, {1, 16}}), + FMT_TRAITS(os_is_yx_osv32_isv4_swizzled_by_2, 1, 1, 2, 0, {0, 1, 2, 3}, "oixy", "oixy?", {{0, 32}, {1, 4}}), + FMT_TRAITS(os_is_yx_osv32_isv4, 1, 1, 2, 0, {0, 1, 2, 3}, "oixy", "oixy?", {{0, 32}, {1, 4}}), + FMT_TRAITS(os_is_zyx_osv32_isv4, 1, 1, 3, 0, {0, 1, 2, 3, 4}, "oizyx", "oixyz", {{0, 32}, {1, 4}}), + FMT_TRAITS(os_is_yx_osv32_isv32p, 1, 1, 1, 0, {0, 1, 2, 3}, "oixy", "oixy?", {}), + FMT_TRAITS(os_is_zyx_isv16_osv16, 1, 1, 3, 0, {0, 1, 2, 3, 4}, "oizyx", "oixyz", {{0, 16}, {1, 16}}), + FMT_TRAITS(is_os_zyx_isv16_osv16, 1, 1, 3, 0, {1, 0, 2, 3, 4}, "iozyx", "oixyz", {{1, 16}, {0, 16}}), + FMT_TRAITS(is_os_yx_isv16_osv16, 1, 1, 2, 0, {1, 0, 2, 3, 4}, "ioyx", "oixy", {{1, 16}, {0, 16}}), + FMT_TRAITS(is_os_zyx_isa8_osv8_isv2, 1, 1, 3, 0, {1, 0, 2, 3, 4}, "iozyx", "ioxyz", {{1, 8}, {0, 8}, {1, 2}}), + FMT_TRAITS(os_is_zyx_isa8_osv8_isv2, 1, 1, 3, 0, {0, 1, 2, 3, 4}, "oizyx", "oixyz", {{1, 8}, {0, 8}, {1, 2}}), + FMT_TRAITS(is_os_yx_isa8_osv8_isv2, 1, 1, 2, 0, {1, 0, 2, 3}, "ioyx", "ioxy?", {{1, 8}, {0, 8}, {1, 2}}), + FMT_TRAITS(os_is_yx_isa8_osv8_isv2, 1, 1, 2, 0, {0, 1, 2, 3}, "oiyx", "oixy?", {{1, 8}, {0, 8}, {1, 2}}), + FMT_TRAITS(os_is_osv32_isv32_swizzled_by_4, 1, 1, 0, 0, {0, 1, 2, 3}, "oixy", "oixy?", {{0, 32}, {1, 32}}), + FMT_TRAITS(os_is_zyx_isv8_osv16_isv2, 1, 1, 3, 0, {0, 1, 2, 3, 4}, "oizyx", "oixyz", {{1, 8}, {0, 16}, {1, 2}}), + FMT_TRAITS(os_zyxi_osv16, 1, 1, 3, 0, {0, 2, 3, 4, 1}, "ozyxi", "oixyz", {{0, 16}}), + FMT_TRAITS(os_is_yx_isv8_osv16_isv2, 1, 1, 2, 0, {0, 1, 2, 3}, "oiyx", "oixy", {{1, 8}, {0, 16}, {1, 2}}), + FMT_TRAITS(os_is_yx_osv16_isv16, 1, 1, 2, 0, {0, 1, 2, 3}, "oiyx", "oixy", {{1, 16}, {0, 16}}), + FMT_TRAITS(os_is_zyx_osv32_isv16, 1, 1, 3, 0, {0, 1, 2, 3, 4}, "oizyx", "oixyz", {{0, 32}, {1, 16}}), + FMT_TRAITS(os_is_zyx_osv64_isv16, 1, 1, 3, 0, {0, 1, 2, 3, 4}, "oizyx", "oixyz", {{0, 64}, {1, 16}}), + FMT_TRAITS(os_iyx_osv32__ai32, 1, 1, 2, 0, {0, 1, 2, 3}, "oiyx", "oixy", {{0, 32}}), + FMT_TRAITS(i_yxs_os_yxsv2_osv16, 1, 1, 2, 0, {1, 2, 3, 0}, "iyxo", "oixy", {{0, 16}}), + FMT_TRAITS(iy_xs_os_xsv2_osv8__ao32, 1, 1, 2, 0, {1, 2, 3, 0}, "iyxo", "oixy", {{2, 2}, {0, 8}}), + FMT_TRAITS(iy_xs_os_xsv2_osv16__ao32, 1, 1, 2, 0, {1, 2, 3, 0}, "iyxo", "oixy", {{2, 2}, {0, 16}}), + FMT_TRAITS(os_i_yxs_osv4_yxsv4, 1, 1, 2, 0, {0, 1, 2, 3}, "oiyx", "oixy", {{0, 4}}), + FMT_TRAITS(os_i_osv16__ai8, 1, 1, 0, 0, {0, 1}, "oi", "oi??", {{1, 8}, {0, 16}}), + FMT_TRAITS(os_i_osv8__ai8, 1, 1, 0, 0, {0, 1}, "oi", "oi??", {{1, 8}, {0, 8}}), + + FMT_TRAITS(goiyx, 1, 1, 2, 1, {0, 1, 2, 3, 4}, "goiyx", "oixy??g", {}), + FMT_TRAITS(gioyx, 1, 1, 2, 1, {0, 2, 1, 3, 4}, "gioyx", "oixy??g", {}), + FMT_TRAITS(goizyx, 1, 1, 3, 1, {0, 1, 2, 3, 4, 5}, "goizyx", "oixyz?g", {}), + FMT_TRAITS(giozyx, 1, 1, 3, 1, {0, 2, 1, 3, 4, 5}, "giozyx", "oixyz?g", {}), + FMT_TRAITS(g_os_iyx_osv16, 1, 1, 2, 1, {0, 1, 2, 3, 4}, "goiyx", "oixy??g", {{0, 16}}), + FMT_TRAITS(g_os_iyx_osv32, 1, 1, 2, 1, {0, 1, 2, 3, 4}, "goiyx", "oixy??g", {{0, 32}}), + FMT_TRAITS(gs_oiyx_gsv16, 1, 1, 2, 1, {0, 1, 2, 3, 4}, "goiyx", "oixy??g", {{6, 16}}), + FMT_TRAITS(gs_oizyx_gsv16, 1, 1, 3, 1, {0, 1, 2, 3, 4, 5}, "goizyx", "oixyz?g", {{6, 16}}), + FMT_TRAITS(gs_oiyx_gsv32, 1, 1, 2, 1, {0, 1, 2, 3, 4}, "goiyx", "oixy??g", {{6, 32}}), + FMT_TRAITS(gs_oizyx_gsv32, 1, 1, 3, 1, {0, 1, 2, 3, 4, 5}, "goizyx", "oixyz?g", {{6, 32}}), + FMT_TRAITS(gyxio, 1, 1, 2, 1, {0, 3, 4, 2, 1}, "gyxio", "oixy??g", {}), + FMT_TRAITS(g_is_os_zyx_isv16_osv16, 1, 1, 3, 1, {0, 2, 1, 3, 4, 5}, "giozyx", "oixyz?g", {{1, 16}, {0, 16}}), + FMT_TRAITS(g_is_os_yx_isv16_osv16, 1, 1, 2, 1, {0, 2, 1, 3, 4}, "gioyx", "oixy??g", {{1, 16}, {0, 16}}), + FMT_TRAITS(g_os_is_zyx_isv8_osv16_isv2, 1, 1, 3, 1, {0, 1, 2, 3, 4, 5}, "goizyx", "oixyz?g", {{1, 8}, {0, 16}, {1, 2}}), + FMT_TRAITS(g_os_is_yx_isv8_osv16_isv2, 1, 1, 2, 1, {0, 1, 2, 3, 4}, "goiyx", "oixy??g", {{1, 8}, {0, 16}, {1, 2}}), + FMT_TRAITS(g_os_is_zyx_isv16_osv16, 1, 1, 3, 1, {0, 1, 2, 3, 4, 5}, "goizyx", "oixyz?g", {{0, 16}, {1, 16}}), + FMT_TRAITS(g_os_is_yx_osv8_isv2, 1, 1, 2, 1, {0, 1, 2, 3, 4}, "goixy", "oixy??g", {{0, 8}, {1, 2}}), + FMT_TRAITS(g_os_is_yx_osv8_isv4, 1, 1, 2, 1, {0, 1, 2, 3, 4}, "goixy", "oixy??g", {{0, 8}, {1, 4}}), + FMT_TRAITS(g_os_is_yx_osv16_isv4, 1, 1, 2, 1, {0, 1, 2, 3, 4}, "goixy", "oixy??g", {{0, 16}, {1, 4}}), + FMT_TRAITS(g_os_is_zyx_osv16_isv16, 1, 1, 3, 1, {0, 1, 2, 3, 4, 5}, "goizyx", "oixyz?g", {{0, 16}, {1, 16}}), + FMT_TRAITS(g_os_zyx_is_osv16_isv4, 1, 1, 3, 1, {0, 1, 2, 3, 4, 5}, "gozyxi", "oixyz?g", {{0, 16}, {1, 4}}), + FMT_TRAITS(g_os_zyx_is_osv16_isv16, 1, 1, 3, 1, {0, 1, 2, 3, 4, 5}, "gozyxi", "oixyz?g", {{0, 16}, {1, 16}}), + FMT_TRAITS(g_os_zyx_is_osv16_isv32, 1, 1, 3, 1, {0, 1, 2, 3, 4, 5}, "gozyxi", "oixyz?g", {{0, 16}, {1, 32}}), + FMT_TRAITS(g_os_zyx_is_osv32_isv4, 1, 1, 3, 1, {0, 1, 2, 3, 4, 5}, "gozyxi", "oixyz?g", {{0, 32}, {1, 4}}), + FMT_TRAITS(g_os_zyx_is_osv32_isv16, 1, 1, 3, 1, {0, 1, 2, 3, 4, 5}, "gozyxi", "oixyz?g", {{0, 32}, {1, 16}}), + FMT_TRAITS(g_os_zyx_is_osv32_isv32, 1, 1, 3, 1, {0, 1, 2, 3, 4, 5}, "gozyxi", "oixyz?g", {{0, 32}, {1, 32}}), + FMT_TRAITS(g_os_is_yx_isa8_osv8_isv2, 1, 1, 2, 1, {0, 1, 2, 3, 4}, "goiyx", "oixy??g", {{1, 8}, {0, 8}, {1, 2}}), + FMT_TRAITS(g_os_is_yx_osa2_isa8_osv8_isv2, 1, 1, 2, 1, {0, 1, 2, 3, 4}, "goiyx", "oixy??g", {{0, 16}, {1, 16}}), + FMT_TRAITS(g_os_is_yx_osa4_isa8_osv8_isv4, 1, 1, 2, 1, {0, 1, 2, 3, 4}, "goiyx", "oixy??g", {{0, 32}, {1, 32}}), + FMT_TRAITS(g_os_is_zyx_osa4_isa8_osv8_isv4, 1, 1, 3, 1, {0, 1, 2, 3, 4, 5}, "goizyx", "oixyz?g", {{0, 32}, {1, 32}}), + FMT_TRAITS(g_os_is_yx_osa4_isa8_osv8_isv2, 1, 1, 2, 1, {0, 1, 2, 3, 4}, "goiyx", "oixy??g", {{0, 32}, {1, 16}}), + FMT_TRAITS(g_os_is_zyx_osa4_isa8_osv8_isv2, 1, 1, 3, 1, {0, 1, 2, 3, 4, 5}, "goizyx", "oixyz?g", {{0, 32}, {1, 16}}), + FMT_TRAITS(g_os_is_yx_osa2_isa8_osv16_isv4, 1, 1, 2, 1, {0, 1, 2, 3, 4}, "goiyx", "oixy??g", {{0, 32}, {1, 32}}), + FMT_TRAITS(g_os_is_yx_osa2_isa8_osv16_isv2, 1, 1, 2, 1, {0, 1, 2, 3, 4}, "goiyx", "oixy??g", {{0, 32}, {1, 16}}), + FMT_TRAITS(gs_oi_yxs_gsv4_yxsv4, 1, 1, 2, 1, {0, 1, 2, 3, 4}, "goiyx", "oixy??g", {{6, 4}}), + FMT_TRAITS(gs_oi_yxs_gsv16_yxsv4, 1, 1, 2, 1, {0, 1, 2, 3, 4}, "goiyx", "oixy??g", {{6, 16}}), + FMT_TRAITS(gs_oi_yxs_gsv32_yxsv4, 1, 1, 2, 1, {0, 1, 2, 3, 4}, "goiyx", "oixy??g", {{6, 32}}), + FMT_TRAITS(g_os_is_yx_isv16_osv16, 1, 1, 2, 1, {0, 1, 2, 3, 4}, "goiyx", "oixy??g", {{1, 16}, {0, 16}}), + FMT_TRAITS(gi_yxs_os_yxsv2_osv16, 1, 1, 2, 1, {0, 2, 3, 4, 1}, "giyxo", "oixy??g", {{0, 16}}), + FMT_TRAITS(giy_xs_os_xsv2_osv8__ao32, 1, 1, 2, 1, {0, 2, 3, 4, 1}, "giyxo", "oixy??g", {{2, 2}, {0, 8}}), + FMT_TRAITS(giy_xs_os_xsv2_osv16__ao32, 1, 1, 2, 1, {0, 2, 3, 4, 1}, "giyxo", "oixy??g", {{2, 2}, {0, 16}}), +}; + const format_traits& format::traits(type fmt) { - #define FMT_TRAITS(fmt, ...) {fmt, {#fmt, __VA_ARGS__}} - - static const std::map traits { - // B - number of Batch dimensions - // F - number of Feature dimensions - // S - number of Spatial dimensions - // G - number of Group dimensions - // Order - dims changing order from rare to often - // Inner order - dims order for internal storage in _sizes array - // Block sizes - vector of pairs of dimension number (by inner order) and block size ordered from rare to often - // Format B F S G Dims order Order Inner order Block sizes - FMT_TRAITS(yxfb, 1, 1, 2, 0, {2, 3, 1, 0}, "yxfb", "bfxy?", {}), - FMT_TRAITS(byxf, 1, 1, 2, 0, {0, 2, 3, 1}, "byxf", "bfxy?", {}), - FMT_TRAITS(bfyx, 1, 1, 2, 0, {0, 1, 2, 3}, "bfyx", "bfxy?", {}), - FMT_TRAITS(fyxb, 1, 1, 2, 0, {1, 2, 3, 0}, "fyxb", "bfxy?", {}), - FMT_TRAITS(b_fs_yx_fsv2, 1, 1, 2, 0, {0, 1, 2, 3}, "bfyx", "bfxy?", {{1, 2}}), - FMT_TRAITS(b_fs_yx_fsv4, 1, 1, 2, 0, {0, 1, 2, 3}, "bfyx", "bfxy?", {{1, 4}}), - FMT_TRAITS(b_fs_yx_fsv16, 1, 1, 2, 0, {0, 1, 2, 3}, "bfyx", "bfxy", {{1, 16}}), - FMT_TRAITS(b_fs_yx_fsv32, 1, 1, 2, 0, {0, 1, 2, 3}, "bfyx", "bfxy", {{1, 32}}), - FMT_TRAITS(b_fs_zyx_fsv2, 1, 1, 3, 0, {0, 1, 2, 3, 4}, "bfzyx", "bfxyz", {{1, 2}}), - FMT_TRAITS(b_fs_zyx_fsv4, 1, 1, 3, 0, {0, 1, 2, 3, 4}, "bfzyx", "bfxyz", {{1, 4}}), - FMT_TRAITS(b_fs_zyx_fsv32, 1, 1, 3, 0, {0, 1, 2, 3, 4}, "bfzyx", "bfxyz", {{1, 32}}), - FMT_TRAITS(bs_xs_xsv8_bsv8, 1, 0, 1, 0, {0, 1}, "bx", "b?x??", {{2, 8}, {0, 8}}), - FMT_TRAITS(bs_xs_xsv8_bsv16, 1, 0, 1, 0, {0, 1}, "bx", "b?x??", {{2, 8}, {0, 16}}), - FMT_TRAITS(bs_x_bsv16, 1, 1, 1, 0, {0, 1}, "bx", "b?x??", {{0, 16}}), - FMT_TRAITS(winograd_2x3_s1_data, 1, 1, 2, 0, {0, 2, 3, 1}, "bxyf", "bfxy?", {}), - FMT_TRAITS(bfzyx, 1, 1, 3, 0, {0, 1, 2, 3, 4}, "bfzyx", "bfxyz", {}), - FMT_TRAITS(bfwzyx, 1, 1, 4, 0, {0, 1, 2, 3, 4, 5}, "bfwzyx", "bfxyzw", {}), - FMT_TRAITS(fs_b_yx_fsv32, 1, 1, 2, 0, {1, 0, 2, 3}, "fbyx", "bfxy?", {{1, 32}}), - FMT_TRAITS(b_fs_yx_32fp, 1, 1, 2, 0, {0, 1, 2, 3}, "bfyx", "bfxy?", {}), - FMT_TRAITS(b_fs_zyx_fsv16, 1, 1, 3, 0, {0, 1, 2, 3, 4}, "bfzyx", "bfxyz", {{1, 16}}), - FMT_TRAITS(bs_fs_zyx_bsv16_fsv32, 1, 1, 3, 0, {0, 1, 2, 3, 4}, "bfzyx", "bfxyz", {{0, 16 }, {1, 32}}), - FMT_TRAITS(bs_fs_zyx_bsv16_fsv16, 1, 1, 3, 0, {0, 1, 2, 3, 4}, "bfzyx", "bfxyz", {{0, 16 }, {1, 16}}), - FMT_TRAITS(bs_fs_yx_bsv16_fsv16, 1, 1, 2, 0, {0, 1, 2, 3}, "bfyx", "bfxy?", {{0, 16 }, {1, 16}}), - FMT_TRAITS(bs_fs_yx_bsv4_fsv4, 1, 1, 2, 0, {0, 1, 2, 3}, "bfyx", "bfxy?", {{0, 4 }, {1, 4}}), - FMT_TRAITS(bs_fs_yx_bsv8_fsv4, 1, 1, 2, 0, {0, 1, 2, 3}, "bfyx", "bfxy?", {{0, 8 }, {1, 4}}), - FMT_TRAITS(bs_fs_zyx_bsv8_fsv4, 1, 1, 3, 0, {0, 1, 2, 3, 4}, "bfzyx", "bfxyz", {{0, 8 }, {1, 4}}), - FMT_TRAITS(bs_fs_yx_bsv8_fsv2, 1, 1, 2, 0, {0, 1, 2, 3}, "bfyx", "bfxy?", {{0, 8 }, {1, 2}}), - FMT_TRAITS(bs_fs_zyx_bsv8_fsv2, 1, 1, 3, 0, {0, 1, 2, 3, 4}, "bfzyx", "bfxyz", {{0, 8 }, {1, 2}}), - FMT_TRAITS(bs_fs_yx_bsv4_fsv2, 1, 1, 2, 0, {0, 1, 2, 3}, "bfyx", "bfxy?", {{0, 4 }, {1, 2}}), - FMT_TRAITS(bs_fs_zyx_bsv4_fsv4, 1, 1, 3, 0, {0, 1, 2, 3, 4}, "bfzyx", "bfxyz", {{0, 4 }, {1, 4}}), - FMT_TRAITS(bs_fs_zyx_bsv4_fsv2, 1, 1, 3, 0, {0, 1, 2, 3, 4}, "bfzyx", "bfxyz", {{0, 4 }, {1, 2}}), - FMT_TRAITS(bs_fs_zyx_bsv32_fsv32, 1, 1, 3, 0, {0, 1, 2, 3, 4}, "bfzyx", "bfxyz", {{0, 32 }, {1, 32}}), - FMT_TRAITS(bs_fs_zyx_bsv32_fsv16, 1, 1, 3, 0, {0, 1, 2, 3, 4}, "bfzyx", "bfxyz", {{0, 32 }, {1, 16}}), - FMT_TRAITS(bs_fs_yx_bsv32_fsv32, 1, 1, 2, 0, {0, 1, 2, 3}, "bfyx", "bfxy?", {{0, 32 }, {1, 32}}), - FMT_TRAITS(bs_fs_yx_bsv32_fsv16, 1, 1, 2, 0, {0, 1, 2, 3}, "bfyx", "bfxy?", {{0, 32 }, {1, 16}}), - FMT_TRAITS(nv12, 1, 1, 2, 0, {0, 1, 2, 3}, "bfyx", "bfxy?", {}), - FMT_TRAITS(image_2d_rgba, 1, 1, 2, 0, {0, 1, 2, 3}, "bfyx", "bfxy?", {}), - - FMT_TRAITS(oiyx, 1, 1, 2, 0, {0, 1, 2, 3}, "oiyx", "oixy", {}), - FMT_TRAITS(ioyx, 1, 1, 2, 0, {1, 0, 2, 3}, "ioyx", "oixy", {}), - FMT_TRAITS(iyxo, 1, 1, 2, 0, {1, 2, 3, 0}, "iyxo", "oixy", {}), - FMT_TRAITS(oyxi, 1, 1, 2, 0, {0, 2, 3, 1}, "oyxi", "oixy", {}), - FMT_TRAITS(yxio, 1, 1, 2, 0, {2, 3, 1, 0}, "yxio", "oixy?", {}), - FMT_TRAITS(oizyx, 1, 1, 3, 0, {0, 1, 2, 3, 4}, "oizyx", "oixyz", {}), - FMT_TRAITS(iozyx, 1, 1, 3, 0, {1, 0, 2, 3, 4}, "iozyx", "oixyz", {}), - FMT_TRAITS(os_is_yx_isv16_osv16, 1, 1, 2, 0, {0, 1, 2, 3}, "oiyx", "oixy", {{1, 16}, {0, 16}}), - FMT_TRAITS(o_is_yx_isv16, 1, 1, 2, 0, {0, 1, 2, 3}, "oiyx", "oixy?", {{1, 16}}), - FMT_TRAITS(os_yxi_osv16, 1, 1, 2, 0, {0, 2, 3, 1}, "oyxi", "oixy?", {{0, 16}}), - FMT_TRAITS(os_iyx_osv16, 1, 1, 2, 0, {0, 1, 2, 3}, "oiyx", "oixy?", {{0, 16}}), - FMT_TRAITS(os_iyx_osv32, 1, 1, 2, 0, {0, 1, 2, 3}, "oiyx", "oixy?", {{0, 32}}), - FMT_TRAITS(os_iyx_osv64, 1, 1, 2, 0, {0, 1, 2, 3}, "oiyx", "oixy?", {{0, 64}}), - FMT_TRAITS(winograd_2x3_s1_weights, 1, 1, 2, 0, {0, 1, 2, 3}, "oiyx", "oixy?", {}), - FMT_TRAITS(winograd_2x3_s1_fused_weights, 1, 1, 2, 0, {3, 2, 1, 0}, "xyio", "oixy?", {}), - FMT_TRAITS(winograd_6x3_s1_fused_weights, 1, 1, 2, 0, {3, 2, 1, 0}, "xyio", "oixy?", {}), - FMT_TRAITS(image_2d_weights_winograd_6x3_s1_fbxyb, 1, 1, 2, 0, {3, 2, 1, 0}, "xyio", "oixy?", {}), - FMT_TRAITS(image_2d_weights_winograd_6x3_s1_xfbyb, 1, 1, 2, 0, {3, 2, 1, 0}, "xyio", "oixy?", {}), - FMT_TRAITS(image_2d_weights_c4_fyx_b, 1, 1, 2, 0, {0, 1, 2, 3}, "oiyx", "oixy?", {}), - FMT_TRAITS(image_2d_weights_c1_b_fyx, 1, 1, 2, 0, {0, 1, 2, 3}, "oiyx", "oixy?", {}), - FMT_TRAITS(lstm_weights_dio, 1, 1, 2, 0, {0, 1, 3, 2}, "oixy", "oixy?", {}), - FMT_TRAITS(os_is_yx_isa8_osv8_isv4, 1, 1, 2, 0, {0, 1, 2, 3}, "oiyx", "oixy?", {}), - FMT_TRAITS(os_is_yx_isa8_osv16_isv4, 1, 1, 2, 0, {0, 1, 2, 3}, "oiyx", "oixy?", {}), - FMT_TRAITS(os_is_yx_isa8_osv8_isv4_swizzled_by_4, 1, 1, 2, 0, {0, 1, 2, 3}, "oiyx", "oixy?", {}), - FMT_TRAITS(os_is_yx_osa4_isa8_osv8_isv2, 1, 1, 2, 0, {0, 1, 2, 3}, "oiyx", "oixy?", {{0, 32}, {1, 16}}), - FMT_TRAITS(os_is_yx_osa4_isa8_osv8_isv4, 1, 1, 2, 0, {0, 1, 2, 3}, "oiyx", "oixy", {{0, 32}, {1, 32}}), - FMT_TRAITS(os_is_zyx_osa4_isa8_osv8_isv2, 1, 1, 3, 0, {0, 1, 2, 3, 4}, "oizyx", "oixyz", {{0, 32}, {1, 16}}), - FMT_TRAITS(os_is_zyx_osa4_isa8_osv8_isv4, 1, 1, 3, 0, {0, 1, 2, 3, 4}, "oizyx", "oixyz", {{0, 32}, {1, 32}}), - FMT_TRAITS(os_is_yx_osa2_isa8_osv16_isv2, 1, 1, 2, 0, {0, 1, 2, 3}, "oiyx", "oixy", {{0, 32}, {1, 16}}), - FMT_TRAITS(os_is_yx_osa2_isa8_osv16_isv4, 1, 1, 2, 0, {0, 1, 2, 3}, "oiyx", "oixy", {{0, 32}, {1, 32}}), - FMT_TRAITS(os_is_yx_osa2_isa8_osv8_isv2, 1, 1, 2, 0, {0, 1, 2, 3}, "oiyx", "oixy", {{0, 16}, {1, 16}}), - FMT_TRAITS(os_is_zyx_osa2_isa8_osv8_isv2, 1, 1, 3, 0, {0, 1, 2, 3, 4}, "oizyx", "oixyz", {{0, 16}, {1, 16}}), - FMT_TRAITS(os_is_zyx_isa8_osv8_isv4, 1, 1, 3, 0, {0, 1, 2, 3, 4}, "oizyx", "oixyz", {{1, 8}, {0, 8}, {1, 4}}), - FMT_TRAITS(os_is_zyx_isa8_osv16_isv4, 1, 1, 3, 0, {0, 1, 2, 3, 4}, "oizyx", "oixyz", {{1, 8}, {0, 16}, {1, 4}}), - FMT_TRAITS(os_is_yx_osa4_isa8_osv8_isv4_swizzled_by_4, 1, 1, 2, 0, {0, 1, 2, 3}, "oiyx", "oixy?", {{0, 32}, {1, 32}}), - FMT_TRAITS(os_is_zyx_osa4_isa8_osv8_isv4_swizzled_by_4, 1, 1, 3, 0, {0, 1, 2, 3, 4}, "oizyx", "oixyz", {{0, 32}, {1, 32}}), - FMT_TRAITS(is_os_yx_osa4_isa8_osv8_isv4, 1, 1, 2, 0, {1, 0, 2, 3}, "ioyx", "ioxy", {{0, 32}, {1, 32}}), - FMT_TRAITS(is_os_yx_isa2_osa8_isv8_osv2, 1, 1, 2, 0, {1, 0, 2, 3}, "ioyx", "ioxy?", {{1, 16}, {0, 16}}), - FMT_TRAITS(is_os_yx_isa4_osa8_isv8_osv4, 1, 1, 2, 0, {1, 0, 2, 3}, "ioyx", "ioxy?", {{1, 32}, {0, 32}}), - FMT_TRAITS(is_o_yx_isv32, 1, 1, 2, 0, {1, 0, 2, 3}, "oyxi", "oixy?", {{1, 32}}), - FMT_TRAITS(is_o32_yx_isv32_swizzled_by_4, 1, 1, 2, 0, {0, 1, 2, 3}, "oyxi", "oixy?", {}), - FMT_TRAITS(os_is_y_x8_osv8_isv4, 1, 1, 2, 0, {0, 1, 2, 3}, "oyxi", "oixy?", {}), - FMT_TRAITS(os_is_y_x8_osv8_isv4_swizzled_by_4, 1, 1, 2, 0, {0, 1, 2, 3}, "oyxi", "oixy?", {}), - FMT_TRAITS(os_is_yx_osv16_isv4, 1, 1, 2, 0, {0, 1, 2, 3}, "oixy", "oixy?", {{0, 16}, {1, 4}}), - FMT_TRAITS(os_is_yx_osv8_isv4, 1, 1, 2, 0, {0, 1, 2, 3}, "oiyx", "oixy", {{1, 4}, {0, 8}}), - FMT_TRAITS(os_is_zyx_osv8_isv4, 1, 1, 3, 0, {0, 1, 2, 3, 4}, "oizyx", "oixyz", {{1, 4}, {0, 8}}), - FMT_TRAITS(os_is_yx_osv8_isv2, 1, 1, 2, 0, {0, 1, 2, 3}, "oiyx", "oixy", {{1, 2}, {0, 8}}), - FMT_TRAITS(os_is_zyx_osv8_isv2, 1, 1, 3, 0, {0, 1, 2, 3, 4}, "oizyx", "oixyz", {{1, 2}, {0, 8}}), - FMT_TRAITS(os_is_zyx_osv16_isv16, 1, 1, 3, 0, {0, 1, 2, 3, 4}, "oizyx", "oixyz", {{0, 16}, {1, 16}}), - FMT_TRAITS(os_is_yx_osv32_isv4_swizzled_by_2, 1, 1, 2, 0, {0, 1, 2, 3}, "oixy", "oixy?", {{0, 32}, {1, 4}}), - FMT_TRAITS(os_is_yx_osv32_isv4, 1, 1, 2, 0, {0, 1, 2, 3}, "oixy", "oixy?", {{0, 32}, {1, 4}}), - FMT_TRAITS(os_is_zyx_osv32_isv4, 1, 1, 3, 0, {0, 1, 2, 3, 4}, "oizyx", "oixyz", {{0, 32}, {1, 4}}), - FMT_TRAITS(os_is_yx_osv32_isv32p, 1, 1, 1, 0, {0, 1, 2, 3}, "oixy", "oixy?", {}), - FMT_TRAITS(os_is_zyx_isv16_osv16, 1, 1, 3, 0, {0, 1, 2, 3, 4}, "oizyx", "oixyz", {{0, 16}, {1, 16}}), - FMT_TRAITS(is_os_zyx_isv16_osv16, 1, 1, 3, 0, {1, 0, 2, 3, 4}, "iozyx", "oixyz", {{1, 16}, {0, 16}}), - FMT_TRAITS(is_os_yx_isv16_osv16, 1, 1, 2, 0, {1, 0, 2, 3, 4}, "ioyx", "oixy", {{1, 16}, {0, 16}}), - FMT_TRAITS(is_os_zyx_isa8_osv8_isv2, 1, 1, 3, 0, {1, 0, 2, 3, 4}, "iozyx", "ioxyz", {{1, 8}, {0, 8}, {1, 2}}), - FMT_TRAITS(os_is_zyx_isa8_osv8_isv2, 1, 1, 3, 0, {0, 1, 2, 3, 4}, "oizyx", "oixyz", {{1, 8}, {0, 8}, {1, 2}}), - FMT_TRAITS(is_os_yx_isa8_osv8_isv2, 1, 1, 2, 0, {1, 0, 2, 3}, "ioyx", "ioxy?", {{1, 8}, {0, 8}, {1, 2}}), - FMT_TRAITS(os_is_yx_isa8_osv8_isv2, 1, 1, 2, 0, {0, 1, 2, 3}, "oiyx", "oixy?", {{1, 8}, {0, 8}, {1, 2}}), - FMT_TRAITS(os_is_osv32_isv32_swizzled_by_4, 1, 1, 0, 0, {0, 1, 2, 3}, "oixy", "oixy?", {{0, 32}, {1, 32}}), - FMT_TRAITS(os_is_zyx_isv8_osv16_isv2, 1, 1, 3, 0, {0, 1, 2, 3, 4}, "oizyx", "oixyz", {{1, 8}, {0, 16}, {1, 2}}), - FMT_TRAITS(os_zyxi_osv16, 1, 1, 3, 0, {0, 2, 3, 4, 1}, "ozyxi", "oixyz", {{0, 16}}), - FMT_TRAITS(os_is_yx_isv8_osv16_isv2, 1, 1, 2, 0, {0, 1, 2, 3}, "oiyx", "oixy", {{1, 8}, {0, 16}, {1, 2}}), - FMT_TRAITS(os_is_yx_osv16_isv16, 1, 1, 2, 0, {0, 1, 2, 3}, "oiyx", "oixy", {{1, 16}, {0, 16}}), - FMT_TRAITS(os_is_zyx_osv32_isv16, 1, 1, 3, 0, {0, 1, 2, 3, 4}, "oizyx", "oixyz", {{0, 32}, {1, 16}}), - FMT_TRAITS(os_is_zyx_osv64_isv16, 1, 1, 3, 0, {0, 1, 2, 3, 4}, "oizyx", "oixyz", {{0, 64}, {1, 16}}), - FMT_TRAITS(os_iyx_osv32__ai32, 1, 1, 2, 0, {0, 1, 2, 3}, "oiyx", "oixy", {{0, 32}}), - FMT_TRAITS(i_yxs_os_yxsv2_osv16, 1, 1, 2, 0, {1, 2, 3, 0}, "iyxo", "oixy", {{0, 16}}), - FMT_TRAITS(iy_xs_os_xsv2_osv8__ao32, 1, 1, 2, 0, {1, 2, 3, 0}, "iyxo", "oixy", {{2, 2}, {0, 8}}), - FMT_TRAITS(iy_xs_os_xsv2_osv16__ao32, 1, 1, 2, 0, {1, 2, 3, 0}, "iyxo", "oixy", {{2, 2}, {0, 16}}), - FMT_TRAITS(os_i_yxs_osv4_yxsv4, 1, 1, 2, 0, {0, 1, 2, 3}, "oiyx", "oixy", {{0, 4}}), - FMT_TRAITS(os_i_osv16__ai8, 1, 1, 0, 0, {0, 1}, "oi", "oi??", {{1, 8}, {0, 16}}), - FMT_TRAITS(os_i_osv8__ai8, 1, 1, 0, 0, {0, 1}, "oi", "oi??", {{1, 8}, {0, 8}}), - - FMT_TRAITS(goiyx, 1, 1, 2, 1, {0, 1, 2, 3, 4}, "goiyx", "oixy??g", {}), - FMT_TRAITS(gioyx, 1, 1, 2, 1, {0, 2, 1, 3, 4}, "gioyx", "oixy??g", {}), - FMT_TRAITS(goizyx, 1, 1, 3, 1, {0, 1, 2, 3, 4, 5}, "goizyx", "oixyz?g", {}), - FMT_TRAITS(giozyx, 1, 1, 3, 1, {0, 2, 1, 3, 4, 5}, "giozyx", "oixyz?g", {}), - FMT_TRAITS(g_os_iyx_osv16, 1, 1, 2, 1, {0, 1, 2, 3, 4}, "goiyx", "oixy??g", {{0, 16}}), - FMT_TRAITS(g_os_iyx_osv32, 1, 1, 2, 1, {0, 1, 2, 3, 4}, "goiyx", "oixy??g", {{0, 32}}), - FMT_TRAITS(gs_oiyx_gsv16, 1, 1, 2, 1, {0, 1, 2, 3, 4}, "goiyx", "oixy??g", {{6, 16}}), - FMT_TRAITS(gs_oizyx_gsv16, 1, 1, 3, 1, {0, 1, 2, 3, 4, 5}, "goizyx", "oixyz?g", {{6, 16}}), - FMT_TRAITS(gs_oiyx_gsv32, 1, 1, 2, 1, {0, 1, 2, 3, 4}, "goiyx", "oixy??g", {{6, 32}}), - FMT_TRAITS(gs_oizyx_gsv32, 1, 1, 3, 1, {0, 1, 2, 3, 4, 5}, "goizyx", "oixyz?g", {{6, 32}}), - FMT_TRAITS(gyxio, 1, 1, 2, 1, {0, 3, 4, 2, 1}, "gyxio", "oixy??g", {}), - FMT_TRAITS(g_is_os_zyx_isv16_osv16, 1, 1, 3, 1, {0, 2, 1, 3, 4, 5}, "giozyx", "oixyz?g", {{1, 16}, {0, 16}}), - FMT_TRAITS(g_is_os_yx_isv16_osv16, 1, 1, 2, 1, {0, 2, 1, 3, 4}, "gioyx", "oixy??g", {{1, 16}, {0, 16}}), - FMT_TRAITS(g_os_is_zyx_isv8_osv16_isv2, 1, 1, 3, 1, {0, 1, 2, 3, 4, 5}, "goizyx", "oixyz?g", {{1, 8}, {0, 16}, {1, 2}}), - FMT_TRAITS(g_os_is_yx_isv8_osv16_isv2, 1, 1, 2, 1, {0, 1, 2, 3, 4}, "goiyx", "oixy??g", {{1, 8}, {0, 16}, {1, 2}}), - FMT_TRAITS(g_os_is_zyx_isv16_osv16, 1, 1, 3, 1, {0, 1, 2, 3, 4, 5}, "goizyx", "oixyz?g", {{0, 16}, {1, 16}}), - FMT_TRAITS(g_os_is_yx_osv8_isv2, 1, 1, 2, 1, {0, 1, 2, 3, 4}, "goixy", "oixy??g", {{0, 8}, {1, 2}}), - FMT_TRAITS(g_os_is_yx_osv8_isv4, 1, 1, 2, 1, {0, 1, 2, 3, 4}, "goixy", "oixy??g", {{0, 8}, {1, 4}}), - FMT_TRAITS(g_os_is_yx_osv16_isv4, 1, 1, 2, 1, {0, 1, 2, 3, 4}, "goixy", "oixy??g", {{0, 16}, {1, 4}}), - FMT_TRAITS(g_os_is_zyx_osv16_isv16, 1, 1, 3, 1, {0, 1, 2, 3, 4, 5}, "goizyx", "oixyz?g", {{0, 16}, {1, 16}}), - FMT_TRAITS(g_os_zyx_is_osv16_isv4, 1, 1, 3, 1, {0, 1, 2, 3, 4, 5}, "gozyxi", "oixyz?g", {{0, 16}, {1, 4}}), - FMT_TRAITS(g_os_zyx_is_osv16_isv16, 1, 1, 3, 1, {0, 1, 2, 3, 4, 5}, "gozyxi", "oixyz?g", {{0, 16}, {1, 16}}), - FMT_TRAITS(g_os_zyx_is_osv16_isv32, 1, 1, 3, 1, {0, 1, 2, 3, 4, 5}, "gozyxi", "oixyz?g", {{0, 16}, {1, 32}}), - FMT_TRAITS(g_os_zyx_is_osv32_isv4, 1, 1, 3, 1, {0, 1, 2, 3, 4, 5}, "gozyxi", "oixyz?g", {{0, 32}, {1, 4}}), - FMT_TRAITS(g_os_zyx_is_osv32_isv16, 1, 1, 3, 1, {0, 1, 2, 3, 4, 5}, "gozyxi", "oixyz?g", {{0, 32}, {1, 16}}), - FMT_TRAITS(g_os_zyx_is_osv32_isv32, 1, 1, 3, 1, {0, 1, 2, 3, 4, 5}, "gozyxi", "oixyz?g", {{0, 32}, {1, 32}}), - FMT_TRAITS(g_os_is_yx_isa8_osv8_isv2, 1, 1, 2, 1, {0, 1, 2, 3, 4}, "goiyx", "oixy??g", {{1, 8}, {0, 8}, {1, 2}}), - FMT_TRAITS(g_os_is_yx_osa2_isa8_osv8_isv2, 1, 1, 2, 1, {0, 1, 2, 3, 4}, "goiyx", "oixy??g", {{0, 16}, {1, 16}}), - FMT_TRAITS(g_os_is_yx_osa4_isa8_osv8_isv4, 1, 1, 2, 1, {0, 1, 2, 3, 4}, "goiyx", "oixy??g", {{0, 32}, {1, 32}}), - FMT_TRAITS(g_os_is_zyx_osa4_isa8_osv8_isv4, 1, 1, 3, 1, {0, 1, 2, 3, 4, 5}, "goizyx", "oixyz?g", {{0, 32}, {1, 32}}), - FMT_TRAITS(g_os_is_yx_osa4_isa8_osv8_isv2, 1, 1, 2, 1, {0, 1, 2, 3, 4}, "goiyx", "oixy??g", {{0, 32}, {1, 16}}), - FMT_TRAITS(g_os_is_zyx_osa4_isa8_osv8_isv2, 1, 1, 3, 1, {0, 1, 2, 3, 4, 5}, "goizyx", "oixyz?g", {{0, 32}, {1, 16}}), - FMT_TRAITS(g_os_is_yx_osa2_isa8_osv16_isv4, 1, 1, 2, 1, {0, 1, 2, 3, 4}, "goiyx", "oixy??g", {{0, 32}, {1, 32}}), - FMT_TRAITS(g_os_is_yx_osa2_isa8_osv16_isv2, 1, 1, 2, 1, {0, 1, 2, 3, 4}, "goiyx", "oixy??g", {{0, 32}, {1, 16}}), - FMT_TRAITS(gs_oi_yxs_gsv4_yxsv4, 1, 1, 2, 1, {0, 1, 2, 3, 4}, "goiyx", "oixy??g", {{6, 4}}), - FMT_TRAITS(gs_oi_yxs_gsv16_yxsv4, 1, 1, 2, 1, {0, 1, 2, 3, 4}, "goiyx", "oixy??g", {{6, 16}}), - FMT_TRAITS(gs_oi_yxs_gsv32_yxsv4, 1, 1, 2, 1, {0, 1, 2, 3, 4}, "goiyx", "oixy??g", {{6, 32}}), - FMT_TRAITS(g_os_is_yx_isv16_osv16, 1, 1, 2, 1, {0, 1, 2, 3, 4}, "goiyx", "oixy??g", {{1, 16}, {0, 16}}), - FMT_TRAITS(gi_yxs_os_yxsv2_osv16, 1, 1, 2, 1, {0, 2, 3, 4, 1}, "giyxo", "oixy??g", {{0, 16}}), - FMT_TRAITS(giy_xs_os_xsv2_osv8__ao32, 1, 1, 2, 1, {0, 2, 3, 4, 1}, "giyxo", "oixy??g", {{2, 2}, {0, 8}}), - FMT_TRAITS(giy_xs_os_xsv2_osv16__ao32, 1, 1, 2, 1, {0, 2, 3, 4, 1}, "giyxo", "oixy??g", {{2, 2}, {0, 16}}), - }; - if (traits.find(fmt) == traits.end()) { - throw std::runtime_error("[GPU] Format description is missing in fmt traits"); - } - return traits.at(fmt); + OPENVINO_ASSERT(format_traits_map.find(fmt) != format_traits_map.end(), "[GPU] Format description is missing in fmt traits"); + return format_traits_map.at(fmt); } std::string format::to_string() const { @@ -190,4 +190,92 @@ std::string format::to_string() const { return traits(value).str; } +format format::get_default_format(size_t rank, bool is_weights, bool is_grouped) { + auto default_fmt = cldnn::format::bfyx; + if (is_weights) { + if (is_grouped) { + if (rank == 5) { + default_fmt = cldnn::format::goiyx; + } else if (rank == 6) { + default_fmt = cldnn::format::goizyx; + } + } else { + if (rank == 4) { + default_fmt = cldnn::format::oiyx; + } else if (rank == 5) { + default_fmt = cldnn::format::oizyx; + } + } + } else { + if (rank == 5) { + default_fmt = cldnn::format::bfzyx; + } else if (rank == 6) { + default_fmt = cldnn::format::bfwzyx; + } + } + return default_fmt; +} + +format format::adjust_to_rank(format fmt, size_t new_rank) { + // TODO: remove as soon as rank extension is not needed anymore + new_rank = std::max(new_rank, 4); + + auto current_traits = format::traits(fmt); + auto current_order = current_traits._order; + auto current_blocking = current_traits.block_sizes; + auto current_rank = current_order.size(); + if (new_rank == current_rank) + return fmt; + + auto is_adjustable = [](const format& fmt) -> bool { + return !format::is_weights_format(fmt) && + !format::is_image_2d(fmt) && + !format::is_winograd(fmt) && + fmt != format::b_fs_yx_32fp; + }; + + // Skip special formats as order + blocking desc may be not enough to properly match them + OPENVINO_ASSERT(is_adjustable(fmt), "Format ", fmt, " is not adjustable"); + + auto align_order = [](std::vector& order, size_t current_rank, size_t new_rank) { + auto max_element_it = std::max_element(order.begin(), order.end()); + for (size_t i = current_rank; i < new_rank; i++) { + max_element_it = std::next(max_element_it); + max_element_it = order.insert(max_element_it, i); + } + }; + + if (new_rank > current_rank) { + align_order(current_order, current_rank, new_rank); + } + + for (auto& kv : format_traits_map) { + auto candidate_tag = kv.first; + auto candidate_traits = kv.second; + auto candidate_order = candidate_traits._order; + auto candidate_blocking = candidate_traits.block_sizes; + auto candidate_rank = candidate_traits.order.size(); + + if (candidate_rank != new_rank || !is_adjustable(candidate_tag)) + continue; + + bool same_blocking_scheme = candidate_blocking == current_blocking; + bool same_dims_scheme = current_traits.batch_num == candidate_traits.batch_num && + current_traits.group_num == candidate_traits.group_num && + current_traits.feature_num == candidate_traits.feature_num; + + if (!same_blocking_scheme || !same_dims_scheme) + continue; + + if (current_rank > candidate_rank) { + align_order(candidate_order, candidate_rank, current_rank); + } + + if (candidate_order == current_order) + return candidate_tag; + } + + OPENVINO_ASSERT(false, "Can't adjust format ", fmt.to_string(), " to the new rank (", new_rank, ")"); +} + } // namespace cldnn diff --git a/src/plugins/intel_gpu/tests/fusions/convolution_fusion_test.cpp b/src/plugins/intel_gpu/tests/fusions/convolution_fusion_test.cpp index 005d9dd0936..01ba4ddd7d9 100644 --- a/src/plugins/intel_gpu/tests/fusions/convolution_fusion_test.cpp +++ b/src/plugins/intel_gpu/tests/fusions/convolution_fusion_test.cpp @@ -2230,7 +2230,7 @@ TEST_P(conv_int8_scale_activation_quantize_i8_eltwise_fp32, basic) { reorder("reorder_bfyx", "sum", p.default_format, data_types::f32) ); - tolerance = 1.f; + tolerance = 2.f; execute(p); } diff --git a/src/plugins/intel_gpu/tests/module_tests/format_test.cpp b/src/plugins/intel_gpu/tests/module_tests/format_test.cpp index 5fe10f7a279..5ab51cbc370 100644 --- a/src/plugins/intel_gpu/tests/module_tests/format_test.cpp +++ b/src/plugins/intel_gpu/tests/module_tests/format_test.cpp @@ -6,6 +6,8 @@ #include "intel_gpu/runtime/format.hpp" +using namespace cldnn; + TEST(format, to_string) { typedef std::underlying_type::type format_underlying_type; for (format_underlying_type i = 0; i < static_cast(cldnn::format::format_num); i++) { @@ -21,3 +23,48 @@ TEST(format, traits) { ASSERT_NO_THROW(cldnn::format::traits(fmt)) << "Can't get traits for format " << i; } } + +struct format_adjust_test_params { + format in_format; + size_t new_rank; + format expected_format; +}; + +class format_adjust_test : public testing::TestWithParam { +public: + static std::string PrintToString(testing::TestParamInfo param_info) { + auto in_fmt = param_info.param.in_format.to_string(); + auto new_rank = std::to_string(param_info.param.new_rank); + auto expected_fmt = param_info.param.expected_format.to_string(); + std::string res = "in_fmt=" + in_fmt + "_new_rank=" + new_rank + "_expected_fmt=" + expected_fmt; + return res; + } + }; + +TEST_P(format_adjust_test, shape_infer) { + auto p = GetParam(); + + if (p.expected_format == format::any) { + cldnn::format fmt = cldnn::format::any; + ASSERT_ANY_THROW(fmt = format::adjust_to_rank(p.in_format, p.new_rank)) << fmt.to_string(); + } else { + ASSERT_EQ(format::adjust_to_rank(p.in_format, p.new_rank), p.expected_format); + } +} + +INSTANTIATE_TEST_SUITE_P(smoke, format_adjust_test, + testing::ValuesIn(std::vector{ + {format::bfyx, 3, format::bfyx}, + {format::bfyx, 4, format::bfyx}, + {format::bfyx, 5, format::bfzyx}, + {format::bfyx, 6, format::bfwzyx}, + {format::bfzyx, 4, format::bfyx}, + {format::bfzyx, 6, format::bfwzyx}, + {format::bfwzyx, 3, format::bfyx}, + {format::b_fs_yx_fsv16, 5, format::b_fs_zyx_fsv16}, + {format::b_fs_zyx_fsv16, 4, format::b_fs_yx_fsv16}, + {format::fs_b_yx_fsv32, 5, format::any}, + {format::nv12, 5, format::any}, + {format::oiyx, 5, format::any}, + }), + format_adjust_test::PrintToString);