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 REORDER_PD_HPP |
18 | #define REORDER_PD_HPP |
19 | |
20 | #include <assert.h> |
21 | |
22 | #include "c_types_map.hpp" |
23 | #include "primitive_attr.hpp" |
24 | #include "type_helpers.hpp" |
25 | #include "utils.hpp" |
26 | |
27 | namespace mkldnn { |
28 | namespace impl { |
29 | |
30 | struct reorder_pd_t: public primitive_desc_t { |
31 | reorder_pd_t(engine_t *engine, const primitive_attr_t *attr, |
32 | engine_t *src_engine, const memory_desc_t *src_md, |
33 | engine_t *dst_engine, const memory_desc_t *dst_md) |
34 | : primitive_desc_t(engine, attr, primitive_kind::reorder) |
35 | , src_engine_(src_engine) |
36 | , dst_engine_(dst_engine) |
37 | , scratchpad_engine_(nullptr) |
38 | , src_md_(*src_md) |
39 | , dst_md_(*dst_md) |
40 | {} |
41 | |
42 | virtual const op_desc_t *op_desc() const override { return nullptr; } |
43 | virtual void init_info() override { impl::init_info(this, this->info_); } |
44 | |
45 | virtual arg_usage_t arg_usage(primitive_arg_index_t arg) const override { |
46 | if (arg == MKLDNN_ARG_FROM) |
47 | return arg_usage_t::input; |
48 | |
49 | if (arg == MKLDNN_ARG_TO) |
50 | return arg_usage_t::output; |
51 | |
52 | return primitive_desc_t::arg_usage(arg); |
53 | } |
54 | |
55 | virtual const memory_desc_t *src_md(int index = 0) const override |
56 | { return index == 0 ? &src_md_ : nullptr; } |
57 | virtual const memory_desc_t *dst_md(int index = 0) const override |
58 | { return index == 0 ? &dst_md_ : nullptr; } |
59 | |
60 | virtual int n_inputs() const override { return 1; } |
61 | virtual int n_outputs() const override { return 1; } |
62 | |
63 | float alpha() const { return attr()->output_scales_.scales_[0]; } |
64 | float beta() const { |
65 | const int sum_idx = attr()->post_ops_.find(primitive_kind::sum); |
66 | return sum_idx == -1 ? 0 : attr()->post_ops_.entry_[sum_idx].sum.scale; |
67 | } |
68 | virtual mkldnn::impl::engine_t *scratchpad_engine() const override |
69 | { return scratchpad_engine_; } |
70 | |
71 | protected: |
72 | engine_t *src_engine_; |
73 | engine_t *dst_engine_; |
74 | engine_t *scratchpad_engine_; |
75 | |
76 | memory_desc_t src_md_; |
77 | memory_desc_t dst_md_; |
78 | }; |
79 | |
80 | } |
81 | } |
82 | |
83 | #endif |
84 | |
85 | // vim: et ts=4 sw=4 cindent cino^=l0,\:0,N-s |
86 | |