From b2317f08ad63c772a01f3a83d4117accb0afe6b5 Mon Sep 17 00:00:00 2001 From: qiuzhongya Date: Tue, 7 Feb 2023 20:12:59 +0800 Subject: [PATCH] add op adapter --- mindspore/ccsrc/transform/graph_ir/op_adapter_map.h | 4 +++- .../graph_ir/op_declare/elewise_calculation_ops_declare.cc | 6 ++++++ .../graph_ir/op_declare/elewise_calculation_ops_declare.h | 3 +++ .../graph_ir/op_declare/matrix_calculation_ops_declare.cc | 1 + .../graph_ir/op_declare/nonlinear_fuc_ops_declare.cc | 6 ++++++ .../graph_ir/op_declare/nonlinear_fuc_ops_declare.h | 3 +++ .../transform/graph_ir/op_declare/selection_ops_declare.cc | 2 +- .../graph_ir/op_declare/transformation_ops_declare.cc | 1 + 8 files changed, 24 insertions(+), 2 deletions(-) diff --git a/mindspore/ccsrc/transform/graph_ir/op_adapter_map.h b/mindspore/ccsrc/transform/graph_ir/op_adapter_map.h index f15b2392db5..6aba7bb52ed 100644 --- a/mindspore/ccsrc/transform/graph_ir/op_adapter_map.h +++ b/mindspore/ccsrc/transform/graph_ir/op_adapter_map.h @@ -167,7 +167,8 @@ constexpr const char kNameExpm1[] = "Expm1"; constexpr const char kNameInplaceAddD[] = "InplaceAdd"; constexpr const char kNameInplaceSubD[] = "InplaceSub"; constexpr const char kNameInplaceUpdateD[] = "InplaceUpdate"; -constexpr const char kNameInTopKD[] = "InTopK"; +constexpr const char kNameInTopK[] = "InTopK"; +constexpr const char kNameInTopKD[] = "InTopKD"; constexpr const char kNameInv[] = "Inv"; constexpr const char kNameInvGrad[] = "InvGrad"; constexpr const char kNameInvert[] = "Invert"; @@ -304,6 +305,7 @@ constexpr const char kNamePrint[] = "Print"; constexpr const char kNameApplyFtrl[] = "ApplyFtrl"; constexpr const char kNameDiag[] = "Diag"; constexpr const char kNameDiagPart[] = "DiagPart"; +constexpr const char kNameDiagPartD[] = "DiagPartD"; constexpr const char kNameSpaceToBatch[] = "SpaceToBatch"; constexpr const char kNameBatchToSpace[] = "BatchToSpace"; constexpr const char kNameTan[] = "Tan"; diff --git a/mindspore/ccsrc/transform/graph_ir/op_declare/elewise_calculation_ops_declare.cc b/mindspore/ccsrc/transform/graph_ir/op_declare/elewise_calculation_ops_declare.cc index c78d996ae4c..742c75312ad 100644 --- a/mindspore/ccsrc/transform/graph_ir/op_declare/elewise_calculation_ops_declare.cc +++ b/mindspore/ccsrc/transform/graph_ir/op_declare/elewise_calculation_ops_declare.cc @@ -42,6 +42,12 @@ REG_ADPT_DESC(Add, prim::kPrimAdd->name(), std::make_shared>(ExtraAttr({{"mode", MakeValue(static_cast(1))}})), std::make_shared>(ExtraAttr({{"mode", MakeValue(static_cast(1))}})))) +// AddV2 +INPUT_MAP(AddV2) = {{1, INPUT_DESC(x1)}, {2, INPUT_DESC(x2)}}; +ATTR_MAP(AddV2) = EMPTY_ATTR_MAP; +OUTPUT_MAP(AddV2) = {{0, OUTPUT_DESC(y)}}; +REG_ADPT_DESC(AddV2, prim::kPrimAddV2->name(), ADPT_DESC(AddV2)) + // AccumulateNV2 INPUT_MAP(AccumulateNV2) = EMPTY_INPUT_MAP; DYN_INPUT_MAP(AccumulateNV2) = {{1, DYN_INPUT_DESC(x)}}; diff --git a/mindspore/ccsrc/transform/graph_ir/op_declare/elewise_calculation_ops_declare.h b/mindspore/ccsrc/transform/graph_ir/op_declare/elewise_calculation_ops_declare.h index a55452c2722..eb3597fbd63 100644 --- a/mindspore/ccsrc/transform/graph_ir/op_declare/elewise_calculation_ops_declare.h +++ b/mindspore/ccsrc/transform/graph_ir/op_declare/elewise_calculation_ops_declare.h @@ -196,6 +196,9 @@ DECLARE_OP_USE_OUTPUT(Assign) DECLARE_OP_ADAPTER(Add) DECLARE_OP_USE_OUTPUT(Add) +DECLARE_OP_ADAPTER(AddV2) +DECLARE_OP_USE_OUTPUT(AddV2) + DECLARE_OP_ADAPTER(Cos) DECLARE_OP_USE_OUTPUT(Cos) diff --git a/mindspore/ccsrc/transform/graph_ir/op_declare/matrix_calculation_ops_declare.cc b/mindspore/ccsrc/transform/graph_ir/op_declare/matrix_calculation_ops_declare.cc index c6c87cc46c6..75ee5ae902a 100644 --- a/mindspore/ccsrc/transform/graph_ir/op_declare/matrix_calculation_ops_declare.cc +++ b/mindspore/ccsrc/transform/graph_ir/op_declare/matrix_calculation_ops_declare.cc @@ -142,6 +142,7 @@ INPUT_MAP(DiagPart) = {{1, INPUT_DESC(x)}}; ATTR_MAP(DiagPart) = EMPTY_ATTR_MAP; OUTPUT_MAP(DiagPart) = {{0, OUTPUT_DESC(y)}}; REG_ADPT_DESC(DiagPart, kNameDiagPart, ADPT_DESC(DiagPart)) +REG_ADPT_DESC(DiagPartD, kNameDiagPartD, ADPT_DESC(DiagPart)) // BatchMatMul INPUT_MAP(BatchMatMul) = {{1, INPUT_DESC(x1)}, {2, INPUT_DESC(x2)}}; diff --git a/mindspore/ccsrc/transform/graph_ir/op_declare/nonlinear_fuc_ops_declare.cc b/mindspore/ccsrc/transform/graph_ir/op_declare/nonlinear_fuc_ops_declare.cc index cdda18e1075..8bd9d1c8c84 100644 --- a/mindspore/ccsrc/transform/graph_ir/op_declare/nonlinear_fuc_ops_declare.cc +++ b/mindspore/ccsrc/transform/graph_ir/op_declare/nonlinear_fuc_ops_declare.cc @@ -207,6 +207,12 @@ OUTPUT_MAP(HardShrink) = {{0, OUTPUT_DESC(output_y)}}; REG_ADPT_DESC(HShrink, prim::kPrimHShrink->name(), ADPT_DESC(HardShrink)) REG_ADPT_DESC(HardShrink, kHardShrinkOpName, ADPT_DESC(HardShrink)) +// HardShrinkGrad +INPUT_MAP(HardShrinkGrad) = {{1, INPUT_DESC(gradients)}, {2, INPUT_DESC(features)}}; +ATTR_MAP(HardShrinkGrad) = {{"lambd", ATTR_DESC(lambd, AnyTraits())}}; +OUTPUT_MAP(HardShrinkGrad) = {{0, OUTPUT_DESC(backprops)}}; +REG_ADPT_DESC(HardShrinkGrad, kHardShrinkGradOpName, ADPT_DESC(HardShrinkGrad)) + // SoftShrink INPUT_MAP(SoftShrink) = {{1, INPUT_DESC(input_x)}}; ATTR_MAP(SoftShrink) = {{"lambd", ATTR_DESC(lambd, AnyTraits())}}; diff --git a/mindspore/ccsrc/transform/graph_ir/op_declare/nonlinear_fuc_ops_declare.h b/mindspore/ccsrc/transform/graph_ir/op_declare/nonlinear_fuc_ops_declare.h index 52743199907..bd3f7a6ef92 100644 --- a/mindspore/ccsrc/transform/graph_ir/op_declare/nonlinear_fuc_ops_declare.h +++ b/mindspore/ccsrc/transform/graph_ir/op_declare/nonlinear_fuc_ops_declare.h @@ -109,6 +109,9 @@ DECLARE_OP_USE_OUTPUT(LeakyRelu) DECLARE_OP_ADAPTER(HardShrink) DECLARE_OP_USE_OUTPUT(HardShrink) +DECLARE_OP_ADAPTER(HardShrinkGrad) +DECLARE_OP_USE_OUTPUT(HardShrinkGrad) + DECLARE_OP_ADAPTER(SoftShrink) DECLARE_OP_USE_OUTPUT(SoftShrink) diff --git a/mindspore/ccsrc/transform/graph_ir/op_declare/selection_ops_declare.cc b/mindspore/ccsrc/transform/graph_ir/op_declare/selection_ops_declare.cc index 32c76cf3c04..803cb6716b5 100644 --- a/mindspore/ccsrc/transform/graph_ir/op_declare/selection_ops_declare.cc +++ b/mindspore/ccsrc/transform/graph_ir/op_declare/selection_ops_declare.cc @@ -73,8 +73,8 @@ REG_ADPT_DESC(TopKV2, kNameTopKV2, ADPT_DESC(TopK)) INPUT_MAP(InTopKD) = {{1, INPUT_DESC(x1)}, {2, INPUT_DESC(x2)}}; ATTR_MAP(InTopKD) = {{"k", ATTR_DESC(k, AnyTraits())}}; OUTPUT_MAP(InTopKD) = {{0, OUTPUT_DESC(y)}}; +REG_ADPT_DESC(InTopK, kNameInTopK, ADPT_DESC(InTopKD)) REG_ADPT_DESC(InTopKD, kNameInTopKD, ADPT_DESC(InTopKD)) - // OneHot INPUT_MAP(OneHot) = {{1, INPUT_DESC(x)}, {2, INPUT_DESC(depth)}, {3, INPUT_DESC(on_value)}, {4, INPUT_DESC(off_value)}}; ATTR_INPUT_MAP(OneHot) = {{"depth", "depth"}}; diff --git a/mindspore/ccsrc/transform/graph_ir/op_declare/transformation_ops_declare.cc b/mindspore/ccsrc/transform/graph_ir/op_declare/transformation_ops_declare.cc index d220cc296e6..5b6b4169c0d 100644 --- a/mindspore/ccsrc/transform/graph_ir/op_declare/transformation_ops_declare.cc +++ b/mindspore/ccsrc/transform/graph_ir/op_declare/transformation_ops_declare.cc @@ -135,6 +135,7 @@ ATTR_INPUT_MAP(BatchToSpaceND) = {{"block_shape", "block_shape"}, {"crops", "cro ATTR_MAP(BatchToSpaceND) = EMPTY_ATTR_MAP; OUTPUT_MAP(BatchToSpaceND) = {{0, OUTPUT_DESC(y)}}; REG_ADPT_DESC(BatchToSpaceND, kNameBatchToSpaceNd, ADPT_DESC(BatchToSpaceND)) +REG_ADPT_DESC(BatchToSpaceNDD, kBatchToSpaceNDDOpName, ADPT_DESC(BatchToSpaceND)) REG_ADPT_DESC(BatchToSpaceTF, kNameBatchToSpaceTF, ADPT_DESC(BatchToSpaceND)) REG_ADPT_DESC(kNameBatchToSpaceNdV2, kNameBatchToSpaceNdV2, ADPT_DESC(BatchToSpaceND)) } // namespace mindspore::transform