49 #ifndef __NEURAL_NETWORKS_TRAINING_DISTRIBUTED_H__ 50 #define __NEURAL_NETWORKS_TRAINING_DISTRIBUTED_H__ 52 #include "algorithms/algorithm.h" 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" 67 namespace neural_networks
83 template<ComputeStep step,
typename algorithmFPType, Method method, CpuType cpu>
84 class DAAL_EXPORT DistributedContainer
91 template<
typename algorithmFPType, Method method, CpuType cpu>
92 class DAAL_EXPORT DistributedContainer<step1Local, algorithmFPType, method, cpu> :
public TrainingContainerIface<distributed>
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;
120 template<
typename algorithmFPType, Method method, CpuType cpu>
121 class DAAL_EXPORT DistributedContainer<step2Master, algorithmFPType, method, cpu> :
public TrainingContainerIface<distributed>
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;
163 template<ComputeStep step,
typename algorithmFPType = DAAL_ALGORITHM_FP_TYPE, Method method = defaultDense>
164 class DAAL_EXPORT Distributed
183 template<
typename algorithmFPType, Method method>
184 class DAAL_EXPORT Distributed<step1Local, algorithmFPType, method> :
public Training<distributed>
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;
192 DistributedInput<step1Local> input;
193 ParameterType parameter;
206 Distributed(
const Distributed<step1Local, algorithmFPType, method> &other) : parameter(other.parameter), input(other.input)
211 virtual ~Distributed() {}
219 services::Status setPartialResult(
const PartialResultPtr& partialResult)
221 _partialResult = partialResult;
222 _pres = _partialResult.get();
223 return services::Status();
230 PartialResultPtr getPartialResult() {
return _partialResult; }
236 ResultPtr getResult()
247 services::Status setResult(
const ResultPtr& res)
249 DAAL_CHECK(res, services::ErrorNullResult)
251 _res = _result.get();
252 return services::Status();
260 services::SharedPtr<Distributed<step1Local, algorithmFPType, method> > clone()
const 262 return services::SharedPtr<Distributed<step1Local, algorithmFPType, method> >(cloneImpl());
269 virtual int getMethod() const DAAL_C11_OVERRIDE {
return(
int) method; }
274 _ac =
new __DAAL_ALGORITHM_CONTAINER(distributed, DistributedContainer, step1Local, algorithmFPType, method)(&_env);
277 _partialResult.reset(
new PartialResultType());
278 _result.reset(
new ResultType());
281 virtual Distributed<step1Local, algorithmFPType, method> *cloneImpl()
const DAAL_C11_OVERRIDE
283 return new Distributed<step1Local, algorithmFPType, method>(*this);
286 virtual services::Status allocateResult() DAAL_C11_OVERRIDE
288 services::Status s = _result->allocate<algorithmFPType>(&input, ¶meter, (int) method);
289 _res = _result.get();
293 services::Status allocatePartialResult() DAAL_C11_OVERRIDE
295 services::Status s = _partialResult->allocate<algorithmFPType>(&input, ¶meter, method);
296 _pres = _partialResult.get();
300 virtual services::Status initializePartialResult() DAAL_C11_OVERRIDE
302 _pres = _partialResult.get();
303 return services::Status();
306 PartialResultPtr _partialResult;
325 template<
typename algorithmFPType, Method method>
326 class DAAL_EXPORT Distributed<step2Master, algorithmFPType, method> :
public Training<distributed>
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;
334 DistributedInput<step2Master> input;
335 ParameterType parameter;
337 Distributed(
const services::SharedPtr<optimization_solver::iterative_solver::Batch >& optimizationSolver_) : parameter(optimizationSolver_)
347 Distributed(
const Distributed<step2Master, algorithmFPType, method> &other) : parameter(other.parameter), input(other.input)
352 virtual ~Distributed() {}
361 services::Status initialize(
const services::Collection<size_t> &dataSize,
const training::Topology &topology)
363 ResultPtr result = getResult();
364 if (!result || !result->get(neural_networks::training::model))
366 return services::Status(services::ErrorNullModel);
368 result->get(neural_networks::training::model)->initialize<algorithmFPType>(dataSize, topology, parameter);
369 return services::Status();
378 services::Status setPartialResult(
const DistributedPartialResultPtr& partialResult)
380 _partialResult = partialResult;
381 _pres = _partialResult.get();
382 return services::Status();
389 DistributedPartialResultPtr getPartialResult() {
return _partialResult; }
395 ResultPtr getResult()
397 return _partialResult->get(resultFromMaster);
405 services::SharedPtr<Distributed<step2Master, algorithmFPType, method> > clone()
const 407 return services::SharedPtr<Distributed<step2Master, algorithmFPType, method> >(cloneImpl());
414 virtual int getMethod() const DAAL_C11_OVERRIDE {
return(
int) method; }
419 _ac =
new __DAAL_ALGORITHM_CONTAINER(distributed, DistributedContainer, step2Master, algorithmFPType, method)(&_env);
422 _partialResult = DistributedPartialResultPtr(
new PartialResultType());
425 virtual Distributed<step2Master, algorithmFPType, method> *cloneImpl()
const DAAL_C11_OVERRIDE
427 return new Distributed<step2Master, algorithmFPType, method>(*this);
430 virtual services::Status allocateResult() DAAL_C11_OVERRIDE
432 return services::Status();
435 services::Status allocatePartialResult() DAAL_C11_OVERRIDE
437 services::Status s = _partialResult->allocate<algorithmFPType>(&input, ¶meter, method);
438 _pres = _partialResult.get();
442 virtual services::Status initializePartialResult() DAAL_C11_OVERRIDE
444 _pres = _partialResult.get();
445 return services::Status();
448 DistributedPartialResultPtr _partialResult;
452 using interface1::Distributed;
453 using interface1::DistributedContainer;
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::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::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::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