1 | namespace dnnl { |
2 | namespace impl { |
3 | namespace gpu { |
4 | namespace ocl { |
5 | const char *xe_lp_x8s8x_compensation_kernel = R"==(/******************************************************************************* )==" "\n" |
6 | R"==(* Copyright 2019-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_types.h" )==" "\n" |
21 | R"==(#include "gpu/ocl/ocl_zero_points.h" )==" "\n" |
22 | R"==(#if WEI_4O8I8O4I )==" "\n" |
23 | R"==(#define OCB ((OC + 31) / 32) )==" "\n" |
24 | R"==(#define ICB ((IC + 31) / 32) )==" "\n" |
25 | R"==(#define KDHW (KD * KH * KW) )==" "\n" |
26 | R"==(#define WEI_BLOCK (32 * 32) )==" "\n" |
27 | R"==(__attribute__((intel_reqd_sub_group_size(8))) )==" "\n" |
28 | R"==(__attribute__((reqd_work_group_size(8, 1, 1))) __kernel void )==" "\n" |
29 | R"==(xe_lp_x8s8x_compensation(const __global int *src_zpoints, )==" "\n" |
30 | R"==(const __global char *wei, __global int *dst) { )==" "\n" |
31 | R"==(const int oc_block_idx = get_global_id(1); )==" "\n" |
32 | R"==(const int g = get_global_id(2); )==" "\n" |
33 | R"==(wei += g * OCB * ICB * KDHW * WEI_BLOCK; )==" "\n" |
34 | R"==(wei += oc_block_idx * ICB * KDHW * WEI_BLOCK; )==" "\n" |
35 | R"==(dst += g * OCB * 32; )==" "\n" |
36 | R"==(dst += oc_block_idx * 32; )==" "\n" |
37 | R"==(#if WITH_SRC_ZPOINTS_PER_IC )==" "\n" |
38 | R"==(src_zpoints += g * IC; )==" "\n" |
39 | R"==(#else )==" "\n" |
40 | R"==(const int z = read_src_zero_point(src_zpoints); )==" "\n" |
41 | R"==(#endif )==" "\n" |
42 | R"==(int4 acc = 0; )==" "\n" |
43 | R"==(for (uint icb = 0; icb < ICB; ++icb) { )==" "\n" |
44 | R"==(#if WITH_SRC_ZPOINTS_PER_IC )==" "\n" |
45 | R"==(const int4 z = read_src_zero_points_32c(src_zpoints, icb * IC_BLOCK); )==" "\n" |
46 | R"==(#endif )==" "\n" |
47 | R"==(for (uint k = 0; k < KDHW; ++k) { )==" "\n" |
48 | R"==(const int8 w0 = as_int8(intel_sub_group_block_read8( )==" "\n" |
49 | R"==((__global uint *)(wei + 0 * IC_BLOCK))); )==" "\n" |
50 | R"==(const int8 w1 = as_int8(intel_sub_group_block_read8( )==" "\n" |
51 | R"==((__global uint *)(wei + 8 * IC_BLOCK))); )==" "\n" |
52 | R"==(const int8 w2 = as_int8(intel_sub_group_block_read8( )==" "\n" |
53 | R"==((__global uint *)(wei + 16 * IC_BLOCK))); )==" "\n" |
54 | R"==(const int8 w3 = as_int8(intel_sub_group_block_read8( )==" "\n" |
55 | R"==((__global uint *)(wei + 24 * IC_BLOCK))); )==" "\n" |
56 | R"==(#if WITH_SRC_ZPOINTS_PER_IC )==" "\n" |
57 | R"==(acc.s0 += calc_src_compensation_x32(z, w0); )==" "\n" |
58 | R"==(acc.s1 += calc_src_compensation_x32(z, w1); )==" "\n" |
59 | R"==(acc.s2 += calc_src_compensation_x32(z, w2); )==" "\n" |
60 | R"==(acc.s3 += calc_src_compensation_x32(z, w3); )==" "\n" |
61 | R"==(#else )==" "\n" |
62 | R"==(unroll_for(uint i = 0; i < 8; ++i) { )==" "\n" |
63 | R"==(acc.s0 = idot4(0x01010101, w0[i], acc.s0); )==" "\n" |
64 | R"==(acc.s1 = idot4(0x01010101, w1[i], acc.s1); )==" "\n" |
65 | R"==(acc.s2 = idot4(0x01010101, w2[i], acc.s2); )==" "\n" |
66 | R"==(acc.s3 = idot4(0x01010101, w3[i], acc.s3); )==" "\n" |
67 | R"==(} )==" "\n" |
68 | R"==(#endif )==" "\n" |
69 | R"==(wei += WEI_BLOCK; )==" "\n" |
70 | R"==(} )==" "\n" |
71 | R"==(} )==" "\n" |
72 | R"==(#if !WITH_SRC_ZPOINTS_PER_IC )==" "\n" |
73 | R"==(acc = z * acc; )==" "\n" |
74 | R"==(#endif )==" "\n" |
75 | R"==(intel_sub_group_block_write4((__global uint *)(dst), as_uint4(acc)); )==" "\n" |
76 | R"==(} )==" "\n" |
77 | R"==(#endif )==" "\n" |
78 | R"==(#if WEI_32G )==" "\n" |
79 | R"==(#define KDHW (KD * KH * KW) )==" "\n" |
80 | R"==(#define WEI_BLOCK 32 )==" "\n" |
81 | R"==(__attribute__((intel_reqd_sub_group_size(16))) )==" "\n" |
82 | R"==(__attribute__((reqd_work_group_size(16, 1, 1))) __kernel void )==" "\n" |
83 | R"==(xe_lp_x8s8x_compensation(const __global int *src_zpoints, )==" "\n" |
84 | R"==(const __global char *wei, __global int *dst) { )==" "\n" |
85 | R"==(const int g_block_idx = get_global_id(1); )==" "\n" |
86 | R"==(wei += g_block_idx * KDHW * WEI_BLOCK; )==" "\n" |
87 | R"==(dst += g_block_idx * WEI_BLOCK; )==" "\n" |
88 | R"==(#if WITH_SRC_ZPOINTS_PER_IC )==" "\n" |
89 | R"==(const int2 z )==" "\n" |
90 | R"==(= read_src_zero_points_32g(src_zpoints, g_block_idx * WEI_BLOCK); )==" "\n" |
91 | R"==(#else )==" "\n" |
92 | R"==(const int z = read_src_zero_point(src_zpoints); )==" "\n" |
93 | R"==(#endif )==" "\n" |
94 | R"==(int2 acc = 0; )==" "\n" |
95 | R"==(#if WITH_SRC_ZPOINTS_PER_IC )==" "\n" |
96 | R"==(#endif )==" "\n" |
97 | R"==(for (uint k = 0; k < KDHW; ++k) { )==" "\n" |
98 | R"==(const int2 w0 = convert_int2(as_char2( )==" "\n" |
99 | R"==(intel_sub_group_block_read_uc2((const __global uchar *)(wei)))); )==" "\n" |
100 | R"==(acc += w0; )==" "\n" |
101 | R"==(wei += WEI_BLOCK; )==" "\n" |
102 | R"==(} )==" "\n" |
103 | R"==(acc = z * acc; )==" "\n" |
104 | R"==(intel_sub_group_block_write2((__global uint *)(dst), as_uint2(acc)); )==" "\n" |
105 | R"==(} )==" "\n" |
106 | R"==(#endif )==" "\n" |
107 | R"==()==" ; |
108 | } |
109 | } |
110 | } |
111 | } |