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.

scope_pass_manager.cc 2.7 kB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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 "parser/tensorflow/scope/scope_pass_manager.h"
  17. #include "parser/common/acl_graph_parser_util.h"
  18. #include "common/util.h"
  19. #include "common/util/error_manager/error_manager.h"
  20. #include "framework/common/debug/ge_log.h"
  21. #include "register/scope/scope_graph_impl.h"
  22. #include "register/scope/scope_pass_impl.h"
  23. namespace ge {
  24. std::shared_ptr<ScopeGraph> ScopePassManager::BuildScopeGraph(domi::tensorflow::GraphDef *graph_def) {
  25. GE_CHK_BOOL_EXEC(graph_def != nullptr, return nullptr, "graph_def is nullptr");
  26. scope_graph_ = ge::parser::MakeShared<ScopeGraph>();
  27. if (scope_graph_ == nullptr) {
  28. REPORT_CALL_ERROR("E19999", "New ScopeGraph failed");
  29. GELOGE(FAILED, "Scope graph make shared failed.");
  30. return nullptr;
  31. }
  32. Status ret = scope_graph_->Init();
  33. if (ret != SUCCESS) {
  34. GELOGE(FAILED, "Scope graph init failed.");
  35. return nullptr;
  36. }
  37. auto &impl = scope_graph_->impl_;
  38. impl->BuildScopeGraph(graph_def);
  39. return scope_graph_;
  40. }
  41. Status ScopePassManager::AddPass(std::unique_ptr<ScopeBasePass> &pass) {
  42. GE_CHECK_NOTNULL(pass);
  43. graph_passes_.push_back(std::move(pass));
  44. return SUCCESS;
  45. }
  46. Status ScopePassManager::Run(std::shared_ptr<ScopeGraph> &graph) {
  47. GE_CHECK_NOTNULL(graph);
  48. bool not_changed = true;
  49. for (auto &pass : graph_passes_) {
  50. GE_CHECK_NOTNULL(pass);
  51. auto &impl = pass->impl_;
  52. if (impl == nullptr) {
  53. GELOGE(ge::MEMALLOC_FAILED, "ScopeBasePass is not properly initialized.");
  54. REPORT_INNER_ERROR("E19999", "ScopeBasePass is not properly initialized");
  55. continue;
  56. }
  57. Status status = impl->Run(graph);
  58. if (status == SUCCESS) {
  59. GELOGI("Run scope pass:%s success.", pass->PassName().c_str());
  60. not_changed = false;
  61. } else if (status != domi::SCOPE_NOT_CHANGED) {
  62. // exception
  63. REPORT_CALL_ERROR("E19999", "Run scope fusion pass [%s] failed.", pass->PassName().c_str());
  64. GELOGE(FAILED, "Pass Run failed, pass name:%s", pass->PassName().c_str());
  65. return status;
  66. }
  67. }
  68. return not_changed ? domi::SCOPE_NOT_CHANGED : SUCCESS;
  69. }
  70. } // namespace ge