Skip to content

Commit 134b1e9

Browse files
authored
[src] Add binary for fbank feature extraction on GPU (#3921)
.. called cudafeatbin/compute-fbank-online-batched-cuda Testing revealed a bug. If the output feature array is allocated with kStrideEqualNumCols, then output features will have zero- padding where they shouldn't. To fix this, we write Mel energies directly into the output feature array for fbank features. (If use_log is specified, this is applied during the MEL banks computation kernel). To run: cd cudafeatbin ./compute-fbank-online-batched-cuda --config=<path to your fbank.conf> \ --batch-size=50 scp:<path to your wav.scp> \ ark,scp:feats-batch.ark,feats-batch.scp To compare with CPU features: pushd ../featbin/;make;popd ../featbin/compute-fbank-feats --config=<path to your fbank.conf> \ scp:<path to your wav.scp> ark,scp:feats-cpu.ark,feats-cpu.scp ../featbin/compare-feats ark:feats-batch.ark ark:feats-cpu.ark You should see a line that says `Features are considered similar since 0.999998 >= 0.99`
1 parent cf2346a commit 134b1e9

File tree

3 files changed

+391
-11
lines changed

3 files changed

+391
-11
lines changed

src/cudafeat/feature-online-batched-spectral-cuda.cc

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -176,17 +176,16 @@ void CudaOnlineBatchedSpectralFeatures::ComputeFinalFeaturesBatched(
176176
cumfcc_opts_.use_power);
177177
CU_SAFE_CALL(cudaGetLastError());
178178

179-
// mel banks
180179
int num_bins = bin_size_;
181-
cuda_mel_banks_compute(lanes, num_lanes, max_chunk_frames_, num_bins,
180+
// mel banks plus optional dct transform
181+
if (cumfcc_opts_.use_dct) {
182+
// MFCC uses dct
183+
cuda_mel_banks_compute(lanes, num_lanes, max_chunk_frames_, num_bins,
182184
std::numeric_limits<float>::epsilon(), offsets_,
183185
sizes_, vecs_, power_spectrum_.Data(),
184186
power_spectrum_.Stride(), cu_mel_energies_.Data(),
185187
cu_mel_energies_.Stride(), cumfcc_opts_.use_log_fbank);
186-
CU_SAFE_CALL(cudaGetLastError());
187-
188-
// dct transform
189-
if (cumfcc_opts_.use_dct) {
188+
CU_SAFE_CALL(cudaGetLastError());
190189
if (cu_features->NumRows() > cu_mel_energies_.NumRows()) {
191190
CuSubMatrix<BaseFloat> cu_feats_sub(*cu_features, 0,
192191
cu_mel_energies_.NumRows(), 0,
@@ -202,12 +201,15 @@ void CudaOnlineBatchedSpectralFeatures::ComputeFinalFeaturesBatched(
202201
mfcc_opts.cepstral_lifter, mfcc_opts.use_energy, mfcc_opts.energy_floor,
203202
cu_signal_log_energy->Data(), cu_signal_log_energy->Stride(),
204203
cu_lifter_coeffs_.Data(), cu_features->Data(), cu_features->Stride());
205-
204+
CU_SAFE_CALL(cudaGetLastError());
206205
} else {
207-
cudaMemcpyAsync(cu_features->Data(), cu_mel_energies_.Data(),
208-
sizeof(BaseFloat) * max_chunk_frames_ * num_lanes *
209-
cu_features->Stride(),
210-
cudaMemcpyDeviceToDevice, cudaStreamPerThread);
206+
// fbank puts the result of mel_banks_compute directly into cu_features
207+
cuda_mel_banks_compute(lanes, num_lanes, max_chunk_frames_, num_bins,
208+
std::numeric_limits<float>::epsilon(), offsets_,
209+
sizes_, vecs_, power_spectrum_.Data(),
210+
power_spectrum_.Stride(), cu_features->Data(),
211+
cu_features->Stride(), cumfcc_opts_.use_log_fbank);
212+
CU_SAFE_CALL(cudaGetLastError());
211213
}
212214
CU_SAFE_CALL(cudaGetLastError());
213215
}

src/cudafeatbin/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ ifeq ($(CUDA), true)
1515
compute-fbank-feats-cuda \
1616
apply-batched-cmvn-online-cuda \
1717
compute-mfcc-online-batched-cuda \
18+
compute-fbank-online-batched-cuda \
1819
compute-online-feats-batched-cuda
1920
endif
2021

0 commit comments

Comments
 (0)