[CPU] Use switch case to ensure to_string methods are complete (#17522)

And add missing cases
Compiler can warn about missed enum entry in switch case
This commit is contained in:
Egor Duplenskii 2023-05-15 17:57:13 +02:00 committed by GitHub
parent 2fb984b60f
commit ab119faa0b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 232 additions and 323 deletions

View File

@ -200,7 +200,7 @@ const InferenceEngine::details::caseless_unordered_map<std::string, Type> type_t
{ "Subgraph", Type::Subgraph},
{ "PriorBox", Type::PriorBox},
{ "PriorBoxClustered", Type::PriorBoxClustered},
{"Interaction", Type::Interaction},
{ "Interaction", Type::Interaction},
{ "MHA", Type::MHA},
{ "Unique", Type::Unique},
{ "Ngram", Type::Ngram}
@ -216,305 +216,219 @@ Type TypeFromName(const std::string& type) {
}
std::string NameFromType(const Type type) {
#define CASE(_alg) case Type::_alg: return #_alg;
switch (type) {
case Type::Generic:
return "Generic";
case Type::Reorder:
return "Reorder";
case Type::Input:
return "Input";
case Type::Output:
return "Output";
case Type::Eye:
return "Eye";
case Type::Convolution:
return "Convolution";
case Type::Deconvolution:
return "Deconvolution";
case Type::Lrn:
return "Lrn";
case Type::Pooling:
return "Pooling";
case Type::AdaptivePooling:
return "AdaptivePooling";
case Type::FullyConnected:
return "FullyConnected";
case Type::MatMul:
return "MatMul";
case Type::Softmax:
return "Softmax";
case Type::Split:
return "Split";
case Type::Concatenation:
return "Concatenation";
case Type::StridedSlice:
return "StridedSlice";
case Type::Reshape:
return "Reshape";
case Type::ShapeOf:
return "ShapeOf";
case Type::NonZero:
return "NonZero";
case Type::Tile:
return "Tile";
case Type::ROIAlign:
return "ROIAlign";
case Type::ROIPooling:
return "ROIPooling";
case Type::PSROIPooling:
return "PSROIPooling";
case Type::DepthToSpace:
return "DepthToSpace";
case Type::BatchToSpace:
return "BatchToSpace";
case Type::Pad:
return "Pad";
case Type::Transpose:
return "Transpose";
case Type::SpaceToDepth:
return "SpaceToDepth";
case Type::SpaceToBatch:
return "SpaceToBatch";
case Type::MemoryOutput:
return "MemoryOutput";
case Type::MemoryInput:
return "MemoryInput";
case Type::RNNSeq:
return "RNNSeq";
case Type::RNNCell:
return "RNNCell";
case Type::Eltwise:
return "Eltwise";
case Type::FakeQuantize:
return "FakeQuantize";
case Type::BinaryConvolution:
return "BinaryConvolution";
case Type::DeformableConvolution:
return "DeformableConvolution";
case Type::MVN:
return "MVN";
case Type::TensorIterator:
return "TensorIterator";
case Type::Convert:
return "Convert";
case Type::ColorConvert:
return "ColorConvert";
case Type::NormalizeL2:
return "NormalizeL2";
case Type::ScatterUpdate:
return "ScatterUpdate";
case Type::ScatterElementsUpdate:
return "ScatterElementsUpdate";
case Type::ScatterNDUpdate:
return "ScatterNDUpdate";
case Type::Interaction:
return "Interaction";
case Type::Interpolate:
return "Interpolate";
case Type::Reduce:
return "Reduce";
case Type::Broadcast:
return "Broadcast";
case Type::EmbeddingSegmentsSum:
return "EmbeddingSegmentsSum";
case Type::EmbeddingBagPackedSum:
return "EmbeddingBagPackedSum";
case Type::EmbeddingBagOffsetsSum:
return "EmbeddingBagOffsetsSum";
case Type::Gather:
return "Gather";
case Type::GatherElements:
return "GatherElements";
case Type::GatherND:
return "GatherND";
case Type::GridSample:
return "GridSample";
case Type::OneHot:
return "OneHot";
case Type::RegionYolo:
return "RegionYolo";
case Type::Roll:
return "Roll";
case Type::ShuffleChannels:
return "ShuffleChannels";
case Type::DFT:
return "DFT";
case Type::RDFT:
return "RDFT";
case Type::Math:
return "Math";
case Type::CTCLoss:
return "CTCLoss";
case Type::Bucketize:
return "Bucketize";
case Type::CTCGreedyDecoder:
return "CTCGreedyDecoder";
case Type::CTCGreedyDecoderSeqLen:
return "CTCGreedyDecoderSeqLen";
case Type::CumSum:
return "CumSum";
case Type::DetectionOutput:
return "DetectionOutput";
case Type::ExperimentalDetectronDetectionOutput:
return "ExperimentalDetectronDetectionOutput";
case Type::If:
return "If";
case Type::LogSoftmax:
return "LogSoftmax";
case Type::TopK:
return "TopK";
case Type::GatherTree:
return "GatherTree";
case Type::GRN:
return "GRN";
case Type::Range:
return "Range";
case Type::Proposal:
return "Proposal";
case Type::ReorgYolo:
return "ReorgYolo";
case Type::ReverseSequence:
return "ReverseSequence";
case Type::ExperimentalDetectronTopKROIs:
return "ExperimentalDetectronTopKROIs";
case Type::ExperimentalDetectronROIFeatureExtractor:
return "ExperimentalDetectronROIFeatureExtractor";
case Type::ExperimentalDetectronPriorGridGenerator:
return "ExperimentalDetectronPriorGridGenerator";
case Type::ExperimentalDetectronGenerateProposalsSingleImage:
return "ExperimentalDetectronGenerateProposalsSingleImage";
case Type::GenerateProposals:
return "GenerateProposals";
case Type::ExtractImagePatches:
return "ExtractImagePatches";
case Type::NonMaxSuppression:
return "NonMaxSuppression";
case Type::MatrixNms:
return "MatrixNms";
case Type::MulticlassNms:
return "MulticlassNms";
case Type::Reference:
return "Reference";
case Type::Subgraph:
return "Subgraph";
case Type::MHA:
return "MHA";
case Type::Unique:
return "Unique";
case Type::Ngram:
return "Ngram";
default:
return "Unknown";
CASE(Generic);
CASE(Reorder);
CASE(Input);
CASE(Output);
CASE(Eye);
CASE(Convolution);
CASE(Deconvolution);
CASE(Lrn);
CASE(Pooling);
CASE(AdaptivePooling);
CASE(FullyConnected);
CASE(MatMul);
CASE(Softmax);
CASE(Split);
CASE(Concatenation);
CASE(StridedSlice);
CASE(Reshape);
CASE(ShapeOf);
CASE(NonZero);
CASE(Tile);
CASE(ROIAlign);
CASE(ROIPooling);
CASE(PSROIPooling);
CASE(DepthToSpace);
CASE(BatchToSpace);
CASE(Pad);
CASE(Transpose);
CASE(SpaceToDepth);
CASE(SpaceToBatch);
CASE(MemoryOutput);
CASE(MemoryInput);
CASE(RNNSeq);
CASE(RNNCell);
CASE(Eltwise);
CASE(FakeQuantize);
CASE(BinaryConvolution);
CASE(DeformableConvolution);
CASE(MVN);
CASE(TensorIterator);
CASE(Convert);
CASE(ColorConvert);
CASE(NormalizeL2);
CASE(ScatterUpdate);
CASE(ScatterElementsUpdate);
CASE(ScatterNDUpdate);
CASE(Interaction);
CASE(Interpolate);
CASE(Reduce);
CASE(Broadcast);
CASE(EmbeddingSegmentsSum);
CASE(EmbeddingBagPackedSum);
CASE(EmbeddingBagOffsetsSum);
CASE(Gather);
CASE(GatherElements);
CASE(GatherND);
CASE(GridSample);
CASE(OneHot);
CASE(RegionYolo);
CASE(Roll);
CASE(ShuffleChannels);
CASE(DFT);
CASE(RDFT);
CASE(Math);
CASE(CTCLoss);
CASE(Bucketize);
CASE(CTCGreedyDecoder);
CASE(CTCGreedyDecoderSeqLen);
CASE(CumSum);
CASE(DetectionOutput);
CASE(ExperimentalDetectronDetectionOutput);
CASE(If);
CASE(LogSoftmax);
CASE(TopK);
CASE(GatherTree);
CASE(GRN);
CASE(Range);
CASE(Proposal);
CASE(ReorgYolo);
CASE(ReverseSequence);
CASE(ExperimentalDetectronTopKROIs);
CASE(ExperimentalDetectronROIFeatureExtractor);
CASE(ExperimentalDetectronPriorGridGenerator);
CASE(ExperimentalDetectronGenerateProposalsSingleImage);
CASE(GenerateProposals);
CASE(ExtractImagePatches);
CASE(NonMaxSuppression);
CASE(MatrixNms);
CASE(MulticlassNms);
CASE(Reference);
CASE(Subgraph);
CASE(PriorBox);
CASE(PriorBoxClustered)
CASE(MHA);
CASE(Unique);
CASE(Ngram);
CASE(Unknown);
}
#undef CASE
return "Unknown";
}
std::string algToString(const Algorithm alg) {
#define CASE(_alg) do { \
if (alg == Algorithm::_alg) return #_alg; \
} while (0)
CASE(Default);
CASE(PoolingMax);
CASE(PoolingAvg);
CASE(ConvolutionCommon);
CASE(ConvolutionGrouped);
CASE(DeconvolutionCommon);
CASE(DeconvolutionGrouped);
CASE(EltwiseAdd);
CASE(EltwiseIsFinite);
CASE(EltwiseIsInf);
CASE(EltwiseIsNaN);
CASE(EltwiseMultiply);
CASE(EltwiseSubtract);
CASE(EltwiseDivide);
CASE(EltwiseFloorMod);
CASE(EltwiseMod);
CASE(EltwiseMaximum);
CASE(EltwiseMinimum);
CASE(EltwiseSquaredDifference);
CASE(EltwisePowerDynamic);
CASE(EltwisePowerStatic);
CASE(EltwiseMulAdd);
CASE(EltwiseEqual);
CASE(EltwiseNotEqual);
CASE(EltwiseGreater);
CASE(EltwiseGreaterEqual);
CASE(EltwiseLess);
CASE(EltwiseLessEqual);
CASE(EltwiseLogicalAnd);
CASE(EltwiseLogicalOr);
CASE(EltwiseLogicalXor);
CASE(EltwiseLogicalNot);
CASE(EltwiseRelu);
CASE(EltwiseGeluErf);
CASE(EltwiseGeluTanh);
CASE(EltwiseElu);
CASE(EltwiseTanh);
CASE(EltwiseSelect);
CASE(EltwiseSigmoid);
CASE(EltwiseAbs);
CASE(EltwiseSqrt);
CASE(EltwiseSoftRelu);
CASE(EltwiseExp);
CASE(EltwiseClamp);
CASE(EltwiseSwish);
CASE(EltwisePrelu);
CASE(EltwiseMish);
CASE(EltwiseHswish);
CASE(EltwiseHsigmoid);
CASE(EltwiseRoundHalfToEven);
CASE(EltwiseRoundHalfAwayFromZero);
CASE(EltwiseErf);
CASE(EltwiseLog);
CASE(FQCommon);
CASE(FQQuantization);
CASE(FQBinarization);
CASE(ROIPoolingMax);
CASE(ROIPoolingBilinear);
CASE(ROIAlignMax);
CASE(ROIAlignAvg);
CASE(PSROIPoolingAverage);
CASE(PSROIPoolingBilinear);
CASE(PSROIPoolingBilinearDeformable);
CASE(ReduceL1);
CASE(ReduceL2);
CASE(ReduceAnd);
CASE(ReduceOr);
CASE(ReduceMax);
CASE(ReduceMean);
CASE(ReduceMin);
CASE(ReduceProd);
CASE(ReduceSum);
CASE(ReduceLogSum);
CASE(ReduceLogSumExp);
CASE(ReduceSumSquare);
CASE(MathAbs);
CASE(MathAcos);
CASE(MathAcosh);
CASE(MathAsin);
CASE(MathAsinh);
CASE(MathAtan);
CASE(MathAtanh);
CASE(MathCeiling);
CASE(MathCos);
CASE(MathCosh);
CASE(MathErf);
CASE(MathFloor);
CASE(MathHardSigmoid);
CASE(MathNegative);
CASE(MathReciprocal);
CASE(MathSelu);
CASE(MathSign);
CASE(MathSin);
CASE(MathSinh);
CASE(MathSoftPlus);
CASE(MathSoftsign);
CASE(MathTan);
CASE(TensorIteratorCommon);
CASE(TensorIteratorLoop);
CASE(ColorConvertNV12toRGB);
CASE(ColorConvertNV12toBGR);
CASE(ColorConvertI420toRGB);
CASE(ColorConvertI420toBGR);
#define CASE(_alg) case Algorithm::_alg: return #_alg;
switch (alg) {
CASE(Default);
CASE(PoolingMax);
CASE(PoolingAvg);
CASE(AdaptivePoolingMax);
CASE(AdaptivePoolingAvg);
CASE(ConvolutionCommon);
CASE(ConvolutionGrouped);
CASE(DeconvolutionCommon);
CASE(DeconvolutionGrouped);
CASE(EltwiseAdd);
CASE(EltwiseIsFinite);
CASE(EltwiseIsInf);
CASE(EltwiseIsNaN);
CASE(EltwiseMultiply);
CASE(EltwiseSubtract);
CASE(EltwiseDivide);
CASE(EltwiseFloorMod);
CASE(EltwiseMod);
CASE(EltwiseMaximum);
CASE(EltwiseMinimum);
CASE(EltwiseSquaredDifference);
CASE(EltwisePowerDynamic);
CASE(EltwisePowerStatic);
CASE(EltwiseMulAdd);
CASE(EltwiseEqual);
CASE(EltwiseNotEqual);
CASE(EltwiseGreater);
CASE(EltwiseGreaterEqual);
CASE(EltwiseLess);
CASE(EltwiseLessEqual);
CASE(EltwiseLogicalAnd);
CASE(EltwiseLogicalOr);
CASE(EltwiseLogicalXor);
CASE(EltwiseLogicalNot);
CASE(EltwiseRelu);
CASE(EltwiseGeluErf);
CASE(EltwiseGeluTanh);
CASE(EltwiseElu);
CASE(EltwiseTanh);
CASE(EltwiseSelect);
CASE(EltwiseSigmoid);
CASE(EltwiseAbs);
CASE(EltwiseSqrt);
CASE(EltwiseSoftRelu);
CASE(EltwiseExp);
CASE(EltwiseClamp);
CASE(EltwiseSwish);
CASE(EltwisePrelu);
CASE(EltwiseMish);
CASE(EltwiseHswish);
CASE(EltwiseHsigmoid);
CASE(EltwiseRoundHalfToEven);
CASE(EltwiseRoundHalfAwayFromZero);
CASE(EltwiseErf);
CASE(EltwiseSoftSign);
CASE(EltwiseLog);
CASE(FQCommon);
CASE(FQQuantization);
CASE(FQBinarization);
CASE(ROIPoolingMax);
CASE(ROIPoolingBilinear);
CASE(ROIAlignMax);
CASE(ROIAlignAvg);
CASE(PSROIPoolingAverage);
CASE(PSROIPoolingBilinear);
CASE(PSROIPoolingBilinearDeformable);
CASE(ReduceL1);
CASE(ReduceL2);
CASE(ReduceAnd);
CASE(ReduceOr);
CASE(ReduceMax);
CASE(ReduceMean);
CASE(ReduceMin);
CASE(ReduceProd);
CASE(ReduceSum);
CASE(ReduceLogSum);
CASE(ReduceLogSumExp);
CASE(ReduceSumSquare);
CASE(MathAbs);
CASE(MathAcos);
CASE(MathAcosh);
CASE(MathAsin);
CASE(MathAsinh);
CASE(MathAtan);
CASE(MathAtanh);
CASE(MathCeiling);
CASE(MathCos);
CASE(MathCosh);
CASE(MathErf);
CASE(MathFloor);
CASE(MathHardSigmoid);
CASE(MathNegative);
CASE(MathReciprocal);
CASE(MathSelu);
CASE(MathSign);
CASE(MathSin);
CASE(MathSinh);
CASE(MathSoftPlus);
CASE(MathSoftsign);
CASE(MathTan);
CASE(TensorIteratorCommon);
CASE(TensorIteratorLoop);
CASE(ColorConvertNV12toRGB);
CASE(ColorConvertNV12toBGR);
CASE(ColorConvertI420toRGB);
CASE(ColorConvertI420toBGR);
}
#undef CASE
return "Undefined";
}

View File

@ -117,7 +117,7 @@ protected:
inPrc, outPrc, inLayout, outLayout,
inputShapes, imageShapes, targetDevice) = GetParam();
selectedType = makeSelectedTypeStr("ref", inPrc);
selectedType = makeSelectedTypeStr("ref_any", ov::test::ElementType::i32);
targetDevice = CommonTestUtils::DEVICE_CPU;
init_input_shapes({ inputShapes, imageShapes });

View File

@ -108,7 +108,7 @@ protected:
inPrc, outPrc, inLayout, outLayout,
inputShapes, imageShapes, targetDevice) = GetParam();
selectedType = makeSelectedTypeStr("ref", inPrc);
selectedType = makeSelectedTypeStr("ref_any", ov::test::ElementType::i32);
targetDevice = CommonTestUtils::DEVICE_CPU;
init_input_shapes({ inputShapes, imageShapes });

View File

@ -11,32 +11,27 @@ namespace CPUTestUtils {
const char* CPUTestsBase::any_type = "any_type";
const char *CPUTestsBase::cpu_fmt2str(cpu_memory_format_t v) {
#define CASE(_fmt) do { \
if (v == _fmt) return #_fmt; \
} while (0)
CASE(undef);
CASE(ncw);
CASE(nCw8c);
CASE(nCw16c);
CASE(nwc);
CASE(nchw);
CASE(nChw8c);
CASE(nChw16c);
CASE(nhwc);
CASE(ncdhw);
CASE(nCdhw8c);
CASE(nCdhw16c);
CASE(ndhwc);
CASE(nc);
CASE(x);
CASE(tnc);
CASE(ntc);
CASE(ldnc);
CASE(ldigo);
CASE(ldgoi);
CASE(ldio);
CASE(ldoi);
CASE(ldgo);
#define CASE(_fmt) case (cpu_memory_format_t::_fmt): return #_fmt;
switch (v) {
CASE(undef);
CASE(ncw);
CASE(nCw8c);
CASE(nCw16c);
CASE(nwc);
CASE(nchw);
CASE(nChw8c);
CASE(nChw16c);
CASE(nhwc);
CASE(ncdhw);
CASE(nCdhw8c);
CASE(nCdhw16c);
CASE(ndhwc);
CASE(nc);
CASE(x);
CASE(ntc);
CASE(ldgoi);
CASE(ldoi);
}
#undef CASE
assert(!"unknown fmt");
return "undef";