Apache SINGA
A distributed deep learning platform .
 All Classes Namespaces Files Functions Variables Typedefs Enumerator Macros
cluster.h
1 #ifndef INCLUDE_UTILS_CLUSTER_H_
2 #define INCLUDE_UTILS_CLUSTER_H_
3 #include <glog/logging.h>
4 #include <string>
5 #include <utility>
6 #include <memory>
7 #include <vector>
8 #include "proto/cluster.pb.h"
9 #include "utils/cluster_rt.h"
10 
11 using std::shared_ptr;
12 using std::string;
13 using std::vector;
14 
15 namespace singa {
16 
22 class Cluster {
23  public:
24  static shared_ptr<Cluster> Get();
25  static shared_ptr<Cluster> Get(const ClusterProto& cluster, int procs_id);
26 
27  const int nserver_groups()const{ return cluster_.nserver_groups(); }
28  const int nworker_groups()const { return cluster_.nworker_groups(); }
29  int nworkers_per_group()const {return cluster_.nworkers_per_group();}
30  int nservers_per_group()const {return cluster_.nservers_per_group();}
31  int nworkers_per_procs()const{return cluster_.nworkers_per_procs();}
32  int nservers_per_procs()const{return cluster_.nservers_per_procs();}
33  int nworker_groups_per_server_group() const {
34  return cluster_.nworker_groups()/cluster_.nserver_groups();
35  }
36 
40  bool has_server()const {
41  if(server_worker_separate()){
42  CHECK_LT(procs_id_, nprocs());
43  return procs_id_>=nworker_procs();
44  }else
45  return procs_id_<nserver_procs();
46  }
50  bool has_worker()const {
51  if(server_worker_separate()){
52  return procs_id_<nworker_procs();
53  }else
54  return procs_id_<nprocs();
55  }
59  int procs_id()const {return procs_id_;}
60  bool server_worker_separate() const {
61  return cluster_.server_worker_separate();
62  }
63  int nworker_procs() const {
64  return nworker_groups()*nworkers_per_group()/nworkers_per_procs();
65  }
66  int nserver_procs() const {
67  return nserver_groups()*nservers_per_group()/nservers_per_procs();
68  }
69  int nprocs() const {
70  return cluster_.nprocs();
71  }
72 
73  const string endpoint() const {
74  return endpoint(procs_id());
75  }
79  const string endpoint(int procs_id) const {
80  CHECK_LT(procs_id, nprocs());
81  CHECK_GE(procs_id, 0);
82  return endpoints_.at(procs_id);
83  }
84  const string workspace() {return cluster_.workspace();}
85  const string vis_folder(){
86  return cluster_.workspace()+"/visualization";
87  }
88  const string log_folder(){
89  if(cluster_.has_log_dir()){
90  return cluster_.workspace()+"log";
91  }else
92  return "";
93  }
94 
95  const int stub_timeout() const {
96  return cluster_.stub_timeout();
97  }
98  const int worker_timeout() const {
99  return cluster_.worker_timeout();
100  }
101  const int server_timeout() const {
102  return cluster_.server_timeout();
103  }
104 
112  shared_ptr<ClusterRuntime> runtime() const {
113  return cluster_rt_;
114  }
115 
116  private:
117  Cluster(const ClusterProto &cluster, int procs_id) ;
118  void SetupFolders(const ClusterProto &cluster);
119 
120  private:
121  int procs_id_;
122  std::vector<std::string> endpoints_;
123  // cluster config proto
124  ClusterProto cluster_;
125  shared_ptr<ClusterRuntime> cluster_rt_;
126  // make this class a singlton
127  static shared_ptr<Cluster> instance_;
128 };
129 
130 } // namespace singa
131 
132 #endif // INCLUDE_UTILS_CLUSTER_H_
bool has_worker() const
Definition: cluster.h:50
Definition: cluster.pb.h:41
shared_ptr< ClusterRuntime > runtime() const
bandwidth MB/s float bandwidth() const { return cluster_.bandwidth(); }
Definition: cluster.h:112
int procs_id() const
Definition: cluster.h:59
Cluster is a singleton object, which provides cluster configuations, e.g., the topology of the cluste...
Definition: cluster.h:22
const string endpoint(int procs_id) const
Definition: cluster.h:79
bool has_server() const
Definition: cluster.h:40