1/*******************************************************************************
2* Copyright 2016-2018 Intel Corporation
3*
4* Licensed under the Apache License, Version 2.0 (the "License");
5* you may not use this file except in compliance with the License.
6* You may obtain a copy of the License at
7*
8* http://www.apache.org/licenses/LICENSE-2.0
9*
10* Unless required by applicable law or agreed to in writing, software
11* distributed under the License is distributed on an "AS IS" BASIS,
12* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13* See the License for the specific language governing permissions and
14* limitations under the License.
15*******************************************************************************/
16
17#ifndef PRIMITIVE_HPP
18#define PRIMITIVE_HPP
19
20#include <assert.h>
21
22#include "mkldnn.h"
23
24#include "c_types_map.hpp"
25#include "nstl.hpp"
26#include "primitive_desc.hpp"
27#include "primitive_exec_types.hpp"
28
29/** \brief A pure virtual primitive class
30 *
31 * Primitive contains links to its inputs & outputs, though it does not track
32 * their readiness on execution step.
33 *
34 * @remark @b Rational.
35 * Dependencies are essential through-out the whole MKL-DNN library, so it
36 * makes sense to include them on the very low level. On the other hand,
37 * tracking them should be a task for corresponding essence, like scheduler,
38 * stream or whatever. Primitive itself should know nothing about the
39 * environment it is running in.
40 *
41 * @note
42 * To make user experience better we should provide API which allows
43 * achieving the best (or good enough) performance when creating primitives
44 * in natural order: i.e. from bottom to top for forward pass and from top to
45 * bottom for backward pass. Please consider restriction [1] in Level 0.
46 */
47struct mkldnn_primitive: public mkldnn::impl::c_compatible {
48 mkldnn_primitive(const mkldnn::impl::primitive_desc_t *pd)
49 : pd_(pd->clone()) {}
50 virtual ~mkldnn_primitive() { delete pd_; }
51
52 /** returns primitive's engine */
53 mkldnn::impl::engine_t *engine() const { return pd_->engine(); }
54 /** returns primitive's inputs */
55 const mkldnn::impl::primitive_desc_t *pd() const { return pd_; }
56 /** returns primitive's kind */
57 mkldnn::impl::primitive_kind_t kind() const { return pd_->kind(); }
58
59 /** executes primitive with execution context @p ctx */
60 virtual mkldnn::impl::status_t execute(const mkldnn::impl::exec_ctx_t &ctx)
61 const = 0;
62
63protected:
64 const mkldnn::impl::primitive_desc_t *pd_;
65
66private:
67 mkldnn_primitive() = delete;
68 mkldnn_primitive(const mkldnn_primitive &) = delete;
69 mkldnn_primitive(mkldnn_primitive &&) = delete;
70 mkldnn_primitive &operator=(const mkldnn_primitive &) = delete;
71 mkldnn_primitive &operator=(mkldnn_primitive &&) = delete;
72};
73
74#endif
75
76// vim: et ts=4 sw=4 cindent cino^=l0,\:0,N-s
77