cuda-decoder-kernels.h
8.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
//
// Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.
// Hugo Braun, Justin Luitjens, Ryan Leary
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef KALDI_CUDA_DECODER_CUDA_DECODER_KERNELS_H_
#define KALDI_CUDA_DECODER_CUDA_DECODER_KERNELS_H_
#include "cudadecoder/cuda-decoder-common.h"
#include "util/stl-utils.h"
namespace kaldi {
namespace cuda_decoder {
// DeviceParams contains all top-level const data used by the kernels
// i.e. the data that won't change between kernel calls (such as memory pointers
// to the main_q)
struct DeviceParams {
ChannelMatrixView<ChannelCounters> d_channels_counters;
LaneMatrixView<LaneCounters> d_lanes_counters;
LaneMatrixView<LaneCounters> h_lanes_counters;
ChannelMatrixView<int2> d_main_q_state_and_cost;
ChannelMatrixView<int32> d_main_q_degrees_prefix_sum;
ChannelMatrixView<int32> d_main_q_arc_offsets;
LaneMatrixView<CostType> d_main_q_acoustic_cost;
LaneMatrixView<InfoToken> d_main_q_info;
LaneMatrixView<int2> d_aux_q_state_and_cost;
LaneMatrixView<InfoToken> d_aux_q_info;
LaneMatrixView<HashmapValueT> d_hashmap_values;
LaneMatrixView<int2> h_list_final_tokens_in_main_q;
LaneMatrixView<float2> d_main_q_extra_and_acoustic_cost;
LaneMatrixView<int32> d_histograms;
LaneMatrixView<int2> d_main_q_block_sums_prefix_sum;
LaneMatrixView<int32> d_main_q_state_hash_idx;
LaneMatrixView<int32> d_main_q_extra_prev_tokens_prefix_sum;
LaneMatrixView<int32> d_main_q_n_extra_prev_tokens_local_idx;
LaneMatrixView<InfoToken> d_main_q_extra_prev_tokens;
int32 max_nlanes;
int32 main_q_capacity, aux_q_capacity;
CostType *d_arc_weights;
int32 *d_arc_nextstates;
int32 *d_arc_pdf_ilabels;
uint32 *d_arc_e_offsets;
uint32 *d_arc_ne_offsets;
CostType *d_fst_final_costs;
int32 nstates;
CostType default_beam;
CostType lattice_beam;
int32 init_channel_id;
StateId init_state;
CostType init_cost;
int32 hashmap_capacity;
int32 max_active;
int32 adaptive_beam_static_segment;
int32 adaptive_beam_bin_width;
};
// KernelParams contains all the kernels arguments that change between kernel
// calls
struct KernelParams {
int32 nlanes_used;
};
// Kernel wrappers
void SaveChannelsStateFromLanesKernel(const dim3 &grid, const dim3 &block,
const cudaStream_t &st,
const DeviceParams &cst_dev_params,
const KernelParams &kernel_params);
void LoadChannelsStateInLanesKernel(const dim3 &grid, const dim3 &block,
const cudaStream_t &st,
const DeviceParams &cst_dev_params,
const KernelParams &kernel_params);
void InitDecodingOnDeviceKernel(const dim3 &grid, const dim3 &block,
const cudaStream_t &st,
const DeviceParams &cst_dev_params,
const KernelParams &kernel_params);
void InitializeInitialLaneKernel(const dim3 &grid, const dim3 &block,
const cudaStream_t &st,
const DeviceParams &cst_dev_params);
void ResetForFrameAndEstimateCutoffKernel(const dim3 &grid, const dim3 &block,
const cudaStream_t &st,
const DeviceParams &cst_dev_params,
const KernelParams &kernel_params);
template <bool IS_EMITTING>
void ExpandArcsKernel(const dim3 &grid, const dim3 &block,
const cudaStream_t &st,
const DeviceParams &cst_dev_params,
const KernelParams &kernel_params);
template <bool IS_EMITTING>
void PostExpandKernel(const dim3 &grid, const dim3 &block,
const cudaStream_t &st,
const DeviceParams &cst_dev_params,
const KernelParams &kernel_params);
void PostContractAndPreprocessKernel(const dim3 &grid, const dim3 &block,
const cudaStream_t &st,
const DeviceParams &cst_dev_params,
const KernelParams &kernel_params);
void NonEmittingPreprocessAndContractKernel(const dim3 &grid, const dim3 &block,
const cudaStream_t &st,
const DeviceParams &cst_dev_params,
const KernelParams &kernel_params);
void FillHashmapWithMainQKernel(const dim3 &grid, const dim3 &block,
const cudaStream_t &st,
const DeviceParams &cst_dev_params,
const KernelParams &kernel_params);
void EmittingPreprocessAndListExtraPrevTokensStep1Kernel(
const dim3 &grid, const dim3 &block, const cudaStream_t &st,
const DeviceParams &cst_dev_params, const KernelParams &kernel_params);
void EmittingPreprocessAndListExtraPrevTokensStep2Kernel(
const dim3 &grid, const dim3 &block, const cudaStream_t &st,
const DeviceParams &cst_dev_params, const KernelParams &kernel_params);
void EmittingPreprocessAndListExtraPrevTokensStep3Kernel(
const dim3 &grid, const dim3 &block, const cudaStream_t &st,
const DeviceParams &cst_dev_params, const KernelParams &kernel_params);
void EmittingPreprocessAndListExtraPrevTokensStep4Kernel(
const dim3 &grid, const dim3 &block, const cudaStream_t &st,
const DeviceParams &cst_dev_params, const KernelParams &kernel_params);
void ComputeLaneOffsetsKernel(const dim3 &grid, const dim3 &block,
const cudaStream_t &st,
const DeviceParams &cst_dev_params,
const KernelParams &kernel_params);
template <typename T>
void ConcatenateLanesDataKernel(const dim3 &grid, const dim3 &block,
const cudaStream_t &st,
const DeviceParams &cst_dev_params,
const KernelParams &kernel_params,
const LaneMatrixView<T> &src, T *concat,
int32 *lane_offsets);
void InitHashmapKernel(const dim3 &grid, const dim3 &block,
const cudaStream_t &st,
const DeviceParams &cst_dev_params);
void ClearHashmapKernel(const dim3 &grid, const dim3 &block,
const cudaStream_t &st,
const DeviceParams &cst_dev_params,
const KernelParams &kernel_params);
void ComputeCostsHistogramKernel(const dim3 &grid, const dim3 &block,
const cudaStream_t &st,
const DeviceParams &cst_dev_params,
const KernelParams &kernel_params,
bool use_aux_q);
void UpdateBeamUsingHistogramKernel(const dim3 &grid, const dim3 &block,
const cudaStream_t &st,
const DeviceParams &cst_dev_params,
const KernelParams &kernel_params,
bool use_aux_q);
void FinalizeProcessNonEmittingKernel(const dim3 &grid, const dim3 &block,
const cudaStream_t &st,
const DeviceParams &cst_dev_params,
const KernelParams &kernel_params);
void GetBestCostStep1Kernel(const dim3 &grid, const dim3 &block,
const cudaStream_t &st,
const DeviceParams &cst_dev_params,
const KernelParams &kernel_params, bool isfinal,
CostType fst_zero);
void GetBestCostStep2Kernel(const dim3 &grid, const dim3 &block,
const cudaStream_t &st,
const DeviceParams &cst_dev_params,
const KernelParams &kernel_params, bool isfinal,
CostType fst_zero);
void GetBestCostStep3Kernel(const dim3 &grid, const dim3 &block,
const cudaStream_t &st,
const DeviceParams &cst_dev_params,
const KernelParams &kernel_params);
typedef unsigned char BinId;
} // namespace kaldi
} // namespace cuda_decoder
#endif // KALDI_CUDA_DECODER_CUDA_DECODER_KERNELS_H_