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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. #ifndef MINDSPORE_CCSRC_BACKEND_OPTIMIZER_SOMAS_SOMAS_NODE_H_
  14. #define MINDSPORE_CCSRC_BACKEND_OPTIMIZER_SOMAS_SOMAS_NODE_H_
  15. #include "backend/optimizer/somas/somas_stream.h"
  16. #include "backend/optimizer/somas/somas_tensor.h"
  17. #include <memory>
  18. #include <set>
  19. #include <string>
  20. #include <unordered_map>
  21. #include <vector>
  22. namespace mindspore {
  23. namespace somas {
  24. class SomasStream;
  25. class SomasTensor;
  26. enum NodeType { kCommonNode, kCommunicationNode };
  27. using SomasStreamPtr = std::shared_ptr<SomasStream>;
  28. using SomasTensorPtr = std::shared_ptr<SomasTensor>;
  29. class SomasNode {
  30. public:
  31. using SomasNodePtr = std::shared_ptr<SomasNode>;
  32. // Public attributes (mutated in code)
  33. std::string scope_full_name_;
  34. std::set<SomasNodePtr>
  35. ancestor_nodes_; // keeping only distance *one* ancestor nodes; enough to ComputeAncestorNodes()
  36. std::set<SomasTensorPtr> tensors_;
  37. std::vector<SomasTensorPtr> input_tensors_;
  38. std::vector<SomasTensorPtr> output_tensors_;
  39. std::vector<SomasTensorPtr> workspace_tensors_;
  40. std::unordered_map<int64_t, size_t> anc_stream_max_order_;
  41. // Constructors/Destructors
  42. SomasNode(size_t id, NodeType type, SomasStreamPtr stream) : id_(id), stream_(stream), type_(type) {}
  43. SomasNode(const SomasNode &) = delete;
  44. SomasNode &operator=(const SomasNode &) = delete;
  45. ~SomasNode() = default;
  46. // Accessors
  47. const size_t &GetId() { return id_; }
  48. SomasStreamPtr GetStream() { return stream_; }
  49. const NodeType &GetType() { return type_; }
  50. // Computing ancestors
  51. void PresetAncestorStreams(const std::vector<SomasStreamPtr> stream_vector);
  52. void ComputeAncestorNodes();
  53. private:
  54. const size_t id_{0};
  55. SomasStreamPtr const stream_;
  56. const NodeType type_;
  57. };
  58. } // namespace somas
  59. } // namespace mindspore
  60. #endif // MINDSPORE_CCSRC_BACKEND_OPTIMIZER_SOMAS_SOMAS_NODE_H_