1 | /******************************************************************************* |
2 | * Copyright 2019-2022 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 GPU_GPU_REORDER_PD_HPP |
18 | #define GPU_GPU_REORDER_PD_HPP |
19 | |
20 | #include "common/reorder_pd.hpp" |
21 | |
22 | namespace dnnl { |
23 | namespace impl { |
24 | namespace gpu { |
25 | |
26 | struct gpu_reorder_pd_t : public reorder_pd_t { |
27 | using reorder_pd_t::reorder_pd_t; |
28 | |
29 | protected: |
30 | bool attr_ok() const { |
31 | return attr()->has_default_values( |
32 | dnnl_primitive_attr::skip_mask_t::zero_points_runtime |
33 | | dnnl_primitive_attr::skip_mask_t::scales_runtime |
34 | | dnnl_primitive_attr::skip_mask_t::post_ops) |
35 | && post_ops_ok(); |
36 | } |
37 | |
38 | bool post_ops_ok() const { |
39 | const auto &post_ops = attr()->post_ops_; |
40 | return post_ops.len() == 0 |
41 | || (post_ops.len() == 1 |
42 | && post_ops.entry_[0].kind == primitive_kind::sum); |
43 | } |
44 | |
45 | bool () const { |
46 | return src_md()->extra.flags == 0 && dst_md()->extra.flags == 0; |
47 | } |
48 | }; |
49 | |
50 | } // namespace gpu |
51 | } // namespace impl |
52 | } // namespace dnnl |
53 | |
54 | #define DECLARE_GPU_REORDER_CREATE() \ |
55 | static status_t create(reorder_pd_t **reorder_pd, engine_t *engine, \ |
56 | const primitive_attr_t *attr, engine_t *src_engine, \ |
57 | const memory_desc_t *src_md, engine_t *dst_engine, \ |
58 | const memory_desc_t *dst_md) { \ |
59 | auto _pd = new pd_t( \ |
60 | attr, src_engine->kind(), src_md, dst_engine->kind(), dst_md); \ |
61 | if (_pd == nullptr) return status::out_of_memory; \ |
62 | if (_pd->init(engine, src_engine, dst_engine) != status::success) { \ |
63 | delete _pd; \ |
64 | return status::unimplemented; \ |
65 | } \ |
66 | _pd->init_scratchpad_md(); \ |
67 | return safe_ptr_assign(*reorder_pd, _pd); \ |
68 | } \ |
69 | friend dnnl::impl::impl_list_item_t; |
70 | |
71 | #endif |
72 | |