1 | /******************************************************************************* |
2 | * Copyright 2020-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_XE_LP_X8S8S32X_1X1_CONVOLUTION_HPP |
18 | #define GPU_XE_LP_X8S8S32X_1X1_CONVOLUTION_HPP |
19 | |
20 | #include "common/c_types_map.hpp" |
21 | #include "gpu/compute/compute.hpp" |
22 | #include "gpu/gpu_convolution_pd.hpp" |
23 | #include "gpu/gpu_primitive.hpp" |
24 | #include "gpu/gpu_resource.hpp" |
25 | #include "gpu/ocl/ocl_stream.hpp" |
26 | #include "gpu/ocl/ocl_utils.hpp" |
27 | #include "gpu/primitive_conf.hpp" |
28 | |
29 | namespace dnnl { |
30 | namespace impl { |
31 | namespace gpu { |
32 | namespace ocl { |
33 | |
34 | struct xe_lp_x8s8x_1x1_convolution_fwd_t : public gpu_primitive_t { |
35 | using gpu_primitive_t::gpu_primitive_t; |
36 | struct pd_t : public gpu_convolution_fwd_pd_t { |
37 | pd_t(const convolution_desc_t *adesc, const primitive_attr_t *attr, |
38 | const convolution_fwd_pd_t *hint_fwd_pd) |
39 | : gpu_convolution_fwd_pd_t(adesc, attr, hint_fwd_pd) {} |
40 | |
41 | DECLARE_COMMON_PD_T("ocl:xe_lp:1x1" , xe_lp_x8s8x_1x1_convolution_fwd_t); |
42 | |
43 | status_t init(engine_t *engine) { |
44 | using namespace prop_kind; |
45 | using namespace data_type; |
46 | auto *compute_engine |
47 | = utils::downcast<compute::compute_engine_t *>(engine); |
48 | |
49 | const auto attr_skip_mask |
50 | = primitive_attr_t::skip_mask_t::oscale_runtime |
51 | | primitive_attr_t::skip_mask_t::zero_points_runtime |
52 | | primitive_attr_t::skip_mask_t::post_ops |
53 | | primitive_attr_t::skip_mask_t::sum_dt; |
54 | |
55 | bool ok = utils::one_of(this->desc()->prop_kind, forward_training, |
56 | forward_inference) |
57 | && this->desc()->alg_kind == alg_kind::convolution_direct |
58 | && utils::one_of(desc()->src_desc.data_type, u8, s8) |
59 | && utils::one_of( |
60 | desc()->dst_desc.data_type, u8, s8, s32, f32) |
61 | && expect_data_types(desc()->src_desc.data_type, s8, f32, |
62 | desc()->dst_desc.data_type, s32) |
63 | && compute_engine->mayiuse( |
64 | compute::device_ext_t::intel_subgroups) |
65 | && attr()->has_default_values( |
66 | attr_skip_mask, desc()->dst_desc.data_type) |
67 | && attr()->post_ops_.check_sum_consistent_dt( |
68 | dst_md()->data_type, true) |
69 | && post_ops_with_binary_ok(attr(), dst_md()->data_type) |
70 | && zero_points_ok(attr()) |
71 | && IMPLICATION(!attr()->output_scales_.has_default_values(), |
72 | utils::one_of( |
73 | attr()->output_scales_.mask_, 0, 1 << 1)); |
74 | if (!ok) return status::unimplemented; |
75 | |
76 | if (dst_md()->offset0 != 0) return status::unimplemented; |
77 | |
78 | CHECK(init_conf(engine)); |
79 | |
80 | if (!compute_engine->mayiuse_sub_group(conf.sub_group_size)) |
81 | return status::unimplemented; |
82 | |
83 | init_scratchpad(); |
84 | |
85 | ok = set_default_formats_common( |
86 | conf.src_tag, conf.wei_tag, conf.dst_tag); |
87 | if (!ok) return status::unimplemented; |
88 | |
89 | CHECK(attr_.set_default_formats(dst_md(0))); |
90 | |
91 | return status::success; |
92 | } |
93 | |
94 | status_t init_conf(engine_t *engine); |
95 | status_t init_kernel_ctx(compute::kernel_ctx_t &kernel_ctx) const; |
96 | void init_scratchpad(); |
97 | |
98 | conv_conf_t conf; |
99 | }; |
100 | |
101 | status_t init(engine_t *engine) override { |
102 | const char *kernel_name = nullptr; |
103 | if (pd()->conf.is_nhwc) |
104 | kernel_name = "xe_lp_nhwc_1x1_conv_fwd_x8s8x" ; |
105 | else |
106 | kernel_name = "xe_lp_1x1_conv_fwd_x8s8x" ; |
107 | |
108 | compute::kernel_ctx_t kernel_ctx; |
109 | auto status = pd()->init_kernel_ctx(kernel_ctx); |
110 | if (status != status::success) return status; |
111 | |
112 | create_kernel(engine, &kernel_, kernel_name, kernel_ctx); |
113 | if (!kernel_) return status::runtime_error; |
114 | |
115 | if (pd()->conf.attr_info.with_src_zpoints) { |
116 | create_kernel(engine, &src_compensation_kernel_, |
117 | "xe_lp_x8s8x_compensation" , kernel_ctx); |
118 | if (!src_compensation_kernel_) return status::runtime_error; |
119 | } |
120 | |
121 | return status::success; |
122 | } |
123 | |
124 | status_t execute(const exec_ctx_t &ctx) const override { |
125 | return execute_forward(ctx); |
126 | } |
127 | |
128 | private: |
129 | status_t execute_forward(const exec_ctx_t &ctx) const; |
130 | const pd_t *pd() const { return (const pd_t *)gpu_primitive_t::pd().get(); } |
131 | compute::kernel_t kernel_; |
132 | compute::kernel_t src_compensation_kernel_; |
133 | }; |
134 | |
135 | } // namespace ocl |
136 | } // namespace gpu |
137 | } // namespace impl |
138 | } // namespace dnnl |
139 | |
140 | #endif |
141 | |