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

layer_forward.h
1 /* file: layer_forward.h */
2 /*******************************************************************************
3 * Copyright 2014-2018 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 neural network layer.
45 //--
46 */
47 
48 #ifndef __LAYER_FORWARD_H__
49 #define __LAYER_FORWARD_H__
50 
51 #include "algorithms/algorithm.h"
52 #include "data_management/data/tensor.h"
53 #include "services/daal_defines.h"
54 #include "algorithms/neural_networks/layers/layer_forward_types.h"
55 #include "layer_forward_container_base.h"
56 
57 namespace daal
58 {
59 namespace algorithms
60 {
64 namespace neural_networks
65 {
69 namespace layers
70 {
74 namespace forward
75 {
76 namespace interface1
77 {
86 class LayerIface : public daal::algorithms::Analysis<batch>
87 {
88 public:
89  typedef algorithms::neural_networks::layers::forward::Input InputType;
90  typedef algorithms::neural_networks::layers::Parameter ParameterType;
91  typedef algorithms::neural_networks::layers::forward::Result ResultType;
92 
93  virtual ~LayerIface() {};
94 
99  virtual forward::ResultPtr getLayerResult() = 0;
100 
105  virtual InputType *getLayerInput() = 0;
106 
111  virtual ParameterType *getLayerParameter() = 0;
112 
118  daal::algorithms::neural_networks::layers::forward::LayerIfacePtr clone() const
119  {
120  return LayerIfacePtr(cloneImpl());
121  }
122 
126  virtual services::Status allocateResult() = 0;
127 
131  virtual services::Status allocateInput() = 0;
132 
136  virtual services::Status initializeInput() = 0;
146  virtual services::Status addInput(forward::ResultPtr result, size_t resultIndex, size_t inputIndex) = 0;
147 
152  virtual layers::forward::LayerIfacePtr getLayerForPrediction() const = 0;
153 
154 protected:
155  virtual LayerIface *cloneImpl() const = 0;
156 };
157 
158 typedef services::SharedPtr<LayerIface> LayerIfacePtr;
169 class LayerIfaceImpl : public LayerIface
170 {
171 public:
172  typedef LayerIface super;
173 
174  typedef super::InputType InputType;
175  typedef super::ParameterType ParameterType;
176  typedef super::ResultType ResultType;
177 
178  virtual ~LayerIfaceImpl() {};
179 
183  virtual services::Status allocateInput() DAAL_C11_OVERRIDE
184  {
185  this->_ac->setArguments(this->_in, this->_res, this->_par);
186  LayerContainerIfaceImpl *ac = dynamic_cast<LayerContainerIfaceImpl *>(_ac);
187  return ac->allocateInput();
188  }
189 
193  virtual services::Status initializeInput() DAAL_C11_OVERRIDE
194  {
195  this->_ac->setArguments(this->_in, this->_res, this->_par);
196  setParameter();
197  LayerContainerIfaceImpl *ac = dynamic_cast<LayerContainerIfaceImpl *>(_ac);
198  return ac->initializeInput();
199  }
200 
204  virtual services::Status addInput(forward::ResultPtr result, size_t resultIndex, size_t inputIndex) DAAL_C11_OVERRIDE
205  {
206  return getLayerInput()->addData(result->getValue(resultIndex), inputIndex);
207  }
208 
213  virtual layers::forward::LayerIfacePtr getLayerForPrediction() const DAAL_C11_OVERRIDE
214  {
215  return this->clone();
216  }
217 
218 protected:
219  virtual void setParameter() DAAL_C11_OVERRIDE
220  {
221  if(this->getLayerParameter())
222  {
223  this->getLayerParameter()->weightsInitializer->getParameter()->layer = services::SharedPtr<LayerIface>(this, services::EmptyDeleter());
224  this->getLayerParameter()->biasesInitializer->getParameter()->layer = services::SharedPtr<LayerIface>(this, services::EmptyDeleter());
225  }
226  }
227 };
228 
229 typedef services::SharedPtr<LayerIfaceImpl> LayerIfaceImplPtr;
231 } // namespace interface1
232 using interface1::LayerIface;
233 using interface1::LayerIfacePtr;
234 using interface1::LayerIfaceImpl;
235 using interface1::LayerIfaceImplPtr;
236 
237 } // namespace forward
238 } // namespace layers
239 } // namespace neural_networks
240 } // namespace algorithms
241 } // namespace daal
242 #endif
daal::algorithms::neural_networks::layers::forward::interface1::LayerIface::getLayerForPrediction
virtual layers::forward::LayerIfacePtr getLayerForPrediction() const =0
daal::algorithms::neural_networks::layers::forward::interface1::LayerIfaceImpl::initializeInput
virtual services::Status initializeInput() DAAL_C11_OVERRIDE
Definition: layer_forward.h:193
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::layers::forward::interface1::LayerIfaceImpl::addInput
virtual services::Status addInput(forward::ResultPtr result, size_t resultIndex, size_t inputIndex) DAAL_C11_OVERRIDE
Definition: layer_forward.h:204
daal::algorithms::neural_networks::layers::forward::interface1::LayerIface::getLayerResult
virtual forward::ResultPtr getLayerResult()=0
daal::algorithms::neural_networks::layers::forward::interface1::LayerContainerIfaceImpl::initializeInput
virtual services::Status initializeInput()
daal::algorithms::neural_networks::layers::interface1::Parameter
Definition: layer_types.h:110
daal::algorithms::neural_networks::layers::forward::interface1::LayerIface
Abstract class which defines interface for the layer.
Definition: layer_forward.h:86
daal::algorithms::neural_networks::layers::forward::interface1::LayerIfaceImpl::allocateInput
virtual services::Status allocateInput() DAAL_C11_OVERRIDE
Definition: layer_forward.h:183
daal::algorithms::neural_networks::layers::forward::interface1::LayerIface::addInput
virtual services::Status addInput(forward::ResultPtr result, size_t resultIndex, size_t inputIndex)=0
daal::algorithms::neural_networks::layers::forward::interface1::Input::addData
virtual services::Status addData(const data_management::TensorPtr &dataTensor, size_t index)
daal_defines.h
daal::algorithms::neural_networks::layers::forward::interface1::LayerIface::getLayerParameter
virtual ParameterType * getLayerParameter()=0
daal::algorithms::neural_networks::layers::forward::interface1::LayerIfaceImpl::getLayerForPrediction
virtual layers::forward::LayerIfacePtr getLayerForPrediction() const DAAL_C11_OVERRIDE
Definition: layer_forward.h:213
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::layers::interface1::Parameter::weightsInitializer
initializers::InitializerIfacePtr weightsInitializer
Definition: layer_types.h:117
daal::algorithms::neural_networks::layers::forward::interface1::Result
Provides methods to access the result obtained with the compute() method of the layer algorithm...
Definition: layer_forward_types.h:241
daal::algorithms::neural_networks::layers::forward::interface1::LayerIface::clone
daal::algorithms::neural_networks::layers::forward::LayerIfacePtr clone() const
Definition: layer_forward.h:118
daal::algorithms::neural_networks::layers::forward::interface1::LayerIface::getLayerInput
virtual InputType * getLayerInput()=0
daal::algorithms::neural_networks::layers::forward::interface1::LayerIface::initializeInput
virtual services::Status initializeInput()=0
daal::algorithms::neural_networks::layers::forward::interface1::LayerIface::allocateInput
virtual services::Status allocateInput()=0
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::interface1::Parameter::biasesInitializer
initializers::InitializerIfacePtr biasesInitializer
Definition: layer_types.h:119
daal::algorithms::neural_networks::layers::forward::interface1::Input
Input objects for layer algorithm
Definition: layer_forward_types.h:149
daal::algorithms::neural_networks::layers::forward::interface1::LayerIface::allocateResult
virtual services::Status allocateResult()=0
daal::algorithms::neural_networks::layers::forward::interface1::LayerContainerIfaceImpl
Provides methods of base container for forward layers. This class is associated with the daal::algori...
Definition: layer_forward_container_base.h:86
daal::services::interface1::EmptyDeleter
Implementation of DeleterIface without pointer destroying.
Definition: daal_shared_ptr.h:125
daal::algorithms::neural_networks::layers::forward::interface1::LayerContainerIfaceImpl::allocateInput
virtual services::Status allocateInput()
daal::algorithms::neural_networks::layers::forward::interface1::LayerIfaceImpl
Implements the abstract interface LayerIface. LayerIfaceImpl is, in turn, the base class for the clas...
Definition: layer_forward.h:169

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