C++ API Reference for Intel® Data Analytics Acceleration Library 2019 Update 4

batch_normalization_layer_forward.h
1 /* file: batch_normalization_layer_forward.h */
2 /*******************************************************************************
3 * Copyright 2014-2019 Intel Corporation.
4 *
5 * This software and the related documents are Intel copyrighted materials, and
6 * your use of them is governed by the express license under which they were
7 * provided to you (License). Unless the License provides otherwise, you may not
8 * use, modify, copy, publish, distribute, disclose or transmit this software or
9 * the related documents without Intel's prior written permission.
10 *
11 * This software and the related documents are provided as is, with no express
12 * or implied warranties, other than those that are expressly stated in the
13 * License.
14 *******************************************************************************/
15 
16 /*
17 //++
18 // Implementation of the interface for the forward batch normalization layer
19 // in the batch processing mode
20 //--
21 */
22 
23 #ifndef __BATCH_NORMALIZATION_LAYER_FORWARD_H__
24 #define __BATCH_NORMALIZATION_LAYER_FORWARD_H__
25 
26 #include "algorithms/algorithm.h"
27 #include "data_management/data/tensor.h"
28 #include "services/daal_defines.h"
29 #include "algorithms/neural_networks/layers/layer.h"
30 #include "algorithms/neural_networks/layers/batch_normalization/batch_normalization_layer_types.h"
31 #include "algorithms/neural_networks/layers/batch_normalization/batch_normalization_layer_forward_types.h"
32 
33 namespace daal
34 {
35 namespace algorithms
36 {
37 namespace neural_networks
38 {
39 namespace layers
40 {
41 namespace batch_normalization
42 {
43 namespace forward
44 {
48 namespace interface1
49 {
65 template<typename algorithmFPType, Method method, CpuType cpu>
66 class DAAL_EXPORT BatchContainer : public layers::forward::LayerContainerIfaceImpl
67 {
68 public:
74  BatchContainer(daal::services::Environment::env *daalEnv);
76  ~BatchContainer();
82  services::Status compute() DAAL_C11_OVERRIDE;
83  services::Status setupCompute() DAAL_C11_OVERRIDE;
84  services::Status resetCompute() DAAL_C11_OVERRIDE;
85  virtual services::Status allocateInput() DAAL_C11_OVERRIDE
86  {
87  Input *input = static_cast<Input *>(_in);
88  return input->allocate<algorithmFPType>(_par, (int) method);
89  }
90 };
91 
110 template<typename algorithmFPType = DAAL_ALGORITHM_FP_TYPE, Method method = defaultDense>
111 class Batch : public layers::forward::LayerIfaceImpl
112 {
113 public:
114  typedef layers::forward::LayerIfaceImpl super;
115 
116  typedef algorithms::neural_networks::layers::batch_normalization::forward::Input InputType;
117  typedef algorithms::neural_networks::layers::batch_normalization::Parameter ParameterType;
118  typedef algorithms::neural_networks::layers::batch_normalization::forward::Result ResultType;
119 
120  ParameterType &parameter;
121  InputType input;
124  Batch() : parameter(_defaultParameter)
125  {
126  initialize();
127  }
128 
134  Batch(ParameterType& parameter) : parameter(parameter), _defaultParameter(parameter)
135  {
136  initialize();
137  }
138 
145  Batch(const Batch<algorithmFPType, method> &other) : super(other),
146  _defaultParameter(other.parameter), parameter(_defaultParameter), input(other.input)
147  {
148  initialize();
149  }
150 
155  virtual int getMethod() const DAAL_C11_OVERRIDE { return(int) method; }
156 
161  virtual InputType *getLayerInput() DAAL_C11_OVERRIDE { return &input; }
162 
167  virtual ParameterType *getLayerParameter() DAAL_C11_OVERRIDE { return &parameter; };
168 
173  layers::forward::ResultPtr getLayerResult() DAAL_C11_OVERRIDE
174  {
175  return getResult();
176  }
177 
182  ResultPtr getResult()
183  {
184  return _result;
185  }
186 
193  services::Status setResult(const ResultPtr& result)
194  {
195  DAAL_CHECK(result, services::ErrorNullResult)
196  _result = result;
197  _res = _result.get();
198  return services::Status();
199  }
200 
207  services::SharedPtr<Batch<algorithmFPType, method> > clone() const
208  {
209  return services::SharedPtr<Batch<algorithmFPType, method> >(cloneImpl());
210  }
211 
217  virtual services::Status allocateResult() DAAL_C11_OVERRIDE
218  {
219  services::Status s = this->_result->template allocate<algorithmFPType>(&(this->input), &parameter, (int) method);
220  this->_res = this->_result.get();
221  return s;
222  }
223 
228  virtual layers::forward::LayerIfacePtr getLayerForPrediction() const DAAL_C11_OVERRIDE
229  {
230  services::SharedPtr<Batch<algorithmFPType, method> > seflCopy = clone();
231  if (_result)
232  {
233  seflCopy->input.set(forward::populationMean, _result->get(auxPopulationMean));
234  seflCopy->input.set(forward::populationVariance, _result->get(auxPopulationVariance));
235  }
236  return services::staticPointerCast<layers::forward::LayerIface>(seflCopy);
237  }
238 
239 protected:
240  virtual Batch<algorithmFPType, method> *cloneImpl() const DAAL_C11_OVERRIDE
241  {
242  return new Batch<algorithmFPType, method>(*this);
243  }
244 
245  void initialize()
246  {
247  Analysis<batch>::_ac = new __DAAL_ALGORITHM_LAYER_CONTAINER(BatchContainer, algorithmFPType, method)(&_env);
248  _in = &input;
249  _par = &parameter;
250  _result.reset(new ResultType());
251  }
252 
253 private:
254  ResultPtr _result;
255  ParameterType _defaultParameter;
256 };
257 
259 } // namespace interface1
260 using interface1::BatchContainer;
261 using interface1::Batch;
262 } // namespace forward
263 } // namespace batch_normalization
264 } // namespace layers
265 } // namespace neural_networks
266 } // namespace algorithms
267 } // namespace daal
268 
269 #endif
daal::algorithms::neural_networks::layers::batch_normalization::forward::populationMean
Definition: batch_normalization_layer_forward_types.h:59
daal::algorithms::neural_networks::layers::batch_normalization::forward::interface1::Batch::input
InputType input
Definition: batch_normalization_layer_forward.h:121
daal
Definition: algorithm_base_common.h:31
daal::algorithms::neural_networks::layers::batch_normalization::forward::interface1::Batch::getResult
ResultPtr getResult()
Definition: batch_normalization_layer_forward.h:182
daal::algorithms::neural_networks::layers::batch_normalization::forward::interface1::Batch::allocateResult
virtual services::Status allocateResult() DAAL_C11_OVERRIDE
Definition: batch_normalization_layer_forward.h:217
daal::algorithms::neural_networks::layers::batch_normalization::forward::interface1::Input
Input objects for the forward batch normalization layer.
Definition: batch_normalization_layer_forward_types.h:73
daal::algorithms::neural_networks::layers::batch_normalization::forward::interface1::Input::allocate
DAAL_EXPORT services::Status allocate(const daal::algorithms::Parameter *parameter, const int method)
daal::algorithms::neural_networks::layers::batch_normalization::forward::interface1::Batch::parameter
ParameterType & parameter
Definition: batch_normalization_layer_forward.h:120
daal::algorithms::neural_networks::layers::batch_normalization::forward::interface1::Batch::getLayerForPrediction
virtual layers::forward::LayerIfacePtr getLayerForPrediction() const DAAL_C11_OVERRIDE
Definition: batch_normalization_layer_forward.h:228
daal::algorithms::neural_networks::layers::batch_normalization::forward::interface1::Batch::getLayerInput
virtual InputType * getLayerInput() DAAL_C11_OVERRIDE
Definition: batch_normalization_layer_forward.h:161
daal::algorithms::neural_networks::layers::batch_normalization::auxPopulationVariance
Definition: batch_normalization_layer_types.h:67
daal_defines.h
daal::algorithms::neural_networks::layers::batch_normalization::forward::interface1::Batch::Batch
Batch()
Definition: batch_normalization_layer_forward.h:124
daal::algorithms::neural_networks::layers::batch_normalization::auxPopulationMean
Definition: batch_normalization_layer_types.h:66
daal::algorithms::neural_networks::layers::batch_normalization::forward::interface1::Batch::getLayerParameter
virtual ParameterType * getLayerParameter() DAAL_C11_OVERRIDE
Definition: batch_normalization_layer_forward.h:167
daal::algorithms::neural_networks::layers::batch_normalization::forward::interface1::Batch::getMethod
virtual int getMethod() const DAAL_C11_OVERRIDE
Definition: batch_normalization_layer_forward.h:155
daal::algorithms::neural_networks::layers::batch_normalization::forward::interface1::Batch
Provides methods for the forward batch normalization layer in the batch processing mode...
Definition: batch_normalization_layer_forward.h:111
daal::algorithms::neural_networks::layers::batch_normalization::forward::interface1::Batch::getLayerResult
layers::forward::ResultPtr getLayerResult() DAAL_C11_OVERRIDE
Definition: batch_normalization_layer_forward.h:173
daal::algorithms::neural_networks::layers::batch_normalization::forward::populationVariance
Definition: batch_normalization_layer_forward_types.h:60
daal::algorithms::neural_networks::layers::batch_normalization::forward::interface1::Batch::Batch
Batch(ParameterType &parameter)
Definition: batch_normalization_layer_forward.h:134
daal::algorithms::neural_networks::layers::batch_normalization::forward::interface1::Batch::clone
services::SharedPtr< Batch< algorithmFPType, method > > clone() const
Definition: batch_normalization_layer_forward.h:207
daal::algorithms::Analysis
Provides methods for execution of operations over data, such as computation of Summary Statistics est...
Definition: analysis.h:68
daal::algorithms::neural_networks::layers::batch_normalization::forward::interface1::BatchContainer
Provides methods to run implementations of the forward batch normalization layer. This class is assoc...
Definition: batch_normalization_layer_forward.h:66
daal::algorithms::neural_networks::layers::batch_normalization::forward::interface1::Batch::Batch
Batch(const Batch< algorithmFPType, method > &other)
Definition: batch_normalization_layer_forward.h:145
daal::algorithms::neural_networks::layers::batch_normalization::forward::interface1::Batch::setResult
services::Status setResult(const ResultPtr &result)
Definition: batch_normalization_layer_forward.h:193
daal::services::ErrorNullResult
Definition: error_indexes.h:96

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