• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright 2023-2024 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 UT_CPP_BACKEND_GRAPH_OPTIMIZER_TEST_FRAMEWORK_
18 #define UT_CPP_BACKEND_GRAPH_OPTIMIZER_TEST_FRAMEWORK_
19 
20 #include "include/backend/optimizer/optimizer.h"
21 #include "include/backend/kernel_graph.h"
22 
23 namespace mindspore::test {
24 void RunPass(const FuncGraphPtr &graph, const std::vector<opt::PassPtr> &passes);
25 
26 class ConstructGraph {
27  public:
28   ConstructGraph();
29   const std::shared_ptr<session::KernelGraph> &GetGraph() const;
30   ParameterPtr NewScalarInput(const std::string &name, const TypePtr &type);
31   ParameterPtr NewTensorInput(const std::string &name, const TypePtr &type, const ShapeVector &shape);
32   ParameterPtr NewTupleInput(const std::string &name, const std::vector<std::pair<TypePtr, ShapeVector>> &pairs);
33   ParameterPtr NewListInput(const std::string &name, const std::vector<std::pair<TypePtr, ShapeVector>> &pairs);
34 
35   ValueNodePtr NewValueNode(const ValuePtr &value);
36   CNodePtr NewCNodeWithoutInfer(const std::string &prim_name, const std::vector<AnfNodePtr> &inputs,
37                                 const mindspore::HashMap<std::string, ValuePtr> &attrs);
38   CNodePtr NewCNode(const std::string &prim_name, const std::vector<AnfNodePtr> &inputs,
39                     const mindspore::HashMap<std::string, ValuePtr> &attrs);
40   void SetOutput(const AnfNodePtr &node);
41   void SetGeneralBuildInfo(const AnfNodePtr &node);
42 
43  private:
44   ParameterPtr NewInput(const std::string &name, const AbstractBasePtr &abs);
45 
46   std::shared_ptr<session::KernelGraph> graph_;
47 };
48 }  // namespace mindspore::test
49 
50 #define UT_CHECK_NULL(pointer) ASSERT_NE(pointer, nullptr)
51 
52 #endif  // UT_CPP_BACKEND_GRAPH_OPTIMIZER_TEST_FRAMEWORK_
53