C++ API Reference for Intel® Data Analytics Acceleration Library 2019 Update 4

neural_networks_training_distributed.h
1 /* file: neural_networks_training_distributed.h */
2 /*******************************************************************************
3 * Copyright 2014-2019 Intel Corporation.
4 *
5 * This software and the related documents are Intel copyrighted materials, and
6 * your use of them is governed by the express license under which they were
7 * provided to you (License). Unless the License provides otherwise, you may not
8 * use, modify, copy, publish, distribute, disclose or transmit this software or
9 * the related documents without Intel's prior written permission.
10 *
11 * This software and the related documents are provided as is, with no express
12 * or implied warranties, other than those that are expressly stated in the
13 * License.
14 *******************************************************************************/
15 
16 /*
17 //++
18 // Implementation of the interface for neural network model-based training
19 // in the distributed processing mode
20 //--
21 */
22 
23 #ifndef __NEURAL_NETWORKS_TRAINING_DISTRIBUTED_H__
24 #define __NEURAL_NETWORKS_TRAINING_DISTRIBUTED_H__
25 
26 #include "algorithms/algorithm.h"
27 
28 #include "services/daal_defines.h"
29 #include "algorithms/neural_networks/neural_networks_types.h"
30 #include "algorithms/neural_networks/neural_networks_training_types.h"
31 #include "algorithms/neural_networks/neural_networks_training_model.h"
32 #include "algorithms/neural_networks/layers/layer.h"
33 
34 namespace daal
35 {
36 namespace algorithms
37 {
41 namespace neural_networks
42 {
43 namespace training
44 {
45 namespace interface1
46 {
57 template<ComputeStep step, typename algorithmFPType, Method method, CpuType cpu>
58 class DAAL_EXPORT DistributedContainer
59 {};
60 
65 template<typename algorithmFPType, Method method, CpuType cpu>
66 class DAAL_EXPORT DistributedContainer<step1Local, algorithmFPType, method, cpu> : public TrainingContainerIface<distributed>
67 {
68 public:
74  DistributedContainer(daal::services::Environment::env *daalEnv);
76  ~DistributedContainer();
80  services::Status compute() DAAL_C11_OVERRIDE;
81  services::Status setupCompute() DAAL_C11_OVERRIDE;
82  services::Status resetCompute() DAAL_C11_OVERRIDE;
87  services::Status finalizeCompute() DAAL_C11_OVERRIDE;
88 };
89 
94 template<typename algorithmFPType, Method method, CpuType cpu>
95 class DAAL_EXPORT DistributedContainer<step2Master, algorithmFPType, method, cpu> : public TrainingContainerIface<distributed>
96 {
97 public:
103  DistributedContainer(daal::services::Environment::env *daalEnv);
105  ~DistributedContainer();
109  services::Status compute() DAAL_C11_OVERRIDE;
110  services::Status setupCompute() DAAL_C11_OVERRIDE;
111  services::Status resetCompute() DAAL_C11_OVERRIDE;
116  services::Status finalizeCompute() DAAL_C11_OVERRIDE;
117 };
118 
119 
137 template<ComputeStep step, typename algorithmFPType = DAAL_ALGORITHM_FP_TYPE, Method method = defaultDense>
138 class DAAL_EXPORT Distributed
139 {};
140 
141 
157 template<typename algorithmFPType, Method method>
158 class DAAL_EXPORT Distributed<step1Local, algorithmFPType, method> : public Training<distributed>
159 {
160 public:
161  typedef algorithms::neural_networks::training::DistributedInput<step1Local> InputType;
162  typedef algorithms::neural_networks::training::Parameter ParameterType;
163  typedef algorithms::neural_networks::training::Result ResultType;
164  typedef algorithms::neural_networks::training::PartialResult PartialResultType;
165 
166  DistributedInput<step1Local> input;
167  ParameterType parameter;
170  Distributed()
171  {
172  initialize();
173  };
174 
180  Distributed(const Distributed<step1Local, algorithmFPType, method> &other) : parameter(other.parameter), input(other.input)
181  {
182  initialize();
183  }
184 
185  virtual ~Distributed() {}
186 
193  services::Status setPartialResult(const PartialResultPtr& partialResult)
194  {
195  _partialResult = partialResult;
196  _pres = _partialResult.get();
197  return services::Status();
198  }
199 
204  PartialResultPtr getPartialResult() { return _partialResult; }
205 
210  ResultPtr getResult()
211  {
212  return _result;
213  }
214 
221  services::Status setResult(const ResultPtr& res)
222  {
223  DAAL_CHECK(res, services::ErrorNullResult)
224  _result = res;
225  _res = _result.get();
226  return services::Status();
227  }
228 
234  services::SharedPtr<Distributed<step1Local, algorithmFPType, method> > clone() const
235  {
236  return services::SharedPtr<Distributed<step1Local, algorithmFPType, method> >(cloneImpl());
237  }
238 
243  virtual int getMethod() const DAAL_C11_OVERRIDE { return(int) method; }
244 
245 protected:
246  void initialize()
247  {
248  _ac = new __DAAL_ALGORITHM_CONTAINER(distributed, DistributedContainer, step1Local, algorithmFPType, method)(&_env);
249  _in = &input;
250  _par = &parameter;
251  _partialResult.reset(new PartialResultType());
252  _result.reset(new ResultType());
253  }
254 
255  virtual Distributed<step1Local, algorithmFPType, method> *cloneImpl() const DAAL_C11_OVERRIDE
256  {
257  return new Distributed<step1Local, algorithmFPType, method>(*this);
258  }
259 
260  virtual services::Status allocateResult() DAAL_C11_OVERRIDE
261  {
262  services::Status s = _result->allocate<algorithmFPType>(&input, &parameter, (int) method);
263  _res = _result.get();
264  return s;
265  }
266 
267  services::Status allocatePartialResult() DAAL_C11_OVERRIDE
268  {
269  services::Status s = _partialResult->allocate<algorithmFPType>(&input, &parameter, method);
270  _pres = _partialResult.get();
271  return s;
272  }
273 
274  virtual services::Status initializePartialResult() DAAL_C11_OVERRIDE
275  {
276  _pres = _partialResult.get();
277  return services::Status();
278  }
279 private:
280  PartialResultPtr _partialResult;
281  ResultPtr _result;
282 };
283 
299 template<typename algorithmFPType, Method method>
300 class DAAL_EXPORT Distributed<step2Master, algorithmFPType, method> : public Training<distributed>
301 {
302 public:
303  typedef algorithms::neural_networks::training::DistributedInput<step2Master> InputType;
304  typedef algorithms::neural_networks::training::Parameter ParameterType;
305  typedef algorithms::neural_networks::training::Result ResultType;
306  typedef algorithms::neural_networks::training::DistributedPartialResult PartialResultType;
307 
308  DistributedInput<step2Master> input;
309  ParameterType parameter;
311  Distributed(const services::SharedPtr<optimization_solver::iterative_solver::Batch >& optimizationSolver_) : parameter(optimizationSolver_)
312  {
313  initialize();
314  };
315 
321  Distributed(const Distributed<step2Master, algorithmFPType, method> &other) : parameter(other.parameter), input(other.input)
322  {
323  initialize();
324  }
325 
326  virtual ~Distributed() {}
327 
335  services::Status initialize(const services::Collection<size_t> &dataSize, const training::Topology &topology)
336  {
337  ResultPtr result = getResult();
338  if (!result || !result->get(neural_networks::training::model))
339  {
340  return services::Status(services::ErrorNullModel);
341  }
342  result->get(neural_networks::training::model)->initialize<algorithmFPType>(dataSize, topology, parameter);
343  return services::Status();
344  }
345 
352  services::Status setPartialResult(const DistributedPartialResultPtr& partialResult)
353  {
354  _partialResult = partialResult;
355  _pres = _partialResult.get();
356  return services::Status();
357  }
358 
363  DistributedPartialResultPtr getPartialResult() { return _partialResult; }
364 
369  ResultPtr getResult()
370  {
371  return _partialResult->get(resultFromMaster);
372  }
373 
379  services::SharedPtr<Distributed<step2Master, algorithmFPType, method> > clone() const
380  {
381  return services::SharedPtr<Distributed<step2Master, algorithmFPType, method> >(cloneImpl());
382  }
383 
388  virtual int getMethod() const DAAL_C11_OVERRIDE { return(int) method; }
389 
390 protected:
391  void initialize()
392  {
393  _ac = new __DAAL_ALGORITHM_CONTAINER(distributed, DistributedContainer, step2Master, algorithmFPType, method)(&_env);
394  _in = &input;
395  _par = &parameter;
396  _partialResult = DistributedPartialResultPtr(new PartialResultType());
397  }
398 
399  virtual Distributed<step2Master, algorithmFPType, method> *cloneImpl() const DAAL_C11_OVERRIDE
400  {
401  return new Distributed<step2Master, algorithmFPType, method>(*this);
402  }
403 
404  virtual services::Status allocateResult() DAAL_C11_OVERRIDE
405  {
406  return services::Status();
407  }
408 
409  services::Status allocatePartialResult() DAAL_C11_OVERRIDE
410  {
411  services::Status s = _partialResult->allocate<algorithmFPType>(&input, &parameter, method);
412  _pres = _partialResult.get();
413  return s;
414  }
415 
416  virtual services::Status initializePartialResult() DAAL_C11_OVERRIDE
417  {
418  _pres = _partialResult.get();
419  return services::Status();
420  }
421 private:
422  DistributedPartialResultPtr _partialResult;
423 };
425 } // namespace interface1
426 using interface1::Distributed;
427 using interface1::DistributedContainer;
428 
429 } // namespace training
430 } // namespace neural_networks
431 } // namespace algorithms
432 } // namespace daal
433 #endif
daal::algorithms::neural_networks::training::interface1::Distributed< step1Local, algorithmFPType, method >::parameter
ParameterType parameter
Definition: neural_networks_training_distributed.h:167
daal::algorithms::neural_networks::training::interface1::Distributed< step1Local, algorithmFPType, method >::setResult
services::Status setResult(const ResultPtr &res)
Definition: neural_networks_training_distributed.h:221
daal
Definition: algorithm_base_common.h:31
daal::algorithms::neural_networks::training::interface1::DistributedInput< step2Master >
Input objects of the neural network training algorithm.
Definition: neural_networks_training_input.h:218
daal::algorithms::neural_networks::training::interface1::Distributed< step2Master, algorithmFPType, method >::Distributed
Distributed(const Distributed< step2Master, algorithmFPType, method > &other)
Definition: neural_networks_training_distributed.h:321
daal::algorithms::neural_networks::training::interface1::Distributed< step1Local, algorithmFPType, method >::Distributed
Distributed()
Definition: neural_networks_training_distributed.h:170
daal::algorithms::neural_networks::training::interface1::Distributed< step2Master, algorithmFPType, method >::initialize
services::Status initialize(const services::Collection< size_t > &dataSize, const training::Topology &topology)
Definition: neural_networks_training_distributed.h:335
daal::algorithms::neural_networks::training::interface1::Distributed< step2Master, algorithmFPType, method >::parameter
ParameterType parameter
Definition: neural_networks_training_distributed.h:309
daal::algorithms::neural_networks::training::interface1::Distributed< step1Local, algorithmFPType, method >::Distributed
Distributed(const Distributed< step1Local, algorithmFPType, method > &other)
Definition: neural_networks_training_distributed.h:180
daal::algorithms::neural_networks::training::interface1::Distributed< step1Local, algorithmFPType, method >::getMethod
virtual int getMethod() const DAAL_C11_OVERRIDE
Definition: neural_networks_training_distributed.h:243
daal_defines.h
daal::algorithms::neural_networks::training::interface1::Distributed< step2Master, algorithmFPType, method >::clone
services::SharedPtr< Distributed< step2Master, algorithmFPType, method > > clone() const
Definition: neural_networks_training_distributed.h:379
daal::algorithms::kmeans::init::interface2::Distributed
class DAAL_EXPORT Distributed
Computes initial clusters for the K-Means algorithm in the distributed processing mode...
Definition: kmeans_init_distributed.h:275
daal::distributed
Definition: daal_defines.h:111
daal::algorithms::neural_networks::training::interface1::Distributed< step2Master, algorithmFPType, method >::setPartialResult
services::Status setPartialResult(const DistributedPartialResultPtr &partialResult)
Definition: neural_networks_training_distributed.h:352
daal::algorithms::neural_networks::training::interface1::Distributed< step1Local, algorithmFPType, method >::clone
services::SharedPtr< Distributed< step1Local, algorithmFPType, method > > clone() const
Definition: neural_networks_training_distributed.h:234
daal::algorithms::neural_networks::training::interface1::Distributed< step1Local, algorithmFPType, method >::input
DistributedInput< step1Local > input
Definition: neural_networks_training_distributed.h:166
daal::algorithms::neural_networks::training::interface1::Distributed< step2Master, algorithmFPType, method >
Provides methods for neural network model-based training in the batch processing mode.
Definition: neural_networks_training_distributed.h:300
daal::services::ErrorNullModel
Definition: error_indexes.h:83
daal::algorithms::neural_networks::training::interface1::Distributed
Provides methods for neural network model-based training in the batch processing mode.
Definition: neural_networks_training_distributed.h:138
daal::algorithms::neural_networks::training::interface1::Distributed< step2Master, algorithmFPType, method >::getResult
ResultPtr getResult()
Definition: neural_networks_training_distributed.h:369
daal::algorithms::neural_networks::training::interface1::Distributed< step1Local, algorithmFPType, method >
Provides methods for neural network model-based training in the batch processing mode.
Definition: neural_networks_training_distributed.h:158
daal::algorithms::kmeans::interface1::DistributedContainer
class DAAL_EXPORT DistributedContainer
Provides methods to run implementations of the K-Means algorithm. This class is associated with the d...
Definition: kmeans_distributed.h:55
daal::step1Local
Definition: daal_defines.h:121
daal::algorithms::neural_networks::training::interface1::Distributed< step1Local, algorithmFPType, method >::getResult
ResultPtr getResult()
Definition: neural_networks_training_distributed.h:210
daal::algorithms::neural_networks::training::interface1::Distributed< step1Local, algorithmFPType, method >::getPartialResult
PartialResultPtr getPartialResult()
Definition: neural_networks_training_distributed.h:204
daal::step2Master
Definition: daal_defines.h:122
daal::algorithms::neural_networks::training::interface1::Distributed< step2Master, algorithmFPType, method >::getPartialResult
DistributedPartialResultPtr getPartialResult()
Definition: neural_networks_training_distributed.h:363
daal::algorithms::neural_networks::training::model
Definition: neural_networks_training_result.h:52
daal::algorithms::neural_networks::training::interface1::DistributedInput< step1Local >
Input objects of the neural network training algorithm in the distributed processing mode...
Definition: neural_networks_training_input.h:178
daal::algorithms::neural_networks::training::interface1::Distributed< step2Master, algorithmFPType, method >::getMethod
virtual int getMethod() const DAAL_C11_OVERRIDE
Definition: neural_networks_training_distributed.h:388
daal::services::ErrorNullResult
Definition: error_indexes.h:96
daal::algorithms::neural_networks::training::interface1::Distributed< step1Local, algorithmFPType, method >::setPartialResult
services::Status setPartialResult(const PartialResultPtr &partialResult)
Definition: neural_networks_training_distributed.h:193
daal::algorithms::neural_networks::training::interface1::DistributedContainer
Class containing methods to train neural network model in the distributed processing mode using algor...
Definition: neural_networks_training_distributed.h:58
daal::algorithms::TrainingContainerIface
Abstract interface class that provides virtual methods to access and run implementations of the model...
Definition: training.h:50
daal::algorithms::Training
Provides methods to train models that depend on the data provided. For example, these methods enable ...
Definition: training.h:60
daal::algorithms::neural_networks::training::interface1::Distributed< step2Master, algorithmFPType, method >::input
DistributedInput< step2Master > input
Definition: neural_networks_training_distributed.h:308

For more complete information about compiler optimizations, see our Optimization Notice.