Skip to content

Commit f72e2ee

Browse files
committed
cpu: tidy: qz -> qz_t
1 parent c194fb6 commit f72e2ee

7 files changed

+57
-54
lines changed

src/cpu/ref_batch_normalization.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright 2016-2024 Intel Corporation
2+
* Copyright 2016-2025 Intel Corporation
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -158,8 +158,8 @@ status_t ref_batch_normalization_fwd_t<d_type>::execute_forward(
158158
}
159159
}
160160
if (d_type == s8)
161-
dst[d_off]
162-
= q10n::qz_a1b0<float, data_t>()(maybe_post_op(bn_res));
161+
dst[d_off] = q10n::qz_a1b0_t<float, data_t>()(
162+
maybe_post_op(bn_res));
163163
else
164164
dst[d_off] = maybe_post_op(bn_res);
165165
}

src/cpu/reorder/simple_reorder.hpp

+28-26
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@ template <impl::data_type_t type>
4646
using data_t = typename prec_traits_t<type>::type;
4747

4848
template <impl::data_type_t type_i, impl::data_type_t type_o>
49-
using _qz_a1b0 = q10n::qz_a1b0<data_t<type_i>, data_t<type_o>>;
49+
using _qz_a1b0 = q10n::qz_a1b0_t<data_t<type_i>, data_t<type_o>>;
5050

5151
template <impl::data_type_t type_i, impl::data_type_t type_o>
52-
using _qz = q10n::qz<data_t<type_i>, data_t<type_o>>;
52+
using _qz = q10n::qz_t<data_t<type_i>, data_t<type_o>>;
5353

5454
namespace fmt_order {
5555
const bool keep = true;
@@ -343,7 +343,7 @@ struct simple_reorder_impl<SIMPLE_REORDER_TEMPL_CALL,
343343
const float s = src_scales[src_scales_mask == 0 ? 0 : os_off];
344344
const float d = dst_scales[dst_scales_mask == 0 ? 0 : os_off];
345345

346-
o = q10n::qz_b0<data_t<type_i>, data_t<type_o>>()(
346+
o = q10n::qz_b0_t<data_t<type_i>, data_t<type_o>>()(
347347
i, s * adj_scale * d);
348348
if (req_comp) cp[g * OC + oc] -= (int32_t)o;
349349
if (has_asymmetric_comp) zp[g * OC + oc] -= (int32_t)o;
@@ -547,7 +547,7 @@ struct simple_reorder_impl<SIMPLE_REORDER_TEMPL_CALL,
547547
const float src_scale = s[src_scales_mask == 0 ? 0 : os_off];
548548
const float dst_scale = d[dst_scales_mask == 0 ? 0 : os_off];
549549
out[index(oc, ic)]
550-
= q10n::qz_b0<data_t<type_i>, data_t<type_o>>()(
550+
= q10n::qz_b0_t<data_t<type_i>, data_t<type_o>>()(
551551
inp[plain_off],
552552
src_scale * adj_scale * dst_scale);
553553
if (req_comp) c[oc] -= (128 * (int32_t)(out[index(oc, ic)]));
@@ -710,7 +710,7 @@ struct simple_reorder_impl<SIMPLE_REORDER_TEMPL_CALL,
710710
for (dim_t oc = 0; oc < oc_block; ++oc) {
711711
const auto plain_off
712712
= oc * plain_d.blocking_desc().strides[w_groups + 0];
713-
out[oc] = q10n::qz_b0<data_t<type_i>, data_t<type_o>>()(
713+
out[oc] = q10n::qz_b0_t<data_t<type_i>, data_t<type_o>>()(
714714
inp[plain_off], s[oc] * adj_scale * d[oc]);
715715
if (has_asymmetric_comp) zp[oc] -= (int32_t)(out[oc]);
716716
}
@@ -904,7 +904,7 @@ struct simple_reorder_impl<SIMPLE_REORDER_TEMPL_CALL,
904904
+ ic * plain_d.blocking_desc().strides[w_groups + 1];
905905
auto index = AB_or_BC_blk_off<tag_traits_t<tag_o>::inner_blks>(
906906
oc, ic);
907-
out[index] = q10n::qz_b0<data_t<type_i>, data_t<type_o>>()(
907+
out[index] = q10n::qz_b0_t<data_t<type_i>, data_t<type_o>>()(
908908
inp[plain_off], s[oc] * adj_scale * d[oc]);
909909

910910
if (has_asymmetric_comp) zp[oc] -= (int32_t)(out[index]);
@@ -1077,8 +1077,9 @@ struct simple_reorder_impl<SIMPLE_REORDER_TEMPL_CALL,
10771077
auto index
10781078
= AB_or_BC_blk_off<tag_traits_t<tag_o>::inner_blks>(
10791079
d0, d1);
1080-
out[index] = q10n::qz_b0<data_t<type_i>, data_t<type_o>>()(
1081-
inp[plain_off], s[0] * adj_scale * d[0]);
1080+
out[index]
1081+
= q10n::qz_b0_t<data_t<type_i>, data_t<type_o>>()(
1082+
inp[plain_off], s[0] * adj_scale * d[0]);
10821083

10831084
auto o = static_cast<int32_t>(out[index]);
10841085
if (req_comp) cp[d1] -= (128 * o);
@@ -1088,16 +1089,17 @@ struct simple_reorder_impl<SIMPLE_REORDER_TEMPL_CALL,
10881089
auto index
10891090
= AB_or_BC_blk_off<tag_traits_t<tag_o>::inner_blks>(
10901091
d0, d1);
1091-
out[index] = q10n::qz_b0<data_t<type_i>, data_t<type_o>>()(
1092-
0, s[0] * adj_scale * d[0]);
1092+
out[index]
1093+
= q10n::qz_b0_t<data_t<type_i>, data_t<type_o>>()(
1094+
0, s[0] * adj_scale * d[0]);
10931095
}
10941096
}
10951097

10961098
for_(int d0 = d0_block; d0 < D0_blksize; ++d0)
10971099
for (int d1 = 0; d1 < D1_blksize; ++d1) {
10981100
auto index = AB_or_BC_blk_off<tag_traits_t<tag_o>::inner_blks>(
10991101
d0, d1);
1100-
out[index] = q10n::qz_b0<data_t<type_i>, data_t<type_o>>()(
1102+
out[index] = q10n::qz_b0_t<data_t<type_i>, data_t<type_o>>()(
11011103
0, s[0] * adj_scale * d[0]);
11021104
}
11031105
};
@@ -1265,7 +1267,7 @@ struct simple_reorder_impl<SIMPLE_REORDER_TEMPL_CALL,
12651267
= src_scales[src_scales_mask == 0 ? 0 : g * OC];
12661268
const float dst_scale
12671269
= dst_scales[dst_scales_mask == 0 ? 0 : g * OC];
1268-
out[g] = q10n::qz_b0<data_t<type_i>, data_t<type_o>>()(
1270+
out[g] = q10n::qz_b0_t<data_t<type_i>, data_t<type_o>>()(
12691271
inp[i_off], src_scale * adj_scale * dst_scale);
12701272
}
12711273
};
@@ -2094,25 +2096,26 @@ struct simple_reorder_impl<SIMPLE_REORDER_TEMPL_CALL,
20942096
if (alpha == 1.0 && beta == 0.0) {
20952097
PRAGMA_OMP_SIMD()
20962098
for (size_t e = start; e < end; ++e) {
2097-
output[e] = q10n::qz_a1b0<data_t<type_i>, data_t<type_o>>()(
2098-
input[e]);
2099+
output[e]
2100+
= q10n::qz_a1b0_t<data_t<type_i>, data_t<type_o>>()(
2101+
input[e]);
20992102
}
21002103
} else if (alpha == 1.0) {
21012104
PRAGMA_OMP_SIMD()
21022105
for (size_t e = start; e < end; ++e) {
2103-
output[e] = q10n::qz_a1<data_t<type_i>, data_t<type_o>>()(
2106+
output[e] = q10n::qz_a1_t<data_t<type_i>, data_t<type_o>>()(
21042107
input[e], output[e], beta);
21052108
}
21062109
} else if (beta == 0.0) {
21072110
PRAGMA_OMP_SIMD()
21082111
for (size_t e = start; e < end; ++e) {
2109-
output[e] = q10n::qz_b0<data_t<type_i>, data_t<type_o>>()(
2112+
output[e] = q10n::qz_b0_t<data_t<type_i>, data_t<type_o>>()(
21102113
input[e], alpha);
21112114
}
21122115
} else {
21132116
PRAGMA_OMP_SIMD()
21142117
for (size_t e = start; e < end; ++e) {
2115-
output[e] = q10n::qz<data_t<type_i>, data_t<type_o>>()(
2118+
output[e] = q10n::qz_t<data_t<type_i>, data_t<type_o>>()(
21162119
input[e], output[e], alpha, beta);
21172120
}
21182121
}
@@ -2121,28 +2124,27 @@ struct simple_reorder_impl<SIMPLE_REORDER_TEMPL_CALL,
21212124
if (alpha == 1.0 && beta == 0.0) {
21222125
PRAGMA_OMP_SIMD()
21232126
for (size_t e = nelems - rem_elems; e < nelems; ++e) {
2124-
output[e] = q10n::qz_a1b0<data_t<type_i>,
2127+
output[e] = q10n::qz_a1b0_t<data_t<type_i>,
21252128
data_t<type_o>>()(input[e]);
21262129
}
21272130
} else if (alpha == 1.0) {
21282131
PRAGMA_OMP_SIMD()
21292132
for (size_t e = nelems - rem_elems; e < nelems; ++e) {
2130-
output[e]
2131-
= q10n::qz_a1<data_t<type_i>, data_t<type_o>>()(
2132-
input[e], output[e], beta);
2133+
output[e] = q10n::qz_a1_t<data_t<type_i>,
2134+
data_t<type_o>>()(input[e], output[e], beta);
21332135
}
21342136
} else if (beta == 0.0) {
21352137
PRAGMA_OMP_SIMD()
21362138
for (size_t e = nelems - rem_elems; e < nelems; ++e) {
2137-
output[e]
2138-
= q10n::qz_b0<data_t<type_i>, data_t<type_o>>()(
2139-
input[e], alpha);
2139+
output[e] = q10n::qz_b0_t<data_t<type_i>,
2140+
data_t<type_o>>()(input[e], alpha);
21402141
}
21412142
} else {
21422143
PRAGMA_OMP_SIMD()
21432144
for (size_t e = nelems - rem_elems; e < nelems; ++e) {
2144-
output[e] = q10n::qz<data_t<type_i>, data_t<type_o>>()(
2145-
input[e], output[e], alpha, beta);
2145+
output[e]
2146+
= q10n::qz_t<data_t<type_i>, data_t<type_o>>()(
2147+
input[e], output[e], alpha, beta);
21462148
}
21472149
}
21482150
}

src/cpu/rnn/ref_postgemm_lstm.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright 2018-2024 Intel Corporation
2+
* Copyright 2018-2025 Intel Corporation
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -188,7 +188,7 @@ rnn_postgemm_sig(rnn_postgemm_fwd_u8_t::lstm_postgemm) {
188188

189189
const auto quantize_f32_u8 = [&](float f) {
190190
float qf = f * data_scale + data_shift;
191-
return q10n::qz_a1b0<float, dst_layer_t>()(qf);
191+
return q10n::qz_a1b0_t<float, dst_layer_t>()(qf);
192192
};
193193

194194
const auto dequantize_s32_f32 = [&](gemm_acc_t s, int gate, int j) {
@@ -229,7 +229,7 @@ rnn_postgemm_sig(rnn_postgemm_fwd_s8_t::lstm_postgemm) {
229229

230230
const auto quantize_f32_s8 = [&](float f) {
231231
float qf = f * data_scale + data_shift;
232-
return q10n::qz_a1b0<float, dst_layer_t>()(qf);
232+
return q10n::qz_a1b0_t<float, dst_layer_t>()(qf);
233233
};
234234

235235
const auto dequantize_s32_f32 = [&](gemm_acc_t s, int gate, int j) {

src/cpu/rnn/ref_postgemm_lstm_projection.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright 2020-2024 Intel Corporation
2+
* Copyright 2020-2025 Intel Corporation
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -104,7 +104,7 @@ rnn_postgemm_sig(rnn_postgemm_fwd_u8_t::lstm_projection_postgemm) {
104104
float qf = f * data_scale + data_shift;
105105
qf = nstl::min(qf, 255.0f);
106106
qf = nstl::max(qf, 0.0f);
107-
return q10n::qz_a1b0<float, dst_layer_t>()(qf);
107+
return q10n::qz_a1b0_t<float, dst_layer_t>()(qf);
108108
};
109109

110110
const auto dequantize_s32_f32 = [&](gemm_acc_t s, int j) {
@@ -149,7 +149,7 @@ rnn_postgemm_sig(rnn_postgemm_fwd_s8_t::lstm_projection_postgemm) {
149149

150150
const auto quantize_f32_s8 = [&](float f) {
151151
const float qf = f * data_scale + data_shift;
152-
return q10n::qz_a1b0<float, dst_layer_t>()(qf);
152+
return q10n::qz_a1b0_t<float, dst_layer_t>()(qf);
153153
};
154154

155155
const auto dequantize_s32_f32 = [&](gemm_acc_t s, int j) {

src/cpu/rnn/ref_rnn.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1423,7 +1423,7 @@ void copy_init_iter_fwd_template(const rnn_conf_t &rnn, const rnn_pd_t *pd,
14231423
const auto maybe_q = [&](input_data_t f) {
14241424
if (quantize) {
14251425
float qf = f * data_scale + data_shift;
1426-
return q10n::qz_a1b0<float, src_data_t>()(qf);
1426+
return q10n::qz_a1b0_t<float, src_data_t>()(qf);
14271427
} else
14281428
return (src_data_t)f;
14291429
};
@@ -1589,7 +1589,7 @@ void copy_res_layer_fwd_template(const rnn_conf_t &rnn, const rnn_pd_t *pd,
15891589
PRAGMA_OMP_SIMD()
15901590
for (int s = 0; s < rnn.dlc; s++) {
15911591
float val = (float)ss[s] + dd[s];
1592-
val = q10n::qz_a1b0<float, src_data_t>()(val);
1592+
val = q10n::qz_a1b0_t<float, src_data_t>()(val);
15931593
dd[s] = (dst_layer_dt)((val - 2 * shift) / scale);
15941594
}
15951595
} else if (rnn_u8u8_case

src/cpu/rnn/rnn_reorders.hpp

+5-4
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ static inline void quantize_igo(int8_t *scratch_quantized,
7676
for (int go = 0; go < G * O; go++) {
7777
const float s = scales[(mask == 0) ? 0 : go];
7878
scratch_quantized[ldi * G * O + go]
79-
= q10n::qz_b0<in_data_t, int8_t>()(
79+
= q10n::qz_b0_t<in_data_t, int8_t>()(
8080
src[ldi * G * O + go], s);
8181
}
8282
}
@@ -100,7 +100,7 @@ static inline void quantize_goi(int8_t *scratch_quantized,
100100
PRAGMA_OMP_SIMD()
101101
for (dim_t i = 0; i < I; i++) {
102102
scratch_quantized[ld * I * G * O + i * G * O + go]
103-
= q10n::qz_b0<in_data_t, int8_t>()(
103+
= q10n::qz_b0_t<in_data_t, int8_t>()(
104104
src[ld * G * O * I + go * I + i], s);
105105
}
106106
});
@@ -271,7 +271,7 @@ struct rnn_data_reorder_t : public primitive_t {
271271
PRAGMA_OMP_SIMD()
272272
for (int j = 0; j < inner_dim; ++j) {
273273
const float in = (float)i_[j] * scale + shift;
274-
o_[j] = q10n::qz_a1b0<float, out_data_t>()(in);
274+
o_[j] = q10n::qz_a1b0_t<float, out_data_t>()(in);
275275
}
276276
}
277277
});
@@ -288,7 +288,8 @@ struct rnn_data_reorder_t : public primitive_t {
288288
const size_t nelems = input_d.nelems();
289289
parallel_nd(nelems, [&](size_t i) {
290290
const float in = (float)input[input_d.off_l(i)] * scale + shift;
291-
output[output_d.off_l(i)] = q10n::qz_a1b0<float, out_data_t>()(in);
291+
output[output_d.off_l(i)]
292+
= q10n::qz_a1b0_t<float, out_data_t>()(in);
292293
});
293294
return status::success;
294295
}

src/cpu/simple_q10n.hpp

+13-13
Original file line numberDiff line numberDiff line change
@@ -82,89 +82,89 @@ inline out_t saturate_and_round(acc_t f) {
8282

8383
/* Quantization with alpha == 1 and beta == 0 */
8484
template <typename in_t, typename out_t, typename enabled = void>
85-
struct qz_a1b0 {
85+
struct qz_a1b0_t {
8686
out_t operator()(in_t in) { return saturate_and_round<out_t>((float)in); }
8787
};
8888

8989
template <typename in_t, typename out_t>
90-
struct qz_a1b0<in_t, out_t,
90+
struct qz_a1b0_t<in_t, out_t,
9191
typename utils::enable_if<true && nstl::is_integral<in_t>::value
9292
&& !is_subset<in_t, out_t>::value>::type> {
9393
out_t operator()(in_t in) { return saturate<out_t>(in); }
9494
};
9595

9696
template <typename in_t, typename out_t>
97-
struct qz_a1b0<in_t, out_t,
97+
struct qz_a1b0_t<in_t, out_t,
9898
typename utils::enable_if<is_subset<in_t, out_t>::value>::type> {
9999
out_t operator()(in_t in) { return (out_t)in; }
100100
};
101101

102102
/* Quantization with alpha == 1 */
103103
template <typename in_t, typename out_t>
104-
struct qz_a1 {
104+
struct qz_a1_t {
105105
out_t operator()(in_t in, out_t out, float beta) {
106106
return saturate_and_round<out_t>((float)in + beta * out);
107107
}
108108
};
109109

110110
template <typename in_t>
111-
struct qz_a1<in_t, float> {
111+
struct qz_a1_t<in_t, float> {
112112
float operator()(in_t in, float out, float beta) {
113113
return (float)in + beta * out;
114114
}
115115
};
116116

117117
/* Quantization with beta == 0 */
118118
template <typename in_t, typename out_t>
119-
struct qz_b0 {
119+
struct qz_b0_t {
120120
out_t operator()(in_t in, float alpha) {
121121
return saturate_and_round<out_t>(alpha * in);
122122
}
123123
};
124124

125125
template <typename in_t>
126-
struct qz_b0<in_t, float> {
126+
struct qz_b0_t<in_t, float> {
127127
float operator()(in_t in, float alpha) { return alpha * in; }
128128
};
129129

130130
/* Quantization */
131131
template <typename in_t, typename out_t>
132-
struct qz {
132+
struct qz_t {
133133
out_t operator()(in_t in, out_t out, float alpha, float beta) {
134134
return saturate_and_round<out_t>(alpha * in + (beta ? beta * out : 0));
135135
}
136136
};
137137

138138
template <typename in_t>
139-
struct qz<in_t, float> {
139+
struct qz_t<in_t, float> {
140140
float operator()(in_t in, float out, float alpha, float beta) {
141141
return alpha * in + (beta ? beta * out : 0);
142142
}
143143
};
144144

145145
template <>
146-
struct qz<bfloat16_t, bfloat16_t> {
146+
struct qz_t<bfloat16_t, bfloat16_t> {
147147
float operator()(bfloat16_t in, bfloat16_t out, float alpha, float beta) {
148148
return (bfloat16_t)(alpha * (float)in + (beta ? beta * (float)out : 0));
149149
}
150150
};
151151

152152
template <>
153-
struct qz<float, bfloat16_t> {
153+
struct qz_t<float, bfloat16_t> {
154154
float operator()(float in, bfloat16_t out, float alpha, float beta) {
155155
return (bfloat16_t)(alpha * in + (beta ? beta * out : 0));
156156
}
157157
};
158158

159159
template <>
160-
struct qz<float16_t, float16_t> {
160+
struct qz_t<float16_t, float16_t> {
161161
float operator()(float16_t in, float16_t out, float alpha, float beta) {
162162
return (float16_t)(alpha * (float)in + (beta ? beta * (float)out : 0));
163163
}
164164
};
165165

166166
template <>
167-
struct qz<float, float16_t> {
167+
struct qz_t<float, float16_t> {
168168
float operator()(float in, float16_t out, float alpha, float beta) {
169169
return (float16_t)(alpha * in + (beta ? beta * out : 0));
170170
}

0 commit comments

Comments
 (0)