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

softmax_layer_backward.h
1 /* file: softmax_layer_backward.h */
2 /*******************************************************************************
3 * Copyright 2014-2020 Intel Corporation
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *******************************************************************************/
17 
18 /*
19 //++
20 // Implementation of the interface for the backward softmax layer in the batch
21 // processing mode
22 //--
23 */
24 
25 #ifndef __SOFTMAX_LAYER_BACKWARD_H__
26 #define __SOFTMAX_LAYER_BACKWARD_H__
27 
28 #include "algorithms/algorithm.h"
29 #include "data_management/data/tensor.h"
30 #include "services/daal_defines.h"
31 #include "algorithms/neural_networks/layers/layer.h"
32 #include "algorithms/neural_networks/layers/softmax/softmax_layer_types.h"
33 #include "algorithms/neural_networks/layers/softmax/softmax_layer_backward_types.h"
34 
35 namespace daal
36 {
37 namespace algorithms
38 {
39 namespace neural_networks
40 {
41 namespace layers
42 {
43 namespace softmax
44 {
45 namespace backward
46 {
47 namespace interface1
48 {
59 template<typename algorithmFPType, Method method, CpuType cpu>
60 class BatchContainer : public daal::algorithms::AnalysisContainerIface<batch>
61 {
62 public:
69  DAAL_DEPRECATED BatchContainer(daal::services::Environment::env *daalEnv);
74  DAAL_DEPRECATED ~BatchContainer();
80  services::Status compute() DAAL_C11_OVERRIDE;
81 };
82 
102 template<typename algorithmFPType = DAAL_ALGORITHM_FP_TYPE, Method method = defaultDense>
103 class Batch : public layers::backward::LayerIfaceImpl
104 {
105 public:
106  typedef layers::backward::LayerIfaceImpl super;
107 
108  typedef algorithms::neural_networks::layers::softmax::backward::Input InputType;
109  typedef algorithms::neural_networks::layers::softmax::Parameter ParameterType;
110  typedef algorithms::neural_networks::layers::softmax::backward::Result ResultType;
111 
112  ParameterType &parameter;
113  InputType input;
119  DAAL_DEPRECATED Batch() : parameter(_defaultParameter)
120  {
121  initialize();
122  }
123 
130  DAAL_DEPRECATED Batch(ParameterType& parameter) : parameter(parameter), _defaultParameter(parameter)
131  {
132  initialize();
133  }
134 
142  Batch(const Batch<algorithmFPType, method> &other) : super(other),
143  _defaultParameter(other.parameter), parameter(_defaultParameter), input(other.input)
144  {
145  initialize();
146  }
147 
152  virtual int getMethod() const DAAL_C11_OVERRIDE { return(int) method; }
153 
158  virtual InputType *getLayerInput() DAAL_C11_OVERRIDE { return &input; }
159 
164  virtual ParameterType *getLayerParameter() DAAL_C11_OVERRIDE { return &parameter; };
165 
170  layers::backward::ResultPtr getLayerResult() DAAL_C11_OVERRIDE
171  {
172  return _result;
173  }
174 
179  ResultPtr getResult()
180  {
181  return _result;
182  }
183 
190  services::Status setResult(const ResultPtr& result)
191  {
192  DAAL_CHECK(result, services::ErrorNullResult)
193  _result = result;
194  _res = _result.get();
195  return services::Status();
196  }
197 
204  services::SharedPtr<Batch<algorithmFPType, method> > clone() const
205  {
206  return services::SharedPtr<Batch<algorithmFPType, method> >(cloneImpl());
207  }
208 
214  virtual services::Status allocateResult() DAAL_C11_OVERRIDE
215  {
216  services::Status s = this->_result->template allocate<algorithmFPType>(&(this->input), &parameter, (int) method);
217  this->_res = this->_result.get();
218  return s;
219  }
220 
221 protected:
222  virtual Batch<algorithmFPType, method> *cloneImpl() const DAAL_C11_OVERRIDE
223  {
224  return new Batch<algorithmFPType, method>(*this);
225  }
226 
227  void initialize()
228  {
229  Analysis<batch>::_ac = new __DAAL_ALGORITHM_CONTAINER(batch, BatchContainer, algorithmFPType, method)(&_env);
230  _in = &input;
231  _par = &parameter;
232  _result.reset(new ResultType());
233  }
234 
235 private:
236  ResultPtr _result;
237  ParameterType _defaultParameter;
238 };
240 } // namespace interface1
241 using interface1::BatchContainer;
242 using interface1::Batch;
243 } // namespace backward
244 } // namespace softmax
245 } // namespace layers
246 } // namespace neural_networks
247 } // namespace algorithms
248 } // namespace daal
249 #endif
daal::algorithms::neural_networks::layers::softmax::backward::interface1::Batch::getLayerInput
virtual InputType * getLayerInput() DAAL_C11_OVERRIDE
Definition: softmax_layer_backward.h:158
daal::batch
Definition: daal_defines.h:112
daal::algorithms::neural_networks::layers::softmax::backward::interface1::BatchContainer
Class containing methods for the backward softmax layer using algorithmFPType precision arithmetic...
Definition: softmax_layer_backward.h:60
daal::algorithms::neural_networks::layers::softmax::backward::interface1::Batch
Computes the results of the backward softmax layer in the batch processing mode.
Definition: softmax_layer_backward.h:103
daal::algorithms::neural_networks::layers::softmax::backward::interface1::Batch::Batch
DAAL_DEPRECATED Batch()
Definition: softmax_layer_backward.h:119
daal::algorithms::neural_networks::layers::softmax::backward::interface1::Batch::getMethod
virtual int getMethod() const DAAL_C11_OVERRIDE
Definition: softmax_layer_backward.h:152
daal::algorithms::neural_networks::layers::softmax::backward::interface1::Batch::input
InputType input
Definition: softmax_layer_backward.h:113
daal::algorithms::neural_networks::layers::softmax::backward::interface1::Batch::clone
services::SharedPtr< Batch< algorithmFPType, method > > clone() const
Definition: softmax_layer_backward.h:204
daal::services::ErrorNullResult
Definition: error_indexes.h:98
daal::algorithms::AnalysisContainerIface
Abstract interface class that provides virtual methods to access and run implementations of the analy...
Definition: analysis.h:55
daal::algorithms::neural_networks::layers::softmax::backward::interface1::BatchContainer::BatchContainer
DAAL_DEPRECATED BatchContainer(daal::services::Environment::env *daalEnv)
daal::algorithms::neural_networks::layers::softmax::backward::interface1::Batch::getLayerResult
layers::backward::ResultPtr getLayerResult() DAAL_C11_OVERRIDE
Definition: softmax_layer_backward.h:170
daal::algorithms::neural_networks::layers::softmax::backward::interface1::Batch::getLayerParameter
virtual ParameterType * getLayerParameter() DAAL_C11_OVERRIDE
Definition: softmax_layer_backward.h:164
daal_defines.h
daal::algorithms::neural_networks::layers::softmax::backward::interface1::Batch::Batch
Batch(const Batch< algorithmFPType, method > &other)
Definition: softmax_layer_backward.h:142
daal::algorithms::neural_networks::layers::softmax::backward::interface1::BatchContainer::~BatchContainer
DAAL_DEPRECATED ~BatchContainer()
daal::algorithms::neural_networks::layers::softmax::backward::interface1::Batch::parameter
ParameterType & parameter
Definition: softmax_layer_backward.h:112
daal::algorithms::neural_networks::layers::softmax::backward::interface1::Batch::Batch
DAAL_DEPRECATED Batch(ParameterType &parameter)
Definition: softmax_layer_backward.h:130
daal::algorithms::neural_networks::layers::softmax::backward::interface1::Batch::allocateResult
virtual services::Status allocateResult() DAAL_C11_OVERRIDE
Definition: softmax_layer_backward.h:214
daal::algorithms::neural_networks::layers::softmax::backward::interface1::BatchContainer::compute
services::Status compute() DAAL_C11_OVERRIDE
daal::algorithms::neural_networks::layers::softmax::backward::interface1::Batch::setResult
services::Status setResult(const ResultPtr &result)
Definition: softmax_layer_backward.h:190
daal::algorithms::Analysis
Provides methods for execution of operations over data, such as computation of Summary Statistics est...
Definition: analysis.h:70
daal::algorithms::neural_networks::layers::softmax::backward::interface1::Batch::getResult
ResultPtr getResult()
Definition: softmax_layer_backward.h:179

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