1 // Copyright (C) 2018-2019 Intel Corporation
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
7 // http://www.apache.org/licenses/LICENSE-2.0
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 #pragma OPENCL EXTENSION cl_khr_fp16 : enable
17 __kernel void ctc_greedy_decoder(const __global INPUT0_TYPE* probabilities,
18 const __global INPUT1_TYPE* sequence_indicators,
19 __global OUTPUT0_TYPE* output_sequences)
21 const int dims = sizeof(INPUT0_DIMS) / sizeof(INPUT0_DIMS[0]);
22 int T_ = INPUT0_DIMS[0];
23 int N_ = INPUT0_DIMS[1];
24 int C_ = INPUT0_DIMS[2];
26 // Fill output_sequences with -1
27 for (int ii = 0; ii < T_*N_; ii++) {
28 output_sequences[ii] = (OUTPUT0_TYPE)(-1.0f);
31 for (int n = 0; n < N_; ++n) {
32 int prev_class_idx = -1;
33 int output_index = n*T_;
35 for (int t = 0; /* check at end */; ++t) {
36 // get maximum probability and its index
37 int max_class_idx = 0;
39 const __global INPUT0_TYPE* probs = probabilities + t*C_*N_ + n*C_;
40 INPUT0_TYPE max_prob = probs[0];
43 for (int c = 1; c < C_; ++c, ++probs) {
44 if (*probs > max_prob) {
50 if (max_class_idx != C_-1 && !(ctc_merge_repeated_ && max_class_idx == prev_class_idx)) {
51 output_sequences[output_index] = max_class_idx;
55 prev_class_idx = max_class_idx;
57 if (t + 1 == T_ || sequence_indicators[(t + 1)*N_ + n] == 0) {