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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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 "backend/optimizer/somas/somas_parameter.h"
  18. #include <memory>
  19. #include <map>
  20. #include <set>
  21. #include <string>
  22. #include <unordered_map>
  23. #include <vector>
  24. namespace mindspore {
  25. namespace somas {
  26. class SomasStream;
  27. class SomasTensor;
  28. enum NodeType { kCommonNode, kCommunicationNode };
  29. using SomasStreamPtr = std::shared_ptr<SomasStream>;
  30. using SomasTensorPtr = std::shared_ptr<SomasTensor>;
  31. class SomasNode {
  32. public:
  33. using SomasNodePtr = std::shared_ptr<SomasNode>;
  34. // Public attributes (mutated in code)
  35. std::string scope_full_name_;
  36. // node's dependency including data dependency and time dependency
  37. std::set<SomasNodePtr> ancestor_nodes_;
  38. std::set<SomasTensorPtr> tensors_;
  39. std::vector<SomasTensorPtr> input_tensors_;
  40. std::vector<SomasTensorPtr> output_tensors_;
  41. std::vector<SomasTensorPtr> workspace_tensors_;
  42. std::map<size_t, SomasParameterPtr> input_parameters_map_;
  43. std::unordered_map<int64_t, size_t> anc_stream_max_order_;
  44. // Constructors/Destructors
  45. SomasNode(size_t id, NodeType type, SomasStreamPtr stream) : id_(id), stream_(stream), type_(type) {}
  46. SomasNode(const SomasNode &) = delete;
  47. SomasNode &operator=(const SomasNode &) = delete;
  48. ~SomasNode() = default;
  49. // Accessors
  50. const size_t &GetId() { return id_; }
  51. SomasStreamPtr GetStream() { return stream_; }
  52. const NodeType &GetType() { return type_; }
  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_