23 #ifndef __NEURAL_NETWORKS_TRAINING_DISTRIBUTED_H__
24 #define __NEURAL_NETWORKS_TRAINING_DISTRIBUTED_H__
26 #include "algorithms/algorithm.h"
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"
41 namespace neural_networks
57 template<ComputeStep step,
typename algorithmFPType, Method method, CpuType cpu>
58 class DAAL_EXPORT DistributedContainer
65 template<
typename algorithmFPType, Method method, CpuType cpu>
66 class DAAL_EXPORT DistributedContainer<step1Local, algorithmFPType, method, cpu> :
public TrainingContainerIface<distributed>
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;
94 template<
typename algorithmFPType, Method method, CpuType cpu>
95 class DAAL_EXPORT DistributedContainer<step2Master, algorithmFPType, method, cpu> :
public TrainingContainerIface<distributed>
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;
137 template<ComputeStep step,
typename algorithmFPType = DAAL_ALGORITHM_FP_TYPE, Method method = defaultDense>
138 class DAAL_EXPORT Distributed
157 template<
typename algorithmFPType, Method method>
158 class DAAL_EXPORT Distributed<step1Local, algorithmFPType, method> :
public Training<distributed>
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;
166 DistributedInput<step1Local> input;
167 ParameterType parameter;
180 Distributed(
const Distributed<step1Local, algorithmFPType, method> &other) : parameter(other.parameter), input(other.input)
185 virtual ~Distributed() {}
193 services::Status setPartialResult(
const PartialResultPtr& partialResult)
195 _partialResult = partialResult;
196 _pres = _partialResult.get();
197 return services::Status();
204 PartialResultPtr getPartialResult() {
return _partialResult; }
210 ResultPtr getResult()
221 services::Status setResult(
const ResultPtr& res)
223 DAAL_CHECK(res, services::ErrorNullResult)
225 _res = _result.get();
226 return services::Status();
234 services::SharedPtr<Distributed<step1Local, algorithmFPType, method> > clone()
const
236 return services::SharedPtr<Distributed<step1Local, algorithmFPType, method> >(cloneImpl());
243 virtual int getMethod() const DAAL_C11_OVERRIDE {
return(
int) method; }
248 _ac =
new __DAAL_ALGORITHM_CONTAINER(distributed, DistributedContainer, step1Local, algorithmFPType, method)(&_env);
251 _partialResult.reset(
new PartialResultType());
252 _result.reset(
new ResultType());
255 virtual Distributed<step1Local, algorithmFPType, method> *cloneImpl() const DAAL_C11_OVERRIDE
257 return new Distributed<step1Local, algorithmFPType, method>(*this);
260 virtual services::Status allocateResult() DAAL_C11_OVERRIDE
262 services::Status s = _result->allocate<algorithmFPType>(&input, ¶meter, (int) method);
263 _res = _result.get();
267 services::Status allocatePartialResult() DAAL_C11_OVERRIDE
269 services::Status s = _partialResult->allocate<algorithmFPType>(&input, ¶meter, method);
270 _pres = _partialResult.get();
274 virtual services::Status initializePartialResult() DAAL_C11_OVERRIDE
276 _pres = _partialResult.get();
277 return services::Status();
280 PartialResultPtr _partialResult;
299 template<
typename algorithmFPType, Method method>
300 class DAAL_EXPORT Distributed<step2Master, algorithmFPType, method> :
public Training<distributed>
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;
308 DistributedInput<step2Master> input;
309 ParameterType parameter;
311 Distributed(
const services::SharedPtr<optimization_solver::iterative_solver::Batch >& optimizationSolver_) : parameter(optimizationSolver_)
321 Distributed(
const Distributed<step2Master, algorithmFPType, method> &other) : parameter(other.parameter), input(other.input)
326 virtual ~Distributed() {}
335 services::Status initialize(
const services::Collection<size_t> &dataSize,
const training::Topology &topology)
337 ResultPtr result = getResult();
338 if (!result || !result->get(neural_networks::training::model))
340 return services::Status(services::ErrorNullModel);
342 result->get(neural_networks::training::model)->initialize<algorithmFPType>(dataSize, topology, parameter);
343 return services::Status();
352 services::Status setPartialResult(
const DistributedPartialResultPtr& partialResult)
354 _partialResult = partialResult;
355 _pres = _partialResult.get();
356 return services::Status();
363 DistributedPartialResultPtr getPartialResult() {
return _partialResult; }
369 ResultPtr getResult()
371 return _partialResult->get(resultFromMaster);
379 services::SharedPtr<Distributed<step2Master, algorithmFPType, method> > clone()
const
381 return services::SharedPtr<Distributed<step2Master, algorithmFPType, method> >(cloneImpl());
388 virtual int getMethod() const DAAL_C11_OVERRIDE {
return(
int) method; }
393 _ac =
new __DAAL_ALGORITHM_CONTAINER(distributed, DistributedContainer, step2Master, algorithmFPType, method)(&_env);
396 _partialResult = DistributedPartialResultPtr(
new PartialResultType());
399 virtual Distributed<step2Master, algorithmFPType, method> *cloneImpl() const DAAL_C11_OVERRIDE
401 return new Distributed<step2Master, algorithmFPType, method>(*this);
404 virtual services::Status allocateResult() DAAL_C11_OVERRIDE
406 return services::Status();
409 services::Status allocatePartialResult() DAAL_C11_OVERRIDE
411 services::Status s = _partialResult->allocate<algorithmFPType>(&input, ¶meter, method);
412 _pres = _partialResult.get();
416 virtual services::Status initializePartialResult() DAAL_C11_OVERRIDE
418 _pres = _partialResult.get();
419 return services::Status();
422 DistributedPartialResultPtr _partialResult;
426 using interface1::Distributed;
427 using interface1::DistributedContainer;
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::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::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::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