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

batch_normalization_layer_forward.h
1 /* file: batch_normalization_layer_forward.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 the forward batch normalization layer
45 // in the batch processing mode
46 //--
47 */
48 
49 #ifndef __BATCH_NORMALIZATION_LAYER_FORWARD_H__
50 #define __BATCH_NORMALIZATION_LAYER_FORWARD_H__
51 
52 #include "algorithms/algorithm.h"
53 #include "data_management/data/tensor.h"
54 #include "services/daal_defines.h"
55 #include "algorithms/neural_networks/layers/layer.h"
56 #include "algorithms/neural_networks/layers/batch_normalization/batch_normalization_layer_types.h"
57 #include "algorithms/neural_networks/layers/batch_normalization/batch_normalization_layer_forward_types.h"
58 
59 namespace daal
60 {
61 namespace algorithms
62 {
63 namespace neural_networks
64 {
65 namespace layers
66 {
67 namespace batch_normalization
68 {
69 namespace forward
70 {
74 namespace interface1
75 {
91 template<typename algorithmFPType, Method method, CpuType cpu>
92 class DAAL_EXPORT BatchContainer : public layers::forward::LayerContainerIfaceImpl
93 {
94 public:
100  BatchContainer(daal::services::Environment::env *daalEnv);
102  ~BatchContainer();
108  services::Status compute() DAAL_C11_OVERRIDE;
109  services::Status setupCompute() DAAL_C11_OVERRIDE;
110  services::Status resetCompute() DAAL_C11_OVERRIDE;
111  virtual services::Status allocateInput() DAAL_C11_OVERRIDE
112  {
113  Input *input = static_cast<Input *>(_in);
114  return input->allocate<algorithmFPType>(_par, (int) method);
115  }
116 };
117 
136 template<typename algorithmFPType = DAAL_ALGORITHM_FP_TYPE, Method method = defaultDense>
137 class Batch : public layers::forward::LayerIfaceImpl
138 {
139 public:
140  typedef layers::forward::LayerIfaceImpl super;
141  Parameter &parameter;
142  Input input;
145  Batch() : parameter(_defaultParameter)
146  {
147  initialize();
148  }
149 
155  Batch(Parameter& parameter) : parameter(parameter), _defaultParameter(parameter)
156  {
157  initialize();
158  }
159 
166  Batch(const Batch<algorithmFPType, method> &other) : super(other),
167  _defaultParameter(other.parameter), parameter(_defaultParameter), input(other.input)
168  {
169  initialize();
170  }
171 
176  virtual int getMethod() const DAAL_C11_OVERRIDE { return(int) method; }
177 
182  virtual Input *getLayerInput() DAAL_C11_OVERRIDE { return &input; }
183 
188  virtual Parameter *getLayerParameter() DAAL_C11_OVERRIDE { return &parameter; };
189 
194  layers::forward::ResultPtr getLayerResult() DAAL_C11_OVERRIDE
195  {
196  return getResult();
197  }
198 
203  ResultPtr getResult()
204  {
205  return _result;
206  }
207 
214  services::Status setResult(const ResultPtr& result)
215  {
216  DAAL_CHECK(result, services::ErrorNullResult)
217  _result = result;
218  _res = _result.get();
219  return services::Status();
220  }
221 
228  services::SharedPtr<Batch<algorithmFPType, method> > clone() const
229  {
230  return services::SharedPtr<Batch<algorithmFPType, method> >(cloneImpl());
231  }
232 
238  virtual services::Status allocateResult() DAAL_C11_OVERRIDE
239  {
240  services::Status s = this->_result->template allocate<algorithmFPType>(&(this->input), &parameter, (int) method);
241  this->_res = this->_result.get();
242  return s;
243  }
244 
249  virtual layers::forward::LayerIfacePtr getLayerForPrediction() const DAAL_C11_OVERRIDE
250  {
251  services::SharedPtr<Batch<algorithmFPType, method> > seflCopy = clone();
252  if (_result)
253  {
254  seflCopy->input.set(forward::populationMean, _result->get(auxPopulationMean));
255  seflCopy->input.set(forward::populationVariance, _result->get(auxPopulationVariance));
256  }
257  return services::staticPointerCast<layers::forward::LayerIface>(seflCopy);
258  }
259 
260 protected:
261  virtual Batch<algorithmFPType, method> *cloneImpl() const DAAL_C11_OVERRIDE
262  {
263  return new Batch<algorithmFPType, method>(*this);
264  }
265 
266  void initialize()
267  {
268  Analysis<batch>::_ac = new __DAAL_ALGORITHM_LAYER_CONTAINER(BatchContainer, algorithmFPType, method)(&_env);
269  _in = &input;
270  _par = &parameter;
271  _result.reset(new Result());
272  }
273 
274 private:
275  ResultPtr _result;
276  Parameter _defaultParameter;
277 };
278 
280 } // namespace interface1
281 using interface1::BatchContainer;
282 using interface1::Batch;
283 } // namespace forward
284 } // namespace batch_normalization
285 } // namespace layers
286 } // namespace neural_networks
287 } // namespace algorithms
288 } // namespace daal
289 
290 #endif
daal::algorithms::neural_networks::layers::batch_normalization::forward::populationMean
Definition: batch_normalization_layer_forward_types.h:85
daal
Definition: algorithm_base_common.h:57
daal::algorithms::neural_networks::layers::batch_normalization::forward::interface1::Batch::getResult
ResultPtr getResult()
Definition: batch_normalization_layer_forward.h:203
daal::algorithms::neural_networks::layers::batch_normalization::forward::interface1::Batch::parameter
Parameter & parameter
Definition: batch_normalization_layer_forward.h:141
daal::algorithms::neural_networks::layers::batch_normalization::forward::interface1::Batch::input
Input input
Definition: batch_normalization_layer_forward.h:142
daal::algorithms::neural_networks::layers::batch_normalization::forward::interface1::Batch::allocateResult
virtual services::Status allocateResult() DAAL_C11_OVERRIDE
Definition: batch_normalization_layer_forward.h:238
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:99
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::getLayerForPrediction
virtual layers::forward::LayerIfacePtr getLayerForPrediction() const DAAL_C11_OVERRIDE
Definition: batch_normalization_layer_forward.h:249
daal::algorithms::neural_networks::layers::batch_normalization::auxPopulationVariance
Definition: batch_normalization_layer_types.h:93
daal_defines.h
daal::algorithms::neural_networks::layers::batch_normalization::forward::interface1::Batch::Batch
Batch()
Definition: batch_normalization_layer_forward.h:145
daal::algorithms::neural_networks::layers::batch_normalization::auxPopulationMean
Definition: batch_normalization_layer_types.h:92
daal::algorithms::neural_networks::layers::batch_normalization::forward::interface1::Batch::getMethod
virtual int getMethod() const DAAL_C11_OVERRIDE
Definition: batch_normalization_layer_forward.h:176
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:137
daal::algorithms::neural_networks::layers::batch_normalization::forward::interface1::Batch::getLayerResult
layers::forward::ResultPtr getLayerResult() DAAL_C11_OVERRIDE
Definition: batch_normalization_layer_forward.h:194
daal::algorithms::neural_networks::layers::batch_normalization::forward::populationVariance
Definition: batch_normalization_layer_forward_types.h:86
daal::algorithms::neural_networks::layers::batch_normalization::forward::interface1::Batch::getLayerInput
virtual Input * getLayerInput() DAAL_C11_OVERRIDE
Definition: batch_normalization_layer_forward.h:182
daal::algorithms::neural_networks::layers::batch_normalization::forward::interface1::Batch::clone
services::SharedPtr< Batch< algorithmFPType, method > > clone() const
Definition: batch_normalization_layer_forward.h:228
daal::algorithms::neural_networks::layers::batch_normalization::forward::interface1::Batch::Batch
Batch(Parameter &parameter)
Definition: batch_normalization_layer_forward.h:155
daal::algorithms::Analysis
Provides methods for execution of operations over data, such as computation of Summary Statistics est...
Definition: analysis.h:94
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:92
daal::algorithms::neural_networks::layers::batch_normalization::forward::interface1::Batch::Batch
Batch(const Batch< algorithmFPType, method > &other)
Definition: batch_normalization_layer_forward.h:166
daal::algorithms::neural_networks::layers::batch_normalization::forward::interface1::Batch::setResult
services::Status setResult(const ResultPtr &result)
Definition: batch_normalization_layer_forward.h:214
daal::algorithms::neural_networks::layers::batch_normalization::forward::interface1::Batch::getLayerParameter
virtual Parameter * getLayerParameter() DAAL_C11_OVERRIDE
Definition: batch_normalization_layer_forward.h:188
daal::services::ErrorNullResult
Definition: error_indexes.h:122

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