24 #ifndef MXNET_KVSTORE_H_ 25 #define MXNET_KVSTORE_H_ 28 #include <unordered_map> 33 #if MXNET_USE_DIST_KVSTORE 35 #endif // MXNET_USE_DIST_KVSTORE 82 virtual void Init(
const std::vector<int>& keys,
83 const std::vector<NDArray>& values) = 0;
89 virtual void Init(
const std::vector<std::string>& str_keys,
90 const std::vector<NDArray>& values) = 0;
127 virtual void Push(
const std::vector<int>& keys,
128 const std::vector<NDArray>& values,
129 int priority = 0) = 0;
137 virtual void Push(
const std::vector<std::string>& str_keys,
138 const std::vector<NDArray>& values,
139 int priority = 0) = 0;
163 virtual void Pull(
const std::vector<int>& keys,
164 const std::vector<NDArray*>& values,
165 int priority = 0) = 0;
172 virtual void Pull(
const std::vector<std::string>& str_keys,
173 const std::vector<NDArray*>& values,
174 int priority = 0) = 0;
180 typedef std::function<void(int, const NDArray&, NDArray*)>
Updater;
191 CHECK(updater) <<
"invalid updater";
203 static void InitPSEnv(
const std::unordered_map<std::string, std::string>& envs) {
204 #if MXNET_USE_DIST_KVSTORE 205 ps::Environment::Init(envs);
207 LOG(FATAL) <<
"compile with USE_DIST_KVSTORE=1 to init parameter server's environment";
208 #endif // MXNET_USE_DIST_KVSTORE 217 #if MXNET_USE_DIST_KVSTORE 218 const char* role_str = ps::Environment::Get()->find(
"DMLC_ROLE");
219 return (role_str ==
nullptr) || (!strcmp(role_str,
"worker"));
222 #endif // MXNET_USE_DIST_KVSTORE 231 #if MXNET_USE_DIST_KVSTORE 232 const char* role_str = ps::Environment::Get()->find(
"DMLC_ROLE");
233 return (role_str !=
nullptr) && (!strcmp(role_str,
"server"));
236 #endif // MXNET_USE_DIST_KVSTORE 240 #if MXNET_USE_DIST_KVSTORE 241 if (!
IsWorkerNode()) LOG(FATAL) <<
"barrier_before_exit takes effect only on worker nodes";
244 LOG(FATAL) <<
"compile with USE_DIST_KVSTORE=1 to enable barrier";
254 #if MXNET_USE_DIST_KVSTORE 255 const char* role_str = ps::Environment::Get()->find(
"DMLC_ROLE");
256 return (role_str !=
nullptr) && (!strcmp(role_str,
"scheduler"));
259 #endif // MXNET_USE_DIST_KVSTORE 316 typedef std::function<void(int, const std::string&)>
Controller;
331 virtual void RunServer(
const Controller& controller) { }
351 #endif // MXNET_KVSTORE_H_ distributed key-value store
Definition: kvstore.h:44
std::function< void(int, const NDArray &, NDArray *)> Updater
the prototype of user-defined updater
Definition: kvstore.h:180
namespace of mxnet
Definition: base.h:126
virtual int get_rank() const
Definition: kvstore.h:268
static KVStore * Create(const char *type="local")
Factory function to create a new KVStore.
Updater updater_
the user-defined updater
Definition: kvstore.h:337
const std::string & type()
return the type
Definition: kvstore.h:64
virtual void Pull(const std::vector< int > &keys, const std::vector< NDArray * > &values, int priority=0)=0
pull a list of key-value pairs from the store
static bool IsSchedulerNode()
Definition: kvstore.h:253
virtual void Barrier()
global barrier among all worker machines
Definition: kvstore.h:298
static void InitPSEnv(const std::unordered_map< std::string, std::string > &envs)
initalize ps-lite environment variables
Definition: kvstore.h:203
virtual void Init(const std::vector< int > &keys, const std::vector< NDArray > &values)=0
Initialize a list of key-value pair to the store.
static bool IsWorkerNode()
Definition: kvstore.h:216
virtual ~KVStore()
virtual destructor
Definition: kvstore.h:47
void set_barrier_before_exit(const bool barrier_before_exit)
Definition: kvstore.h:239
virtual int get_num_dead_node(int node_id, int timeout=60) const
Definition: kvstore.h:287
virtual void RunServer(const Controller &controller)
Run as server (or scheduler)
Definition: kvstore.h:331
virtual void Push(const std::vector< int > &keys, const std::vector< NDArray > &values, int priority=0)=0
push a list of key-value pairs into the store
virtual void SendCommandToServers(int cmd_id, const std::string &cmd_body)
Send a command to all server nodes.
Definition: kvstore.h:311
std::string type_
the kvstore type
Definition: kvstore.h:342
std::function< void(int, const std::string &)> Controller
the prototype of a server controller
Definition: kvstore.h:316
virtual void set_updater(const Updater &updater)
set an updater
Definition: kvstore.h:190
virtual int get_group_size() const
Definition: kvstore.h:275
std::atomic< bool > barrier_before_exit_
whether to do barrier when finalize
Definition: kvstore.h:347
static bool IsServerNode()
Definition: kvstore.h:230