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 <vector> 21 #include <algorithm> 22 23 #include "frontend/operator/ops.h" 24 #include "frontend/optimizer/irpass.h" 25 #include "frontend/optimizer/optimizer.h" 26 #include "ir/visitor.h" 27 28 namespace mindspore { 29 namespace opt { 30 namespace irpass { 31 // {prim::kPrimSparseTensorGetIndices, {prim::kPrimMakeSparseTensor, Xs}} 32 // {prim::kPrimSparseTensorGetValues, {prim::kPrimMakeSparseTensor, Xs}} 33 // {prim::kPrimSparseTensorGetDenseShape, {prim::kPrimMakeSparseTensor, Xs}} 34 class SparseTensorEliminater : public OptimizerCaller { 35 public: operator()36 AnfNodePtr operator()(const OptimizerPtr &, const AnfNodePtr &node) override { 37 PatternNode x, y, z; 38 auto sparse = PPrimitive(prim::kPrimMakeSparseTensor, x, y, z).MinExtraNodes(0); 39 MATCH_REPLACE(node, PPrimitive(prim::kPrimSparseTensorGetIndices, sparse), x); 40 MATCH_REPLACE(node, PPrimitive(prim::kPrimSparseTensorGetValues, sparse), y); 41 MATCH_REPLACE(node, PPrimitive(prim::kPrimSparseTensorGetDenseShape, sparse), z); 42 return nullptr; 43 } 44 }; 45 } // namespace irpass 46 } // namespace opt 47 } // namespace mindspore 48 #endif // MINDSPORE_CCSRC_FRONTEND_OPTIMIZER_IRPASS_SPARSE_TENSOR_ELIMINATE_H_ 49