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.7 kB

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