mxnet
kvstore.h
Go to the documentation of this file.
1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements. See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership. The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the
7  * "License"); you may not use this file except in compliance
8  * with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15  * KIND, either express or implied. See the License for the
16  * specific language governing permissions and limitations
17  * under the License.
18  */
19 
26 #ifndef MXNET_CPP_KVSTORE_H_
27 #define MXNET_CPP_KVSTORE_H_
28 
29 #include <string>
30 #include <vector>
31 #include "mxnet-cpp/ndarray.h"
32 
33 namespace mxnet {
34 namespace cpp {
35 
36 class KVStore {
37  public:
38  static void SetType(const std::string& type);
39  static void RunServer();
40  static void Init(int key, const NDArray& val);
41  static void Init(const std::string& key, const NDArray& val);
42  static void Init(const std::vector<int>& keys, const std::vector<NDArray>& vals);
43  static void Init(const std::vector<std::string>& keys, const std::vector<NDArray>& vals);
44  static void Push(int key, const NDArray& val, int priority = 0);
45  static void Push(const std::string& key, const NDArray& val, int priority = 0);
46  static void Push(const std::vector<int>& keys,
47  const std::vector<NDArray>& vals,
48  int priority = 0);
49  static void Push(const std::vector<std::string>& keys,
50  const std::vector<NDArray>& vals,
51  int priority = 0);
52  static void Pull(int key, NDArray* out, int priority = 0);
53  static void Pull(const std::string& key, NDArray* out, int priority = 0);
54  static void Pull(const std::vector<int>& keys, std::vector<NDArray>* outs, int priority = 0);
55  static void Pull(const std::vector<std::string>& keys,
56  std::vector<NDArray>* outs,
57  int priority = 0);
58  // TODO(lx): put lr in optimizer or not?
59  static void SetOptimizer(std::unique_ptr<Optimizer> optimizer, bool local = false);
60  static std::string GetType();
61  static int GetRank();
62  static int GetNumWorkers();
63  static void Barrier();
64  static std::string GetRole();
65 
66  private:
67  KVStore();
68  static KVStoreHandle& get_handle();
69  static std::unique_ptr<Optimizer>& get_optimizer();
70  static KVStore*& get_kvstore();
71  static void Controller(int head, const char* body, void* controller_handle);
72  static void Updater(int key, NDArrayHandle recv, NDArrayHandle local, void* handle_);
73 };
74 
75 } // namespace cpp
76 } // namespace mxnet
77 
78 #endif // MXNET_CPP_KVSTORE_H_
mxnet
namespace of mxnet
Definition: api_registry.h:33
mxnet::cpp::KVStore::Barrier
static void Barrier()
mxnet::cpp::KVStore::GetRole
static std::string GetRole()
mxnet::cpp::NDArray
NDArray interface.
Definition: ndarray.h:122
mxnet::cpp::KVStore::Push
static void Push(int key, const NDArray &val, int priority=0)
ndarray.h
definition of ndarray
mxnet::cpp::KVStore::SetOptimizer
static void SetOptimizer(std::unique_ptr< Optimizer > optimizer, bool local=false)
mxnet::cpp::KVStore::Init
static void Init(int key, const NDArray &val)
KVStoreHandle
void * KVStoreHandle
handle to KVStore
Definition: c_api.h:100
mxnet::cpp::KVStore::SetType
static void SetType(const std::string &type)
mxnet::cpp::KVStore::RunServer
static void RunServer()
mxnet::cpp::KVStore::GetType
static std::string GetType()
mxnet::NDArrayHandle
Definition: ndarray_handle.h:40
mxnet::cpp::KVStore::GetNumWorkers
static int GetNumWorkers()
mxnet::cpp::KVStore::GetRank
static int GetRank()
mxnet::cpp::KVStore
Definition: kvstore.h:36
mxnet::cpp::KVStore::Pull
static void Pull(int key, NDArray *out, int priority=0)