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

neural_networks_training_distributed.h
1 /* file: neural_networks_training_distributed.h */
2 /*******************************************************************************
3 * Copyright 2014-2020 Intel Corporation
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *******************************************************************************/
17 
18 /*
19 //++
20 // Implementation of the interface for neural network model-based training
21 // in the distributed processing mode
22 //--
23 */
24 
25 #ifndef __NEURAL_NETWORKS_TRAINING_DISTRIBUTED_H__
26 #define __NEURAL_NETWORKS_TRAINING_DISTRIBUTED_H__
27 
28 #include "algorithms/algorithm.h"
29 
30 #include "services/daal_defines.h"
31 #include "algorithms/neural_networks/neural_networks_types.h"
32 #include "algorithms/neural_networks/neural_networks_training_types.h"
33 #include "algorithms/neural_networks/neural_networks_training_model.h"
34 #include "algorithms/neural_networks/layers/layer.h"
35 
36 namespace daal
37 {
38 namespace algorithms
39 {
43 namespace neural_networks
44 {
45 namespace training
46 {
47 namespace interface1
48 {
60 template<ComputeStep step, typename algorithmFPType, Method method, CpuType cpu>
61 class DistributedContainer
62 {};
63 
69 template<typename algorithmFPType, Method method, CpuType cpu>
70 class DistributedContainer<step1Local, algorithmFPType, method, cpu> : public TrainingContainerIface<distributed>
71 {
72 public:
79  DAAL_DEPRECATED DistributedContainer(daal::services::Environment::env *daalEnv);
83  DAAL_DEPRECATED ~DistributedContainer();
88  DAAL_DEPRECATED services::Status compute() DAAL_C11_OVERRIDE;
92  DAAL_DEPRECATED services::Status setupCompute() DAAL_C11_OVERRIDE;
96  DAAL_DEPRECATED services::Status resetCompute() DAAL_C11_OVERRIDE;
102  DAAL_DEPRECATED services::Status finalizeCompute() DAAL_C11_OVERRIDE;
103 };
104 
110 template<typename algorithmFPType, Method method, CpuType cpu>
111 class DistributedContainer<step2Master, algorithmFPType, method, cpu> : public TrainingContainerIface<distributed>
112 {
113 public:
120  DAAL_DEPRECATED DistributedContainer(daal::services::Environment::env *daalEnv);
124  DAAL_DEPRECATED ~DistributedContainer();
129  DAAL_DEPRECATED services::Status compute() DAAL_C11_OVERRIDE;
133  DAAL_DEPRECATED services::Status setupCompute() DAAL_C11_OVERRIDE;
137  DAAL_DEPRECATED services::Status resetCompute() DAAL_C11_OVERRIDE;
143  DAAL_DEPRECATED services::Status finalizeCompute() DAAL_C11_OVERRIDE;
144 };
145 
146 
166 template<ComputeStep step, typename algorithmFPType = DAAL_ALGORITHM_FP_TYPE, Method method = defaultDense>
167 class DAAL_EXPORT Distributed
168 {};
169 
170 
188 template<typename algorithmFPType, Method method>
189 class DAAL_EXPORT Distributed<step1Local, algorithmFPType, method> : public Training<distributed>
190 {
191 public:
192  typedef algorithms::neural_networks::training::DistributedInput<step1Local> InputType;
193  typedef algorithms::neural_networks::training::Parameter ParameterType;
194  typedef algorithms::neural_networks::training::Result ResultType;
195  typedef algorithms::neural_networks::training::PartialResult PartialResultType;
196 
197  DistributedInput<step1Local> input;
198  ParameterType parameter;
203  DAAL_DEPRECATED Distributed()
204  {
205  initialize();
206  };
207 
214  Distributed(const Distributed<step1Local, algorithmFPType, method> &other) : parameter(other.parameter), input(other.input)
215  {
216  initialize();
217  }
218 
222  virtual ~Distributed() {}
223 
231  DAAL_DEPRECATED services::Status setPartialResult(const PartialResultPtr& partialResult)
232  {
233  _partialResult = partialResult;
234  _pres = _partialResult.get();
235  return services::Status();
236  }
237 
243  DAAL_DEPRECATED PartialResultPtr getPartialResult() { return _partialResult; }
244 
250  DAAL_DEPRECATED ResultPtr getResult()
251  {
252  return _result;
253  }
254 
262  DAAL_DEPRECATED services::Status setResult(const ResultPtr& res)
263  {
264  DAAL_CHECK(res, services::ErrorNullResult)
265  _result = res;
266  _res = _result.get();
267  return services::Status();
268  }
269 
276  DAAL_DEPRECATED services::SharedPtr<Distributed<step1Local, algorithmFPType, method> > clone() const
277  {
278  return services::SharedPtr<Distributed<step1Local, algorithmFPType, method> >(cloneImpl());
279  }
280 
286  DAAL_DEPRECATED_VIRTUAL virtual int getMethod() const DAAL_C11_OVERRIDE { return(int) method; }
287 
288 protected:
292  void initialize()
293  {
294  _ac = new __DAAL_ALGORITHM_CONTAINER(distributed, DistributedContainer, step1Local, algorithmFPType, method)(&_env);
295  _in = &input;
296  _par = &parameter;
297  _partialResult.reset(new PartialResultType());
298  _result.reset(new ResultType());
299  }
300 
304  DAAL_DEPRECATED_VIRTUAL virtual Distributed<step1Local, algorithmFPType, method> *cloneImpl() const DAAL_C11_OVERRIDE
305  {
306  return new Distributed<step1Local, algorithmFPType, method>(*this);
307  }
308 
312  DAAL_DEPRECATED_VIRTUAL virtual services::Status allocateResult() DAAL_C11_OVERRIDE
313  {
314  services::Status s = _result->allocate<algorithmFPType>(&input, &parameter, (int) method);
315  _res = _result.get();
316  return s;
317  }
318 
322  DAAL_DEPRECATED services::Status allocatePartialResult() DAAL_C11_OVERRIDE
323  {
324  services::Status s = _partialResult->allocate<algorithmFPType>(&input, &parameter, method);
325  _pres = _partialResult.get();
326  return s;
327  }
328 
332  DAAL_DEPRECATED_VIRTUAL virtual services::Status initializePartialResult() DAAL_C11_OVERRIDE
333  {
334  _pres = _partialResult.get();
335  return services::Status();
336  }
337 private:
338  PartialResultPtr _partialResult;
339  ResultPtr _result;
340 };
341 
359 template<typename algorithmFPType, Method method>
360 class DAAL_EXPORT Distributed<step2Master, algorithmFPType, method> : public Training<distributed>
361 {
362 public:
363  typedef algorithms::neural_networks::training::DistributedInput<step2Master> InputType;
364  typedef algorithms::neural_networks::training::Parameter ParameterType;
365  typedef algorithms::neural_networks::training::Result ResultType;
366  typedef algorithms::neural_networks::training::DistributedPartialResult PartialResultType;
367 
368  DistributedInput<step2Master> input;
369  ParameterType parameter;
374  DAAL_DEPRECATED Distributed(const services::SharedPtr<optimization_solver::iterative_solver::Batch >& optimizationSolver_) : parameter(optimizationSolver_)
375  {
376  initialize();
377  };
378 
385  Distributed(const Distributed<step2Master, algorithmFPType, method> &other) : parameter(other.parameter), input(other.input)
386  {
387  initialize();
388  }
389 
393  virtual ~Distributed() {}
394 
403  DAAL_DEPRECATED services::Status initialize(const services::Collection<size_t> &dataSize, const training::Topology &topology)
404  {
405  ResultPtr result = getResult();
406  if (!result || !result->get(neural_networks::training::model))
407  {
408  return services::Status(services::ErrorNullModel);
409  }
410  result->get(neural_networks::training::model)->initialize<algorithmFPType>(dataSize, topology, parameter);
411  return services::Status();
412  }
413 
421  DAAL_DEPRECATED services::Status setPartialResult(const DistributedPartialResultPtr& partialResult)
422  {
423  _partialResult = partialResult;
424  _pres = _partialResult.get();
425  return services::Status();
426  }
427 
433  DAAL_DEPRECATED DistributedPartialResultPtr getPartialResult() { return _partialResult; }
434 
440  ResultPtr getResult()
441  {
442  return _partialResult->get(resultFromMaster);
443  }
444 
451  DAAL_DEPRECATED services::SharedPtr<Distributed<step2Master, algorithmFPType, method> > clone() const
452  {
453  return services::SharedPtr<Distributed<step2Master, algorithmFPType, method> >(cloneImpl());
454  }
455 
461  DAAL_DEPRECATED_VIRTUAL virtual int getMethod() const DAAL_C11_OVERRIDE { return(int) method; }
462 
463 protected:
467  void initialize()
468  {
469  _ac = new __DAAL_ALGORITHM_CONTAINER(distributed, DistributedContainer, step2Master, algorithmFPType, method)(&_env);
470  _in = &input;
471  _par = &parameter;
472  _partialResult = DistributedPartialResultPtr(new PartialResultType());
473  }
474 
478  DAAL_DEPRECATED_VIRTUAL virtual Distributed<step2Master, algorithmFPType, method> *cloneImpl() const DAAL_C11_OVERRIDE
479  {
480  return new Distributed<step2Master, algorithmFPType, method>(*this);
481  }
482 
486  DAAL_DEPRECATED_VIRTUAL virtual services::Status allocateResult() DAAL_C11_OVERRIDE
487  {
488  return services::Status();
489  }
490 
494  DAAL_DEPRECATED services::Status allocatePartialResult() DAAL_C11_OVERRIDE
495  {
496  services::Status s = _partialResult->allocate<algorithmFPType>(&input, &parameter, method);
497  _pres = _partialResult.get();
498  return s;
499  }
500 
504  DAAL_DEPRECATED_VIRTUAL virtual services::Status initializePartialResult() DAAL_C11_OVERRIDE
505  {
506  _pres = _partialResult.get();
507  return services::Status();
508  }
509 private:
510  DistributedPartialResultPtr _partialResult;
511 };
513 } // namespace interface1
514 using interface1::Distributed;
515 using interface1::DistributedContainer;
516 
517 } // namespace training
518 } // namespace neural_networks
519 } // namespace algorithms
520 } // namespace daal
521 #endif
daal::step1Local
Definition: daal_defines.h:123
daal::algorithms::neural_networks::training::interface1::Distributed< step1Local, algorithmFPType, method >::initialize
void initialize()
Definition: neural_networks_training_distributed.h:292
daal::algorithms::neural_networks::training::interface1::Distributed< step2Master, algorithmFPType, method >::cloneImpl
virtual DAAL_DEPRECATED_VIRTUAL Distributed< step2Master, algorithmFPType, method > * cloneImpl() const DAAL_C11_OVERRIDE
Definition: neural_networks_training_distributed.h:478
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:167
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:189
daal::algorithms::neural_networks::training::interface1::Distributed< step2Master, algorithmFPType, method >::~Distributed
virtual ~Distributed()
Definition: neural_networks_training_distributed.h:393
daal::algorithms::neural_networks::training::interface1::Distributed< step2Master, algorithmFPType, method >::initialize
void initialize()
Definition: neural_networks_training_distributed.h:467
daal::algorithms::neural_networks::training::interface1::Distributed< step2Master, algorithmFPType, method >::input
DistributedInput< step2Master > input
Definition: neural_networks_training_distributed.h:368
daal::algorithms::neural_networks::training::interface1::Distributed< step1Local, algorithmFPType, method >::Distributed
DAAL_DEPRECATED Distributed()
Definition: neural_networks_training_distributed.h:203
daal::step2Master
Definition: daal_defines.h:124
daal::algorithms::neural_networks::training::interface1::Distributed< step2Master, algorithmFPType, method >::getMethod
virtual DAAL_DEPRECATED_VIRTUAL int getMethod() const DAAL_C11_OVERRIDE
Definition: neural_networks_training_distributed.h:461
daal::algorithms::neural_networks::training::interface1::Distributed< step2Master, algorithmFPType, method >::clone
DAAL_DEPRECATED services::SharedPtr< Distributed< step2Master, algorithmFPType, method > > clone() const
Definition: neural_networks_training_distributed.h:451
daal::algorithms::neural_networks::training::interface1::Distributed< step2Master, algorithmFPType, method >::allocateResult
virtual DAAL_DEPRECATED_VIRTUAL services::Status allocateResult() DAAL_C11_OVERRIDE
Definition: neural_networks_training_distributed.h:486
daal::algorithms::neural_networks::training::interface1::Distributed< step2Master, algorithmFPType, method >::parameter
ParameterType parameter
Definition: neural_networks_training_distributed.h:369
daal::algorithms::neural_networks::training::interface1::Distributed< step1Local, algorithmFPType, method >::setResult
DAAL_DEPRECATED services::Status setResult(const ResultPtr &res)
Definition: neural_networks_training_distributed.h:262
daal::services::ErrorNullResult
Definition: error_indexes.h:98
daal::algorithms::neural_networks::training::interface1::Distributed< step2Master, algorithmFPType, method >::initializePartialResult
virtual DAAL_DEPRECATED_VIRTUAL services::Status initializePartialResult() DAAL_C11_OVERRIDE
Definition: neural_networks_training_distributed.h:504
daal::algorithms::neural_networks::training::interface1::Distributed< step1Local, algorithmFPType, method >::clone
DAAL_DEPRECATED services::SharedPtr< Distributed< step1Local, algorithmFPType, method > > clone() const
Definition: neural_networks_training_distributed.h:276
daal::algorithms::neural_networks::training::interface1::DistributedInput< step2Master >
Input objects of the neural network training algorithm.
Definition: neural_networks_training_input.h:255
daal::algorithms::kmeans::init::interface2::Distributed
class DAAL_EXPORT Distributed
Computes initial clusters for K-Means algorithm in the distributed processing mode.
Definition: kmeans_init_distributed.h:277
daal::algorithms::neural_networks::training::interface1::Distributed< step1Local, algorithmFPType, method >::getMethod
virtual DAAL_DEPRECATED_VIRTUAL int getMethod() const DAAL_C11_OVERRIDE
Definition: neural_networks_training_distributed.h:286
daal::algorithms::neural_networks::training::interface1::Distributed< step2Master, algorithmFPType, method >::getPartialResult
DAAL_DEPRECATED DistributedPartialResultPtr getPartialResult()
Definition: neural_networks_training_distributed.h:433
daal::algorithms::neural_networks::training::interface1::Distributed< step2Master, algorithmFPType, method >::allocatePartialResult
DAAL_DEPRECATED services::Status allocatePartialResult() DAAL_C11_OVERRIDE
Definition: neural_networks_training_distributed.h:494
daal_defines.h
daal::algorithms::neural_networks::training::interface1::Distributed< step2Master, algorithmFPType, method >::Distributed
DAAL_DEPRECATED Distributed(const services::SharedPtr< optimization_solver::iterative_solver::Batch > &optimizationSolver_)
Definition: neural_networks_training_distributed.h:374
daal::algorithms::neural_networks::training::interface1::Distributed< step2Master, algorithmFPType, method >::initialize
DAAL_DEPRECATED services::Status initialize(const services::Collection< size_t > &dataSize, const training::Topology &topology)
Definition: neural_networks_training_distributed.h:403
daal::algorithms::neural_networks::training::interface1::Distributed< step1Local, algorithmFPType, method >::allocateResult
virtual DAAL_DEPRECATED_VIRTUAL services::Status allocateResult() DAAL_C11_OVERRIDE
Definition: neural_networks_training_distributed.h:312
daal::algorithms::neural_networks::training::interface1::Distributed< step1Local, algorithmFPType, method >::parameter
ParameterType parameter
Definition: neural_networks_training_distributed.h:198
daal::algorithms::neural_networks::training::interface1::Distributed< step2Master, algorithmFPType, method >::setPartialResult
DAAL_DEPRECATED services::Status setPartialResult(const DistributedPartialResultPtr &partialResult)
Definition: neural_networks_training_distributed.h:421
daal::algorithms::neural_networks::training::interface1::Distributed< step1Local, algorithmFPType, method >::initializePartialResult
virtual DAAL_DEPRECATED_VIRTUAL services::Status initializePartialResult() DAAL_C11_OVERRIDE
Definition: neural_networks_training_distributed.h:332
daal::services::ErrorNullModel
Definition: error_indexes.h:85
daal::algorithms::Training
Provides methods to train models that depend on the data provided. For example, these methods enable ...
Definition: training.h:62
daal::algorithms::neural_networks::training::interface1::Distributed< step1Local, algorithmFPType, method >::allocatePartialResult
DAAL_DEPRECATED services::Status allocatePartialResult() DAAL_C11_OVERRIDE
Definition: neural_networks_training_distributed.h:322
daal::algorithms::neural_networks::training::interface1::Distributed< step2Master, algorithmFPType, method >::Distributed
Distributed(const Distributed< step2Master, algorithmFPType, method > &other)
Definition: neural_networks_training_distributed.h:385
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:61
daal::algorithms::neural_networks::training::interface1::Distributed< step1Local, algorithmFPType, method >::Distributed
Distributed(const Distributed< step1Local, algorithmFPType, method > &other)
Definition: neural_networks_training_distributed.h:214
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:202
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:360
daal::algorithms::neural_networks::training::interface1::Distributed< step1Local, algorithmFPType, method >::getResult
DAAL_DEPRECATED ResultPtr getResult()
Definition: neural_networks_training_distributed.h:250
daal::algorithms::neural_networks::training::interface1::Distributed< step1Local, algorithmFPType, method >::getPartialResult
DAAL_DEPRECATED PartialResultPtr getPartialResult()
Definition: neural_networks_training_distributed.h:243
daal::algorithms::neural_networks::training::interface1::Distributed< step1Local, algorithmFPType, method >::cloneImpl
virtual DAAL_DEPRECATED_VIRTUAL Distributed< step1Local, algorithmFPType, method > * cloneImpl() const DAAL_C11_OVERRIDE
Definition: neural_networks_training_distributed.h:304
daal::algorithms::neural_networks::training::interface1::Distributed< step2Master, algorithmFPType, method >::getResult
ResultPtr getResult()
Definition: neural_networks_training_distributed.h:440
daal::algorithms::neural_networks::training::interface1::Distributed< step1Local, algorithmFPType, method >::input
DistributedInput< step1Local > input
Definition: neural_networks_training_distributed.h:197
daal::distributed
Definition: daal_defines.h:113
daal::algorithms::neural_networks::training::model
Definition: neural_networks_training_result.h:54
daal::algorithms::neural_networks::training::interface1::Distributed< step1Local, algorithmFPType, method >::setPartialResult
DAAL_DEPRECATED services::Status setPartialResult(const PartialResultPtr &partialResult)
Definition: neural_networks_training_distributed.h:231
daal::algorithms::TrainingContainerIface
Abstract interface class that provides virtual methods to access and run implementations of the model...
Definition: training.h:52
daal::algorithms::neural_networks::training::interface1::Distributed< step1Local, algorithmFPType, method >::~Distributed
virtual ~Distributed()
Definition: neural_networks_training_distributed.h:222

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