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.

somas_node.cc 1.7 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /**
  2. * Copyright 2020 Huawei Technologies Co., Ltd
  3. * Licensed under the Apache License, Version 2.0 (the "License");
  4. * you may not use this file except in compliance with the License.
  5. * You may obtain a copy of the License at
  6. * http://www.apache.org/licenses/LICENSE-2.0
  7. * Unless required by applicable law or agreed to in writing, software
  8. * distributed under the License is distributed on an "AS IS" BASIS,
  9. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. * See the License for the specific language governing permissions and
  11. * limitations under the License.
  12. */
  13. #include "backend/optimizer/somas/somas_node.h"
  14. #include <algorithm>
  15. namespace mindspore {
  16. namespace somas {
  17. void SomasNode::ComputeAncestorNodes() {
  18. // Fast algorithm: assuming nodes execute this function in the received topological order
  19. int64_t thisId = this->GetStream()->GetId();
  20. for (SomasNodePtr node : ancestor_nodes_) {
  21. int64_t ancestorId = node->GetStream()->GetId();
  22. // Map Improvement for max_ancestor_order
  23. if (thisId != ancestorId) {
  24. this->anc_stream_max_order_[ancestorId] = std::max(this->anc_stream_max_order_[ancestorId], node->GetId());
  25. }
  26. for (SomasStreamPtr stream : node->GetStream()->ancestor_streams_) {
  27. this->anc_stream_max_order_[stream->GetId()] =
  28. std::max(this->anc_stream_max_order_[stream->GetId()], node->anc_stream_max_order_[stream->GetId()]);
  29. }
  30. }
  31. }
  32. void SomasNode::PresetAncestorStreams(const std::vector<SomasStreamPtr> stream_vector) {
  33. for (SomasStreamPtr stream : stream_vector) {
  34. anc_stream_max_order_[stream->GetId()] = 0;
  35. }
  36. }
  37. } // namespace somas
  38. } // namespace mindspore