1 /** 2 * Copyright 2020 Huawei Technologies Co., Ltd 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef MINDSPORE_CCSRC_FRONTEND_OPTIMIZER_IRPASS_SPARSE_TENSOR_ELIMINATE_H_ 18 #define MINDSPORE_CCSRC_FRONTEND_OPTIMIZER_IRPASS_SPARSE_TENSOR_ELIMINATE_H_ 19 20 #include "frontend/operator/ops.h" 21 #include "mindspore/core/ops/sparse_tensor_ops.h" 22 #include "frontend/optimizer/irpass.h" 23 #include "frontend/optimizer/optimizer.h" 24 #include "ir/visitor.h" 25 #include "ir/pattern_matcher.h" 26 27 namespace mindspore { 28 namespace opt { 29 namespace irpass { 30 // {prim::kPrimSparseTensorGetIndices, {prim::kPrimMakeSparseTensor, Xs}} 31 // {prim::kPrimSparseTensorGetValues, {prim::kPrimMakeSparseTensor, Xs}} 32 // {prim::kPrimSparseTensorGetDenseShape, {prim::kPrimMakeSparseTensor, Xs}} 33 class SparseTensorEliminater : public OptimizerCaller { 34 public: operator()35 AnfNodePtr operator()(const OptimizerPtr &, const AnfNodePtr &node) override { 36 PatternNode x; 37 PatternNode y; 38 PatternNode z; 39 auto sparse = PPrimitive(prim::kPrimMakeCOOTensor, x, y, z).MinExtraNodes(0); 40 MATCH_REPLACE(node, PPrimitive(prim::kPrimCOOTensorGetIndices, sparse), x); 41 MATCH_REPLACE(node, PPrimitive(prim::kPrimCOOTensorGetValues, sparse), y); 42 MATCH_REPLACE(node, PPrimitive(prim::kPrimCOOTensorGetDenseShape, sparse), z); 43 return nullptr; 44 } 45 }; 46 } // namespace irpass 47 } // namespace opt 48 } // namespace mindspore 49 #endif // MINDSPORE_CCSRC_FRONTEND_OPTIMIZER_IRPASS_SPARSE_TENSOR_ELIMINATE_H_ 50