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, int priority = 0);
48  static void Push(const std::vector<std::string>& keys,
49  const std::vector<NDArray>& vals, int priority = 0);
50  static void Pull(int key, NDArray* out, int priority = 0);
51  static void Pull(const std::string& key, NDArray* out, int priority = 0);
52  static void Pull(const std::vector<int>& keys,
53  std::vector<NDArray>* outs, int priority = 0);
54  static void Pull(const std::vector<std::string>& keys,
55  std::vector<NDArray>* outs, int priority = 0);
56  // TODO(lx): put lr in optimizer or not?
57  static void SetOptimizer(std::unique_ptr<Optimizer> optimizer, bool local = false);
58  static std::string GetType();
59  static int GetRank();
60  static int GetNumWorkers();
61  static void Barrier();
62  static std::string GetRole();
63 
64  private:
65  KVStore();
66  static KVStoreHandle& get_handle();
67  static std::unique_ptr<Optimizer>& get_optimizer();
68  static KVStore*& get_kvstore();
69  static void Controller(int head, const char* body, void* controller_handle);
70  static void Updater(int key, NDArrayHandle recv, NDArrayHandle local, void* handle_);
71 };
72 
73 } // namespace cpp
74 } // namespace mxnet
75 
76 #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: api_registry.h:33
static void SetOptimizer(std::unique_ptr< Optimizer > optimizer, bool local=false)
NDArray interface.
Definition: ndarray.h:120
static void Push(int key, const NDArray &val, int priority=0)
static int GetNumWorkers()
static std::string GetType()
void * NDArrayHandle
handle to NDArray
Definition: c_api.h:66
static int GetRank()
void * KVStoreHandle
handle to KVStore
Definition: c_api.h:84
static void RunServer()
Definition: kvstore.h:36