1 | /******************************************************************************* |
2 | * Copyright 2019-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 | #include "rnn/rnn_aux.hpp" |
18 | #include "utils/parallel.hpp" |
19 | |
20 | namespace rnn { |
21 | |
22 | void copy(int64_t dimc, int64_t dimr, int64_t ld_src, int64_t ld_dst, |
23 | const float *src_, float *dst_, rnn_action_t action, |
24 | bool saturate_to_u8) { |
25 | AOC<const float> src(src_, dimc, ld_src); |
26 | AOC<float> dst(dst_, dimc, ld_dst); |
27 | |
28 | benchdnn_parallel_nd(dimc, [&](int64_t i) { |
29 | for (int64_t j = 0; j < dimr; j++) { |
30 | dst(i, j) = (action == action_sum ? dst(i, j) : 0) + src(i, j); |
31 | if (saturate_to_u8) |
32 | dst(i, j) = saturate_and_round<dnnl_u8>(dst(i, j)); |
33 | } |
34 | }); |
35 | } |
36 | |
37 | void data_q10n(int64_t dimc, int64_t dimr, int64_t ld_src, float *src_, |
38 | float data_scale, float data_shift) { |
39 | AOC<float> src(src_, dimc, ld_src); |
40 | benchdnn_parallel_nd(dimc, [&](int64_t i) { |
41 | for (int64_t j = 0; j < dimr; j++) |
42 | src(i, j) = saturate_and_round<dnnl_u8>( |
43 | data_scale * src(i, j) + data_shift); |
44 | }); |
45 | } |
46 | |
47 | void data_deq10n(int64_t dimc, int64_t dimr, int64_t ld_src, float *src_, |
48 | float data_scale, float data_shift) { |
49 | AOC<float> src(src_, dimc, ld_src); |
50 | benchdnn_parallel_nd(dimc, [&](int64_t i) { |
51 | for (int64_t j = 0; j < dimr; j++) |
52 | src(i, j) = (src(i, j) - data_shift) / data_scale; |
53 | }); |
54 | } |
55 | |
56 | } // namespace rnn |
57 | |