1 /*******************************************************************************
2 * Copyright 2016-2018 Intel Corporation
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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 *******************************************************************************/
24 #include "c_types_map.hpp"
27 #include "primitive_desc.hpp"
29 /** \brief A pure virtual primitive class
31 * Primitive contains links to its inputs & outputs, though it does not track
32 * their readiness on execution step.
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.
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.
47 struct mkldnn_primitive: public mkldnn::impl::c_compatible {
48 typedef mkldnn::impl::nstl::vector<mkldnn::impl::primitive_at_t>
50 typedef mkldnn::impl::nstl::vector<const mkldnn::impl::primitive_t *>
53 mkldnn_primitive(const mkldnn::impl::primitive_desc_t *pd,
54 const input_vector &inputs, const output_vector &outputs)
59 virtual ~mkldnn_primitive() { delete pd_; }
61 /** returns primitive's engine */
62 mkldnn::impl::engine_t *engine() const { return pd_->engine(); }
63 /** returns primitive's inputs */
64 const input_vector &inputs() const { return inputs_; }
65 /** returns primitive's outputs */
66 const output_vector &outputs() const { return outputs_; }
67 /** returns primitive's primitive desc */
68 const mkldnn::impl::primitive_desc_t *pd() const { return pd_; }
69 /** returns primitive's kind */
70 mkldnn::impl::primitive_kind_t kind() const { return pd_->kind(); }
72 /** executes primitive with resulting event @p e
75 * a resulting event. It is primitive responsibility to set @p e state
76 * after actual computations are done
78 * @remark @b Rational.
79 * Suppose engine has a task pool and for some reasons submission failed.
80 * In this case primitive will set @p e's state to event::error
82 virtual void execute(mkldnn::impl::event_t *e) const = 0;
84 /** returns data handle. Applicable for memory primitives only. */
85 virtual mkldnn::impl::status_t get_data_handle(void **handle) const {
87 assert(this->kind() == mkldnn::impl::primitive_kind::memory);
88 return mkldnn::impl::status::invalid_arguments;
90 /** sets data handle. Applicable for memory primitives only. */
91 virtual mkldnn::impl::status_t set_data_handle(void *handle) {
93 assert(this->kind() == mkldnn::impl::primitive_kind::memory);
94 return mkldnn::impl::status::invalid_arguments;
98 const mkldnn::impl::primitive_desc_t *pd_;
100 output_vector outputs_;
103 mkldnn_primitive() = delete;
104 mkldnn_primitive(const mkldnn_primitive &) = delete;
105 mkldnn_primitive(mkldnn_primitive &&) = delete;
106 mkldnn_primitive &operator=(const mkldnn_primitive &) = delete;
107 mkldnn_primitive &operator=(mkldnn_primitive &&) = delete;
112 // vim: et ts=4 sw=4 cindent cino^=l0,\:0,N-s