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

softmax_layer_forward.h
1 /* file: softmax_layer_forward.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 forward softmax layer in the batch
21 // processing mode
22 //--
23 */
24 
25 #ifndef __SOFTMAX_LAYER_FORWARD_H__
26 #define __SOFTMAX_LAYER_FORWARD_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_forward_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 forward
46 {
47 namespace interface1
48 {
59 template<typename algorithmFPType, Method method, CpuType cpu>
60 class BatchContainer : public layers::forward::LayerContainerIfaceImpl
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 
101 template<typename algorithmFPType = DAAL_ALGORITHM_FP_TYPE, Method method = defaultDense>
102 class Batch : public layers::forward::LayerIfaceImpl
103 {
104 public:
105  typedef layers::forward::LayerIfaceImpl super;
106 
107  typedef algorithms::neural_networks::layers::softmax::forward::Input InputType;
108  typedef algorithms::neural_networks::layers::softmax::Parameter ParameterType;
109  typedef algorithms::neural_networks::layers::softmax::forward::Result ResultType;
110 
111  ParameterType &parameter;
112  InputType input;
118  Batch() : parameter(_defaultParameter)
119  {
120  initialize();
121  };
122 
129  DAAL_DEPRECATED Batch(ParameterType& parameter) : parameter(parameter), _defaultParameter(parameter)
130  {
131  initialize();
132  }
133 
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 
203  services::SharedPtr<Batch<algorithmFPType, method> > clone() const
204  {
205  return services::SharedPtr<Batch<algorithmFPType, method> >(cloneImpl());
206  }
207 
213  virtual services::Status allocateResult() DAAL_C11_OVERRIDE
214  {
215  services::Status s = this->_result->template allocate<algorithmFPType>(&(this->input), &parameter, (int) method);
216  this->_res = this->_result.get();
217  return s;
218  }
219 
220 protected:
221  virtual Batch<algorithmFPType, method> *cloneImpl() const DAAL_C11_OVERRIDE
222  {
223  return new Batch<algorithmFPType, method>(*this);
224  }
225 
226  void initialize()
227  {
228  Analysis<batch>::_ac = new __DAAL_ALGORITHM_LAYER_CONTAINER(BatchContainer, algorithmFPType, method)(&_env);
229  _in = &input;
230  _par = &parameter;
231  _result.reset(new ResultType());
232  }
233 
234 private:
235  ResultPtr _result;
236  ParameterType _defaultParameter;
237 };
239 } // namespace interface1
240 using interface1::BatchContainer;
241 using interface1::Batch;
242 } // namespace forward
243 } // namespace softmax
244 } // namespace layers
245 } // namespace neural_networks
246 } // namespace algorithms
247 } // namespace daal
248 #endif
daal::algorithms::neural_networks::layers::softmax::forward::interface1::BatchContainer
Class containing methods for the forward softmax layer using algorithmFPType precision arithmetic...
Definition: softmax_layer_forward.h:60
daal::algorithms::neural_networks::layers::softmax::forward::interface1::Batch::getLayerInput
virtual InputType * getLayerInput() DAAL_C11_OVERRIDE
Definition: softmax_layer_forward.h:157
daal::algorithms::neural_networks::layers::softmax::forward::interface1::Batch::Batch
Batch()
Definition: softmax_layer_forward.h:118
daal::algorithms::neural_networks::layers::softmax::forward::interface1::Batch::getMethod
virtual int getMethod() const DAAL_C11_OVERRIDE
Definition: softmax_layer_forward.h:151
daal::algorithms::neural_networks::layers::softmax::forward::interface1::Batch::input
InputType input
Definition: softmax_layer_forward.h:112
daal::algorithms::neural_networks::layers::softmax::forward::interface1::BatchContainer::~BatchContainer
DAAL_DEPRECATED ~BatchContainer()
daal::services::ErrorNullResult
Definition: error_indexes.h:98
daal::algorithms::neural_networks::layers::softmax::forward::interface1::Batch::clone
services::SharedPtr< Batch< algorithmFPType, method > > clone() const
Definition: softmax_layer_forward.h:203
daal::algorithms::neural_networks::layers::softmax::forward::interface1::BatchContainer::BatchContainer
DAAL_DEPRECATED BatchContainer(daal::services::Environment::env *daalEnv)
daal_defines.h
daal::algorithms::neural_networks::layers::softmax::forward::interface1::Batch::getLayerParameter
virtual ParameterType * getLayerParameter() DAAL_C11_OVERRIDE
Definition: softmax_layer_forward.h:163
daal::algorithms::neural_networks::layers::softmax::forward::interface1::Batch::Batch
Batch(const Batch< algorithmFPType, method > &other)
Definition: softmax_layer_forward.h:141
daal::algorithms::neural_networks::layers::softmax::forward::interface1::Batch::getLayerResult
layers::forward::ResultPtr getLayerResult() DAAL_C11_OVERRIDE
Definition: softmax_layer_forward.h:169
daal::algorithms::neural_networks::layers::softmax::forward::interface1::Batch
Computes the results of the forward softmax layer in the batch processing mode.
Definition: softmax_layer_forward.h:102
daal::algorithms::neural_networks::layers::softmax::forward::interface1::Batch::Batch
DAAL_DEPRECATED Batch(ParameterType &parameter)
Definition: softmax_layer_forward.h:129
daal::algorithms::neural_networks::layers::softmax::forward::interface1::Batch::parameter
ParameterType & parameter
Definition: softmax_layer_forward.h:111
daal::algorithms::neural_networks::layers::softmax::forward::interface1::BatchContainer::compute
services::Status compute() DAAL_C11_OVERRIDE
daal::algorithms::neural_networks::layers::softmax::forward::interface1::Batch::setResult
services::Status setResult(const ResultPtr &result)
Definition: softmax_layer_forward.h:189
daal::algorithms::neural_networks::layers::softmax::forward::interface1::Batch::allocateResult
virtual services::Status allocateResult() DAAL_C11_OVERRIDE
Definition: softmax_layer_forward.h:213
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::forward::interface1::Batch::getResult
ResultPtr getResult()
Definition: softmax_layer_forward.h:178

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