Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/cudafeat/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,16 @@ ifeq ($(CUDA), true)
TESTFILES =

ifeq ($(CUDA), true)
OBJFILES += feature-window-cuda.o feature-mfcc-cuda.o feature-online-cmvn-cuda.o
OBJFILES += feature-window-cuda.o feature-mfcc-cuda.o feature-online-cmvn-cuda.o \
online-ivector-feature-cuda-kernels.o online-ivector-feature-cuda.o \
online-cuda-feature-pipeline.o
endif

LIBNAME = kaldi-cudafeat

ADDLIBS = ../feat/kaldi-feat.a ../util/kaldi-util.a ../matrix/kaldi-matrix.a \
../base/kaldi-base.a ../cudamatrix/kaldi-cudamatrix.a \
../gmm/kaldi-gmm.a ../online2/kaldi-online2.a
../gmm/kaldi-gmm.a ../ivector/kaldi-ivector.a ../online2/kaldi-online2.a

LDFLAGS += $(CUDA_LDFLAGS)
LDLIBS += $(CUDA_LDLIBS)
Expand Down
3 changes: 3 additions & 0 deletions src/cudafeat/feature-mfcc-cuda.cu
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@
// 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.

#if HAVE_CUDA == 1
#include <nvToolsExt.h>
#include <cub/cub.cuh>
#endif

#include "cudafeat/feature-mfcc-cuda.h"
#include "cudamatrix/cu-rand.h"
Expand Down
2 changes: 2 additions & 0 deletions src/cudafeat/feature-window-cuda.cu
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#if HAVE_CUDA == 1
#include <nvToolsExt.h>
#endif
#include "cudafeat/feature-window-cuda.h"
#include "matrix/matrix-functions.h"

Expand Down
70 changes: 70 additions & 0 deletions src/cudafeat/online-cuda-feature-pipeline.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// cudafeat/online-cuda-feature-pipleine.cc

// Copyright 2013 Johns Hopkins University (author: Daniel Povey)

// See ../../COPYING for clarification regarding multiple authors
//
// 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
//
// THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
// WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
// MERCHANTABLITY OR NON-INFRINGEMENT.
// See the Apache 2 License for the specific language governing permissions and
// limitations under the License.

#include "cudafeat/online-cuda-feature-pipeline.h"

namespace kaldi {

OnlineCudaFeaturePipeline::OnlineCudaFeaturePipeline(
const OnlineNnet2FeaturePipelineConfig &config)
: info_(config), mfcc(NULL), ivector(NULL) {
if (info_.feature_type == "mfcc") {
mfcc = new CudaMfcc(info_.mfcc_opts);
}

if (info_.use_ivectors) {
OnlineIvectorExtractionConfig ivector_extraction_opts;
ReadConfigFromFile(config.ivector_extraction_config,
&ivector_extraction_opts);
info_.ivector_extractor_info.Init(ivector_extraction_opts);

// Only these ivector options are currently supported
ivector_extraction_opts.use_most_recent_ivector = true;
ivector_extraction_opts.greedy_ivector_extractor = true;

ivector = new IvectorExtractorFastCuda(ivector_extraction_opts);
}
}

OnlineCudaFeaturePipeline::~OnlineCudaFeaturePipeline() {
if (mfcc != NULL) delete mfcc;
if (ivector != NULL) delete ivector;
}

void OnlineCudaFeaturePipeline::ComputeFeatures(
const CuVectorBase<BaseFloat> &cu_wave, BaseFloat sample_freq,
CuMatrix<BaseFloat> *input_features,
CuVector<BaseFloat> *ivector_features) {
if (info_.feature_type == "mfcc") {
// MFCC
float vtln_warp = 1.0;
mfcc->ComputeFeatures(cu_wave, sample_freq, vtln_warp, input_features);
} else {
KALDI_ASSERT(false);
}

// Ivector
if (info_.use_ivectors && ivector_features != NULL) {
ivector->GetIvector(*input_features, ivector_features);
} else {
KALDI_ASSERT(false);
}
}

} // namespace kaldi
55 changes: 55 additions & 0 deletions src/cudafeat/online-cuda-feature-pipeline.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// cudafeat/online-cuda-feature-pipeline.h

// Copyright 2013-2014 Johns Hopkins University (author: Daniel Povey)

// See ../../COPYING for clarification regarding multiple authors
//
// 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
//
// THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
// WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
// MERCHANTABLITY OR NON-INFRINGEMENT.
// See the Apache 2 License for the specific language governing permissions and
// limitations under the License.

#ifndef KALDI_CUDAFEAT_ONLINE_CUDA_FEATURE_PIPELINE_H_
#define KALDI_CUDAFEAT_ONLINE_CUDA_FEATURE_PIPELINE_H_

#include <deque>
#include <string>
#include <vector>

#include "base/kaldi-error.h"
#include "cudafeat/feature-mfcc-cuda.h"
#include "cudafeat/online-ivector-feature-cuda.h"
#include "matrix/matrix-lib.h"
#include "online2/online-nnet2-feature-pipeline.h"
#include "util/common-utils.h"

namespace kaldi {

class OnlineCudaFeaturePipeline {
public:
explicit OnlineCudaFeaturePipeline(
const OnlineNnet2FeaturePipelineConfig &config);

void ComputeFeatures(const CuVectorBase<BaseFloat> &cu_wave,
BaseFloat sample_freq,
CuMatrix<BaseFloat> *input_features,
CuVector<BaseFloat> *ivector_features);

~OnlineCudaFeaturePipeline();

private:
OnlineNnet2FeaturePipelineInfo info_;
CudaMfcc *mfcc;
IvectorExtractorFastCuda *ivector;
};
} // namespace kaldi

#endif // KALDI_CUDAFEAT_ONLINE_CUDA_FEATURE_EXTRACTOR_H_
Loading