1 | namespace dnnl { |
2 | namespace impl { |
3 | namespace gpu { |
4 | namespace ocl { |
5 | const char *ref_prelu_kernel = R"==(/******************************************************************************* )==" "\n" |
6 | R"==(* Copyright 2020-2021 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_eltwise.h" )==" "\n" |
21 | R"==(#include "gpu/ocl/ocl_types.h" )==" "\n" |
22 | R"==(#if IS_FWD )==" "\n" |
23 | R"==(__kernel void ref_prelu_fwd(const __global SRC_DATA_T *src, )==" "\n" |
24 | R"==(const __global WEI_DATA_T *weights, __global DST_DATA_T *dst) { )==" "\n" |
25 | R"==(const int d0 = GWS_GET_D0(); )==" "\n" |
26 | R"==(const int d1 = GWS_GET_D1(); )==" "\n" |
27 | R"==(const int d2 = GWS_GET_D2(); )==" "\n" |
28 | R"==(const int d3 = GWS_GET_D3(); )==" "\n" |
29 | R"==(const int d4 = GWS_GET_D4(); )==" "\n" |
30 | R"==(const int d5 = GWS_GET_D5(); )==" "\n" |
31 | R"==(const unsigned data_off = OFF_MD(SRC, d0, d1, d2, d3, d4, d5); )==" "\n" |
32 | R"==(const unsigned wei_off = OFF_MD(WEI, d0 % WEI_D0, d1 % WEI_D1, d2 % WEI_D2, )==" "\n" |
33 | R"==(d3 % WEI_D3, d4 % WEI_D4, d5 % WEI_D5); )==" "\n" |
34 | R"==(const float src_data = SRC_TO_REF(src[data_off]); )==" "\n" |
35 | R"==(const float wei_data = WEI_TO_REF(weights[wei_off]); )==" "\n" |
36 | R"==(const float res_data = relu_fwd(src_data, wei_data); )==" "\n" |
37 | R"==(dst[data_off] = TO_DST(res_data); )==" "\n" |
38 | R"==(} )==" "\n" |
39 | R"==(#else )==" "\n" |
40 | R"==(__kernel void ref_prelu_bwd(const __global SRC_DATA_T *src, )==" "\n" |
41 | R"==(const __global WEI_DATA_T *weights, const __global DST_DATA_T *diff_dst, )==" "\n" |
42 | R"==(__global DIFF_SRC_DATA_T *diff_src, )==" "\n" |
43 | R"==(__global DIFF_WEI_DATA_T *diff_weights) { )==" "\n" |
44 | R"==(const int d0 = GWS_GET_D0(); )==" "\n" |
45 | R"==(const int d1 = GWS_GET_D1(); )==" "\n" |
46 | R"==(const int d2 = GWS_GET_D2(); )==" "\n" |
47 | R"==(const int d3 = GWS_GET_D3(); )==" "\n" |
48 | R"==(const int d4 = GWS_GET_D4(); )==" "\n" |
49 | R"==(const int d5 = GWS_GET_D5(); )==" "\n" |
50 | R"==(const unsigned data_off = OFF_MD(SRC, d0 % SRC_D0, d1 % SRC_D1, d2 % SRC_D2, )==" "\n" |
51 | R"==(d3 % SRC_D3, d4 % SRC_D4, d5 % SRC_D5); )==" "\n" |
52 | R"==(const unsigned data_off_pd = OFF_MD(SRC, d0 % SRC_PD0, d1 % SRC_PD1, )==" "\n" |
53 | R"==(d2 % SRC_PD2, d3 % SRC_PD3, d4 % SRC_PD4, d5 % SRC_PD5); )==" "\n" |
54 | R"==(const unsigned wei_off = OFF_MD(WEI, d0 % WEI_D0, d1 % WEI_D1, d2 % WEI_D2, )==" "\n" |
55 | R"==(d3 % WEI_D3, d4 % WEI_D4, d5 % WEI_D5); )==" "\n" |
56 | R"==(const float src_data = SRC_TO_REF(src[data_off]); )==" "\n" |
57 | R"==(const float diff_dst_data = DST_TO_REF(diff_dst[data_off]); )==" "\n" |
58 | R"==(const float wei_data = WEI_TO_REF(weights[wei_off]); )==" "\n" |
59 | R"==(float diff_src_data )==" "\n" |
60 | R"==(= src_data > 0 ? diff_dst_data : diff_dst_data * wei_data; )==" "\n" |
61 | R"==(if (data_off != data_off_pd) diff_src_data = 0.f; )==" "\n" |
62 | R"==(#define COORDINATES_ARE_IN_RANGE(mem_prefix) \ )==" "\n" |
63 | R"==(({ \ )==" "\n" |
64 | R"==(bool is_in_range = d0 < CONCAT2(mem_prefix, _PD0) \ )==" "\n" |
65 | R"==(&& d1 < CONCAT2(mem_prefix, _PD1) \ )==" "\n" |
66 | R"==(&& d2 < CONCAT2(mem_prefix, _PD2) \ )==" "\n" |
67 | R"==(&& d3 < CONCAT2(mem_prefix, _PD3) \ )==" "\n" |
68 | R"==(&& d4 < CONCAT2(mem_prefix, _PD4) \ )==" "\n" |
69 | R"==(&& d5 < CONCAT2(mem_prefix, _PD5); \ )==" "\n" |
70 | R"==(is_in_range; \ )==" "\n" |
71 | R"==(}) )==" "\n" |
72 | R"==(if (COORDINATES_ARE_IN_RANGE(SRC)) )==" "\n" |
73 | R"==(diff_src[data_off_pd] = TO_SRC(diff_src_data); )==" "\n" |
74 | R"==(if (!COORDINATES_ARE_IN_RANGE(DIFF_WEI)) return; )==" "\n" |
75 | R"==(const unsigned diff_wei_off = OFF_MD(DIFF_WEI, d0 % DIFF_WEI_D0, )==" "\n" |
76 | R"==(d1 % DIFF_WEI_D1, d2 % DIFF_WEI_D2, d3 % DIFF_WEI_D3, )==" "\n" |
77 | R"==(d4 % DIFF_WEI_D4, d5 % DIFF_WEI_D5); )==" "\n" |
78 | R"==(const unsigned diff_wei_off_pd = OFF_MD(DIFF_WEI, d0 % DIFF_WEI_PD0, )==" "\n" |
79 | R"==(d1 % DIFF_WEI_PD1, d2 % DIFF_WEI_PD2, d3 % DIFF_WEI_PD3, )==" "\n" |
80 | R"==(d4 % DIFF_WEI_PD4, d5 % DIFF_WEI_PD5); )==" "\n" |
81 | R"==(float diff_wei_data = src_data > 0 ? 0 : diff_dst_data * src_data; )==" "\n" |
82 | R"==(if (diff_wei_off != diff_wei_off_pd) diff_wei_data = 0.f; )==" "\n" |
83 | R"==(#if DIFF_WEI_DT_F32 )==" "\n" |
84 | R"==(diff_weights[diff_wei_off_pd] = diff_wei_data; )==" "\n" |
85 | R"==(#else )==" "\n" |
86 | R"==(diff_weights[diff_wei_off_pd] = TO_DIFF_WEI(diff_wei_data); )==" "\n" |
87 | R"==(#endif )==" "\n" |
88 | R"==(} )==" "\n" |
89 | R"==(#endif )==" "\n" |
90 | R"==()==" ; |
91 | } |
92 | } |
93 | } |
94 | } |