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 
27 #ifndef MXNET_CPP_KVSTORE_H_
28 #define MXNET_CPP_KVSTORE_H_
29 
30 #include <string>
31 #include <vector>
32 #include "mxnet-cpp/ndarray.h"
33 
34 namespace mxnet {
35 namespace cpp {
36 
37 class KVStore {
38  public:
39  static void SetType(const std::string& type);
40  static void RunServer();
41  static void Init(int key, const NDArray& val);
42  static void Init(const std::string& key, const NDArray& val);
43  static void Init(const std::vector<int>& keys, const std::vector<NDArray>& vals);
44  static void Init(const std::vector<std::string>& keys, const std::vector<NDArray>& vals);
45  static void Push(int key, const NDArray& val, int priority = 0);
46  static void Push(const std::string& key, const NDArray& val, int priority = 0);
47  static void Push(const std::vector<int>& keys,
48  const std::vector<NDArray>& vals, int priority = 0);
49  static void Push(const std::vector<std::string>& keys,
50  const std::vector<NDArray>& vals, int priority = 0);
51  static void Pull(int key, NDArray* out, int priority = 0);
52  static void Pull(const std::string& key, NDArray* out, int priority = 0);
53  static void Pull(const std::vector<int>& keys,
54  std::vector<NDArray>* outs, int priority = 0);
55  static void Pull(const std::vector<std::string>& keys,
56  std::vector<NDArray>* outs, int priority = 0);
57  // TODO(lx): put lr in optimizer or not?
58  static void SetOptimizer(std::unique_ptr<Optimizer> optimizer, bool local = false);
59  static std::string GetType();
60  static int GetRank();
61  static int GetNumWorkers();
62  static void Barrier();
63  static std::string GetRole();
64 
65  private:
66  KVStore();
67  static KVStoreHandle& get_handle();
68  static std::unique_ptr<Optimizer>& get_optimizer();
69  static KVStore*& get_kvstore();
70  static void Controller(int head, const char* body, void* controller_handle);
71  static void Updater(int key, NDArrayHandle recv, NDArrayHandle local, void* handle_);
72 };
73 
74 } // namespace cpp
75 } // namespace mxnet
76 
77 #endif // MXNET_CPP_KVSTORE_H_
static std::string GetRole()
static void Pull(int key, NDArray *out, int priority=0)
static void Init(int key, const NDArray &val)
static void Barrier()
static void SetType(const std::string &type)
namespace of mxnet
Definition: base.h:89
static void SetOptimizer(std::unique_ptr< Optimizer > optimizer, bool local=false)
NDArray interface.
Definition: ndarray.h:121
static void Push(int key, const NDArray &val, int priority=0)
void * KVStoreHandle
handle to KVStore
Definition: c_api.h:85
void * NDArrayHandle
handle to NDArray
Definition: c_api.h:67
static int GetNumWorkers()
static std::string GetType()
static int GetRank()
static void RunServer()
Definition: kvstore.h:37