Apache SINGA
A distributed deep learning platform .
 All Classes Namespaces Files Functions Variables Typedefs Macros
driver.h
1 /************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21 
22 #ifndef SINGA_DRIVER_H_
23 #define SINGA_DRIVER_H_
24 
25 #include "singa.h"
26 
27 namespace singa {
28 
29 class Driver {
30  public:
37  void Init(int argc, char** argv);
46  template<typename Subclass, typename Type>
47  int RegisterLayer(const Type& type);
56  template<typename Subclass, typename Type>
57  int RegisterUpdater(const Type& type);
66  template<typename Subclass, typename Type>
67  int RegisterLRGenerator(const Type& type);
76  template<typename Subclass, typename Type>
77  int RegisterWorker(const Type& type);
86  template<typename Subclass, typename Type>
87  int RegisterParam(const Type& type);
96  template<typename Subclass, typename Type>
97  int RegisterParamGenerator(const Type& type);
98 
104  void Submit(bool resume, const JobProto& job);
109  inline int job_id() const { return job_id_; }
114  inline JobProto job_conf() const { return job_conf_; }
115 
116  private:
117  int job_id_;
118  JobProto job_conf_;
119  SingaProto singa_conf_;
120 };
121 
122 template<typename Subclass, typename Type>
123 int Driver::RegisterLayer(const Type& type) {
124  auto factory = Singleton<Factory<singa::Layer>>::Instance();
125  factory->Register(type, CreateInstance(Subclass, Layer));
126  return 1;
127 }
128 
129 template<typename Subclass, typename Type>
130 int Driver::RegisterParam(const Type& type) {
131  auto factory = Singleton<Factory<singa::Param>>::Instance();
132  factory->Register(type, CreateInstance(Subclass, Param));
133  return 1;
134 }
135 
136 template<typename Subclass, typename Type>
137 int Driver::RegisterParamGenerator(const Type& type) {
138  auto factory = Singleton<Factory<singa::ParamGenerator>>::Instance();
139  factory->Register(type, CreateInstance(Subclass, ParamGenerator));
140  return 1;
141 }
142 
143 template<typename Subclass, typename Type>
144 int Driver::RegisterUpdater(const Type& type) {
145  auto factory = Singleton<Factory<singa::Updater>>::Instance();
146  factory->Register(type, CreateInstance(Subclass, Updater));
147  return 1;
148 }
149 
150 template<typename Subclass, typename Type>
151 int Driver::RegisterLRGenerator(const Type& type) {
152  auto factory = Singleton<Factory<singa::LRGenerator>>::Instance();
153  factory->Register(type, CreateInstance(Subclass, LRGenerator));
154  return 1;
155 }
156 
157 template<typename Subclass, typename Type>
158 int Driver::RegisterWorker(const Type& type) {
159  auto factory = Singleton<Factory<singa::Worker>>::Instance();
160  factory->Register(type, CreateInstance(Subclass, Worker));
161  return 1;
162 }
163 
164 } // namespace singa
165 
166 #endif // SINGA_DRIVER_H_
JobProto job_conf() const
Definition: driver.h:114
Definition: driver.h:29
int RegisterLRGenerator(const Type &type)
Register a learning rate generator subclasses.
Definition: driver.h:151
The Worker class which runs the training algorithm.
Definition: worker.h:42
Base learning rate generator.
Definition: updater.h:36
Base paramter class.
Definition: param.h:93
int RegisterParam(const Type &type)
Register a Param subclass.
Definition: driver.h:130
int RegisterParamGenerator(const Type &type)
Register ParamGenerator subclasses for initalizing Param objects.
Definition: driver.h:137
void Init(int argc, char **argv)
Init SINGA, including init glog, parse job id and job conf from cmd line, and register built-in layer...
int RegisterWorker(const Type &type)
Register a Worker subclass.
Definition: driver.h:158
Base parameter generator which intializes parameter values.
Definition: param.h:37
Updater for Param.
Definition: updater.h:88
int job_id() const
Definition: driver.h:109
Base layer class.
Definition: layer.h:44
void Submit(bool resume, const JobProto &job)
Submit the job configuration for starting the job.
int RegisterUpdater(const Type &type)
Register an Updater subclass.
Definition: driver.h:144
Thread-safe implementation for C++11 according to http://stackoverflow.com/questions/2576022/efficien...
Definition: singleton.h:30
int RegisterLayer(const Type &type)
Register a Layer subclass.
Definition: driver.h:123