You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

optimizer_test.cc 2.4 kB

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