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

neural_networks_training_distributed.h
1 /* file: neural_networks_training_distributed.h */
2 /*******************************************************************************
3 * Copyright 2014-2017 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  DistributedInput<step1Local> input;
188  Parameter parameter;
191  Distributed()
192  {
193  initialize();
194  };
195 
201  Distributed(const Distributed<step1Local, algorithmFPType, method> &other) : parameter(other.parameter), input(other.input)
202  {
203  initialize();
204  }
205 
206  virtual ~Distributed() {}
207 
214  services::Status setPartialResult(const PartialResultPtr& partialResult)
215  {
216  _partialResult = partialResult;
217  _pres = _partialResult.get();
218  return services::Status();
219  }
220 
225  PartialResultPtr getPartialResult() { return _partialResult; }
226 
231  ResultPtr getResult()
232  {
233  return _result;
234  }
235 
242  services::Status setResult(const ResultPtr& res)
243  {
244  DAAL_CHECK(res, services::ErrorNullResult)
245  _result = res;
246  _res = _result.get();
247  return services::Status();
248  }
249 
255  services::SharedPtr<Distributed<step1Local, algorithmFPType, method> > clone() const
256  {
257  return services::SharedPtr<Distributed<step1Local, algorithmFPType, method> >(cloneImpl());
258  }
259 
264  virtual int getMethod() const DAAL_C11_OVERRIDE { return(int) method; }
265 
266 protected:
267  void initialize()
268  {
269  _ac = new __DAAL_ALGORITHM_CONTAINER(distributed, DistributedContainer, step1Local, algorithmFPType, method)(&_env);
270  _in = &input;
271  _par = &parameter;
272  _partialResult.reset(new PartialResult());
273  _result.reset(new Result());
274  }
275 
276  virtual Distributed<step1Local, algorithmFPType, method> *cloneImpl() const DAAL_C11_OVERRIDE
277  {
278  return new Distributed<step1Local, algorithmFPType, method>(*this);
279  }
280 
281  virtual services::Status allocateResult() DAAL_C11_OVERRIDE
282  {
283  services::Status s = _result->allocate<algorithmFPType>(&input, &parameter, (int) method);
284  _res = _result.get();
285  return s;
286  }
287 
288  services::Status allocatePartialResult() DAAL_C11_OVERRIDE
289  {
290  services::Status s = _partialResult->allocate<algorithmFPType>(&input, &parameter, method);
291  _pres = _partialResult.get();
292  return s;
293  }
294 
295  virtual services::Status initializePartialResult() DAAL_C11_OVERRIDE
296  {
297  _pres = _partialResult.get();
298  return services::Status();
299  }
300 private:
301  PartialResultPtr _partialResult;
302  ResultPtr _result;
303 };
304 
320 template<typename algorithmFPType, Method method>
321 class DAAL_EXPORT Distributed<step2Master, algorithmFPType, method> : public Training<distributed>
322 {
323 public:
324  DistributedInput<step2Master> input;
325  Parameter parameter;
327  Distributed(const services::SharedPtr<optimization_solver::iterative_solver::Batch >& optimizationSolver_) : parameter(optimizationSolver_)
328  {
329  initialize();
330  };
331 
337  Distributed(const Distributed<step2Master, algorithmFPType, method> &other) : parameter(other.parameter), input(other.input)
338  {
339  initialize();
340  }
341 
342  virtual ~Distributed() {}
343 
351  services::Status initialize(const services::Collection<size_t> &dataSize, const training::Topology &topology)
352  {
353  ResultPtr result = getResult();
354  if (!result || !result->get(neural_networks::training::model))
355  {
356  return services::Status(services::ErrorNullModel);
357  }
358  result->get(neural_networks::training::model)->initialize<algorithmFPType>(dataSize, topology, parameter);
359  return services::Status();
360  }
361 
368  services::Status setPartialResult(const DistributedPartialResultPtr& partialResult)
369  {
370  _partialResult = partialResult;
371  _pres = _partialResult.get();
372  return services::Status();
373  }
374 
379  DistributedPartialResultPtr getPartialResult() { return _partialResult; }
380 
385  ResultPtr getResult()
386  {
387  return _partialResult->get(resultFromMaster);
388  }
389 
395  services::SharedPtr<Distributed<step2Master, algorithmFPType, method> > clone() const
396  {
397  return services::SharedPtr<Distributed<step2Master, algorithmFPType, method> >(cloneImpl());
398  }
399 
404  virtual int getMethod() const DAAL_C11_OVERRIDE { return(int) method; }
405 
406 protected:
407  void initialize()
408  {
409  _ac = new __DAAL_ALGORITHM_CONTAINER(distributed, DistributedContainer, step2Master, algorithmFPType, method)(&_env);
410  _in = &input;
411  _par = &parameter;
412  _partialResult = DistributedPartialResultPtr(new DistributedPartialResult());
413  }
414 
415  virtual Distributed<step2Master, algorithmFPType, method> *cloneImpl() const DAAL_C11_OVERRIDE
416  {
417  return new Distributed<step2Master, algorithmFPType, method>(*this);
418  }
419 
420  virtual services::Status allocateResult() DAAL_C11_OVERRIDE
421  {
422  return services::Status();
423  }
424 
425  services::Status allocatePartialResult() DAAL_C11_OVERRIDE
426  {
427  services::Status s = _partialResult->allocate<algorithmFPType>(&input, &parameter, method);
428  _pres = _partialResult.get();
429  return s;
430  }
431 
432  virtual services::Status initializePartialResult() DAAL_C11_OVERRIDE
433  {
434  _pres = _partialResult.get();
435  return services::Status();
436  }
437 private:
438  DistributedPartialResultPtr _partialResult;
439 };
441 } // namespace interface1
442 using interface1::Distributed;
443 using interface1::DistributedContainer;
444 
445 } // namespace training
446 } // namespace neural_networks
447 } // namespace algorithms
448 } // namespace daal
449 #endif
daal::algorithms::neural_networks::training::interface1::Distributed< step1Local, algorithmFPType, method >::parameter
Parameter parameter
Definition: neural_networks_training_distributed.h:188
daal::algorithms::neural_networks::training::interface1::Distributed< step1Local, algorithmFPType, method >::setResult
services::Status setResult(const ResultPtr &res)
Definition: neural_networks_training_distributed.h:242
daal
Definition: algorithm_base_common.h:57
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:337
daal::algorithms::neural_networks::training::interface1::Distributed< step1Local, algorithmFPType, method >::Distributed
Distributed()
Definition: neural_networks_training_distributed.h:191
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:351
daal::algorithms::neural_networks::training::interface1::Distributed< step1Local, algorithmFPType, method >::Distributed
Distributed(const Distributed< step1Local, algorithmFPType, method > &other)
Definition: neural_networks_training_distributed.h:201
daal::algorithms::neural_networks::training::interface1::Distributed< step1Local, algorithmFPType, method >::getMethod
virtual int getMethod() const DAAL_C11_OVERRIDE
Definition: neural_networks_training_distributed.h:264
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:395
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:132
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::algorithms::neural_networks::training::interface1::Parameter
Class representing the parameters of neural network.
Definition: neural_networks_training_model.h:85
daal::algorithms::neural_networks::training::interface1::Distributed< step2Master, algorithmFPType, method >::parameter
Parameter parameter
Definition: neural_networks_training_distributed.h:325
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:368
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:255
daal::algorithms::neural_networks::training::interface1::Distributed< step1Local, algorithmFPType, method >::input
DistributedInput< step1Local > input
Definition: neural_networks_training_distributed.h:187
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:321
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:385
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:142
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:231
daal::algorithms::neural_networks::training::interface1::Distributed< step1Local, algorithmFPType, method >::getPartialResult
PartialResultPtr getPartialResult()
Definition: neural_networks_training_distributed.h:225
daal::step2Master
Definition: daal_defines.h:143
daal::algorithms::neural_networks::training::interface1::Distributed< step2Master, algorithmFPType, method >::getPartialResult
DistributedPartialResultPtr getPartialResult()
Definition: neural_networks_training_distributed.h:379
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:404
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:214
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::algorithms::neural_networks::training::interface1::Distributed< step2Master, algorithmFPType, method >::input
DistributedInput< step2Master > input
Definition: neural_networks_training_distributed.h:324

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