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 #include <iostream>
17 #include <memory>
18
19 #include "common/common_test.h"
20 #include "common/py_func_graph_fetcher.h"
21
22 #include "ir/anf.h"
23 #include "frontend/operator/ops.h"
24 #include "frontend/optimizer/cse_pass.h"
25 #include "frontend/optimizer/optimizer.h"
26 #include "frontend/optimizer/irpass.h"
27 #include "frontend/optimizer/irpass/gradient_eliminate.h"
28 #include "debug/draw.h"
29
30 namespace mindspore {
31 namespace opt {
32 using Var = mindspore::Var;
33
34 class TestOptOptimizer : public UT::Common {
35 public:
TestOptOptimizer()36 TestOptOptimizer() : getPyFun("gtest_input.optimizer.opt_test", true), irpass() {}
37 UT::PyFuncGraphFetcher getPyFun;
38 irpass::OptimizeIRPassLib irpass;
39 };
40
TEST_F(TestOptOptimizer,test_step_opt)41 TEST_F(TestOptOptimizer, test_step_opt) {
42 FuncGraphPtr before = getPyFun("test_expandJ");
43
44 ASSERT_TRUE(nullptr != before);
45 pipeline::ResourcePtr res = std::make_shared<pipeline::Resource>();
46 std::shared_ptr<Optimizer> optimizer =
47 Optimizer::MakeOptimizer("ut_test", res,
48 {{"main",
49 {
50 // Branch culling
51 irpass.switch_simplify_,
52
53 // Safe inlining
54 irpass.arithmetic_simplify_,
55 irpass.inline_,
56 }},
57 {"grad", opt::OptPassConfig(opt::irpass::ExpandJPrim())},
58 {"cse", OptPassConfig(CSEPass(false))}},
59 true);
60 EXPECT_TRUE(optimizer.get() != nullptr);
61
62 auto after = optimizer->step(before);
63 }
64
65 } // namespace opt
66 } // namespace mindspore
67