• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
17 #ifndef MINDSPORE_CCSRC_BACKEND_OPTIMIZER_SOMAS_SOMAS_NODE_H_
18 #define MINDSPORE_CCSRC_BACKEND_OPTIMIZER_SOMAS_SOMAS_NODE_H_
19 
20 #include "backend/optimizer/somas/somas_stream.h"
21 #include "backend/optimizer/somas/somas_tensor.h"
22 #include "backend/optimizer/somas/somas_parameter.h"
23 
24 #include <memory>
25 #include <map>
26 #include <set>
27 #include <string>
28 #include <unordered_map>
29 #include <vector>
30 
31 namespace mindspore {
32 namespace somas {
33 class SomasStream;
34 class SomasTensor;
35 
36 enum NodeType { kCommonNode, kCommunicationNode };
37 
38 using SomasStreamPtr = std::shared_ptr<SomasStream>;
39 using SomasTensorPtr = std::shared_ptr<SomasTensor>;
40 
41 class SomasNode {
42  public:
43   using SomasNodePtr = std::shared_ptr<SomasNode>;
44   // Public attributes (mutated in code)
45   std::string scope_full_name_;
46 
47   // node's dependency including data dependency and time dependency
48   std::set<SomasNodePtr> ancestor_nodes_;
49   std::set<SomasTensorPtr> tensors_;
50 
51   std::vector<SomasTensorPtr> input_tensors_;
52   std::vector<SomasTensorPtr> output_tensors_;
53   std::vector<SomasTensorPtr> workspace_tensors_;
54   std::map<size_t, SomasParameterPtr> input_parameters_map_;
55 
56   std::unordered_map<int64_t, size_t> anc_stream_max_order_;
57 
58   // Constructors/Destructors
SomasNode(size_t id,NodeType type,SomasStreamPtr stream)59   SomasNode(size_t id, NodeType type, SomasStreamPtr stream) : id_(id), stream_(stream), type_(type) {}
60   SomasNode(const SomasNode &) = delete;
61   SomasNode &operator=(const SomasNode &) = delete;
62   ~SomasNode() = default;
63 
64   // Accessors
GetId()65   const size_t &GetId() { return id_; }
GetStream()66   SomasStreamPtr GetStream() { return stream_; }
GetType()67   const NodeType &GetType() { return type_; }
68 
69  private:
70   const size_t id_{0};
71   SomasStreamPtr const stream_;
72   const NodeType type_;
73 };
74 }  // namespace somas
75 }  // namespace mindspore
76 
77 #endif  // MINDSPORE_CCSRC_BACKEND_OPTIMIZER_SOMAS_SOMAS_NODE_H_
78