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

layer_forward.h
1 /* file: 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 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  virtual ~LayerIface() {};
90 
95  virtual forward::ResultPtr getLayerResult() = 0;
96 
101  virtual Input *getLayerInput() = 0;
102 
107  virtual Parameter *getLayerParameter() = 0;
108 
114  daal::algorithms::neural_networks::layers::forward::LayerIfacePtr clone() const
115  {
116  return LayerIfacePtr(cloneImpl());
117  }
118 
122  virtual services::Status allocateResult() = 0;
123 
127  virtual services::Status allocateInput() = 0;
128 
132  virtual services::Status initializeInput() = 0;
142  virtual services::Status addInput(forward::ResultPtr result, size_t resultIndex, size_t inputIndex) = 0;
143 
148  virtual layers::forward::LayerIfacePtr getLayerForPrediction() const = 0;
149 
150 protected:
151  virtual LayerIface *cloneImpl() const = 0;
152 };
153 
154 typedef services::SharedPtr<LayerIface> LayerIfacePtr;
165 class LayerIfaceImpl : public LayerIface
166 {
167 public:
168  virtual ~LayerIfaceImpl() {};
169 
173  virtual services::Status allocateInput() DAAL_C11_OVERRIDE
174  {
175  this->_ac->setArguments(this->_in, this->_res, this->_par);
176  LayerContainerIfaceImpl *ac = dynamic_cast<LayerContainerIfaceImpl *>(_ac);
177  return ac->allocateInput();
178  }
179 
183  virtual services::Status initializeInput() DAAL_C11_OVERRIDE
184  {
185  this->_ac->setArguments(this->_in, this->_res, this->_par);
186  setParameter();
187  LayerContainerIfaceImpl *ac = dynamic_cast<LayerContainerIfaceImpl *>(_ac);
188  return ac->initializeInput();
189  }
190 
194  virtual services::Status addInput(forward::ResultPtr result, size_t resultIndex, size_t inputIndex) DAAL_C11_OVERRIDE
195  {
196  return getLayerInput()->addData(result->getValue(resultIndex), inputIndex);
197  }
198 
203  virtual layers::forward::LayerIfacePtr getLayerForPrediction() const DAAL_C11_OVERRIDE
204  {
205  return this->clone();
206  }
207 
208 protected:
209  virtual void setParameter() DAAL_C11_OVERRIDE
210  {
211  if(this->getLayerParameter())
212  {
213  this->getLayerParameter()->weightsInitializer->getParameter()->layer = services::SharedPtr<LayerIface>(this, services::EmptyDeleter());
214  this->getLayerParameter()->biasesInitializer->getParameter()->layer = services::SharedPtr<LayerIface>(this, services::EmptyDeleter());
215  }
216  }
217 };
218 
219 typedef services::SharedPtr<LayerIfaceImpl> LayerIfaceImplPtr;
221 } // namespace interface1
222 using interface1::LayerIface;
223 using interface1::LayerIfacePtr;
224 using interface1::LayerIfaceImpl;
225 using interface1::LayerIfaceImplPtr;
226 
227 } // namespace forward
228 } // namespace layers
229 } // namespace neural_networks
230 } // namespace algorithms
231 } // namespace daal
232 #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:183
daal::algorithms::neural_networks::layers::forward::interface1::LayerIface::getLayerInput
virtual Input * getLayerInput()=0
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:194
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::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:173
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::LayerIfaceImpl::getLayerForPrediction
virtual layers::forward::LayerIfacePtr getLayerForPrediction() const DAAL_C11_OVERRIDE
Definition: layer_forward.h:203
daal::algorithms::neural_networks::layers::forward::interface1::LayerIface::getLayerParameter
virtual Parameter * getLayerParameter()=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::neural_networks::layers::forward::interface1::LayerIface::clone
daal::algorithms::neural_networks::layers::forward::LayerIfacePtr clone() const
Definition: layer_forward.h:114
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::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::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:165

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