1 | namespace dnnl { |
2 | namespace impl { |
3 | namespace gpu { |
4 | namespace ocl { |
5 | const char *ref_inner_product_kernel = R"==(/******************************************************************************* )==" "\n" |
6 | R"==(* Copyright 2019-2022 Intel Corporation )==" "\n" |
7 | R"==(* )==" "\n" |
8 | R"==(* Licensed under the Apache License, Version 2.0 (the "License"); )==" "\n" |
9 | R"==(* you may not use this file except in compliance with the License. )==" "\n" |
10 | R"==(* You may obtain a copy of the License at )==" "\n" |
11 | R"==(* )==" "\n" |
12 | R"==(* http: )==" "\n" |
13 | R"==(* )==" "\n" |
14 | R"==(* Unless required by applicable law or agreed to in writing, software )==" "\n" |
15 | R"==(* distributed under the License is distributed on an "AS IS" BASIS, )==" "\n" |
16 | R"==(* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. )==" "\n" |
17 | R"==(* See the License for the specific language governing permissions and )==" "\n" |
18 | R"==(* limitations under the License. )==" "\n" |
19 | R"==(*******************************************************************************/ )==" "\n" |
20 | R"==(#include "gpu/ocl/ocl_post_ops.h" )==" "\n" |
21 | R"==(#include "gpu/ocl/ocl_types.h" )==" "\n" |
22 | R"==(#if IS_FWD == 1 )==" "\n" |
23 | R"==(KERNEL_ATTR )==" "\n" |
24 | R"==(__kernel void ref_inner_product_fwd(__global SRC_DATA_T *src, )==" "\n" |
25 | R"==(__global WEI_DATA_T *wei, __global BIA_DATA_T *bias, )==" "\n" |
26 | R"==(__global DST_DATA_T *dst POST_OP_ARGS, __global float *src_scales, )==" "\n" |
27 | R"==(__global float *wei_scales, __global float *dst_scales) { )==" "\n" |
28 | R"==(const int mb = GWS_GET_MB(); )==" "\n" |
29 | R"==(const int oc = GWS_GET_OC(); )==" "\n" |
30 | R"==(ACC_DATA_T d = 0; )==" "\n" |
31 | R"==(#if HAS_SPATIAL == 1 )==" "\n" |
32 | R"==(for (int ic = 0; ic < IC; ++ic) )==" "\n" |
33 | R"==(for (int kd = 0; kd < KD; ++kd) )==" "\n" |
34 | R"==(for (int kh = 0; kh < KH; ++kh) )==" "\n" |
35 | R"==(for (int kw = 0; kw < KW; ++kw) { )==" "\n" |
36 | R"==(const uint src_off = SRC_OFF(mb, ic, kd, kh, kw); )==" "\n" |
37 | R"==(const uint wei_off = WEI_OFF(0, oc, ic, kd, kh, kw); )==" "\n" |
38 | R"==(#else )==" "\n" |
39 | R"==(for (int ic = 0; ic < IC_TOTAL; ++ic) { )==" "\n" |
40 | R"==(const uint src_off = mb * IC_TOTAL + ic; )==" "\n" |
41 | R"==(const uint wei_off = oc * IC_TOTAL + ic; )==" "\n" |
42 | R"==(#endif )==" "\n" |
43 | R"==(d += SRC_TO_REF(src[src_off]) * WEI_TO_REF(wei[wei_off]); )==" "\n" |
44 | R"==(} )==" "\n" |
45 | R"==(DATA_T tmp = d; )==" "\n" |
46 | R"==(#if WITH_SRC_SCALES )==" "\n" |
47 | R"==(tmp *= src_scales[0]; )==" "\n" |
48 | R"==(#endif )==" "\n" |
49 | R"==(#if WITH_WEI_SCALES )==" "\n" |
50 | R"==(#if WEI_SCALES_MASK == 0 )==" "\n" |
51 | R"==(tmp *= wei_scales[0]; )==" "\n" |
52 | R"==(#else )==" "\n" |
53 | R"==(tmp *= wei_scales[oc]; )==" "\n" |
54 | R"==(#endif )==" "\n" |
55 | R"==(#endif )==" "\n" |
56 | R"==(#if WITH_BIAS )==" "\n" |
57 | R"==(tmp += BIA_TO_REF(bias[oc]); )==" "\n" |
58 | R"==(#endif )==" "\n" |
59 | R"==(float dest_data; )==" "\n" |
60 | R"==(#if WITH_SUM )==" "\n" |
61 | R"==(dest_data = DST_TO_REF(dst[mb * OC + oc]); )==" "\n" |
62 | R"==(#endif )==" "\n" |
63 | R"==(APPLY_POST_OPS_SERIAL_BINARY_2D( )==" "\n" |
64 | R"==(tmp, DATA_T, dest_data, float, mb, 1, oc, 1); )==" "\n" |
65 | R"==(#if WITH_DST_SCALES )==" "\n" |
66 | R"==(tmp /= dst_scales[0]; )==" "\n" |
67 | R"==(#endif )==" "\n" |
68 | R"==(dst[mb * OC + oc] = TO_DST(tmp); )==" "\n" |
69 | R"==(} )==" "\n" |
70 | R"==(#endif )==" "\n" |
71 | R"==(#if IS_BWD_D == 1 )==" "\n" |
72 | R"==(KERNEL_ATTR )==" "\n" |
73 | R"==(__kernel void ref_inner_product_bwd_data(__global SRC_DATA_T *diff_src, )==" "\n" |
74 | R"==(__global WEI_DATA_T *wei, __global DST_DATA_T *diff_dst) { )==" "\n" |
75 | R"==(const int mb = GWS_GET_MB_IC() / IC; )==" "\n" |
76 | R"==(const int ic = GWS_GET_MB_IC() % IC; )==" "\n" |
77 | R"==(const int kd = GWS_GET_KD(); )==" "\n" |
78 | R"==(const int kh = GWS_GET_KH(); )==" "\n" |
79 | R"==(const int kw = GWS_GET_KW(); )==" "\n" |
80 | R"==(float ds = 0.0f; )==" "\n" |
81 | R"==(for (int oc = 0; oc < OC; ++oc) { )==" "\n" |
82 | R"==(const uint diff_dst_off = DST_OFF(mb, oc, 0, 0, 0); )==" "\n" |
83 | R"==(const uint wei_off = WEI_OFF(0, oc, ic, kd, kh, kw); )==" "\n" |
84 | R"==(ds += DST_TO_REF(diff_dst[diff_dst_off]) * WEI_TO_REF(wei[wei_off]); )==" "\n" |
85 | R"==(} )==" "\n" |
86 | R"==(const uint diff_src_off = SRC_OFF(mb, ic, kd, kh, kw); )==" "\n" |
87 | R"==(diff_src[diff_src_off] = REF_TO_SRC(ds); )==" "\n" |
88 | R"==(} )==" "\n" |
89 | R"==(#endif )==" "\n" |
90 | R"==(#if IS_BWD_W == 1 )==" "\n" |
91 | R"==(KERNEL_ATTR )==" "\n" |
92 | R"==(__kernel void ref_inner_product_bwd_weights(__global SRC_DATA_T *src, )==" "\n" |
93 | R"==(__global WEI_DATA_T *diff_wei, __global BIA_DATA_T *diff_bias, )==" "\n" |
94 | R"==(__global DST_DATA_T *diff_dst) { )==" "\n" |
95 | R"==(const int oc = GWS_GET_OC(); )==" "\n" |
96 | R"==(const int ic = GWS_GET_IC(); )==" "\n" |
97 | R"==(const int kd = GWS_GET_KD(); )==" "\n" |
98 | R"==(const int kh = GWS_GET_KH(); )==" "\n" |
99 | R"==(const int kw = GWS_GET_KW(); )==" "\n" |
100 | R"==(float ds = 0.0f; )==" "\n" |
101 | R"==(for (int mb = 0; mb < MB; ++mb) { )==" "\n" |
102 | R"==(const uint diff_dst_off = DST_OFF(mb, oc, 0, 0, 0); )==" "\n" |
103 | R"==(const uint src_off = SRC_OFF(mb, ic, kd, kh, kw); )==" "\n" |
104 | R"==(ds += DST_TO_REF(diff_dst[diff_dst_off]) * SRC_TO_REF(src[src_off]); )==" "\n" |
105 | R"==(} )==" "\n" |
106 | R"==(const uint diff_wei_off = WEI_OFF(0, oc, ic, kd, kh, kw); )==" "\n" |
107 | R"==(diff_wei[diff_wei_off] = REF_TO_WEI(ds); )==" "\n" |
108 | R"==(#if WITH_BIAS == 1 )==" "\n" |
109 | R"==(if (ic == 0) { )==" "\n" |
110 | R"==(float db = 0.0f; )==" "\n" |
111 | R"==(for (int mb = 0; mb < MB; ++mb) { )==" "\n" |
112 | R"==(const uint diff_dst_off = DST_OFF(mb, oc, 0, 0, 0); )==" "\n" |
113 | R"==(db += DST_TO_REF(diff_dst[diff_dst_off]); )==" "\n" |
114 | R"==(} )==" "\n" |
115 | R"==(diff_bias[oc] = REF_TO_BIA(db); )==" "\n" |
116 | R"==(} )==" "\n" |
117 | R"==(#endif )==" "\n" |
118 | R"==(} )==" "\n" |
119 | R"==(#endif )==" "\n" |
120 | R"==()==" ; |
121 | } |
122 | } |
123 | } |
124 | } |