mxnet
|
distributed key-value store More...
#include <kvstore.h>
Public Types | |
typedef std::function< void(int, const NDArray &, NDArray *)> | Updater |
the prototype of user-defined updater More... | |
typedef std::function< void(const std::string &, const NDArray &, NDArray *)> | StrUpdater |
the prototype of user-defined updater with string keys More... | |
typedef std::function< void(int, const std::string &)> | Controller |
the prototype of a server controller More... | |
Public Member Functions | |
virtual | ~KVStore () |
virtual destructor More... | |
const std::string & | type () |
return the type More... | |
virtual void | Init (const std::vector< int > &keys, const std::vector< NDArray > &values)=0 |
Initialize a list of key-value pair to the store. More... | |
virtual void | Init (const std::vector< std::string > &str_keys, const std::vector< NDArray > &values)=0 |
Initialize a list of key-value pair to the store. More... | |
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 More... | |
virtual void | Push (const std::vector< std::string > &str_keys, const std::vector< NDArray > &values, int priority=0)=0 |
push a list of key-value pairs into the store More... | |
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 More... | |
virtual void | Pull (const std::vector< std::string > &str_keys, const std::vector< NDArray * > &values, int priority=0)=0 |
pull a list of key-value pairs from the store More... | |
virtual void | PullRowSparse (const std::vector< int > &str_keys, const std::vector< std::pair< NDArray *, NDArray >> &val_rowids, int priority=0)=0 |
pull a list of key-value pairs from the store. The NDArray pulled back will be in row_sparse storage with only the specified row_ids present (others rows are zeros). More... | |
virtual void | PullRowSparse (const std::vector< std::string > &str_keys, const std::vector< std::pair< NDArray *, NDArray >> &val_rowids, int priority=0)=0 |
pull a list of key-value pairs from the store, where each key is a string. The NDArray pulled back will be in row_sparse storage with only the specified row_ids present (others rows are zeros). More... | |
virtual void | set_updater (const Updater &updater) |
set an updater More... | |
virtual void | set_updater (const StrUpdater &updater) |
set an updater with string keys More... | |
void | set_barrier_before_exit (const bool barrier_before_exit) |
virtual int | get_rank () const |
virtual int | get_group_size () const |
virtual int | get_num_dead_node (int node_id, int timeout=60) const |
virtual void | Barrier () |
global barrier among all worker machines More... | |
virtual void | SendCommandToServers (int cmd_id, const std::string &cmd_body) |
Send a command to all server nodes. More... | |
virtual void | RunServer (const Controller &controller) |
Run as server (or scheduler) More... | |
Static Public Member Functions | |
static KVStore * | Create (const char *type="local") |
Factory function to create a new KVStore. More... | |
static void | InitPSEnv (const std::unordered_map< std::string, std::string > &envs) |
initalize ps-lite environment variables More... | |
static bool | IsWorkerNode () |
static bool | IsServerNode () |
static bool | IsSchedulerNode () |
Protected Attributes | |
Updater | updater_ |
the user-defined updater More... | |
StrUpdater | str_updater_ |
the user-defined updater with string keys More... | |
std::string | type_ |
the kvstore type More... | |
std::atomic< bool > | barrier_before_exit_ {true} |
whether to do barrier when finalize More... | |
distributed key-value store
A distributed key-value store for data synchronization over multiple devices/machines. It support user-defined updater.
typedef std::function<void(int, const std::string&)> mxnet::KVStore::Controller |
the prototype of a server controller
typedef std::function<void(const std::string&, const NDArray&, NDArray*)> mxnet::KVStore::StrUpdater |
the prototype of user-defined updater with string keys
typedef std::function<void(int, const NDArray&, NDArray*)> mxnet::KVStore::Updater |
the prototype of user-defined updater
|
inlinevirtual |
virtual destructor
|
inlinevirtual |
|
static |
Factory function to create a new KVStore.
type | The type of the kvstore,
|
|
inlinevirtual |
|
inlinevirtual |
node_id | can be a node group or a single node |
timeout | a node fails to send heartbeart in {timeout} seconds will be presumed as 'dead' |
Always return 0 when type == "local"
|
inlinevirtual |
Always return 0 when type == "local"
|
pure virtual |
Initialize a list of key-value pair to the store.
One must initialize the key before Push and Pull, and a key should be only initialized once
It returns after data have been initialized successfully.
For multiple workers, all workers must call Init. But only worker 0 (get_rank() == 0)'s values are used for initialization. So others' values can be empty (but not keys). This function blocks until all workers are finished. That means, any worker can push and pull on the keys now.
keys | a list of unique keys |
values | a list of values |
|
pure virtual |
Initialize a list of key-value pair to the store.
keys | a list of unique keys in string format |
values | a list of values |
|
inlinestatic |
initalize ps-lite environment variables
envs | key-value environment variables |
|
inlinestatic |
Always returns false when type == "local"
|
inlinestatic |
Always returns false when type == "local"
|
inlinestatic |
Always returns true when type == "local"
|
pure virtual |
pull a list of key-value pairs from the store
One must call Init() on key before. And value should be pre-allocated
This function returns after adding a pull operator to the engine. Any following operator requiring reading value will be blocked until the actual pull is finished. One can wait the pull is finished by
keys | the list of keys |
values | the list of buffers for the pulled data, they should be preallocated |
priority | Priority of the action. |
|
pure virtual |
pull a list of key-value pairs from the store
keys | the list of keys in string format |
values | the list of buffers for the pulled data, they should be preallocated |
priority | Priority of the action. |
|
pure virtual |
pull a list of key-value pairs from the store. The NDArray pulled back will be in row_sparse storage with only the specified row_ids present (others rows are zeros).
keys | the list of keys |
values | the list of buffers - row_id pairs |
priority | the priority of the action. |
|
pure virtual |
pull a list of key-value pairs from the store, where each key is a string. The NDArray pulled back will be in row_sparse storage with only the specified row_ids present (others rows are zeros).
keys | the list of keys in string format |
values | the list of buffers - row_id pairs |
priority | the priority of the action. |
|
pure virtual |
push a list of key-value pairs into the store
If a key appears mulitple times in keys, then the according values will be aggregated (summed) before pushing.
The (aggregated) values are merged into the store one by one
One can set a user-defined updater by set_updater. The default updater is Assign.
This function returns after adding a push operator to the engine. Any following operator requiring writing value will be blocked until the actual push is finished. One can wait the push is finished by
One must call Init() on every key before. And the value NDArray should be always has the same shape as being inited.
keys | the list of keys |
values | the list of values |
priority | Priority of the action. |
|
pure virtual |
push a list of key-value pairs into the store
keys | the list of keys in string format |
values | the list of values |
priority | Priority of the action. |
|
inlinevirtual |
Run as server (or scheduler)
The behavior of a server:
controller | the user-defined server controller |
|
inlinevirtual |
Send a command to all server nodes.
Send a command to all server nodes, which will make each server node run controller
This function returns after the command has been executed in all server nodes
cmd_id | the head of the command |
cmd_body | the body of the command |
|
inline |
|
inlinevirtual |
set an updater
Given a key, assume x is the received (pushed) value and y is the value stored on the store node. The store updates y by h(x, &y)
. The default h is ASSIGN, namely *y = x
.
updater | user-defined updater, default is assign |
|
inlinevirtual |
set an updater with string keys
Given a string key, assume x is the received (pushed) value and y is the value stored on the store node. The store updates y by h(x, &y)
. The default h is ASSIGN, namely *y = x
.
updater | user-defined string updater, default is assign |
|
inline |
return the type
|
protected |
whether to do barrier when finalize
|
protected |
the user-defined updater with string keys
|
protected |
the kvstore type
|
protected |
the user-defined updater