runtime_graph.h 2.3 KB
Newer Older
L
LiYuRio 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
// Copyright (c) 2021 PaddlePaddle Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#pragma once
16
#include <memory>
17
#include <string>
18 19 20 21 22
#include <unordered_map>
#include <vector>
#include "paddle/fluid/distributed/fleet_executor/fleet_executor_desc.pb.h"
#include "paddle/fluid/framework/op_proto_maker.h"
#include "paddle/fluid/platform/macros.h"
L
LiYuRio 已提交
23 24 25

namespace paddle {
namespace distributed {
26
class TaskNode;
L
LiYuRio 已提交
27 28 29 30 31

class RuntimeGraph final {
 public:
  RuntimeGraph() = default;
  ~RuntimeGraph() = default;
32 33
  const std::unordered_map<int64_t, TaskNode*>& interceptor_id_to_node() const {
    return interceptor_id_to_node_;
34
  }
35 36
  const std::unordered_map<int64_t, int64_t>& interceptor_id_to_rank() const {
    return interceptor_id_to_rank_;
37
  }
38 39 40 41
  const std::unordered_map<int64_t, std::unordered_set<int64_t>>&
  carrier_id_to_interceptor_ids() const {
    return carrier_id_to_interceptor_ids_;
  }
42
  void SetInterceptorIdToRank(
43 44
      const std::unordered_map<int64_t, int64_t>& interceptor_id_to_rank) {
    interceptor_id_to_rank_ = interceptor_id_to_rank;
45 46
  }
  void SetInterceptorIdToNode(
47 48
      const std::unordered_map<int64_t, TaskNode*>& interceptor_id_to_node) {
    interceptor_id_to_node_ = interceptor_id_to_node;
49
  }
50 51 52 53 54
  void SetCarrierIdToInterceptorIds(
      const std::unordered_map<int64_t, std::unordered_set<int64_t>>&
          carrier_id_to_interceptor_ids) {
    carrier_id_to_interceptor_ids_ = carrier_id_to_interceptor_ids;
  }
55
  std::string DebugString() const;
L
LiYuRio 已提交
56

57
 private:
L
LiYuRio 已提交
58
  DISABLE_COPY_AND_ASSIGN(RuntimeGraph);
59 60
  std::unordered_map<int64_t, TaskNode*> interceptor_id_to_node_;
  std::unordered_map<int64_t, int64_t> interceptor_id_to_rank_;
61 62
  std::unordered_map<int64_t, std::unordered_set<int64_t>>
      carrier_id_to_interceptor_ids_;
L
LiYuRio 已提交
63 64 65 66
};

}  // namespace distributed
}  // namespace paddle