已合并
conv clean code #5831
huafeng793创建于 6月8日
conv clean code #5831
已合并
共 5 个文件变更+26-29
| @@ -16,9 +16,6 @@ | |||
| 16 | 16 | ||
| 17 | 17 | ||
| 18 | 18 | ||
| 19 | - | ||
| 20 | - | ||
| 21 | - | ||
| 22 | 19 | ||
| 23 | 20 | ||
| 24 | 21 | ||
| @@ -58,7 +58,7 @@ bool Conv3dToConv3dV2FusionPass::CheckSocCapability() | |||
| 58 | return true; | 58 | return true; |
| 59 | } | 59 | } |
| 60 | 60 | ||
| 61 | -bool Conv3dToConv3dV2FusionPass::CheckPostCubeInOutNode(const GNode &convNode) | 61 | +bool Conv3dToConv3dV2FusionPass::CheckPostCubeInOutNode(const GNode &convNode) const |
| 62 | { | 62 | { |
| 63 | auto convOutputNodes = convNode.GetOutDataNodesAndPortIndexs(OUTPUT_INDEX); | 63 | auto convOutputNodes = convNode.GetOutDataNodesAndPortIndexs(OUTPUT_INDEX); |
| 64 | for (size_t i = 0; i < convOutputNodes.size(); ++i) { | 64 | for (size_t i = 0; i < convOutputNodes.size(); ++i) { |
| @@ -76,7 +76,7 @@ bool Conv3dToConv3dV2FusionPass::CheckPostCubeInOutNode(const GNode &convNode) | |||
| 76 | return false; | 76 | return false; |
| 77 | } | 77 | } |
| 78 | 78 | ||
| 79 | -bool Conv3dToConv3dV2FusionPass::CheckTransDataInInputNode(const GNode &convNode) | 79 | +bool Conv3dToConv3dV2FusionPass::CheckTransDataInInputNode(const GNode &convNode) const |
| 80 | { | 80 | { |
| 81 | auto nodePtr = convNode.GetInDataNodesAndPortIndexs(INPUT_FMAP_INDEX).first; | 81 | auto nodePtr = convNode.GetInDataNodesAndPortIndexs(INPUT_FMAP_INDEX).first; |
| 82 | FUSION_PASS_CHECK(nodePtr == nullptr, | 82 | FUSION_PASS_CHECK(nodePtr == nullptr, |
| @@ -102,7 +102,7 @@ bool Conv3dToConv3dV2FusionPass::CheckTransDataInInputNode(const GNode &convNode | |||
| 102 | return false; | 102 | return false; |
| 103 | } | 103 | } |
| 104 | 104 | ||
| 105 | -bool Conv3dToConv3dV2FusionPass::CheckIFMRInSameOutputNode(const GNode &convNode) | 105 | +bool Conv3dToConv3dV2FusionPass::CheckIFMRInSameOutputNode(const GNode &convNode) const |
| 106 | { | 106 | { |
| 107 | auto convOutputNodes = convNode.GetOutDataNodesAndPortIndexs(OUTPUT_INDEX); | 107 | auto convOutputNodes = convNode.GetOutDataNodesAndPortIndexs(OUTPUT_INDEX); |
| 108 | for (size_t i = 0; i < convOutputNodes.size(); ++i) { | 108 | for (size_t i = 0; i < convOutputNodes.size(); ++i) { |
| @@ -54,9 +54,9 @@ protected: | |||
| 54 | 54 | ||
| 55 | private: | 55 | private: |
| 56 | bool CheckSocCapability(); | 56 | bool CheckSocCapability(); |
| 57 | - bool CheckPostCubeInOutNode(const ge::GNode &convNode); | 57 | + bool CheckPostCubeInOutNode(const ge::GNode &convNode) const; |
| 58 | - bool CheckTransDataInInputNode(const ge::GNode &convNode); | 58 | + bool CheckTransDataInInputNode(const ge::GNode &convNode) const; |
| 59 | - bool CheckIFMRInSameOutputNode(const ge::GNode &convNode); | 59 | + bool CheckIFMRInSameOutputNode(const ge::GNode &convNode) const; |
| 60 | void InitMember(); | 60 | void InitMember(); |
| 61 | 61 | ||
| 62 | bool supportOut2L1Dn2Nz = false; | 62 | bool supportOut2L1Dn2Nz = false; |
| @@ -291,6 +291,7 @@ constexpr size_t CONV_1D_DIM_SIZE = 3; | |||
| 291 | constexpr size_t CONV_2D_DIM_SIZE = 4; | 291 | constexpr size_t CONV_2D_DIM_SIZE = 4; |
| 292 | constexpr size_t CONV_3D_DIM_SIZE = 5; | 292 | constexpr size_t CONV_3D_DIM_SIZE = 5; |
| 293 | constexpr size_t CONST_VALUE_TWO = 2; | 293 | constexpr size_t CONST_VALUE_TWO = 2; |
| 294 | +constexpr size_t CONST_VALUE_FOUR = 4; | ||
| 294 | static constexpr uint64_t MAX_UINT16 = 65536; | 295 | static constexpr uint64_t MAX_UINT16 = 65536; |
| 295 | 296 | ||
| 296 | struct TensorMeta { | 297 | struct TensorMeta { |
| @@ -787,40 +788,40 @@ public: | |||
| 787 | size_t inputDim = engine.meta.input.shape.size(); | 788 | size_t inputDim = engine.meta.input.shape.size(); |
| 788 | 789 | ||
| 789 | auto strideSize = engine.meta.stride.size(); | 790 | auto strideSize = engine.meta.stride.size(); |
| 790 | - if (strideSize != inputDim - 2) { | 791 | + if (strideSize != inputDim - CONST_VALUE_TWO) { |
| 791 | OP_LOGE_FOR_INVALID_LISTSIZE(engine.entityName, "strides", std::to_string(strideSize), | 792 | OP_LOGE_FOR_INVALID_LISTSIZE(engine.entityName, "strides", std::to_string(strideSize), |
| 792 | - std::to_string(inputDim - 2)); | 793 | + std::to_string(inputDim - CONST_VALUE_TWO)); |
| 793 | return ACLNN_ERR_PARAM_INVALID; | 794 | return ACLNN_ERR_PARAM_INVALID; |
| 794 | } | 795 | } |
| 795 | 796 | ||
| 796 | auto dilationSize = engine.meta.dilation.size(); | 797 | auto dilationSize = engine.meta.dilation.size(); |
| 797 | - if (dilationSize != inputDim - 2) { | 798 | + if (dilationSize != inputDim - CONST_VALUE_TWO) { |
| 798 | OP_LOGE_FOR_INVALID_LISTSIZE(engine.entityName, "dilations", std::to_string(dilationSize), | 799 | OP_LOGE_FOR_INVALID_LISTSIZE(engine.entityName, "dilations", std::to_string(dilationSize), |
| 799 | - std::to_string(inputDim - 2)); | 800 | + std::to_string(inputDim - CONST_VALUE_TWO)); |
| 800 | return ACLNN_ERR_PARAM_INVALID; | 801 | return ACLNN_ERR_PARAM_INVALID; |
| 801 | } | 802 | } |
| 802 | 803 | ||
| 803 | auto paddingSize = engine.meta.padding.size(); | 804 | auto paddingSize = engine.meta.padding.size(); |
| 804 | if (((inputDim == CONV_1D_DIM_SIZE || inputDim == CONV_2D_DIM_SIZE) && !engine.params.transposed) || | 805 | if (((inputDim == CONV_1D_DIM_SIZE || inputDim == CONV_2D_DIM_SIZE) && !engine.params.transposed) || |
| 805 | (inputDim == CONV_2D_DIM_SIZE && engine.params.transposed)) { | 806 | (inputDim == CONV_2D_DIM_SIZE && engine.params.transposed)) { |
| 806 | - if (!Any(paddingSize, Equal<size_t>, inputDim - 2, inputDim * 2 - 4)) { | 807 | + if (!Any(paddingSize, Equal<size_t>, inputDim - CONST_VALUE_TWO, inputDim * CONST_VALUE_TWO - CONST_VALUE_FOUR)) { |
| 807 | OP_LOGE_FOR_INVALID_LISTSIZE(engine.entityName, "pads", std::to_string(paddingSize), | 808 | OP_LOGE_FOR_INVALID_LISTSIZE(engine.entityName, "pads", std::to_string(paddingSize), |
| 808 | - std::to_string(inputDim - 2) + " or " + std::to_string(inputDim * 2 - 4)); | 809 | + std::to_string(inputDim - CONST_VALUE_TWO) + " or " + std::to_string(inputDim * CONST_VALUE_TWO - CONST_VALUE_FOUR)); |
| 809 | return ACLNN_ERR_PARAM_INVALID; | 810 | return ACLNN_ERR_PARAM_INVALID; |
| 810 | } | 811 | } |
| 811 | } else { | 812 | } else { |
| 812 | - if (paddingSize != inputDim - 2) { | 813 | + if (paddingSize != inputDim - CONST_VALUE_TWO) { |
| 813 | OP_LOGE_FOR_INVALID_LISTSIZE(engine.entityName, "pads", std::to_string(paddingSize), | 814 | OP_LOGE_FOR_INVALID_LISTSIZE(engine.entityName, "pads", std::to_string(paddingSize), |
| 814 | - std::to_string(inputDim - 2)); | 815 | + std::to_string(inputDim - CONST_VALUE_TWO)); |
| 815 | return ACLNN_ERR_PARAM_INVALID; | 816 | return ACLNN_ERR_PARAM_INVALID; |
| 816 | } | 817 | } |
| 817 | } | 818 | } |
| 818 | 819 | ||
| 819 | if (engine.params.transposed) { | 820 | if (engine.params.transposed) { |
| 820 | auto outputPaddingSize = engine.meta.outputPadding.size(); | 821 | auto outputPaddingSize = engine.meta.outputPadding.size(); |
| 821 | - if (outputPaddingSize != inputDim - 2) { | 822 | + if (outputPaddingSize != inputDim - CONST_VALUE_TWO) { |
| 822 | OP_LOGE_FOR_INVALID_LISTSIZE(engine.entityName, "outputPadding", std::to_string(outputPaddingSize), | 823 | OP_LOGE_FOR_INVALID_LISTSIZE(engine.entityName, "outputPadding", std::to_string(outputPaddingSize), |
| 823 | - std::to_string(inputDim - 2)); | 824 | + std::to_string(inputDim - CONST_VALUE_TWO)); |
| 824 | return ACLNN_ERR_PARAM_INVALID; | 825 | return ACLNN_ERR_PARAM_INVALID; |
| 825 | } | 826 | } |
| 826 | } | 827 | } |
| @@ -921,23 +922,23 @@ public: | |||
| 921 | } | 922 | } |
| 922 | 923 | ||
| 923 | auto strideSize = engine.meta.stride.size(); | 924 | auto strideSize = engine.meta.stride.size(); |
| 924 | - if (strideSize != inputDim - 2) { | 925 | + if (strideSize != inputDim - CONST_VALUE_TWO) { |
| 925 | OP_LOGE_FOR_INVALID_LISTSIZE(engine.entityName, "strides", std::to_string(strideSize), | 926 | OP_LOGE_FOR_INVALID_LISTSIZE(engine.entityName, "strides", std::to_string(strideSize), |
| 926 | - std::to_string(inputDim - 2)); | 927 | + std::to_string(inputDim - CONST_VALUE_TWO)); |
| 927 | return ACLNN_ERR_PARAM_INVALID; | 928 | return ACLNN_ERR_PARAM_INVALID; |
| 928 | } | 929 | } |
| 929 | 930 | ||
| 930 | auto dilationSize = engine.meta.dilation.size(); | 931 | auto dilationSize = engine.meta.dilation.size(); |
| 931 | - if (dilationSize != inputDim - 2) { | 932 | + if (dilationSize != inputDim - CONST_VALUE_TWO) { |
| 932 | OP_LOGE_FOR_INVALID_LISTSIZE(engine.entityName, "dilations", std::to_string(dilationSize), | 933 | OP_LOGE_FOR_INVALID_LISTSIZE(engine.entityName, "dilations", std::to_string(dilationSize), |
| 933 | - std::to_string(inputDim - 2)); | 934 | + std::to_string(inputDim - CONST_VALUE_TWO)); |
| 934 | return ACLNN_ERR_PARAM_INVALID; | 935 | return ACLNN_ERR_PARAM_INVALID; |
| 935 | } | 936 | } |
| 936 | 937 | ||
| 937 | auto paddingSize = engine.meta.padding.size(); | 938 | auto paddingSize = engine.meta.padding.size(); |
| 938 | - if (paddingSize != inputDim - 2) { | 939 | + if (paddingSize != inputDim - CONST_VALUE_TWO) { |
| 939 | OP_LOGE_FOR_INVALID_LISTSIZE(engine.entityName, "pads", std::to_string(paddingSize), | 940 | OP_LOGE_FOR_INVALID_LISTSIZE(engine.entityName, "pads", std::to_string(paddingSize), |
| 940 | - std::to_string(inputDim - 2)); | 941 | + std::to_string(inputDim - CONST_VALUE_TWO)); |
| 941 | return ACLNN_ERR_PARAM_INVALID; | 942 | return ACLNN_ERR_PARAM_INVALID; |
| 942 | } | 943 | } |
| 943 | 944 | ||
| @@ -1815,7 +1816,6 @@ private: | |||
| 1815 | int64_t outputShapeN = output.N(); | 1816 | int64_t outputShapeN = output.N(); |
| 1816 | int64_t outputShapeC = output.C(); | 1817 | int64_t outputShapeC = output.C(); |
| 1817 | int64_t outputShapeL = output.L(); | 1818 | int64_t outputShapeL = output.L(); |
| 1818 | - | ||
| 1819 | if (!All(0L, LessEqual<int64_t>, inputShapeN, inputShapeC, inputShapeL, weightShapeN, weightShapeC, | 1819 | if (!All(0L, LessEqual<int64_t>, inputShapeN, inputShapeC, inputShapeL, weightShapeN, weightShapeC, |
| 1820 | weightShapeL, outputShapeN, outputShapeC, outputShapeL)) { | 1820 | weightShapeL, outputShapeN, outputShapeC, outputShapeL)) { |
| 1821 | OP_LOGE_FOR_INVALID_SHAPES_WITH_REASON(entityName, "x, filter, y", | 1821 | OP_LOGE_FOR_INVALID_SHAPES_WITH_REASON(entityName, "x, filter, y", |
| @@ -584,7 +584,7 @@ class FormatsChecker : public QuantConvolutionChecker { | |||
| 584 | public: | 584 | public: |
| 585 | FormatsChecker() = default; | 585 | FormatsChecker() = default; |
| 586 | ~FormatsChecker() override = default; | 586 | ~FormatsChecker() override = default; |
| 587 | - aclnnStatus CheckBias(QuantConvEngine &engine) | 587 | + aclnnStatus CheckBias(QuantConvEngine &engine) const |
| 588 | { | 588 | { |
| 589 | if (engine.params.bias) { | 589 | if (engine.params.bias) { |
| 590 | auto biasFormat = engine.meta.bias.format; | 590 | auto biasFormat = engine.meta.bias.format; |
| @@ -597,7 +597,7 @@ public: | |||
| 597 | return ACLNN_SUCCESS; | 597 | return ACLNN_SUCCESS; |
| 598 | } | 598 | } |
| 599 | 599 | ||
| 600 | - aclnnStatus CheckScale(QuantConvEngine &engine) | 600 | + aclnnStatus CheckScale(QuantConvEngine &engine) const |
| 601 | { | 601 | { |
| 602 | auto scaleFormat = engine.meta.scale.format; | 602 | auto scaleFormat = engine.meta.scale.format; |
| 603 | if (scaleFormat != Format::FORMAT_ND) { | 603 | if (scaleFormat != Format::FORMAT_ND) { |
| @@ -608,7 +608,7 @@ public: | |||
| 608 | return ACLNN_SUCCESS; | 608 | return ACLNN_SUCCESS; |
| 609 | } | 609 | } |
| 610 | 610 | ||
| 611 | - aclnnStatus CheckFormat2D(QuantConvEngine &engine) | 611 | + aclnnStatus CheckFormat2D(QuantConvEngine &engine) const |
| 612 | { | 612 | { |
| 613 | if (!IsSocSupportND()) { | 613 | if (!IsSocSupportND()) { |
| 614 | return ACLNN_SUCCESS; | 614 | return ACLNN_SUCCESS; |