C++ API Reference for Intel® Data Analytics Acceleration Library 2018 Update 2

neural_networks_training_distributed.h
1 /* file: neural_networks_training_distributed.h */
2 /*******************************************************************************
3 * Copyright 2014-2018 Intel Corporation
4 * All Rights Reserved.
5 *
6 * If this software was obtained under the Intel Simplified Software License,
7 * the following terms apply:
8 *
9 * The source code, information and material ("Material") contained herein is
10 * owned by Intel Corporation or its suppliers or licensors, and title to such
11 * Material remains with Intel Corporation or its suppliers or licensors. The
12 * Material contains proprietary information of Intel or its suppliers and
13 * licensors. The Material is protected by worldwide copyright laws and treaty
14 * provisions. No part of the Material may be used, copied, reproduced,
15 * modified, published, uploaded, posted, transmitted, distributed or disclosed
16 * in any way without Intel's prior express written permission. No license under
17 * any patent, copyright or other intellectual property rights in the Material
18 * is granted to or conferred upon you, either expressly, by implication,
19 * inducement, estoppel or otherwise. Any license under such intellectual
20 * property rights must be express and approved by Intel in writing.
21 *
22 * Unless otherwise agreed by Intel in writing, you may not remove or alter this
23 * notice or any other notice embedded in Materials by Intel or Intel's
24 * suppliers or licensors in any way.
25 *
26 *
27 * If this software was obtained under the Apache License, Version 2.0 (the
28 * "License"), the following terms apply:
29 *
30 * You may not use this file except in compliance with the License. You may
31 * obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
32 *
33 *
34 * Unless required by applicable law or agreed to in writing, software
35 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
36 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
37 *
38 * See the License for the specific language governing permissions and
39 * limitations under the License.
40 *******************************************************************************/
41 
42 /*
43 //++
44 // Implementation of the interface for neural network model-based training
45 // in the distributed processing mode
46 //--
47 */
48 
49 #ifndef __NEURAL_NETWORKS_TRAINING_DISTRIBUTED_H__
50 #define __NEURAL_NETWORKS_TRAINING_DISTRIBUTED_H__
51 
52 #include "algorithms/algorithm.h"
53 
54 #include "services/daal_defines.h"
55 #include "algorithms/neural_networks/neural_networks_types.h"
56 #include "algorithms/neural_networks/neural_networks_training_types.h"
57 #include "algorithms/neural_networks/neural_networks_training_model.h"
58 #include "algorithms/neural_networks/layers/layer.h"
59 
60 namespace daal
61 {
62 namespace algorithms
63 {
67 namespace neural_networks
68 {
69 namespace training
70 {
71 namespace interface1
72 {
83 template<ComputeStep step, typename algorithmFPType, Method method, CpuType cpu>
84 class DAAL_EXPORT DistributedContainer
85 {};
86 
91 template<typename algorithmFPType, Method method, CpuType cpu>
92 class DAAL_EXPORT DistributedContainer<step1Local, algorithmFPType, method, cpu> : public TrainingContainerIface<distributed>
93 {
94 public:
100  DistributedContainer(daal::services::Environment::env *daalEnv);
102  ~DistributedContainer();
106  services::Status compute() DAAL_C11_OVERRIDE;
107  services::Status setupCompute() DAAL_C11_OVERRIDE;
108  services::Status resetCompute() DAAL_C11_OVERRIDE;
113  services::Status finalizeCompute() DAAL_C11_OVERRIDE;
114 };
115 
120 template<typename algorithmFPType, Method method, CpuType cpu>
121 class DAAL_EXPORT DistributedContainer<step2Master, algorithmFPType, method, cpu> : public TrainingContainerIface<distributed>
122 {
123 public:
129  DistributedContainer(daal::services::Environment::env *daalEnv);
131  ~DistributedContainer();
135  services::Status compute() DAAL_C11_OVERRIDE;
136  services::Status setupCompute() DAAL_C11_OVERRIDE;
137  services::Status resetCompute() DAAL_C11_OVERRIDE;
142  services::Status finalizeCompute() DAAL_C11_OVERRIDE;
143 };
144 
145 
163 template<ComputeStep step, typename algorithmFPType = DAAL_ALGORITHM_FP_TYPE, Method method = defaultDense>
164 class DAAL_EXPORT Distributed
165 {};
166 
167 
183 template<typename algorithmFPType, Method method>
184 class DAAL_EXPORT Distributed<step1Local, algorithmFPType, method> : public Training<distributed>
185 {
186 public:
187  typedef algorithms::neural_networks::training::DistributedInput<step1Local> InputType;
188  typedef algorithms::neural_networks::training::Parameter ParameterType;
189  typedef algorithms::neural_networks::training::Result ResultType;
190  typedef algorithms::neural_networks::training::PartialResult PartialResultType;
191 
192  DistributedInput<step1Local> input;
193  ParameterType parameter;
196  Distributed()
197  {
198  initialize();
199  };
200 
206  Distributed(const Distributed<step1Local, algorithmFPType, method> &other) : parameter(other.parameter), input(other.input)
207  {
208  initialize();
209  }
210 
211  virtual ~Distributed() {}
212 
219  services::Status setPartialResult(const PartialResultPtr& partialResult)
220  {
221  _partialResult = partialResult;
222  _pres = _partialResult.get();
223  return services::Status();
224  }
225 
230  PartialResultPtr getPartialResult() { return _partialResult; }
231 
236  ResultPtr getResult()
237  {
238  return _result;
239  }
240 
247  services::Status setResult(const ResultPtr& res)
248  {
249  DAAL_CHECK(res, services::ErrorNullResult)
250  _result = res;
251  _res = _result.get();
252  return services::Status();
253  }
254 
260  services::SharedPtr<Distributed<step1Local, algorithmFPType, method> > clone() const
261  {
262  return services::SharedPtr<Distributed<step1Local, algorithmFPType, method> >(cloneImpl());
263  }
264 
269  virtual int getMethod() const DAAL_C11_OVERRIDE { return(int) method; }
270 
271 protected:
272  void initialize()
273  {
274  _ac = new __DAAL_ALGORITHM_CONTAINER(distributed, DistributedContainer, step1Local, algorithmFPType, method)(&_env);
275  _in = &input;
276  _par = &parameter;
277  _partialResult.reset(new PartialResultType());
278  _result.reset(new ResultType());
279  }
280 
281  virtual Distributed<step1Local, algorithmFPType, method> *cloneImpl() const DAAL_C11_OVERRIDE
282  {
283  return new Distributed<step1Local, algorithmFPType, method>(*this);
284  }
285 
286  virtual services::Status allocateResult() DAAL_C11_OVERRIDE
287  {
288  services::Status s = _result->allocate<algorithmFPType>(&input, &parameter, (int) method);
289  _res = _result.get();
290  return s;
291  }
292 
293  services::Status allocatePartialResult() DAAL_C11_OVERRIDE
294  {
295  services::Status s = _partialResult->allocate<algorithmFPType>(&input, &parameter, method);
296  _pres = _partialResult.get();
297  return s;
298  }
299 
300  virtual services::Status initializePartialResult() DAAL_C11_OVERRIDE
301  {
302  _pres = _partialResult.get();
303  return services::Status();
304  }
305 private:
306  PartialResultPtr _partialResult;
307  ResultPtr _result;
308 };
309 
325 template<typename algorithmFPType, Method method>
326 class DAAL_EXPORT Distributed<step2Master, algorithmFPType, method> : public Training<distributed>
327 {
328 public:
329  typedef algorithms::neural_networks::training::DistributedInput<step2Master> InputType;
330  typedef algorithms::neural_networks::training::Parameter ParameterType;
331  typedef algorithms::neural_networks::training::Result ResultType;
332  typedef algorithms::neural_networks::training::DistributedPartialResult PartialResultType;
333 
334  DistributedInput<step2Master> input;
335  ParameterType parameter;
337  Distributed(const services::SharedPtr<optimization_solver::iterative_solver::Batch >& optimizationSolver_) : parameter(optimizationSolver_)
338  {
339  initialize();
340  };
341 
347  Distributed(const Distributed<step2Master, algorithmFPType, method> &other) : parameter(other.parameter), input(other.input)
348  {
349  initialize();
350  }
351 
352  virtual ~Distributed() {}
353 
361  services::Status initialize(const services::Collection<size_t> &dataSize, const training::Topology &topology)
362  {
363  ResultPtr result = getResult();
364  if (!result || !result->get(neural_networks::training::model))
365  {
366  return services::Status(services::ErrorNullModel);
367  }
368  result->get(neural_networks::training::model)->initialize<algorithmFPType>(dataSize, topology, parameter);
369  return services::Status();
370  }
371 
378  services::Status setPartialResult(const DistributedPartialResultPtr& partialResult)
379  {
380  _partialResult = partialResult;
381  _pres = _partialResult.get();
382  return services::Status();
383  }
384 
389  DistributedPartialResultPtr getPartialResult() { return _partialResult; }
390 
395  ResultPtr getResult()
396  {
397  return _partialResult->get(resultFromMaster);
398  }
399 
405  services::SharedPtr<Distributed<step2Master, algorithmFPType, method> > clone() const
406  {
407  return services::SharedPtr<Distributed<step2Master, algorithmFPType, method> >(cloneImpl());
408  }
409 
414  virtual int getMethod() const DAAL_C11_OVERRIDE { return(int) method; }
415 
416 protected:
417  void initialize()
418  {
419  _ac = new __DAAL_ALGORITHM_CONTAINER(distributed, DistributedContainer, step2Master, algorithmFPType, method)(&_env);
420  _in = &input;
421  _par = &parameter;
422  _partialResult = DistributedPartialResultPtr(new PartialResultType());
423  }
424 
425  virtual Distributed<step2Master, algorithmFPType, method> *cloneImpl() const DAAL_C11_OVERRIDE
426  {
427  return new Distributed<step2Master, algorithmFPType, method>(*this);
428  }
429 
430  virtual services::Status allocateResult() DAAL_C11_OVERRIDE
431  {
432  return services::Status();
433  }
434 
435  services::Status allocatePartialResult() DAAL_C11_OVERRIDE
436  {
437  services::Status s = _partialResult->allocate<algorithmFPType>(&input, &parameter, method);
438  _pres = _partialResult.get();
439  return s;
440  }
441 
442  virtual services::Status initializePartialResult() DAAL_C11_OVERRIDE
443  {
444  _pres = _partialResult.get();
445  return services::Status();
446  }
447 private:
448  DistributedPartialResultPtr _partialResult;
449 };
451 } // namespace interface1
452 using interface1::Distributed;
453 using interface1::DistributedContainer;
454 
455 } // namespace training
456 } // namespace neural_networks
457 } // namespace algorithms
458 } // namespace daal
459 #endif
daal::algorithms::neural_networks::training::interface1::Distributed< step1Local, algorithmFPType, method >::parameter
ParameterType parameter
Definition: neural_networks_training_distributed.h:193
daal::algorithms::neural_networks::training::interface1::Topology
Class defining a neural network topology - a set of layers and connection between them - on the train...
Definition: neural_networks_training_topology.h:66
daal::algorithms::neural_networks::training::interface1::Distributed< step1Local, algorithmFPType, method >::setResult
services::Status setResult(const ResultPtr &res)
Definition: neural_networks_training_distributed.h:247
daal::services::interface1::Environment::_envStruct
The environment structure.
Definition: env_detect.h:95
daal::services::interface1::Status
Class that holds the results of API calls. In case of API routine failure it contains the list of err...
Definition: error_handling.h:491
daal
Definition: algorithm_base_common.h:57
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:260
daal::algorithms::neural_networks::training::interface1::DistributedInput< step2Master >
Input objects of the neural network training algorithm.
Definition: neural_networks_training_input.h:244
daal::algorithms::neural_networks::training::interface1::Distributed< step2Master, algorithmFPType, method >::Distributed
Distributed(const Distributed< step2Master, algorithmFPType, method > &other)
Definition: neural_networks_training_distributed.h:347
daal::algorithms::neural_networks::training::interface1::Distributed< step1Local, algorithmFPType, method >::Distributed
Distributed()
Definition: neural_networks_training_distributed.h:196
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:361
daal::algorithms::neural_networks::training::interface1::Distributed< step2Master, algorithmFPType, method >::parameter
ParameterType parameter
Definition: neural_networks_training_distributed.h:335
daal::algorithms::neural_networks::training::interface1::Distributed< step1Local, algorithmFPType, method >::Distributed
Distributed(const Distributed< step1Local, algorithmFPType, method > &other)
Definition: neural_networks_training_distributed.h:206
daal::algorithms::neural_networks::training::interface1::Distributed< step1Local, algorithmFPType, method >::getMethod
virtual int getMethod() const DAAL_C11_OVERRIDE
Definition: neural_networks_training_distributed.h:269
daal::algorithms::neural_networks::training::interface1::DistributedInput
Input objects of the neural network training algorithm in the distributed processing mode...
Definition: neural_networks_training_input.h:196
daal_defines.h
daal::algorithms::kmeans::init::interface1::Distributed
class DAAL_EXPORT Distributed
Computes initial clusters for the K-Means algorithm in the distributed processing mode...
Definition: kmeans_init_distributed.h:281
daal::distributed
Definition: daal_defines.h:133
daal::algorithms::neural_networks::training::interface1::DistributedPartialResult
Provides methods to access partial result obtained with the compute() method of the neural network tr...
Definition: neural_networks_training_partial_result.h:165
daal::services::interface1::SharedPtr
Shared pointer that retains shared ownership of an object through a pointer. Several SharedPtr object...
Definition: daal_shared_ptr.h:187
daal::algorithms::neural_networks::training::interface1::Parameter
Class representing the parameters of neural network.
Definition: neural_networks_training_model.h:85
daal::services::interface1::SharedPtr::get
T * get() const
Definition: daal_shared_ptr.h:332
daal::algorithms::neural_networks::training::interface1::Result
Provides methods to access result obtained with the compute() method of the neural network training a...
Definition: neural_networks_training_result.h:91
daal::algorithms::neural_networks::training::interface1::Distributed< step2Master, algorithmFPType, method >::setPartialResult
services::Status setPartialResult(const DistributedPartialResultPtr &partialResult)
Definition: neural_networks_training_distributed.h:378
daal::algorithms::neural_networks::training::interface1::Distributed< step1Local, algorithmFPType, method >::input
DistributedInput< step1Local > input
Definition: neural_networks_training_distributed.h:192
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:326
daal::services::ErrorNullModel
Definition: error_indexes.h:109
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:164
daal::algorithms::neural_networks::training::interface1::Distributed< step2Master, algorithmFPType, method >::getResult
ResultPtr getResult()
Definition: neural_networks_training_distributed.h:395
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:184
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:81
daal::step1Local
Definition: daal_defines.h:143
daal::algorithms::neural_networks::training::interface1::PartialResult
Provides methods to access partial result obtained with the compute() method of the neural network tr...
Definition: neural_networks_training_partial_result.h:107
daal::algorithms::neural_networks::training::interface1::Distributed< step1Local, algorithmFPType, method >::getResult
ResultPtr getResult()
Definition: neural_networks_training_distributed.h:236
daal::algorithms::neural_networks::training::interface1::Distributed< step1Local, algorithmFPType, method >::getPartialResult
PartialResultPtr getPartialResult()
Definition: neural_networks_training_distributed.h:230
daal::step2Master
Definition: daal_defines.h:144
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:405
daal::algorithms::neural_networks::training::interface1::Distributed< step2Master, algorithmFPType, method >::getPartialResult
DistributedPartialResultPtr getPartialResult()
Definition: neural_networks_training_distributed.h:389
daal::algorithms::neural_networks::training::model
Definition: neural_networks_training_result.h:78
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:204
daal::algorithms::neural_networks::training::interface1::Distributed< step2Master, algorithmFPType, method >::getMethod
virtual int getMethod() const DAAL_C11_OVERRIDE
Definition: neural_networks_training_distributed.h:414
daal::services::ErrorNullResult
Definition: error_indexes.h:122
daal::algorithms::neural_networks::training::interface1::Distributed< step1Local, algorithmFPType, method >::setPartialResult
services::Status setPartialResult(const PartialResultPtr &partialResult)
Definition: neural_networks_training_distributed.h:219
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:84
daal::algorithms::TrainingContainerIface
Abstract interface class that provides virtual methods to access and run implementations of the model...
Definition: training.h:76
daal::algorithms::Training
Provides methods to train models that depend on the data provided. For example, these methods enable ...
Definition: training.h:86
daal::services::interface1::Collection
Class that implements functionality of the Collection container.
Definition: collection.h:69
daal::algorithms::neural_networks::training::interface1::Distributed< step2Master, algorithmFPType, method >::input
DistributedInput< step2Master > input
Definition: neural_networks_training_distributed.h:334

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