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

algorithm_container_base_common.h
1 /* file: algorithm_container_base_common.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 base classes defining algorithm interface.
45 //--
46 */
47 
48 #ifndef __ALGORITHM_CONTAINER_BASE_COMMON_H__
49 #define __ALGORITHM_CONTAINER_BASE_COMMON_H__
50 
51 #include "services/daal_memory.h"
52 #include "services/daal_kernel_defines.h"
53 #include "services/error_handling.h"
54 #include "services/env_detect.h"
55 #include "algorithms/algorithm_types.h"
56 #include "algorithms/algorithm_kernel.h"
57 
58 namespace daal
59 {
60 namespace algorithms
61 {
62 
70 namespace interface1
71 {
72 
79 class AlgorithmContainerIface
80 {
81 public:
82  DAAL_NEW_DELETE();
83 
84  virtual ~AlgorithmContainerIface() {}
85 };
86 
93 class AlgorithmContainerIfaceImpl : public AlgorithmContainerIface
94 {
95 public:
100  AlgorithmContainerIfaceImpl(daal::services::Environment::env *daalEnv) : _env(daalEnv), _kernel(NULL) {}
101 
102  virtual ~AlgorithmContainerIfaceImpl() {}
103 
108  void setEnvironment(daal::services::Environment::env *daalEnv)
109  {
110  _env = daalEnv;
111  }
112 
113 protected:
114  daal::services::Environment::env *_env;
115  Kernel *_kernel;
116 };
117 
127 template<ComputeMode mode> class AlgorithmContainer : public AlgorithmContainerIfaceImpl
128 {
129 public:
134  AlgorithmContainer(daal::services::Environment::env *daalEnv) : AlgorithmContainerIfaceImpl(daalEnv) {}
135 
136  virtual ~AlgorithmContainer() {}
137 
143  virtual services::Status compute() = 0;
144 
149  virtual services::Status finalizeCompute() = 0;
150 
154  virtual services::Status setupCompute() = 0;
155 
159  virtual services::Status resetCompute() = 0;
160 
164  virtual services::Status setupFinalizeCompute() = 0;
165 
169  virtual services::Status resetFinalizeCompute() = 0;
170 };
171 
181 template<ComputeMode mode> class AlgorithmContainerImpl : public AlgorithmContainer<mode>
182 {
183 public:
188  AlgorithmContainerImpl(daal::services::Environment::env *daalEnv = 0) : AlgorithmContainer<mode>(daalEnv), _in(0), _pres(0), _res(0), _par(0) {}
189 
190  virtual ~AlgorithmContainerImpl() {}
191 
198  void setArguments(Input *in, PartialResult *pres, Parameter *par)
199  {
200  _in = in;
201  _pres = pres;
202  _par = par;
203  }
204 
209  void setPartialResult(PartialResult *pres)
210  {
211  _pres = pres;
212  }
213 
218  void setResult(Result *res)
219  {
220  _res = res;
221  }
222 
227  Result *getResult() const
228  {
229  return _res;
230  }
231 
232  virtual services::Status setupCompute() DAAL_C11_OVERRIDE { return services::Status(); }
233 
234  virtual services::Status resetCompute() DAAL_C11_OVERRIDE { return services::Status(); }
235 
236  virtual services::Status setupFinalizeCompute() DAAL_C11_OVERRIDE { return services::Status(); }
237 
238  virtual services::Status resetFinalizeCompute() DAAL_C11_OVERRIDE { return services::Status(); }
239 
240 protected:
241  Input *_in;
242  PartialResult *_pres;
243  Result *_res;
244  Parameter *_par;
245 };
246 
262 template<ComputeMode mode,
263  typename sse2Container
264  DAAL_KERNEL_SSSE3_ONLY(typename ssse3Container)
265  DAAL_KERNEL_SSE42_ONLY(typename sse42Container)
266  DAAL_KERNEL_AVX_ONLY(typename avxContainer)
267  DAAL_KERNEL_AVX2_ONLY(typename avx2Container)
268  DAAL_KERNEL_AVX512_mic_ONLY(typename avx512_micContainer)
269  DAAL_KERNEL_AVX512_ONLY(typename avx512Container)
270 >
271 class DAAL_EXPORT AlgorithmDispatchContainer : public AlgorithmContainerImpl<mode>
272 {
273 public:
278  AlgorithmDispatchContainer(daal::services::Environment::env *daalEnv);
279 
280  virtual ~AlgorithmDispatchContainer() { delete _cntr; }
281 
282  virtual services::Status compute() DAAL_C11_OVERRIDE
283  {
284  _cntr->setArguments(this->_in, this->_pres, this->_par);
285  return _cntr->compute();
286  }
287 
288  virtual services::Status finalizeCompute() DAAL_C11_OVERRIDE
289  {
290  _cntr->setArguments(this->_in, this->_pres, this->_par);
291  _cntr->setResult(this->_res);
292  return _cntr->finalizeCompute();
293  }
294 
295  virtual services::Status setupCompute() DAAL_C11_OVERRIDE
296  {
297  _cntr->setArguments(this->_in, this->_pres, this->_par);
298  _cntr->setResult(this->_res);
299  return _cntr->setupCompute();
300  }
301 
302  virtual services::Status resetCompute() DAAL_C11_OVERRIDE
303  {
304  return _cntr->resetCompute();
305  }
306 
307 protected:
308  AlgorithmContainerImpl<mode> *_cntr;
309 };
310 
311 #define __DAAL_ALGORITHM_CONTAINER(Mode, ContainerTemplate, ...) \
312  AlgorithmDispatchContainer< Mode, \
313  ContainerTemplate<__VA_ARGS__, sse2> \
314  DAAL_KERNEL_SSSE3_CONTAINER(ContainerTemplate, __VA_ARGS__) \
315  DAAL_KERNEL_SSE42_CONTAINER(ContainerTemplate, __VA_ARGS__) \
316  DAAL_KERNEL_AVX_CONTAINER(ContainerTemplate, __VA_ARGS__) \
317  DAAL_KERNEL_AVX2_CONTAINER(ContainerTemplate, __VA_ARGS__) \
318  DAAL_KERNEL_AVX512_mic_CONTAINER(ContainerTemplate, __VA_ARGS__) \
319  DAAL_KERNEL_AVX512_CONTAINER(ContainerTemplate, __VA_ARGS__)>
320 
322 } // namespace interface1
323 using interface1::AlgorithmContainerImpl;
324 using interface1::AlgorithmDispatchContainer;
325 
326 }
327 }
328 #endif
daal::algorithms::interface1::AlgorithmContainerIfaceImpl::AlgorithmContainerIfaceImpl
AlgorithmContainerIfaceImpl(daal::services::Environment::env *daalEnv)
Definition: algorithm_container_base_common.h:100
daal::algorithms::interface1::AlgorithmContainer::setupCompute
virtual services::Status setupCompute()=0
daal::algorithms::interface1::AlgorithmContainerImpl::resetCompute
virtual services::Status resetCompute() DAAL_C11_OVERRIDE
Definition: algorithm_container_base_common.h:234
daal::algorithms::interface1::AlgorithmContainerImpl::AlgorithmContainerImpl
AlgorithmContainerImpl(daal::services::Environment::env *daalEnv=0)
Definition: algorithm_container_base_common.h:188
daal
Definition: algorithm_base_common.h:57
daal::algorithms::interface1::AlgorithmContainerImpl
Abstract interface class that provides virtual methods to access and run implementations of the algor...
Definition: algorithm_container_base_common.h:181
daal::algorithms::interface1::Result
Base class to represent final results of the computation. Algorithm-specific final results are repres...
Definition: algorithm_types.h:331
daal::algorithms::interface1::AlgorithmDispatchContainer::finalizeCompute
virtual services::Status finalizeCompute() DAAL_C11_OVERRIDE
Definition: algorithm_container_base_common.h:288
daal::algorithms::interface1::AlgorithmContainerImpl::setPartialResult
void setPartialResult(PartialResult *pres)
Definition: algorithm_container_base_common.h:209
daal::algorithms::interface1::AlgorithmDispatchContainer
Implements a container to dispatch algorithms to cpu-specific implementations.
Definition: algorithm_container_base_common.h:271
daal::algorithms::interface1::Kernel
Base class to represent algorithm implementation
Definition: algorithm_kernel.h:72
daal::algorithms::interface1::AlgorithmDispatchContainer::setupCompute
virtual services::Status setupCompute() DAAL_C11_OVERRIDE
Definition: algorithm_container_base_common.h:295
daal::algorithms::interface1::AlgorithmContainerImpl::getResult
Result * getResult() const
Definition: algorithm_container_base_common.h:227
daal::algorithms::interface1::PartialResult
Base class to represent partial results of the computation. Algorithm-specific partial results are re...
Definition: algorithm_types.h:253
daal::algorithms::interface1::AlgorithmDispatchContainer::compute
virtual services::Status compute() DAAL_C11_OVERRIDE
Definition: algorithm_container_base_common.h:282
daal::algorithms::interface1::AlgorithmContainer::AlgorithmContainer
AlgorithmContainer(daal::services::Environment::env *daalEnv)
Definition: algorithm_container_base_common.h:134
daal::algorithms::interface1::Parameter
Base class to represent computation parameters. Algorithm-specific parameters are represented as deri...
Definition: algorithm_types.h:86
daal::algorithms::interface1::AlgorithmContainerIfaceImpl::setEnvironment
void setEnvironment(daal::services::Environment::env *daalEnv)
Definition: algorithm_container_base_common.h:108
daal::algorithms::interface1::AlgorithmContainerImpl::setArguments
void setArguments(Input *in, PartialResult *pres, Parameter *par)
Definition: algorithm_container_base_common.h:198
daal::algorithms::interface1::AlgorithmContainer::finalizeCompute
virtual services::Status finalizeCompute()=0
daal::algorithms::interface1::AlgorithmContainerIfaceImpl
Implements the abstract interface AlgorithmContainerIfaceImpl. It is associated with the Algorithm cl...
Definition: algorithm_container_base_common.h:93
daal::algorithms::interface1::AlgorithmContainer::resetFinalizeCompute
virtual services::Status resetFinalizeCompute()=0
daal::algorithms::interface1::AlgorithmContainer::compute
virtual services::Status compute()=0
daal::algorithms::interface1::AlgorithmContainerIface
Implements the abstract interface AlgorithmContainerIface. It is associated with the Algorithm class ...
Definition: algorithm_container_base_common.h:79
daal::algorithms::interface1::AlgorithmContainer::resetCompute
virtual services::Status resetCompute()=0
daal::algorithms::interface1::AlgorithmContainerImpl::setupFinalizeCompute
virtual services::Status setupFinalizeCompute() DAAL_C11_OVERRIDE
Definition: algorithm_container_base_common.h:236
daal::algorithms::interface1::AlgorithmContainerImpl::resetFinalizeCompute
virtual services::Status resetFinalizeCompute() DAAL_C11_OVERRIDE
Definition: algorithm_container_base_common.h:238
daal::algorithms::interface1::AlgorithmContainerImpl::setResult
void setResult(Result *res)
Definition: algorithm_container_base_common.h:218
daal::algorithms::interface1::AlgorithmContainer
Abstract interface class that provides virtual methods to access and run implementations of the algor...
Definition: algorithm_container_base_common.h:127
daal::algorithms::interface1::Input
Base class to represent computation input arguments. Algorithm-specific input arguments are represent...
Definition: algorithm_types.h:217
daal::ComputeMode
ComputeMode
Definition: daal_defines.h:129
daal_kernel_defines.h
daal::algorithms::interface1::AlgorithmContainer::setupFinalizeCompute
virtual services::Status setupFinalizeCompute()=0
daal::algorithms::interface1::AlgorithmDispatchContainer::resetCompute
virtual services::Status resetCompute() DAAL_C11_OVERRIDE
Definition: algorithm_container_base_common.h:302
daal::algorithms::interface1::AlgorithmContainerImpl::setupCompute
virtual services::Status setupCompute() DAAL_C11_OVERRIDE
Definition: algorithm_container_base_common.h:232

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