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

convolution2d_layer_forward.h
1 /* file: convolution2d_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 two-dimensional (2D) convolution layer in the batch
19 // processing mode
20 //--
21 */
22 
23 #ifndef __CONVOLUTION2D_LAYER_FORWARD_H__
24 #define __CONVOLUTION2D_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/convolution2d/convolution2d_layer_types.h"
31 #include "algorithms/neural_networks/layers/convolution2d/convolution2d_layer_forward_types.h"
32 
33 namespace daal
34 {
35 namespace algorithms
36 {
37 namespace neural_networks
38 {
39 namespace layers
40 {
41 namespace convolution2d
42 {
43 namespace forward
44 {
45 namespace interface1
46 {
62 template<typename algorithmFPType, Method method, CpuType cpu>
63 class DAAL_EXPORT BatchContainer : public layers::forward::LayerContainerIfaceImpl
64 {
65 public:
71  BatchContainer(daal::services::Environment::env *daalEnv);
73  ~BatchContainer();
79  services::Status compute() DAAL_C11_OVERRIDE;
80  services::Status setupCompute() DAAL_C11_OVERRIDE;
81  services::Status resetCompute() DAAL_C11_OVERRIDE;
82 
83  virtual services::Status allocateInput() DAAL_C11_OVERRIDE
84  {
85  Input *input = static_cast<Input *>(_in);
86  return input->allocate<algorithmFPType>(_par, (int) method);
87  }
88 };
89 
107 template<typename algorithmFPType = DAAL_ALGORITHM_FP_TYPE, Method method = defaultDense>
108 class Batch : public layers::forward::LayerIfaceImpl
109 {
110 public:
111  typedef layers::forward::LayerIfaceImpl super;
112 
113  typedef algorithms::neural_networks::layers::convolution2d::forward::Input InputType;
114  typedef algorithms::neural_networks::layers::convolution2d::Parameter ParameterType;
115  typedef algorithms::neural_networks::layers::convolution2d::forward::Result ResultType;
116 
117  ParameterType &parameter;
118  InputType input;
121  Batch() : parameter(_defaultParameter)
122  {
123  initialize();
124  };
125 
131  Batch(ParameterType& parameter) : parameter(parameter), _defaultParameter(parameter)
132  {
133  initialize();
134  };
135 
141  Batch(const Batch<algorithmFPType, method> &other) : super(other),
142  _defaultParameter(other.parameter), parameter(_defaultParameter), input(other.input)
143  {
144  initialize();
145  }
146 
151  virtual int getMethod() const DAAL_C11_OVERRIDE { return(int) method; }
152 
157  virtual InputType *getLayerInput() DAAL_C11_OVERRIDE { return &input; }
158 
163  virtual ParameterType *getLayerParameter() DAAL_C11_OVERRIDE { return &parameter; };
164 
169  layers::forward::ResultPtr getLayerResult() DAAL_C11_OVERRIDE
170  {
171  return getResult();
172  }
173 
178  ResultPtr getResult()
179  {
180  return _result;
181  }
182 
189  services::Status setResult(const ResultPtr& result)
190  {
191  DAAL_CHECK(result, services::ErrorNullResult)
192  _result = result;
193  _res = _result.get();
194  return services::Status();
195  }
196 
202  services::SharedPtr<Batch<algorithmFPType, method> > clone() const
203  {
204  return services::SharedPtr<Batch<algorithmFPType, method> >(cloneImpl());
205  }
206 
207  virtual services::Status allocateResult() DAAL_C11_OVERRIDE
208  {
209  services::Status s = this->_result->template allocate<algorithmFPType>(&(this->input), &parameter, (int) method);
210  this->_res = this->_result.get();
211  return s;
212  }
213 
214 protected:
215  virtual Batch<algorithmFPType, method> *cloneImpl() const DAAL_C11_OVERRIDE
216  {
217  return new Batch<algorithmFPType, method>(*this);
218  }
219 
220  void initialize()
221  {
222  Analysis<batch>::_ac = new __DAAL_ALGORITHM_LAYER_CONTAINER(BatchContainer, algorithmFPType, method)(&_env);
223  _in = &input;
224  _par = &parameter;
225  _result.reset(new ResultType());
226  }
227 
228 private:
229  ResultPtr _result;
230  ParameterType _defaultParameter;
231 };
232 
234 } // namespace interface1
235 using interface1::BatchContainer;
236 using interface1::Batch;
237 } // namespace forward
238 } // namespace convolution2d
239 } // namespace layers
240 } // namespace neural_networks
241 } // namespace algorithms
242 } // namespace daal
243 #endif
daal
Definition: algorithm_base_common.h:31
daal::algorithms::neural_networks::layers::convolution2d::forward::interface1::Batch::getResult
ResultPtr getResult()
Definition: convolution2d_layer_forward.h:178
daal::algorithms::neural_networks::layers::convolution2d::forward::interface1::Batch::Batch
Batch(const Batch< algorithmFPType, method > &other)
Definition: convolution2d_layer_forward.h:141
daal::algorithms::neural_networks::layers::convolution2d::forward::interface1::Batch::getLayerResult
layers::forward::ResultPtr getLayerResult() DAAL_C11_OVERRIDE
Definition: convolution2d_layer_forward.h:169
daal::algorithms::neural_networks::layers::convolution2d::forward::interface1::Batch::Batch
Batch(ParameterType &parameter)
Definition: convolution2d_layer_forward.h:131
daal::algorithms::neural_networks::layers::convolution2d::forward::interface1::Input
Input objects for the forward 2D convolution layer
Definition: convolution2d_layer_forward_types.h:63
daal::algorithms::neural_networks::layers::convolution2d::forward::interface1::Batch::parameter
ParameterType & parameter
Definition: convolution2d_layer_forward.h:117
daal_defines.h
daal::algorithms::neural_networks::layers::convolution2d::forward::interface1::Batch::input
InputType input
Definition: convolution2d_layer_forward.h:118
daal::algorithms::neural_networks::layers::convolution2d::forward::interface1::Batch
Provides methods for forward 2D convolution layer computations in the batch processing mode...
Definition: convolution2d_layer_forward.h:108
daal::algorithms::neural_networks::layers::convolution2d::forward::interface1::Batch::Batch
Batch()
Definition: convolution2d_layer_forward.h:121
daal::algorithms::neural_networks::layers::convolution2d::forward::interface1::BatchContainer
Provides methods to run implementations of the forward 2D convolution layer. This class is associated...
Definition: convolution2d_layer_forward.h:63
daal::algorithms::neural_networks::layers::convolution2d::forward::interface1::Batch::getMethod
virtual int getMethod() const DAAL_C11_OVERRIDE
Definition: convolution2d_layer_forward.h:151
daal::algorithms::neural_networks::layers::convolution2d::forward::interface1::Batch::setResult
services::Status setResult(const ResultPtr &result)
Definition: convolution2d_layer_forward.h:189
daal::algorithms::neural_networks::layers::convolution2d::forward::interface1::Batch::clone
services::SharedPtr< Batch< algorithmFPType, method > > clone() const
Definition: convolution2d_layer_forward.h:202
daal::algorithms::neural_networks::layers::convolution2d::forward::interface1::Batch::getLayerInput
virtual InputType * getLayerInput() DAAL_C11_OVERRIDE
Definition: convolution2d_layer_forward.h:157
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::convolution2d::forward::interface1::Input::allocate
DAAL_EXPORT services::Status allocate(const daal::algorithms::Parameter *parameter, const int method)
daal::services::ErrorNullResult
Definition: error_indexes.h:96
daal::algorithms::neural_networks::layers::convolution2d::forward::interface1::Batch::getLayerParameter
virtual ParameterType * getLayerParameter() DAAL_C11_OVERRIDE
Definition: convolution2d_layer_forward.h:163

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